-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpolygongroupcontrolmenucontroller.cpp
176 lines (129 loc) · 5.49 KB
/
polygongroupcontrolmenucontroller.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "polygongroupcontrolmenucontroller.h"
#include <graphicsscene3dview.h>
#include <polygongroup.h>
#include <polygonobject.h>
#include <pointobject.h>
PolygonGroupControlMenuController::PolygonGroupControlMenuController(QObject *parent)
: QmlComponentController(parent)
, m_polygonListModel(new QStandardItemModel)
{
auto roleNames = m_polygonListModel->roleNames();
roleNames[Qt::UserRole+1] = "color";
m_polygonListModel->setItemRoleNames(roleNames);
}
void PolygonGroupControlMenuController::onVisibilityCheckBoxCheckedChanged(bool checked)
{
if(!m_graphicsSceneView)
return;
auto polygonGroup = m_graphicsSceneView->polygonGroup();
QMetaObject::invokeMethod(reinterpret_cast <QObject*>(polygonGroup.get()), "setVisible", Q_ARG(bool, checked));
}
void PolygonGroupControlMenuController::onPolygonListItemRemoveButtonClicked(const QModelIndex &index)
{
if(!index.isValid())
return;
if(!m_graphicsSceneView)
return;
auto polygonGroup = m_graphicsSceneView->polygonGroup();
if(index.parent() == m_polygonListModel->invisibleRootItem()->index()){
QMetaObject::invokeMethod(reinterpret_cast <QObject*>(polygonGroup.get()), "removePolygonAt", Q_ARG(int, index.row()));
}else{
auto polygon = polygonGroup->at(index.parent().row());
QMetaObject::invokeMethod(reinterpret_cast <QObject*>(polygon.get()), "removeAt", Q_ARG(int, index.row()));
}
m_polygonListModel->removeRows(index.row(), 1, index.parent());
}
void PolygonGroupControlMenuController::onPointCoordSpinBoxValueChanged(QVector3D coord, const QModelIndex &index)
{
if(!m_graphicsSceneView)
return;
if(!index.isValid() || !index.parent().isValid())
return;
auto polygonGroup = m_graphicsSceneView->polygonGroup();
auto polygon = polygonGroup->at(index.parent().row());
auto point = polygon->at(index.row());
auto item = m_polygonListModel->itemFromIndex(index);
item->setData(QString("x: %1, y: %2, z: %3")
.arg(coord.x())
.arg(coord.y())
.arg(coord.z()),
Qt::DisplayRole);
QMetaObject::invokeMethod(point.get(),
"setPosition",
Q_ARG(QVector3D, coord));
}
void PolygonGroupControlMenuController::onAddPolygonButtonClicked()
{
if(!m_graphicsSceneView)
return;
auto polygonGroup = m_graphicsSceneView->polygonGroup();
auto polygon = std::make_shared<PolygonObject>();
auto item = new QStandardItem("Polygon");
item->setData(polygon->color(), Qt::UserRole + 1);
m_polygonListModel->invisibleRootItem()->setChild(m_polygonListModel->rowCount(), item);
QMetaObject::invokeMethod(polygonGroup.get(), "addPolygon", Q_ARG(std::shared_ptr<PolygonObject>, polygon));
}
void PolygonGroupControlMenuController::onAddPointButtonClicked(const QModelIndex &index)
{
if(!m_graphicsSceneView)
return;
if(!index.isValid() || index.parent().isValid())
return;
auto polygonGroup = m_graphicsSceneView->polygonGroup();
auto polygon = polygonGroup->at(index.row());
auto point = std::make_shared<PointObject>();
auto item = m_polygonListModel->itemFromIndex(index);
item->setChild(item->rowCount(), new QStandardItem(QString("x: %1, y: %2, z: %3")
.arg(point->x())
.arg(point->y())
.arg(point->z())));
QMetaObject::invokeMethod(polygon.get(), "append", Q_ARG(std::shared_ptr<PointObject>, point));
}
void PolygonGroupControlMenuController::onPolygonColorDialogAccepted(QColor color, const QModelIndex& index)
{
if(!m_graphicsSceneView)
return;
if(!index.isValid() || index.parent().isValid())
return;
auto polygonGroup = m_graphicsSceneView->polygonGroup();
auto polygon = polygonGroup->at(index.row());
auto item = m_polygonListModel->itemFromIndex(index);
item->setData(color, Qt::UserRole + 1);
QMetaObject::invokeMethod(polygon.get(), "setColor", Q_ARG(QColor, color));
}
void PolygonGroupControlMenuController::setGraphicsSceneView(GraphicsScene3dView *sceneView)
{
m_graphicsSceneView = sceneView;
}
QVector3D PolygonGroupControlMenuController::getPointCoord(const QModelIndex &pointIndex)
{
if(!m_graphicsSceneView)
return {};
if(!pointIndex.isValid() || !pointIndex.parent().isValid())
return {};
auto polygonGroup = m_graphicsSceneView->polygonGroup();
auto polygon = polygonGroup->at(pointIndex.parent().row());
return {}/*polygon->at(pointIndex.row())*/;
}
PointObject *PolygonGroupControlMenuController::pointAt(const QModelIndex &pointIndex) const
{
if(!m_graphicsSceneView)
return nullptr;
if(!pointIndex.isValid() || !pointIndex.parent().isValid())
return nullptr;
auto polygonGroup = m_graphicsSceneView->polygonGroup();
auto polygon = polygonGroup->at(pointIndex.parent().row());
return polygon->at(pointIndex.row()).get();
}
QStandardItemModel *PolygonGroupControlMenuController::polygonListModel() const
{
return m_polygonListModel.get();
}
PolygonGroup *PolygonGroupControlMenuController::polygonGroup() const
{
if(!m_graphicsSceneView)
return nullptr;
return m_graphicsSceneView->polygonGroup().get();
}
void PolygonGroupControlMenuController::findComponent()
{}