/
pluginitemmodel.h
127 lines (86 loc) · 3.66 KB
/
pluginitemmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://gnu.org/licenses>.
*******************************************************************************/
//==============================================================================
// Plugin item model
//==============================================================================
#pragma once
//==============================================================================
#include <QAbstractItemModel>
#include <QIcon>
//==============================================================================
namespace OpenCOR {
//==============================================================================
class PluginItemModel;
//==============================================================================
class PluginItem
{
public:
explicit PluginItem(const QIcon &pIcon, const QString &pName);
explicit PluginItem(const QString &pName = QString());
~PluginItem();
void setParentAndModel(PluginItem *pParent, PluginItemModel *pModel);
PluginItem * parent() const;
PluginItem * child(int pIndex) const;
int childCount() const;
bool hasChildren() const;
int index() const;
QModelIndex modelIndex() const;
bool isHidden() const;
void setHidden(bool pHidden);
bool hasCheckBox() const;
void setHasCheckBox(bool pHasCheckBox);
bool isCheckable() const;
void setCheckable(bool pCheckable);
Qt::CheckState checkState() const;
void setCheckState(Qt::CheckState pCheckState);
QIcon icon() const;
QString name() const;
void insert(int pIndex, PluginItem *pItem);
void append(PluginItem *pItem);
private:
PluginItemModel *mModel = nullptr;
PluginItem *mParent = nullptr;
QVector<PluginItem *> mChildren;
bool mHidden = false;
bool mHasCheckBox = false;
bool mCheckable = false;
Qt::CheckState mCheckState;
QIcon mIcon;
QString mName;
};
//==============================================================================
class PluginItemModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit PluginItemModel(QObject *pParent);
~PluginItemModel() override;
QModelIndex index(int pRow, int pColumn,
const QModelIndex &pParent = {}) const override;
QModelIndex parent(const QModelIndex &pChild) const override;
int rowCount(const QModelIndex &pParent = {}) const override;
int columnCount(const QModelIndex &pParent = {}) const override;
QVariant data(const QModelIndex &pIndex,
int pRole = Qt::DisplayRole) const override;
PluginItem * invisibleRootItem() const;
PluginItem * itemFromIndex(const QModelIndex &pIndex) const;
QModelIndex createIndex(int pRow, PluginItem *pParent) const;
private:
PluginItem *mRootItem;
};
//==============================================================================
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================