(Created page with "The current KDevelop code base is very inconsistent when it comes to the coding style. So please adhere to the file's coding style you are working on / patching. For new files /...") |
|||
| (2 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
The current KDevelop code base is very inconsistent when it comes to the coding style. So please adhere to the file's coding style you are working on / patching. | The current KDevelop code base is very inconsistent when it comes to the coding style. So please adhere to the file's coding style you are working on / patching. | ||
| − | For new files / projects / plugins, please use the [[Policies/Kdelibs_Coding_Style]] guidelines. | + | For new files / projects / plugins, please use the [[Policies/Kdelibs_Coding_Style]] guidelines. Here are a few special additions: |
| + | |||
| + | == QObject and Access Modifiers == | ||
| + | |||
| + | <syntaxhighlight lang="cpp-qt"> | ||
| + | // wrong | ||
| + | class Foo : public QObject { | ||
| + | Q_OBJECT | ||
| + | public: | ||
| + | Foo(); | ||
| + | private: | ||
| + | int bla; | ||
| + | }; | ||
| + | |||
| + | // correct foo.h | ||
| + | class Foo: public QObject | ||
| + | { | ||
| + | Q_OBJECT | ||
| + | public: | ||
| + | Foo(); | ||
| + | private: | ||
| + | int m_bla; | ||
| + | }; | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == Class Initialization == | ||
| + | |||
| + | <syntaxhighlight lang="cpp-qt"> | ||
| + | // wrong foo.h | ||
| + | class Foo : public Bar { | ||
| + | public: | ||
| + | Foo(int i, int j) : Bar(i), bla(j) { /* do stuff */ } | ||
| + | private: | ||
| + | int bla; | ||
| + | }; | ||
| + | |||
| + | // correct foo.h | ||
| + | class Foo: public Bar | ||
| + | { | ||
| + | public: | ||
| + | Foo(int i, int j); | ||
| + | private: | ||
| + | int m_bla; | ||
| + | }; | ||
| + | // foo.cpp | ||
| + | Foo::Foo(int i, int j) | ||
| + | : Bar(i) | ||
| + | , m_bla(j) | ||
| + | { | ||
| + | // do stuff | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == Using Namespaces == | ||
| + | |||
| + | Never add a "using namespace ..." to a header. Do use that though in every .cpp file , esp. for the KDevelop namespace. Public API should always be in the KDevelop namespace. | ||
The current KDevelop code base is very inconsistent when it comes to the coding style. So please adhere to the file's coding style you are working on / patching.
For new files / projects / plugins, please use the Policies/Kdelibs_Coding_Style guidelines. Here are a few special additions:
// wrong class Foo : public QObject { Q_OBJECT public: Foo(); private: int bla; }; // correct foo.h class Foo: public QObject { Q_OBJECT public: Foo(); private: int m_bla; };
// wrong foo.h class Foo : public Bar { public: Foo(int i, int j) : Bar(i), bla(j) { /* do stuff */ } private: int bla; }; // correct foo.h class Foo: public Bar { public: Foo(int i, int j); private: int m_bla; }; // foo.cpp Foo::Foo(int i, int j) : Bar(i) , m_bla(j) { // do stuff }
Never add a "using namespace ..." to a header. Do use that though in every .cpp file , esp. for the KDevelop namespace. Public API should always be in the KDevelop namespace.