dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobjecttreemodel.h
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  *
30  * Additional note on redistribution: The copyright and license notices above
31  * must be maintained in each individual source file that is a derivative work
32  * of this source file; otherwise redistribution is prohibited.
33  */
34 
35 #ifndef UAVOBJECTTREEMODEL_H
36 #define UAVOBJECTTREEMODEL_H
37 
38 #include "treeitem.h"
39 #include <QAbstractItemModel>
40 #include <QtCore/QMap>
41 #include <QtCore/QList>
42 #include <QColor>
43 #include <QFont>
44 
45 class TopTreeItem;
46 class ObjectTreeItem;
47 class DataObjectTreeItem;
48 class UAVObject;
49 class UAVDataObject;
50 class UAVMetaObject;
51 class UAVObjectField;
52 class UAVObjectManager;
53 class QSignalMapper;
54 class QTimer;
55 
56 class UAVObjectTreeModel : public QAbstractItemModel
57 {
58  Q_OBJECT
59 public:
60  explicit UAVObjectTreeModel(QObject *parent = nullptr, bool useScientificNotation = false);
62 
63  QVariant data(const QModelIndex &index, int role) const;
64  bool setData(const QModelIndex &index, const QVariant &value, int role);
65  Qt::ItemFlags flags(const QModelIndex &index) const;
66  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
67  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
68  QModelIndex parent(const QModelIndex &index) const;
69  int rowCount(const QModelIndex &parent = QModelIndex()) const;
70  int columnCount(const QModelIndex &parent = QModelIndex()) const;
71 
72  TopTreeItem *getSettingsTree() { return m_settingsTree; }
73  TopTreeItem *getNonSettingsTree() { return m_nonSettingsTree; }
74 
75  void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
76  void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
77  void setNotPresentOnHwColor(QColor color) { m_notPresentOnHwColor = color; }
78  void setOnlyHighlightChangedValues(bool highlight) { m_onlyHighlightChangedValues = highlight; }
79 
82 
83  QModelIndex getIndex(int indexRow, int indexCol, TopTreeItem *topTreeItem)
84  {
85  return createIndex(indexRow, indexCol, topTreeItem);
86  }
87 
88 signals:
90 public slots:
91  void newObject(UAVObject *obj);
92  void initializeModel(bool useScientificFloatNotation = true);
93  void instanceRemove(UAVObject *);
94 private slots:
95  void highlightUpdatedObject(UAVObject *obj);
96  void updateHighlight(TreeItem *);
97  void presentOnHardwareChangedCB(UAVDataObject *);
98 
99 private:
100  void setupModelData(UAVObjectManager *objManager,
101  bool useScientificFloatNotation = true);
102  QModelIndex index(TreeItem *item);
103  void addDataObject(UAVDataObject *obj);
104  MetaObjectTreeItem *addMetaObject(UAVMetaObject *obj, TreeItem *parent);
105  void addArrayField(UAVObjectField *field, TreeItem *parent);
106  void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
107  void addInstance(UAVObject *obj, TreeItem *parent);
108 
109  QString updateMode(quint8 updateMode);
110  ObjectTreeItem *findObjectTreeItem(UAVObject *obj);
111  DataObjectTreeItem *findDataObjectTreeItem(UAVDataObject *obj);
112  MetaObjectTreeItem *findMetaObjectTreeItem(UAVMetaObject *obj);
113 
114  TreeItem *m_rootItem;
115  TopTreeItem *m_settingsTree;
116  TopTreeItem *m_nonSettingsTree;
117  QColor m_recentlyUpdatedColor;
118  QColor m_manuallyChangedColor;
119  QColor m_updatedOnlyColor;
120  QColor m_isPresentOnHwColor;
121  QColor m_notPresentOnHwColor;
122  QFont m_nonDefaultValueFont;
123  QFont m_defaultValueFont;
124  bool m_onlyHighlightChangedValues;
125  bool m_useScientificFloatNotation;
126  bool m_hideNotPresent;
127  UAVObjectManager *objManager;
128  // Highlight manager to handle highlighting of tree items.
129  HighLightManager *m_highlightManager;
130  bool isInitialized;
131 };
132 
133 #endif // UAVOBJECTTREEMODEL_H
UAVObjectTreeModel(QObject *parent=nullptr, bool useScientificNotation=false)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void setRecentlyUpdatedColor(QColor color)
int columnCount(const QModelIndex &parent=QModelIndex()) const
void newObject(UAVObject *obj)
QVariant data(const QModelIndex &index, int role) const
QModelIndex parent(const QModelIndex &index) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
QList< QModelIndex > getMetaDataIndexes()
QList< QModelIndex > getDataObjectIndexes()
QModelIndex getIndex(int indexRow, int indexCol, TopTreeItem *topTreeItem)
void setOnlyHighlightChangedValues(bool highlight)
void instanceRemove(UAVObject *)
Qt::ItemFlags flags(const QModelIndex &index) const
bool setData(const QModelIndex &index, const QVariant &value, int role)
void setNotPresentOnHwColor(QColor color)
TopTreeItem * getSettingsTree()
Definition: icore.h:39
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void initializeModel(bool useScientificFloatNotation=true)
void setManuallyChangedColor(QColor color)
void presentOnHardwareChanged()
TopTreeItem * getNonSettingsTree()