diff --git a/CodingStyle.cc b/CodingStyle.cc new file mode 100644 index 0000000000000000000000000000000000000000..283e6bd7d1f408108222682b5373ae92616a73ac --- /dev/null +++ b/CodingStyle.cc @@ -0,0 +1,96 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +// The above copyright block should be at the top of every file. + +/// @file +/// @brief This is an example class c++ file which is used to describe the QGroundControl +/// coding style. In general almost everything in here has some coding style meaning. +/// For example, note how this doxygen block uses the /// variant as the preferred style +/// of doxygen marker. Not all style choices are explained. +/// +/// @author Don Gagne + +#include "CodingStyle.h" +#include "QGCApplication.h" + +#include +#include + +// Note how the Qt headers and the QGroundControl headers above are kept seperate + +Q_LOGGING_CATEGORY(CodingStyleLog, "CodingStyleLog") + +CodingStyle::CodingStyle(QObject* parent) : + QObject(parent), + _protectedVariable(1), + _privateVariable1(2), + _privateVariable2(3) +{ + +} + +/// Document non-obvious private methods in the code file. +void CodingStyle::_privateMethod(void) +{ + // Always include braces even for single line if/for/... + if (uas != _uasId) { + return; + } + + // Note the brace placement + if (_lastSeenComponent == -1) { + _lastSeenComponent = component; + } else { + Q_ASSERT(component == _lastSeenComponent); // Asserts are your friend + } +} + +void CodingStyle::_privateMethod2(void) +{ + Fact* fact = qobject_cast(sender()); + Q_ASSERT(fact); + + QVariant typedValue; + switch (fact->type()) { + case FactMetaData::valueTypeInt8: + case FactMetaData::valueTypeInt16: + case FactMetaData::valueTypeInt32: + typedValue.setValue(QVariant(value.toInt())); + break; + + case FactMetaData::valueTypeUint8: + case FactMetaData::valueTypeUint16: + case FactMetaData::valueTypeUint32: + typedValue.setValue(value.toUInt()); + break; + + case FactMetaData::valueTypeFloat: + typedValue.setValue(value.toFloat()); + break; + + case FactMetaData::valueTypeDouble: + typedValue.setValue(value.toDouble()); + break; + } +} diff --git a/CodingStyle.h b/CodingStyle.h new file mode 100644 index 0000000000000000000000000000000000000000..1d27864902ca35cff66407df59ba17cafed91370 --- /dev/null +++ b/CodingStyle.h @@ -0,0 +1,93 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +// The above copyright block should be at the top of every file. + +/// @file +/// @brief This is an example class header file which is used to describe the QGroundControl +/// coding style. In general almost everything in here has some coding style meaning. +/// For example, note how this doxygen block uses the /// variant as the preferred style +/// of doxygen marker. Not all style choices are explained. +/// +/// @author Don Gagne + +#ifndef CodingStyle_h +#define CodingStyle_h + +#include +#include +#include +#include + +#include "Fact.h" +#include "UASInterface.h" + +// Note how the Qt headers and the QGroundControl headers above are kept seperate + +// If you are going to use a logging category for a class it should have the same name as the class +// with a suffix of Log. +Q_DECLARE_LOGGING_CATEGORY(CodingStyleLog) + +/// Here is the class documentation. Class names are PascalCase. + +class CodingStyle : public QObject +{ + Q_OBJECT + +public: + CodingStyle(QObject* parent = NULL); + ~CodingStyle(); + + /// Document public methods which are non-obvious in the header file + bool publicMethod1(void); + +signals: + /// Document signals which are non-obvious in the header file + void qtSignal(void); + +public slots: + // Public slots should only be used if the slot is connected to from another class. Majority of slots + // should be private. + void publicSlot(void); + + // Don't use protected methods or variables unless the class is specifically meant to be used as a base class. +protected: + int _protectedVariable; ///< variable names are camelCase + + void _protectedMethod(void); ///< method names are camelCase + +private slots: + void _privateSlot(void); + +private: + // Private methods and variable names begin with an "_". Documentation for + // non-obvious private methods goes in the code file, not the header. + void _privateMethod(void); + + /// Document non-obvious variables in the header file. Long descriptions go here. + int _privateVariable1; + + int _privateVariable2; ///< Short descriptions go here +}; + +#endif \ No newline at end of file