-
Notifications
You must be signed in to change notification settings - Fork 948
Coding Style
The coding style of the project is based on the coding style of Qt. An overview of this coding style can be found here:
Important: Note that like the KDE Frameworks Coding Style we have one exception on top of the Qt one: we use curly braces even when the body of a conditional statement contains only one line.
Member variables should be prefixed with a underscore. For example write _myClassVariable instead of myClassVariable.
When possible use data structures from Qt. For example use QVector instead of std::vector.
When possible use algorithms from the STL or Qt. For example use std::copy_if instead of coding it by hand.
QSharedPointer should be used instead of std::shared_ptr. However, it is okay to use a STL smart pointer if there is no equivalent in Qt, like std::unique_ptr.
Names of unit tests should follow the scheme proposed by Roy Osherove in his book The Art of Unit Testing. The general scheme is:
void testUnitOfWork_stateUnderTest_expectedBehaviour()
It is explained here.
The following shows how a class that inherits from QObject should be declared:
class Foo : public QObject
{
Q_OBJECT
Q_PROPERTY(....)
public:
enum Bar {
};
Q_ENUM(Bar)
static void staticMethods();
explicit Foo(QObject *parent = nullptr);
bool publicMethod() const;
signals:
void mySignal();
protected slots:
void protectedSlot();
protected:
void protectedMethod();
private slots:
void privateSlot();
private:
void privateMethod();
bool _member;
};