-
Notifications
You must be signed in to change notification settings - Fork 0
/
instansemodel.cpp
80 lines (69 loc) · 1.84 KB
/
instansemodel.cpp
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
#include "instansemodel.h"
QHash<int, QByteArray> InstanseModel::roleNames() const
{
QHash<int, QByteArray> rez;
rez[BBYtypes::mtrans] = "mtrans";
rez[BBYtypes::mscale] = "mscale";
rez[BBYtypes::mtextTrans] = "mtextTrans";
rez[mttext] = "mttext";
return rez;
}
void InstanseModel::clearAll()
{
if (boundydata.size()==0)
return;
beginRemoveRows(QModelIndex(), 0, boundydata.size()-1);
for (int i = 0; i < boundydata.size(); ++i)
{
delete boundydata[i];
}
boundydata.clear();
endRemoveRows();
}
void InstanseModel::updateAll()
{
beginInsertRows(QModelIndex(), 0, boundydata.size()-1);
endInsertRows();
qDebug() << "updated" << boundydata.size();
}
InstanseModel::InstanseModel(QObject *parent)
: QAbstractListModel(parent)
{
}
QVariant InstanseModel::headerData(int section, Qt::Orientation orientation, int role) const
{
// FIXME: Implement me!
return QVariant();
}
int InstanseModel::rowCount(const QModelIndex &parent) const
{
// For list models only the root node (an invalid parent) should return the list's size. For all
// other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
// if (parent.isValid())
return boundydata.size();
// return 0;
// FIXME: Implement me!
}
QVariant InstanseModel::data(const QModelIndex &index, int role) const
{
// qDebug() << role << index.isValid();
if (!index.isValid())
return QVariant();
switch ((BBYtypes)role) {
case InstanseModel::mttext:
return boundydata[index.row()]->getText();
case InstanseModel::mtrans:
return boundydata[index.row()]->getTrans();
case InstanseModel::mtextTrans:
return boundydata[index.row()]->getTextTrans();
case InstanseModel::mscale:
return boundydata[index.row()]->getSacle();
}
// FIXME: Implement me!
return QVariant();
// ::fromValue(*boundydata[index.row()]);
}
InstanseModel::~InstanseModel()
{
clearAll();
}