src/widgets/vertexobjecteditor.cpp

Sun, 18 Mar 2018 12:33:29 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 18 Mar 2018 12:33:29 +0200
changeset 1298
dbc8bb2a4d84
parent 1297
389516787a4c
child 1302
e14d7826373a
permissions
-rw-r--r--

fixed infinite recursion and integrated the subfilereference editor

1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include <QDoubleSpinBox>
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "../linetypes/modelobject.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include "vertexobjecteditor.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include "ui_vertexobjecteditor.h"
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 #include "../dialogs/colorselector.h"
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1296
diff changeset
6 #include "../guiutilities.h"
1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) :
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 QDialog {parent},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 object {object},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 ui {*new Ui_VertexObjectEditor},
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 vertexGrid {new QGridLayout}
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 this->ui.setupUi(this);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 this->ui.verticesContainer->setLayout(this->vertexGrid);
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1296
diff changeset
16 this->currentColor = this->object->color();
1298
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
17 setColorButton(this->ui.color, this->currentColor);
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
18
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
19 connect(
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
20 this->ui.color,
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
21 &QPushButton::clicked,
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
22 [&]()
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
23 {
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
24 if (ColorSelector::selectColor(this, this->currentColor, this->currentColor))
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
25 ::setColorButton(this->ui.color, this->currentColor);
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
26 }
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
27 );
1296
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 QDoubleSpinBox* spinbox = new QDoubleSpinBox;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 spinbox->setMinimum(-1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 spinbox->setMaximum(1e6);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 spinbox->setDecimals(5);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 this->vertexGrid->addWidget(spinbox, i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 spinbox->setValue(this->object->vertex(i)[axis]);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 VertexObjectEditor::~VertexObjectEditor()
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 delete &this->ui;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 return qobject_cast<QDoubleSpinBox*>(widget);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 void VertexObjectEditor::accept()
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 for (int i : range(0, 1, object->numVertices() - 1))
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 Vertex vertex;
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 for (Axis axis : {X, Y, Z})
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 {
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 QDoubleSpinBox* spinbox = this->spinboxAt(i, axis);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 if (spinbox)
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 vertex.setCoordinate(axis, spinbox->value());
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 this->object->setVertex(i, vertex);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 }
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 this->object->setColor(this->currentColor);
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 QDialog::accept();
aee618d087ff Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 }

mercurial