Standards

From Avogadro - Free cross-platform molecule editor
Revision as of 13:42, 27 January 2011 by Annulen (talk | contribs) (Naming: Updated external link)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

When in doubt about standards, consider the policies which KDE has set (see #Links).

Formatting

Two spaces, no tabs.

Naming

All classes used in avogadro or libavogadro should exist in the Avogadro namespace.

Classes should start with a capital letter.

Variables should start with a lowercase with each successive word capitalized.

QString *nameString;
QTextEdit *nameText;
QTreeView *moleculeTree;

Acronyms are also lowercased.

QString *remoteUrlString;

For setter/getter functions, prefix 'set' for the setter and include no prefix for the getter. (consistent with QT)

void setValue(int i) / int value()
void setHidden(bool h) / bool isHidden()

For more information see: Designing Qt-Style C++ APIs

Documentation

See Documentation

Example

namespace Avogadro {
  /**
   * @class Test
   * @brief Class used for nothing.
   * @author Author Guy
   *
   * The Test class is not used by avogadro.  It is provided as a demonstration
   * of proper formatting and comment procedure.
   */
  class TestPrivate
  class A_EXPORT Test : public QObject
  {
    Q_OBJECT

    public:
      /**
       * Constructor
       *
       * @param parent the object parent
       */
      Test(QObject *parent=0);

    private:
      TestPrivate * const d;

    private Q_SLOTS:
      /**
       * Function that does something used internally by the class.
       * 
       * @sa testSignal
       */
      void testSlot();

    Q_SIGNALS:
      /**
       * Emitted when something happens
       *
       * @param parameter signal parameter
       */
      void testSignal(void *parameter);
  };
}

Links

KDE Library Code Policy (include naming conventions)