QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ObjectItemModelBase.cc
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#include "ObjectItemModelBase.h"
11#include "QGCLoggingCategory.h"
12
13#include <QtQml/QQmlEngine>
14
15QGC_LOGGING_CATEGORY(ObjectItemModelBaseLog, "API.ObjectItemModelBase")
16
18 : QAbstractItemModel(parent)
19{
20 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
21}
22
24{
26 qCWarning(ObjectItemModelBaseLog) << "Destroyed with unbalanced nesting of begin/endResetModel calls - _resetModelNestingCount:" << _resetModelNestingCount << this;
27 }
28}
29
30QHash<int, QByteArray> ObjectItemModelBase::roleNames() const
31{
32 return {
33 { ObjectRole, "object" },
34 { TextRole, "text" },
35 };
36}
37
39{
40 _dirty |= dirty;
41 emit dirtyChanged(_dirty);
42}
43
45{
46 if (_resetModelNestingCount == 0) {
47 qCDebug(ObjectItemModelBaseLog) << "First beginResetModel - calling QAbstractItemModel::beginResetModel" << this;
48 QAbstractItemModel::beginResetModel();
49 }
51 qCDebug(ObjectItemModelBaseLog) << "Reset model nesting count" << _resetModelNestingCount << this;
52}
53
55{
56 if (_resetModelNestingCount == 0) {
57 qCWarning(ObjectItemModelBaseLog) << "endResetModel called without prior beginResetModel";
58 return;
59 }
61 qCDebug(ObjectItemModelBaseLog) << "Reset model nesting count" << _resetModelNestingCount << this;
62 if (_resetModelNestingCount == 0) {
63 qCDebug(ObjectItemModelBaseLog) << "Last endResetModel - calling QAbstractItemModel::endResetModel" << this;
64 QAbstractItemModel::endResetModel();
65 emit countChanged(count());
66 }
67}
68
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void endResetModel()
Depth-counted endResetModel — only the outermost call has effect.
QHash< int, QByteArray > roleNames() const override
void beginResetModel()
Depth-counted beginResetModel — only the outermost call has effect.
static constexpr int ObjectRole
virtual int count() const =0
void _childDirtyChanged(bool dirty)
static constexpr int TextRole
void dirtyChanged(bool dirty)
int count READ count NOTIFY countChanged(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) bool dirty() const