Coding standards

Z Kadu

.h structure

  • Header
  • Includes
  • Forwarded class declarations
  • Macros
  • Class definition

.cpp structure

  • Header
  • Function definitions
  • Initialization of class static members
  • Implementation of class methods (in order as in .h file)

Header

Every .cpp and .h files should have this header included:

/*
 * %kadu copyright begin%
 * %kadu copyright end%
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

Include order

Every file should include only *really needed* header files. When it is possible - use class forwarding instead of header inclusion. Headers should be ordered in the following way:

  • Qt headers
  • (blank line)
  • system headers
  • (blank line)
  • Kadu core headers
  • (blank line)
  • Kadu module headers

Qt headers are prefixed with Qt module: #include <QtGui/QWidget>

Each group of headers should be ordered by alphabetical order of directories, subdirectories and file names, example:

#include "/x/b/c/d/e.h"
#include "/x/b/c/d/z.h"
#include "/x/z/x.h"
#include "/x/a.h"
#include "aaaa.h"

Forwarded class declarations

Forward class definitions are orderered like includes:

  • Qt forward class declarations
  • (blank line)
  • Kadu forward class definitions

Each group is sorted alphabetically.

Class definitions

class NewClass : public ParentClass
{
  Q_OBJECT

  [private part]

private slots:
  [private slots]

protected:
  [protected part]

protected slots:
  [protected slots]

public:
  [public par]

public slots:
  [public slots]

signals:
  [signals]

}

Constructor - initializators

When defining constructors, use the following syntax for initializators:

ClassName::ClassName([parameters]) :
        ParentClass([parameters]), Field([value]), Field([value]),
        Field([value]), Field([Value])
{
}

Use two tabs for indentation.


Osobiste