QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ParameterEditorController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QLoggingCategory>
4#include <QtCore/QObject>
5#include <QtQmlIntegration/QtQmlIntegration>
6
9#include "FactMetaData.h"
10
11Q_DECLARE_LOGGING_CATEGORY(ParameterEditorControllerLog)
12
14
15class ParameterTableModel : public QAbstractTableModel
16{
17 Q_OBJECT
18
19public:
20 explicit ParameterTableModel(QObject* parent = nullptr);
21 ~ParameterTableModel() override;
22
23 typedef QVector<QVariant> ColumnData;
24
25 enum {
26 FactRole = Qt::UserRole + 1
27 };
28
29 enum {
33 };
34
35 Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
36
37 void append (Fact* fact);
38 void insert (int row, Fact* fact);
39 void clear ();
40 void beginReset ();
41 void endReset ();
42 Fact* factAt(int row) const;
43
44 // Overrides from QAbstractTableModel
45 int rowCount (const QModelIndex & parent = QModelIndex()) const override;
46 int columnCount (const QModelIndex &parent = QModelIndex()) const override;
47 QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const override;
48 QHash<int, QByteArray> roleNames(void) const override;
49
50 signals:
51 void rowCountChanged(int count);
52
53private:
54 bool _isResetting() const { return _resetNestingCount > 0; }
55
56 int _tableViewColCount = 3;
57 QList<ColumnData> _tableData;
58 uint _resetNestingCount = 0;
59};
60
61class ParameterEditorGroup : public QObject
62{
63 Q_OBJECT
64
65public:
66 ParameterEditorGroup(QObject* parent);
67
68 Q_PROPERTY(QString name MEMBER name CONSTANT)
69 Q_PROPERTY(QAbstractTableModel* facts READ getFacts CONSTANT)
70
71 QAbstractTableModel* getFacts(void) { return &facts; }
72
74 QString name;
76};
77
78class ParameterEditorCategory : public QObject
79{
80 Q_OBJECT
81
82public:
83 ParameterEditorCategory(QObject* parent) : QObject(parent) { }
84
85 Q_PROPERTY(QString name MEMBER name CONSTANT)
86 Q_PROPERTY(QmlObjectListModel* groups READ getGroups CONSTANT)
87
88 QmlObjectListModel* getGroups(void) { return &groups; }
89
90 QString name;
92 QMap<QString, ParameterEditorGroup*> mapGroupName2Group;
93};
94
95class ParameterEditorDiff : public QObject
96{
97 Q_OBJECT
98
99public:
100 ParameterEditorDiff(QObject* parent) : QObject(parent) { }
101
102 Q_PROPERTY(int componentId MEMBER componentId CONSTANT)
103 Q_PROPERTY(QString name MEMBER name CONSTANT)
104 Q_PROPERTY(QString fileValue MEMBER fileValue CONSTANT)
105 Q_PROPERTY(QString vehicleValue MEMBER vehicleValue CONSTANT)
106 Q_PROPERTY(bool noVehicleValue MEMBER noVehicleValue CONSTANT)
107 Q_PROPERTY(QString units MEMBER units CONSTANT)
108 Q_PROPERTY(bool load MEMBER load NOTIFY loadChanged)
109
110 int componentId;
111 QString name;
113 QString fileValue;
114 QVariant fileValueVar;
116 bool noVehicleValue = false;
117 QString units;
118 bool load = true;
119
120signals:
121 void loadChanged(bool load);
122};
123
125{
126 Q_OBJECT
127 QML_ELEMENT
128 Q_PROPERTY(QString searchText MEMBER _searchText NOTIFY searchTextChanged)
129 Q_PROPERTY(QmlObjectListModel* categories READ categories CONSTANT)
130 Q_PROPERTY(QObject* currentCategory READ currentCategory WRITE setCurrentCategory NOTIFY currentCategoryChanged)
131 Q_PROPERTY(QObject* currentGroup READ currentGroup WRITE setCurrentGroup NOTIFY currentGroupChanged)
132 Q_PROPERTY(QAbstractTableModel* parameters MEMBER _parameters NOTIFY parametersChanged)
133 Q_PROPERTY(bool showModifiedOnly MEMBER _showModifiedOnly NOTIFY showModifiedOnlyChanged)
134
135 // These property are related to the diff associated with a load from file
136 Q_PROPERTY(bool diffOtherVehicle MEMBER _diffOtherVehicle NOTIFY diffOtherVehicleChanged)
137 Q_PROPERTY(bool diffMultipleComponents MEMBER _diffMultipleComponents NOTIFY diffMultipleComponentsChanged)
138 Q_PROPERTY(QmlObjectListModel* diffList READ diffList CONSTANT)
139
140public:
141 explicit ParameterEditorController(QObject *parent = nullptr);
143
144 Q_INVOKABLE void saveToFile (const QString& filename);
145 Q_INVOKABLE bool buildDiffFromFile (const QString& filename);
146 Q_INVOKABLE void clearDiff (void);
147 Q_INVOKABLE void sendDiff (void);
148 Q_INVOKABLE void refresh (void);
149 Q_INVOKABLE void resetAllToDefaults (void);
150 Q_INVOKABLE void resetAllToVehicleConfiguration (void);
151
152 QObject* currentCategory (void) { return _currentCategory; }
153 QObject* currentGroup (void) { return _currentGroup; }
154 QmlObjectListModel* categories (void) { return &_categories; }
155 QmlObjectListModel* diffList (void) { return &_diffList; }
156 void setCurrentCategory (QObject* currentCategory);
157 void setCurrentGroup (QObject* currentGroup);
158
159signals:
160 void searchTextChanged (QString searchText);
164 void diffOtherVehicleChanged (bool diffOtherVehicle);
165 void diffMultipleComponentsChanged (bool diffMultipleComponents);
166 void parametersChanged (void);
167
168private slots:
169 void _currentCategoryChanged(void);
170 void _currentGroupChanged (void);
171 void _searchTextChanged (void);
172 void _buildLists (void);
173 void _buildListsForComponent(int compId);
174 void _factAdded (int compId, Fact* fact);
175
176private:
177 bool _shouldShow(Fact *fact) const;
178 void _performSearch();
179
180private:
181 ParameterManager* _parameterMgr = nullptr;
182 QString _searchText;
183 QTimer _searchTimer;
184 ParameterEditorCategory* _currentCategory = nullptr;
185 ParameterEditorGroup* _currentGroup = nullptr;
186 bool _showModifiedOnly = false;
187 bool _diffOtherVehicle = false;
188 bool _diffMultipleComponents = false;
189
190 QmlObjectListModel _categories;
191 QmlObjectListModel _diffList;
192 ParameterTableModel _searchParameters;
193 QAbstractTableModel* _parameters = nullptr;
194 QMap<QString, ParameterEditorCategory*> _mapCategoryName2Category;
195};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
Used for handling missing Facts from C++ code.
A Fact is used to hold a single value within the system.
Definition Fact.h:19
QMap< QString, ParameterEditorGroup * > mapGroupName2Group
QString name MEMBER name CONSTANT(QmlObjectListModel *groups READ getGroups CONSTANT) QmlObjectListModel *getGroups(void)
void diffMultipleComponentsChanged(bool diffMultipleComponents)
void searchTextChanged(QString searchText)
void currentCategoryChanged(void)
void diffOtherVehicleChanged(bool diffOtherVehicle)
void showModifiedOnlyChanged(void)
void loadChanged(bool load)
FactMetaData::ValueType_t valueType
int componentId MEMBER componentId CONSTANT(QString name MEMBER name CONSTANT) 1(QString fileValue MEMBER fileValue CONSTANT) 1(QString vehicleValue MEMBER vehicleValue CONSTANT) 1(bool noVehicleValue MEMBER noVehicleValue CONSTANT) 1(QString units MEMBER units CONSTANT) 1(bool load MEMBER load NOTIFY loadChanged) int componentId
QString name MEMBER name CONSTANT(QAbstractTableModel *facts READ getFacts CONSTANT) QAbstractTableModel *getFacts(void)
QVector< QVariant > ColumnData
void insert(int row, Fact *fact)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int rowCount READ rowCount NOTIFY rowCountChanged void append(Fact *fact)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QHash< int, QByteArray > roleNames(void) const override
void rowCountChanged(int count)
void endReset()
Supports nesting - only outermost call has effect.
void beginReset()
Supports nesting - only outermost call has effect.