-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMapModel.cpp
62 lines (56 loc) · 1.37 KB
/
MapModel.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
#include "MapModel.h"
using namespace q2d::util;
MapModel::MapModel(QObject* parent) :
QAbstractTableModel(parent) {
m_map = nullptr;
}
int
MapModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
if (m_map) {
return m_map->count();
}
return 0;
}
int
MapModel::columnCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return 2;
}
QVariant
MapModel::data(const QModelIndex &index, int role) const {
if (m_map == nullptr) {
return QVariant();
}
if (index.row() < 0 ||
index.row() >= m_map->count() ||
role != Qt::DisplayRole) {
return QVariant();
}
if (index.column() == 0) {
return m_map->keys().at(index.row());
}
if (index.column() == 1) {
return m_map->values().at(index.row());
}
return QVariant();
}
QVariant
MapModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return tr("Variable");
case 1:
return tr("Assignment");
default:
return QString("Column %1").arg(section + 1);
}
} else {
return QString::number(section);
}
} else {
return QVariant();
}
}