QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LoggingCategoryModel.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QAbstractItemModel>
4#include <QtCore/QAbstractListModel>
5#include <QtCore/QList>
6#include <QtCore/QObject>
7#include <QtCore/QString>
8#include <QtQmlIntegration/QtQmlIntegration>
9
10#include <functional>
11
12class QGCLoggingCategoryItem : public QObject
13{
14 Q_OBJECT
15
16 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
17
18public:
19 QGCLoggingCategoryItem(const QString& shortCategory_, const QString& fullCategory_, bool enabled_,
20 QObject* parent = nullptr);
21
22 bool enabled() const { return _enabled; }
23
24 void setEnabled(bool enabled);
26
28 QString fullCategory;
29
30signals:
32
33private:
34 bool _enabled = false;
35 bool _updatingFromManager = false;
36};
37
38class LoggingCategoryFlatModel : public QAbstractListModel
39{
40 Q_OBJECT
41 QML_ELEMENT
42 QML_UNCREATABLE("")
43
44public:
45 enum class Roles
46 {
47 ShortNameRole = Qt::UserRole + 1,
50 };
51 Q_ENUM(Roles)
52
53 explicit LoggingCategoryFlatModel(QObject* parent = nullptr);
54
55 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
56 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
57 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
58 Qt::ItemFlags flags(const QModelIndex& index) const override;
59 QHash<int, QByteArray> roleNames() const override;
60
62 QGCLoggingCategoryItem* findByFullName(const QString& fullName) const;
63
64 int count() const { return _items.count(); }
65
66 QGCLoggingCategoryItem* at(int i) const { return _items.at(i); }
67
68private:
69 QList<QGCLoggingCategoryItem*> _items;
70};
71
72// ---------------------------------------------------------------------------
73// Tree model (proper QAbstractItemModel for TreeView)
74// ---------------------------------------------------------------------------
75
77{
80 QList<LoggingCategoryTreeNode*> children;
81 bool expanded = false;
82
84};
85
86class LoggingCategoryTreeModel : public QAbstractItemModel
87{
91
92public:
93 enum class Roles
94 {
95 ShortNameRole = Qt::UserRole + 1,
98 };
100
101 explicit LoggingCategoryTreeModel(QObject* parent = nullptr);
103
104 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
105 QModelIndex parent(const QModelIndex& child) const override;
106 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
107 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
108 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
109 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
110 Qt::ItemFlags flags(const QModelIndex& index) const override;
111 QHash<int, QByteArray> roleNames() const override;
112 bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
113
114 void insertCategory(const QStringList& pathSegments, const QString& fullCategory, QGCLoggingCategoryItem* item);
115 void forEachItem(const std::function<void(QGCLoggingCategoryItem*)>& fn);
116
117private:
118 LoggingCategoryTreeNode* nodeFromIndex(const QModelIndex& index) const;
119 LoggingCategoryTreeNode* findOrCreateIntermediateNode(LoggingCategoryTreeNode* parent, const QString& segment,
120 const QString& fullPrefix);
121 int insertionIndex(LoggingCategoryTreeNode* parent, const QString& name) const;
122
124};
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QHash< int, QByteArray > roleNames() const override
void insertSorted(QGCLoggingCategoryItem *item)
QGCLoggingCategoryItem * findByFullName(const QString &fullName) const
QGCLoggingCategoryItem * at(int i) const
Qt::ItemFlags flags(const QModelIndex &index) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
QModelIndex parent(const QModelIndex &child) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
~LoggingCategoryTreeModel() override
void forEachItem(const std::function< void(QGCLoggingCategoryItem *)> &fn)
QHash< int, QByteArray > roleNames() const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void insertCategory(const QStringList &pathSegments, const QString &fullCategory, QGCLoggingCategoryItem *item)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
LoggingCategoryTreeNode * parent
QList< LoggingCategoryTreeNode * > children
QGCLoggingCategoryItem * item