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
128
129
130
131
132
133
134
135
136
137
|
/* Copyright 2013 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INSTANCELIST_H
#define INSTANCELIST_H
#include <QList>
#include <QMap>
#include <QSet>
#include <qabstractitemmodel.h>
enum IMI_type
{
IMI_Root,
IMI_Group,
IMI_Instance
};
class InstanceModel;
class InstanceGroup;
class InstanceBase;
class InstanceModelItem
{
public:
virtual IMI_type getModelItemType() const = 0;
virtual InstanceModelItem * getParent() const = 0;
virtual int numChildren() const = 0;
virtual InstanceModelItem * getChild(int index) const = 0;
virtual InstanceModel * getModel() const = 0;
virtual QVariant data(int role) const = 0;
virtual int getRow() const = 0;
};
class InstanceGroup : public InstanceModelItem
{
public:
InstanceGroup(const QString& name, InstanceModel * model);
~InstanceGroup();
QString getName() const;
void setName(const QString& name);
bool isHidden() const;
void setHidden(bool hidden);
virtual IMI_type getModelItemType() const
{
return IMI_Group;
}
virtual InstanceModelItem* getParent() const;
virtual InstanceModelItem* getChild ( int index ) const;
virtual int numChildren() const;
virtual InstanceModel * getModel() const
{
return model;
};
virtual QVariant data ( int column ) const;
int getIndexOf(InstanceBase * inst)
{
return instances.indexOf(inst);
};
virtual int getRow() const;
void addInstance ( InstanceBase* inst );
protected:
QString name;
InstanceModel * model;
QVector<InstanceBase*> instances;
bool hidden;
int row;
};
class InstanceModel : public QAbstractItemModel, public InstanceModelItem
{
public:
explicit InstanceModel(QObject *parent = 0);
~InstanceModel();
virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const;
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual QModelIndex index ( int row, int column, const QModelIndex& parent = QModelIndex() ) const;
virtual QModelIndex parent ( const QModelIndex& child ) const;
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
void addInstance(InstanceBase *inst, const QString& groupName = "Ungrouped");
void setInstanceGroup(InstanceBase *inst, const QString & groupName);
InstanceGroup* getGroupByName(const QString & name) const;
void initialLoad(QString dir);
bool saveGroupInfo() const;
virtual IMI_type getModelItemType() const
{
return IMI_Root;
}
virtual InstanceModelItem * getParent() const
{
return nullptr;
};
virtual int numChildren() const;
virtual InstanceModelItem* getChild ( int index ) const;
virtual InstanceModel* getModel() const
{
return nullptr;
};
virtual QVariant data ( int column ) const;
int getIndexOf(const InstanceGroup * grp) const
{
return groups.indexOf((InstanceGroup *) grp);
};
virtual int getRow() const
{
return 0;
};
signals:
public slots:
private:
QString groupFile;
QVector<InstanceGroup*> groups;
InstanceGroup * implicitGroup;
};
#endif // INSTANCELIST_H
|