-
Notifications
You must be signed in to change notification settings - Fork 6
/
RendererModel.cpp
122 lines (104 loc) · 3.83 KB
/
RendererModel.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
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
#include "RendererModel.h"
#include "SimpleMarkerSymbol.h"
RendererModel::RendererModel()
{
}
void RendererModel::setRenderer(Esri::ArcGISRuntime::ClassBreaksRenderer *renderer)
{
beginResetModel();
m_renderer = renderer;
endResetModel();
}
int RendererModel::rowCount(const QModelIndex &parent) const
{
if(parent.isValid() || !m_renderer)
return 0;
return m_renderer->classBreaks()->rowCount();
}
QVariant RendererModel::data(const QModelIndex &index, int role) const
{
if (!m_renderer)
return QVariant();
switch(role)
{
case RendererRoles::Name:
return m_renderer->classBreaks()->at(index.row())->label();
case RendererRoles::Description:
return m_renderer->classBreaks()->at(index.row())->description();
case RendererRoles::Minimum:
return m_renderer->classBreaks()->at(index.row())->minValue();
case RendererRoles::Maximum:
return m_renderer->classBreaks()->at(index.row())->maxValue();
case RendererRoles::Color:
return reinterpret_cast<Esri::ArcGISRuntime::SimpleMarkerSymbol*>(m_renderer->classBreaks()->at(index.row())->symbol())->color();
case RendererRoles::Shape:
return static_cast<int>(reinterpret_cast<Esri::ArcGISRuntime::SimpleMarkerSymbol*>(m_renderer->classBreaks()->at(index.row())->symbol())->style());
case RendererRoles::Size:
return reinterpret_cast<Esri::ArcGISRuntime::SimpleMarkerSymbol*>(m_renderer->classBreaks()->at(index.row())->symbol())->size();
}
return QVariant();
}
QHash<int, QByteArray> RendererModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[RendererRoles::Name] = "Name";
roles[RendererRoles::Description] = "Description";
roles[RendererRoles::Minimum] = "Minimum";
roles[RendererRoles::Maximum] = "Maximum";
roles[RendererRoles::Color] = "Color";
roles[RendererRoles::Size] = "Size";
roles[RendererRoles::Shape] = "Shape";
return roles;
}
bool RendererModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!m_renderer)
return false;
switch(role)
{
case RendererRoles::Name:
{
m_renderer->classBreaks()->at(index.row())->setLabel(value.toString());
break;
}
case RendererRoles::Description:
{
m_renderer->classBreaks()->at(index.row())->setDescription(value.toString());
break;
}
case RendererRoles::Minimum:
{
m_renderer->classBreaks()->at(index.row())->setMinValue(value.toDouble());
break;
}
case RendererRoles::Maximum:
{
m_renderer->classBreaks()->at(index.row())->setMaxValue(value.toDouble());
break;
}
case RendererRoles::Color:
{
reinterpret_cast<Esri::ArcGISRuntime::SimpleMarkerSymbol*>(m_renderer->classBreaks()->at(index.row())->symbol())->setColor(value.value<QColor>());
break;
}
case RendererRoles::Size:
{
reinterpret_cast<Esri::ArcGISRuntime::SimpleMarkerSymbol*>(m_renderer->classBreaks()->at(index.row())->symbol())->setSize(value.toFloat());
break;
}
case RendererRoles::Shape:
{
reinterpret_cast<Esri::ArcGISRuntime::SimpleMarkerSymbol*>(m_renderer->classBreaks()->at(index.row())->symbol())->setStyle(
static_cast<Esri::ArcGISRuntime::SimpleMarkerSymbolStyle>(value.toInt()));
break;
}
}
emit dataChanged(index, index, {role});
return true;
}
Qt::ItemFlags RendererModel::flags(const QModelIndex &index) const
{
if (index.isValid())
return QAbstractListModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsEditable;
return QAbstractListModel::flags(index);
}