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(QString units MEMBER units CONSTANT)
108 Q_PROPERTY(bool load MEMBER load NOTIFY loadChanged)
109
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 Q_PROPERTY(bool showFavoritesOnly MEMBER _showFavoritesOnly NOTIFY showFavoritesOnlyChanged)
135 Q_PROPERTY(bool hideReadOnly MEMBER _hideReadOnly NOTIFY hideReadOnlyChanged)
136 Q_PROPERTY(QStringList favoriteParameterNames READ favoriteParameterNames NOTIFY favoritesChanged)
137
138 // These property are related to the diff associated with a load from file
139 Q_PROPERTY(bool diffOtherVehicle MEMBER _diffOtherVehicle NOTIFY diffOtherVehicleChanged)
140 Q_PROPERTY(bool diffMultipleComponents MEMBER _diffMultipleComponents NOTIFY diffMultipleComponentsChanged)
141 Q_PROPERTY(QmlObjectListModel* diffList READ diffList CONSTANT)
142
143public:
144 explicit ParameterEditorController(QObject *parent = nullptr);
146
147 Q_INVOKABLE void saveToFile (const QString& filename);
148 Q_INVOKABLE bool buildDiffFromFile (const QString& filename);
149 Q_INVOKABLE void clearDiff (void);
150 Q_INVOKABLE void sendDiff (void);
151 Q_INVOKABLE void refresh (void);
152 Q_INVOKABLE void resetAllToDefaults (void);
153 Q_INVOKABLE void resetAllToVehicleConfiguration (void);
154 Q_INVOKABLE void toggleFavorite (const QString& paramName);
155 Q_INVOKABLE bool isFavorite (const QString& paramName) const;
156 Q_INVOKABLE void clearAllFavorites (void);
157
158 QObject* currentCategory (void) { return _currentCategory; }
159 QObject* currentGroup (void) { return _currentGroup; }
160 QmlObjectListModel* categories (void) { return &_categories; }
161 QmlObjectListModel* diffList (void) { return &_diffList; }
162 QStringList favoriteParameterNames (void) const;
163 void setCurrentCategory (QObject* currentCategory);
164 void setCurrentGroup (QObject* currentGroup);
165
166signals:
167 void searchTextChanged (QString searchText);
173 void favoritesChanged (void);
174 void diffOtherVehicleChanged (bool diffOtherVehicle);
175 void diffMultipleComponentsChanged (bool diffMultipleComponents);
176 void parametersChanged (void);
177
178private slots:
179 void _currentCategoryChanged(void);
180 void _currentGroupChanged (void);
181 void _searchTextChanged (void);
182 void _hideReadOnlyChanged (void);
183 void _buildLists (void);
184 void _buildListsForComponent(int compId);
185 void _factAdded (int compId, Fact* fact);
186
187private:
188 bool _shouldShow(Fact *fact) const;
189 void _performSearch();
190 void _loadFavorites();
191 void _saveFavorites();
192
193private:
194 ParameterManager* _parameterMgr = nullptr;
195 QString _searchText;
196 QTimer _searchTimer;
197 ParameterEditorCategory* _currentCategory = nullptr;
198 ParameterEditorGroup* _currentGroup = nullptr;
199 bool _showModifiedOnly = false;
200 bool _showFavoritesOnly = false;
201 bool _hideReadOnly = false;
202 bool _diffOtherVehicle = false;
203 bool _diffMultipleComponents = false;
204 QSet<QString> _favoriteNames;
205
206 QmlObjectListModel _categories;
207 QmlObjectListModel _diffList;
208 ParameterTableModel _searchParameters;
209 QAbstractTableModel* _parameters = nullptr;
210 QMap<QString, ParameterEditorCategory*> _mapCategoryName2Category;
211};
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 showFavoritesOnlyChanged(void)
QmlObjectListModel * diffList(void)
QmlObjectListModel * categories(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
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.