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(bool invalidFileValue MEMBER invalidFileValue CONSTANT)
109 Q_PROPERTY(QString units MEMBER units CONSTANT)
110 Q_PROPERTY(bool load MEMBER load NOTIFY loadChanged)
111
113 QString name;
115 QString fileValue;
116 QVariant fileValueVar;
118 bool noVehicleValue = false;
119 bool cannotSend = false;
120 bool invalidFileValue = false;
121 QString units;
122 bool load = true;
123
124signals:
125 void loadChanged(bool load);
126};
127
129{
130 Q_OBJECT
131 QML_ELEMENT
132 Q_PROPERTY(QString searchText MEMBER _searchText NOTIFY searchTextChanged)
133 Q_PROPERTY(QmlObjectListModel* categories READ categories CONSTANT)
134 Q_PROPERTY(QObject* currentCategory READ currentCategory WRITE setCurrentCategory NOTIFY currentCategoryChanged)
135 Q_PROPERTY(QObject* currentGroup READ currentGroup WRITE setCurrentGroup NOTIFY currentGroupChanged)
136 Q_PROPERTY(QAbstractTableModel* parameters MEMBER _parameters NOTIFY parametersChanged)
137 Q_PROPERTY(bool showModifiedOnly MEMBER _showModifiedOnly NOTIFY showModifiedOnlyChanged)
138 Q_PROPERTY(bool showFavoritesOnly MEMBER _showFavoritesOnly NOTIFY showFavoritesOnlyChanged)
139 Q_PROPERTY(bool hideReadOnly MEMBER _hideReadOnly NOTIFY hideReadOnlyChanged)
140 Q_PROPERTY(QStringList favoriteParameterNames READ favoriteParameterNames NOTIFY favoritesChanged)
141
142 // These property are related to the diff associated with a load from file
145 Q_PROPERTY(QmlObjectListModel* diffList READ diffList CONSTANT)
146 Q_PROPERTY(int diffParsedCount READ diffParsedCount NOTIFY diffParsedCountChanged)
152 Q_PROPERTY(QStringList diffMissingParams READ diffMissingParams NOTIFY diffMissingParamsChanged)
153 Q_PROPERTY(QStringList diffInvalidParams READ diffInvalidParams NOTIFY diffInvalidParamsChanged)
154
155public:
156 explicit ParameterEditorController(QObject *parent = nullptr);
158
159 Q_INVOKABLE void saveToFile (const QString& filename);
160 Q_INVOKABLE bool buildDiffFromFile (const QString& filename);
161 Q_INVOKABLE void clearDiff (void);
162 Q_INVOKABLE void sendDiff (void);
163 Q_INVOKABLE void refresh (void);
164 Q_INVOKABLE void resetAllToDefaults (void);
165 Q_INVOKABLE void resetAllToVehicleConfiguration (void);
166 Q_INVOKABLE void toggleFavorite (const QString& paramName);
167 Q_INVOKABLE bool isFavorite (const QString& paramName) const;
168 Q_INVOKABLE void clearAllFavorites (void);
169
170 QObject* currentCategory (void) { return _currentCategory; }
171 QObject* currentGroup (void) { return _currentGroup; }
172 QmlObjectListModel* categories (void) { return &_categories; }
173 QmlObjectListModel* diffList (void) { return &_diffList; }
174 bool diffOtherVehicle (void) const { return _diffOtherVehicle; }
175 bool diffMultipleComponents (void) const { return _diffMultipleComponents; }
176 int diffParsedCount (void) const { return _diffParsedCount; }
177 int diffUnchangedCount (void) const { return _diffUnchangedCount; }
178 int diffReadOnlyCount (void) const { return _diffReadOnlyCount; }
179 int diffNoVehicleCount (void) const { return _diffNoVehicleCount; }
180 int diffSendableCount (void) const { return _diffSendableCount; }
181 int diffSelectedCount (void) const { return _diffSelectedCount; }
182 QStringList diffMissingParams (void) const { return _diffMissingParams; }
183 QStringList diffInvalidParams (void) const { return _diffInvalidParams; }
184 QStringList favoriteParameterNames (void) const;
185 void setCurrentCategory (QObject* currentCategory);
186 void setCurrentGroup (QObject* currentGroup);
187
188signals:
189 void searchTextChanged (QString searchText);
195 void favoritesChanged (void);
206 void parametersChanged (void);
207
208private slots:
209 void _currentCategoryChanged(void);
210 void _currentGroupChanged (void);
211 void _searchTextChanged (void);
212 void _hideReadOnlyChanged (void);
213 void _buildLists (void);
214 void _buildListsForComponent(int compId);
215 void _factAdded (int compId, Fact* fact);
216
217private:
218 bool _shouldShow(Fact *fact) const;
219 void _performSearch();
220 void _loadFavorites();
221 void _saveFavorites();
222 void _updateDiffSelectedCount();
223
227 static bool _convertFileValue(const FactMetaData& metaData, const QString& fileValueStr, QVariant& typedValue,
228 QString& errorString);
229
231 template <typename T, typename SignalFn>
232 void _setDiffProperty(T& member, const T& value, SignalFn changedSignal);
233
234 ParameterManager* _parameterMgr = nullptr;
235 QString _searchText;
236 QTimer _searchTimer;
237 ParameterEditorCategory* _currentCategory = nullptr;
238 ParameterEditorGroup* _currentGroup = nullptr;
239 bool _showModifiedOnly = false;
240 bool _showFavoritesOnly = false;
241 bool _hideReadOnly = false;
242 bool _diffOtherVehicle = false;
243 bool _diffMultipleComponents = false;
244 int _diffParsedCount = 0;
245 int _diffUnchangedCount = 0;
246 int _diffReadOnlyCount = 0;
247 int _diffNoVehicleCount = 0;
248 int _diffSendableCount = 0;
249 int _diffSelectedCount = 0;
250 QStringList _diffMissingParams;
251 QStringList _diffInvalidParams;
252 QSet<QString> _favoriteNames;
253
254 QmlObjectListModel _categories;
255 QmlObjectListModel _diffList;
256 ParameterTableModel _searchParameters;
257 QAbstractTableModel* _parameters = nullptr;
258 QMap<QString, ParameterEditorCategory*> _mapCategoryName2Category;
259};
Holds the meta data associated with a Fact.
FactPanelController(QObject *parent=nullptr)
A Fact is used to hold a single value within the system.
Definition Fact.h:15
QMap< QString, ParameterEditorGroup * > mapGroupName2Group
QmlObjectListModel * getGroups(void)
QStringList diffInvalidParams(void) const
void diffMissingParamsChanged(const QStringList &diffMissingParams)
QStringList diffMissingParams(void) const
Q_INVOKABLE void resetAllToVehicleConfiguration(void)
void showFavoritesOnlyChanged(void)
Q_INVOKABLE bool buildDiffFromFile(const QString &filename)
void diffSelectedCountChanged(int diffSelectedCount)
QmlObjectListModel * diffList(void)
QmlObjectListModel * categories(void)
void diffMultipleComponentsChanged(bool diffMultipleComponents)
Q_INVOKABLE void toggleFavorite(const QString &paramName)
void diffParsedCountChanged(int diffParsedCount)
void diffReadOnlyCountChanged(int diffReadOnlyCount)
Q_INVOKABLE void clearAllFavorites(void)
void diffNoVehicleCountChanged(int diffNoVehicleCount)
QStringList favoriteParameterNames(void) const
void setCurrentGroup(QObject *currentGroup)
Q_INVOKABLE void saveToFile(const QString &filename)
void diffUnchangedCountChanged(int diffUnchangedCount)
ParameterEditorController(QObject *parent=nullptr)
void searchTextChanged(QString searchText)
void currentCategoryChanged(void)
void diffOtherVehicleChanged(bool diffOtherVehicle)
void setCurrentCategory(QObject *currentCategory)
void diffSendableCountChanged(int diffSendableCount)
Q_INVOKABLE bool isFavorite(const QString &paramName) const
void diffInvalidParamsChanged(const QStringList &diffInvalidParams)
void showModifiedOnlyChanged(void)
Q_INVOKABLE void resetAllToDefaults(void)
bool invalidFileValue
File value cannot be converted to the parameter's type.
bool cannotSend
Shown but never sent: MP param not on vehicle, or invalid file value.
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.
ParameterTableModel(QObject *parent=nullptr)