dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobjectfield.h
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 #ifndef UAVOBJECTFIELD_H
29 #define UAVOBJECTFIELD_H
30 
32 #include "uavobjects/uavobject.h"
33 #include <QStringList>
34 #include <QVariant>
35 #include <QList>
36 #include <QMap>
37 
38 class UAVObject;
39 
40 class UAVOBJECTS_EXPORT UAVObjectField : public QObject
41 {
42  Q_OBJECT
43 
44 public:
45  enum FieldType {
46  INT8 = 0,
55  STRING
56  };
57  enum LimitType { EQUAL, NOT_EQUAL, BETWEEN, BIGGER, SMALLER };
58  enum DisplayType { DEC, HEX, BIN, OCT };
59 
60  struct LimitStruct
61  {
64  int board;
65  };
66 
67  UAVObjectField(const QString &name, const QString &units, FieldType type, int numElements,
68  const QStringList &options, const QList<int> &indices,
69  const QString &limits = QString(), const QString &description = QString(),
70  const QList<QVariant> defaultValues = QList<QVariant>(),
71  const DisplayType display = DEC);
72  UAVObjectField(const QString &name, const QString &units, FieldType type,
73  const QStringList &elementNames, const QStringList &options,
74  const QList<int> &indices, const QString &limits = QString(),
75  const QString &description = QString(),
76  const QList<QVariant> defaultValues = QList<QVariant>(),
77  const DisplayType display = DEC);
78  void initialize(quint8 *data, quint32 dataOffset, UAVObject *obj);
79  UAVObject *getObject() const;
80  FieldType getType() const;
81  QString getTypeAsString() const;
82  QString getName() const;
83  QString getUnits() const;
84  int getNumElements() const;
85  QStringList getElementNames() const;
86  QString getElementName(int index = 0) const;
87  int getElementIndex(const QString &name) const;
88  QStringList getOptions() const;
94  bool hasOption(const QString &option);
95  qint32 pack(quint8 *dataOut);
96  qint32 unpack(const quint8 *dataIn);
97  QVariant getValue(int index = 0) const;
98  bool checkValue(const QVariant &data, int index = 0) const;
99  void setValue(const QVariant &data, int index = 0);
100  double getDouble(int index = 0) const;
101  void setDouble(double value, int index = 0);
102  size_t getNumBytes() const;
103  bool isNumeric() const;
104  bool isText() const;
105  QString toString() const;
106  QString getDescription() const;
112  QVariant getDefaultValue(int index = 0) const;
118  bool isDefaultValue(int index = 0);
123  int getDisplayIntegerBase() const;
128  QString getDisplayPrefix() const;
129 
130  bool isWithinLimits(QVariant var, int index, int board = 0) const;
131  QVariant getMaxLimit(int index, int board = 0) const;
132  QVariant getMinLimit(int index, int board = 0) const;
133 signals:
134  void fieldUpdated(UAVObjectField *field);
135 
136 protected:
137  QString name;
138  QString units;
140  QStringList elementNames;
142  std::map<int, int> enumToIndex;
143  QStringList options;
145  size_t elementSize;
146  size_t offset;
147  quint8 *data;
149  QMap<int, QList<LimitStruct>> elementLimits;
150  QString description;
153 
154  void clear();
155  void constructorInitialize(const QString &name, const QString &units, FieldType type,
156  const QStringList &elementNames, const QStringList &options,
157  const QList<int> &indices, const QString &limits,
158  const QString &description, const QList<QVariant> defaultValues,
159  const DisplayType display);
160  void limitsInitialize(const QString &limits);
161 };
162 
163 #endif // UAVOBJECTFIELD_H
164 
DisplayType display
UAVObject * obj
QMap< int, QList< LimitStruct > > elementLimits
DataFields data
QList< QVariant > defaultValues
QList< QVariant > values
numElements
QList< int > indices
QStringList options
QStringList elementNames
std::map< int, int > enumToIndex