-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrmapobjectmodel.cpp
More file actions
executable file
·156 lines (134 loc) · 5.04 KB
/
rmapobjectmodel.cpp
File metadata and controls
executable file
·156 lines (134 loc) · 5.04 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "rmapobjectmodel.h"
#include <QRect>
#include <QDebug>
//--------------------------------------------------------------------------------------
RMapObjectModel::RMapObjectModel(QObject *parent) :
QAbstractTableModel(parent),
is_modify(true),
map_object_id(0)
{
}
//--------------------------------------------------------------------------------------
RMapObjectModel::~RMapObjectModel()
{
}
// копируем нужные нам опции из текущей модели
// функция вызывается каскадно, таким образом настройки модели копируются
// сверху вниз по дереву наследования
//--------------------------------------------------------------------------------------
void RMapObjectModel::initModel(RMapObjectModel *m) const
{
m->map_object_geometry = map_object_geometry;
m->blockSignals(signalsBlocked());
}
//--------------------------------------------------------------------------------------
const QRect &RMapObjectModel::mapObjectGeometry() const
{ return map_object_geometry; }
//--------------------------------------------------------------------------------------
void RMapObjectModel::setMapObjectGeometry(const QRect &rect)
{
if (map_object_geometry != rect) {
map_object_geometry = rect;
emit(dataChanged(createIndex(EN_XPOS, EN_VALUE), createIndex(EN_HEIGHT, EN_VALUE)));
}
}
//--------------------------------------------------------------------------------------
bool RMapObjectModel::isModified() const
{ return is_modify; }
//--------------------------------------------------------------------------------------
void RMapObjectModel::setModified(bool modify)
{ is_modify = modify; }
//--------------------------------------------------------------------------------------
int RMapObjectModel::mapObjectID() const
{ return map_object_id; }
//--------------------------------------------------------------------------------------
void RMapObjectModel::setMapObjectID(int id)
{ map_object_id = id; }
//--------------------------------------------------------------------------------------
int RMapObjectModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return EN_COLUMNS_COUNT;
}
//--------------------------------------------------------------------------------------
bool RMapObjectModel::isValid() const
{ return true; }
//--------------------------------------------------------------------------------------
QVariant RMapObjectModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case EN_PROPERTY:
return QString(tr("Свойство"));
case EN_VALUE:
return QString(tr("Значение"));
}
}
return QVariant();
}
//--------------------------------------------------------------------------------------
Qt::ItemFlags RMapObjectModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled;
return QAbstractTableModel::flags(index) | (index.column() == EN_PROPERTY ? Qt::ItemIsEnabled : Qt::ItemIsEditable);
}
//--------------------------------------------------------------------------------------
QVariant RMapObjectModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole || role == Qt::EditRole) {
if (index.column() == EN_PROPERTY) {
switch (index.row()) {
case EN_XPOS:
return QString(tr("Координата Х"));
case EN_YPOS:
return QString(tr("Координата У"));
case EN_WIDTH:
return QString(tr("Ширина"));
case EN_HEIGHT:
return QString(tr("Высота"));
}
} else if (index.column() == EN_VALUE) {
switch (index.row()) {
case EN_XPOS:
return map_object_geometry.left();
case EN_YPOS:
return map_object_geometry.top();
case EN_WIDTH:
return map_object_geometry.width();
case EN_HEIGHT:
return map_object_geometry.height();
}
}
}
return QVariant();
}
//--------------------------------------------------------------------------------------
bool RMapObjectModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole) {
switch (index.row()) {
case EN_XPOS:
map_object_geometry.moveLeft(value.toInt());
break;
case EN_YPOS:
map_object_geometry.moveTop(value.toInt());
break;
case EN_WIDTH:
map_object_geometry.setWidth(value.toInt());
break;
case EN_HEIGHT:
map_object_geometry.setHeight(value.toInt());
break;
default:
return false;
}
emit(dataChanged(index, index));
return true;
}
return false;
}