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/QObject>
4#include <QtCore/QSet>
5#include <QtQmlIntegration/QtQmlIntegration>
6
9#include "FactMetaData.h"
10
12
13class ParameterTableModel : public QAbstractTableModel
14{
15 Q_OBJECT
16
17public:
18 explicit ParameterTableModel(QObject* parent = nullptr);
19 ~ParameterTableModel() override;
20
21 typedef QVector<QVariant> ColumnData;
22
23 enum {
24 FactRole = Qt::UserRole + 1
25 };
26
27 enum {
32 };
33
34 Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
35
36 void append (Fact* fact);
37 void insert (int row, Fact* fact);
38 void clear ();
39 void beginReset ();
40 void endReset ();
41 Fact* factAt(int row) const;
42
43 // Overrides from QAbstractTableModel
44 int rowCount (const QModelIndex & parent = QModelIndex()) const override;
45 int columnCount (const QModelIndex &parent = QModelIndex()) const override;
46 QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const override;
47 QVariant headerData (int section, Qt::Orientation orientation, 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 = 4;
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
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(bool cannotSend MEMBER cannotSend CONSTANT)
108 Q_PROPERTY(QString units MEMBER units CONSTANT)
109 Q_PROPERTY(bool load MEMBER load NOTIFY loadChanged)
110
112 QString name;
114 QString fileValue;
115 QVariant fileValueVar;
117 bool noVehicleValue = false;
118 bool cannotSend = false;
119 QString units;
120 bool load = true;
121
122signals:
123 void loadChanged(bool load);
124};
125
127{
128 Q_OBJECT
129 QML_ELEMENT
130 Q_PROPERTY(QString searchText MEMBER _searchText NOTIFY searchTextChanged)
131 Q_PROPERTY(QmlObjectListModel* categories READ categories CONSTANT)
132 Q_PROPERTY(QObject* currentCategory READ currentCategory WRITE setCurrentCategory NOTIFY currentCategoryChanged)
133 Q_PROPERTY(QObject* currentGroup READ currentGroup WRITE setCurrentGroup NOTIFY currentGroupChanged)
134 Q_PROPERTY(QAbstractTableModel* parameters MEMBER _parameters NOTIFY parametersChanged)
135 Q_PROPERTY(bool showModifiedOnly MEMBER _showModifiedOnly NOTIFY showModifiedOnlyChanged)
136 Q_PROPERTY(bool showFavoritesOnly MEMBER _showFavoritesOnly NOTIFY showFavoritesOnlyChanged)
137 Q_PROPERTY(bool hideReadOnly MEMBER _hideReadOnly NOTIFY hideReadOnlyChanged)
138 Q_PROPERTY(QStringList favoriteParameterNames READ favoriteParameterNames NOTIFY favoritesChanged)
139
140 // These property are related to the diff associated with a load from file
141 Q_PROPERTY(bool diffOtherVehicle READ diffOtherVehicle NOTIFY diffOtherVehicleChanged)
142 Q_PROPERTY(bool diffMultipleComponents READ diffMultipleComponents NOTIFY diffMultipleComponentsChanged)
143 Q_PROPERTY(QmlObjectListModel* diffList READ diffList CONSTANT)
144 Q_PROPERTY(int diffParsedCount READ diffParsedCount NOTIFY diffParsedCountChanged)
145 Q_PROPERTY(int diffUnchangedCount READ diffUnchangedCount NOTIFY diffUnchangedCountChanged)
146 Q_PROPERTY(int diffReadOnlyCount READ diffReadOnlyCount NOTIFY diffReadOnlyCountChanged)
147 Q_PROPERTY(int diffNoVehicleCount READ diffNoVehicleCount NOTIFY diffNoVehicleCountChanged)
148 Q_PROPERTY(int diffSendableCount READ diffSendableCount NOTIFY diffSendableCountChanged)
149 Q_PROPERTY(int diffSelectedCount READ diffSelectedCount NOTIFY diffSelectedCountChanged)
150 Q_PROPERTY(QStringList diffMissingParams READ diffMissingParams NOTIFY diffMissingParamsChanged)
151
152public:
153 explicit ParameterEditorController(QObject *parent = nullptr);
155
156 Q_INVOKABLE void saveToFile (const QString& filename);
157 Q_INVOKABLE bool buildDiffFromFile (const QString& filename);
158 Q_INVOKABLE void clearDiff (void);
159 Q_INVOKABLE void sendDiff (void);
160 Q_INVOKABLE void refresh (void);
161 Q_INVOKABLE void resetAllToDefaults (void);
162 Q_INVOKABLE void resetAllToVehicleConfiguration (void);
163 Q_INVOKABLE void toggleFavorite (const QString& paramName);
164 Q_INVOKABLE bool isFavorite (const QString& paramName) const;
165 Q_INVOKABLE void clearAllFavorites (void);
166
167 QObject* currentCategory (void) { return _currentCategory; }
168 QObject* currentGroup (void) { return _currentGroup; }
169 QmlObjectListModel* categories (void) { return &_categories; }
170 QmlObjectListModel* diffList (void) { return &_diffList; }
171 bool diffOtherVehicle (void) const { return _diffOtherVehicle; }
172 bool diffMultipleComponents (void) const { return _diffMultipleComponents; }
173 int diffParsedCount (void) const { return _diffParsedCount; }
174 int diffUnchangedCount (void) const { return _diffUnchangedCount; }
175 int diffReadOnlyCount (void) const { return _diffReadOnlyCount; }
176 int diffNoVehicleCount (void) const { return _diffNoVehicleCount; }
177 int diffSendableCount (void) const { return _diffSendableCount; }
178 int diffSelectedCount (void) const { return _diffSelectedCount; }
179 QStringList diffMissingParams (void) const { return _diffMissingParams; }
180 QStringList favoriteParameterNames (void) const;
181 void setCurrentCategory (QObject* currentCategory);
182 void setCurrentGroup (QObject* currentGroup);
183
184signals:
185 void searchTextChanged (QString searchText);
191 void favoritesChanged (void);
192 void diffOtherVehicleChanged (bool diffOtherVehicle);
193 void diffMultipleComponentsChanged (bool diffMultipleComponents);
194 void diffParsedCountChanged (int diffParsedCount);
195 void diffUnchangedCountChanged (int diffUnchangedCount);
196 void diffReadOnlyCountChanged (int diffReadOnlyCount);
197 void diffNoVehicleCountChanged (int diffNoVehicleCount);
198 void diffSendableCountChanged (int diffSendableCount);
199 void diffSelectedCountChanged (int diffSelectedCount);
200 void diffMissingParamsChanged (const QStringList& diffMissingParams);
201 void parametersChanged (void);
202
203private slots:
204 void _currentCategoryChanged(void);
205 void _currentGroupChanged (void);
206 void _searchTextChanged (void);
207 void _hideReadOnlyChanged (void);
208 void _buildLists (void);
209 void _buildListsForComponent(int compId);
210 void _factAdded (int compId, Fact* fact);
211
212private:
213 bool _shouldShow(Fact *fact) const;
214 void _performSearch();
215 void _loadFavorites();
216 void _saveFavorites();
217 void _updateDiffSelectedCount();
218
220 template <typename T, typename SignalFn>
221 void _setDiffProperty(T& member, const T& value, SignalFn changedSignal);
222
223 ParameterManager* _parameterMgr = nullptr;
224 QString _searchText;
225 QTimer _searchTimer;
226 ParameterEditorCategory* _currentCategory = nullptr;
227 ParameterEditorGroup* _currentGroup = nullptr;
228 bool _showModifiedOnly = false;
229 bool _showFavoritesOnly = false;
230 bool _hideReadOnly = false;
231 bool _diffOtherVehicle = false;
232 bool _diffMultipleComponents = false;
233 int _diffParsedCount = 0;
234 int _diffUnchangedCount = 0;
235 int _diffReadOnlyCount = 0;
236 int _diffNoVehicleCount = 0;
237 int _diffSendableCount = 0;
238 int _diffSelectedCount = 0;
239 QStringList _diffMissingParams;
240 QSet<QString> _favoriteNames;
241
242 QmlObjectListModel _categories;
243 QmlObjectListModel _diffList;
244 ParameterTableModel _searchParameters;
245 QAbstractTableModel* _parameters = nullptr;
246 QMap<QString, ParameterEditorCategory*> _mapCategoryName2Category;
247};
Holds the meta data associated with a Fact.
Used for handling missing Facts from C++ code.
A Fact is used to hold a single value within the system.
Definition Fact.h:17
QMap< QString, ParameterEditorGroup * > mapGroupName2Group
QmlObjectListModel * getGroups(void)
void diffMissingParamsChanged(const QStringList &diffMissingParams)
QStringList diffMissingParams(void) const
void showFavoritesOnlyChanged(void)
void diffSelectedCountChanged(int diffSelectedCount)
QmlObjectListModel * diffList(void)
QmlObjectListModel * categories(void)
void diffMultipleComponentsChanged(bool diffMultipleComponents)
void diffParsedCountChanged(int diffParsedCount)
void diffReadOnlyCountChanged(int diffReadOnlyCount)
void diffNoVehicleCountChanged(int diffNoVehicleCount)
void diffUnchangedCountChanged(int diffUnchangedCount)
void searchTextChanged(QString searchText)
void currentCategoryChanged(void)
void diffOtherVehicleChanged(bool diffOtherVehicle)
void diffSendableCountChanged(int diffSendableCount)
void showModifiedOnlyChanged(void)
bool cannotSend
Param not on vehicle and file has no type info (MP format) - shown but never sent.
void loadChanged(bool load)
FactMetaData::ValueType_t valueType
QAbstractTableModel * getFacts(void)
QVector< QVariant > ColumnData
void insert(int row, Fact *fact)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) 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.