QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ObjectItemModelBase.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10#pragma once
11
12#include <QtCore/QAbstractItemModel>
13#include <QtQmlIntegration/QtQmlIntegration>
14
19class ObjectItemModelBase : public QAbstractItemModel
20{
21 Q_OBJECT
22
23public:
24 explicit ObjectItemModelBase(QObject* parent = nullptr);
25 ~ObjectItemModelBase() override;
26
27 Q_PROPERTY(int count READ count NOTIFY countChanged)
28 Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
29
30 bool dirty() const { return _dirty; }
31
33 void beginResetModel();
34
36 void endResetModel();
37
38 virtual int count() const = 0;
39 virtual bool isEmpty() const { return (count() == 0); }
40 virtual void setDirty(bool dirty) = 0;
41 virtual void clear() = 0;
42
43signals:
45 void dirtyChanged(bool dirty);
46
47protected slots:
48 void _childDirtyChanged(bool dirty);
49
50protected:
51 QHash<int, QByteArray> roleNames() const override;
53
54 bool _dirty = false;
56
57 static constexpr int ObjectRole = Qt::UserRole;
58 static constexpr int TextRole = Qt::UserRole + 1;
59};
Common base for QObject*-based item models (flat lists and trees).
void endResetModel()
Depth-counted endResetModel — only the outermost call has effect.
QHash< int, QByteArray > roleNames() const override
virtual void setDirty(bool dirty)=0
void beginResetModel()
Depth-counted beginResetModel — only the outermost call has effect.
static constexpr int ObjectRole
virtual int count() const =0
virtual void clear()=0
void _childDirtyChanged(bool dirty)
static constexpr int TextRole
void dirtyChanged(bool dirty)
void countChanged(int count)
virtual bool isEmpty() const