Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full customization of Qt creator coding style?

Is there a way to fully customize the preferred coding style in QT creator?

Here's what I mean by example (I'll directly use just a part from the example code from Qt creator's settings):

class Complex
{
public:
    Complex(double re, double im)
        : _re(re), _im(im)
    {}
    double modulus() const
    {
        return sqrt(_re * _re + _im * _im);
    }
private:
    double _re;
    double _im;
};

I want this to become:

class complex // <- lower latter
{
public:
    complex( double re, double im ) // <- spaces after/before ()
    : // <- new line
         _re( re ), // <- spaces after/before ()
        _im( im ) // <- new line and spaces after/before ()
    {
    } // <- new line
    // <- new line
    double modulus() const
    {
        return sqrt( _re * _re + _im * _im ); // <- spaces after/before ()
    }
// <- new line
private:
    double _re;
    double _im;
};

And so on, you get the idea.

Is there some plugin for this or is there some "manual" way to achieve this? A lot of other editors have this option (for example, eclipse and slickedit)


Edit: Argh, I just saw this coding style and these coding conventions. Does this mean, I can't use my own coding style even for code, that just uses QT?

Also, I know about Tools -> Options -> C++ -> Code Style -> copy and then edit, but it's very limited. For example, I can't modify any of the things, noted as c++ comments in the example above.

like image 606
Kiril Kirov Avatar asked Apr 03 '14 19:04

Kiril Kirov


1 Answers

Yes, Beautifier plugin can do that. It is integrated in QtCreator 3.*.*

To enable it go to "Help -> About plugins..." and there check "Beautifier" box in "C++" group.

It uses external tools and can use only these three: Clang-format (part of llvm/tools), Uncrustify and Artistic Style, so you have to install at least one of them.

After install you may either select a popular style (e.g. K&R, Google, GNU) or provide your own configuration file. For convenience' sake you may use UniversalIndentGUI.

You may also be interested in some style choices.

like image 80
zorgit Avatar answered Oct 05 '22 08:10

zorgit