FlightGear next
PropertyItemModel.hxx
Go to the documentation of this file.
1#ifndef PROPERTYITEMMODEL_HXX
2#define PROPERTYITEMMODEL_HXX
3
4#include <QAbstractListModel>
5#include <QQmlListProperty>
6
7#include <simgear/props/props.hxx>
8
11
12#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
13#define QML_LIST_INDEX_TYPE qsizetype
14#else
15#define QML_LIST_INDEX_TYPE int
16#endif
17
18class PropertyItemModel : public QAbstractListModel,
19 public SGPropertyChangeListener
20{
21 Q_OBJECT
22
23 Q_PROPERTY(QString rootPath READ rootPath WRITE setRootPath NOTIFY rootChanged)
24
25 Q_PROPERTY(FGQmlPropertyNode* root READ root WRITE setRoot NOTIFY rootChanged)
26
28 Q_PROPERTY(QQmlListProperty<PropertyItemModelRoleMapping> mappings READ mappings NOTIFY mappingsChanged)
29 // list property storing child/role mapping
30
31 QQmlListProperty<PropertyItemModelRoleMapping> mappings();
32public:
34
35 int rowCount(const QModelIndex &parent) const override;
36
37 QVariant data(const QModelIndex &index, int role) const override;
38
39 QHash<int, QByteArray> roleNames() const override;
40
41 QString rootPath() const;
42
43 QString childNameFilter() const;
44
45 FGQmlPropertyNode* root() const;
46
47public slots:
48 void setRootPath(QString rootPath);
49
51
53
54signals:
56
58
60protected:
61 // implement property-change listener to watch for changes to the
62 // underlying nodes
63 void valueChanged(SGPropertyNode *node) override;
64 void childAdded(SGPropertyNode *parent, SGPropertyNode *child) override;
65 void childRemoved(SGPropertyNode *parent, SGPropertyNode *child) override;
66
67private:
68 void rebuild();
69
70 void innerSetRoot(SGPropertyNode_ptr root);
71
72 static void append_mapping(QQmlListProperty<PropertyItemModelRoleMapping> *list,
74 static PropertyItemModelRoleMapping* at_mapping(QQmlListProperty<PropertyItemModelRoleMapping>* list, QML_LIST_INDEX_TYPE index);
75 static QML_LIST_INDEX_TYPE count_mapping(QQmlListProperty<PropertyItemModelRoleMapping>* list);
76 static void clear_mapping(QQmlListProperty<PropertyItemModelRoleMapping> *list);
77
78 SGPropertyNode_ptr _modelRoot;
79 QVector<PropertyItemModelRoleMapping*> _roleMappings;
80 QString _childNameFilter;
81
82 mutable std::vector<SGPropertyNode_ptr> _nodes;
83};
84
85#endif // PROPERTYITEMMODEL_HXX
#define QML_LIST_INDEX_TYPE
FGQmlPropertyNode * root
void childRemoved(SGPropertyNode *parent, SGPropertyNode *child) override
QHash< int, QByteArray > roleNames() const override
void setRootPath(QString rootPath)
void setChildNameFilter(QString childNameFilter)
void childNameFilterChanged(QString childNameFilter)
QVariant data(const QModelIndex &index, int role) const override
void childAdded(SGPropertyNode *parent, SGPropertyNode *child) override
int rowCount(const QModelIndex &parent) const override
void setRoot(FGQmlPropertyNode *root)
void valueChanged(SGPropertyNode *node) override
QQmlListProperty< PropertyItemModelRoleMapping > mappings