src/dialogs/subfilereferenceeditor.cpp

Sat, 26 May 2018 17:28:15 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 26 May 2018 17:28:15 +0300
changeset 1389
3fb8ad4d27b1
parent 1387
6393b6020c62
child 1391
5fa4bf1fc781
permissions
-rw-r--r--

refactored signal blocking

1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
1 /*
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
2 * LDForge: LDraw parts authoring CAD
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
4 *
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
5 * This program is free software: you can redistribute it and/or modify
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
6 * it under the terms of the GNU General Public License as published by
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
8 * (at your option) any later version.
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
9 *
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
10 * This program is distributed in the hope that it will be useful,
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
13 * GNU General Public License for more details.
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
14 *
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
15 * You should have received a copy of the GNU General Public License
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
17 */
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
18
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "subfilereferenceeditor.h"
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include "ui_subfilereferenceeditor.h"
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include "../linetypes/modelobject.h"
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 #include "../primitives.h"
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 #include "../guiutilities.h"
1298
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
24 #include "../dialogs/colorselector.h"
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 SubfileReferenceEditor::SubfileReferenceEditor(LDSubfileReference* reference, QWidget* parent) :
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 QDialog {parent},
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 reference {reference},
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 ui {*new Ui::SubfileReferenceEditor}
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 this->ui.setupUi(this);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 this->ui.referenceName->setText(reference->referenceName());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 this->color = reference->color();
1299
b692088dc1a6 fixed color handling
Teemu Piippo <teemu@hecknology.net>
parents: 1298
diff changeset
34 ::setColorButton(this->ui.colorButton, this->color);
1313
4baed9f54de3 reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents: 1299
diff changeset
35 this->ui.positionX->setValue(reference->position().x);
4baed9f54de3 reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents: 1299
diff changeset
36 this->ui.positionY->setValue(reference->position().y);
4baed9f54de3 reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents: 1299
diff changeset
37 this->ui.positionZ->setValue(reference->position().z);
1298
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
38 connect(
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
39 this->ui.colorButton,
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
40 &QPushButton::clicked,
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
41 [&]()
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
42 {
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
43 if (ColorSelector::selectColor(this, this->color, this->color))
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
44 ::setColorButton(this->ui.colorButton, this->color);
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
45 }
dbc8bb2a4d84 fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents: 1297
diff changeset
46 );
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 for (int i : {0, 1, 2})
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 for (int j : {0, 1, 2})
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr;
1389
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
52 withSignalsBlocked(spinbox, [&]()
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
53 {
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
54 spinbox->setValue(reference->transformationMatrix()(i, j));
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
55 });
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
56 connect(
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
57 spinbox,
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
58 qOverload<double>(&QDoubleSpinBox::valueChanged),
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
59 this,
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
60 &SubfileReferenceEditor::matrixChanged
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
61 );
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 connect(
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 this->ui.primitivesTreeView,
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 &QTreeView::clicked,
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 [&](const QModelIndex& index)
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 QAbstractItemModel* model = this->ui.primitivesTreeView->model();
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 QVariant primitiveName = model->data(index, PrimitiveManager::PrimitiveNameRole);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 if (primitiveName.isValid())
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 this->ui.referenceName->setText(primitiveName.toString());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 );
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
75
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
76 for (QDoubleSpinBox* spinbox : {this->ui.scalingX, this->ui.scalingY, this->ui.scalingZ})
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
77 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
78 connect(
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
79 spinbox,
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
80 qOverload<double>(&QDoubleSpinBox::valueChanged),
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
81 this,
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
82 &SubfileReferenceEditor::scalingChanged
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
83 );
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
84 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
85
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
86 // Fill in the initial scaling values
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
87 for (int column : {0, 1, 2})
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
88 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
89 QDoubleSpinBox* spinbox = this->vectorElement(column);
1389
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
90 withSignalsBlocked(spinbox, [&]()
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
91 {
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
92 spinbox->setValue(this->matrixScaling(column));
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
93 });
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
94 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
95 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
96
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
97 SubfileReferenceEditor::~SubfileReferenceEditor()
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
98 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
99 delete &this->ui;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
100 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
101
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
102 /*
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
103 * Returns a spinbox from the matrix grid at position (row, column).
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
104 * Row and column must be within [0, 2].
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
105 */
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
106 QDoubleSpinBox* SubfileReferenceEditor::matrixCell(int row, int column) const
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
107 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
108 if (qBound(0, row, 2) != row or qBound(0, column, 2) != column)
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
109 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
110 throw std::out_of_range {"bad row and column values"};
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
111 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
112 else
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
113 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
114 QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(row, column);
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
115 return item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
116 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
117 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
118
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
119 /*
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
120 * Returns a spinbox for the vector element at the given position
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
121 * Index must be within [0, 2]
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
122 */
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
123 QDoubleSpinBox* SubfileReferenceEditor::vectorElement(int index)
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
124 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
125 switch (index)
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
126 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
127 case 0:
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
128 return this->ui.scalingX;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
129
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
130 case 1:
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
131 return this->ui.scalingY;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
132
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
133 case 2:
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
134 return this->ui.scalingZ;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
135
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
136 default:
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
137 throw std::out_of_range {"bad index"};
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
138 }
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
139 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141 void SubfileReferenceEditor::accept()
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143 this->reference->setReferenceName(this->ui.referenceName->text());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
144 Matrix transformationMatrix;
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 for (int i : {0, 1, 2})
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 for (int j : {0, 1, 2})
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147 {
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
148 transformationMatrix(i, j) = this->matrixCell(i, j)->value();
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
149 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 this->reference->setTransformationMatrix(transformationMatrix);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151 this->reference->setPosition({
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
152 this->ui.positionX->value(),
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
153 this->ui.positionY->value(),
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
154 this->ui.positionZ->value()
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
155 });
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
156 this->reference->setColor(this->color);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
157 QDialog::accept();
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
158 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
159
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160 void SubfileReferenceEditor::setPrimitivesTree(PrimitiveManager* primitives)
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
161 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162 this->ui.primitivesTreeView->setModel(primitives);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
163 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
164
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
165 double SubfileReferenceEditor::matrixScaling(int column) const
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
166 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
167 return sqrt(
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
168 pow(this->matrixCell(0, column)->value(), 2) +
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
169 pow(this->matrixCell(1, column)->value(), 2) +
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
170 pow(this->matrixCell(2, column)->value(), 2)
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
171 );
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
172 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
173
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
174 /*
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
175 * Updates the appropriate matrix column when a scaling vector element is changed.
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
176 */
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
177 void SubfileReferenceEditor::scalingChanged()
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
178 {
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
179 for (int column : {0, 1, 2})
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
180 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
181 if (this->sender() == this->vectorElement(column))
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
182 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
183 double oldScaling = this->matrixScaling(column);
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
184 double newScaling = static_cast<QDoubleSpinBox*>(this->sender())->value();
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
185
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
186 if (not qFuzzyCompare(newScaling, 0.0))
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
187 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
188 for (int row : {0, 1, 2})
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
189 {
1387
6393b6020c62 added a doublespinbox variant that uses "." as the decimal point and omits trailing zeros
Teemu Piippo <teemu@hecknology.net>
parents: 1386
diff changeset
190 double cellValue = this->matrixCell(row, column)->value();
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
191 cellValue *= newScaling / oldScaling;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
192 QDoubleSpinBox* cellWidget = this->matrixCell(row, column);
1389
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
193 withSignalsBlocked(cellWidget, [&]()
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
194 {
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
195 cellWidget->setValue(cellValue);
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
196 });
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
197 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
198 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
199
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
200 break;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
201 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
202 }
1297
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
203 }
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
204
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
205 /*
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
206 * Finds the position for the given cell widget.
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
207 */
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
208 QPair<int, int> SubfileReferenceEditor::cellPosition(QDoubleSpinBox* cellWidget)
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
209 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
210 for (int row : {0, 1, 2})
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
211 for (int column : {0, 1, 2})
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
212 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
213 if (this->matrixCell(row, column) == cellWidget)
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
214 return {row, column};
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
215 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
216
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
217 throw std::out_of_range {"widget is not in the matrix"};
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
218 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
219
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
220 /*
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
221 * Updates the appropriate scaling vector element when a matrix cell is changed.
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
222 */
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
223 void SubfileReferenceEditor::matrixChanged()
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
224 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
225 QDoubleSpinBox* cellWidget = static_cast<QDoubleSpinBox*>(this->sender());
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
226
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
227 try
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
228 {
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
229 int column = this->cellPosition(cellWidget).second;
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
230 QDoubleSpinBox* spinbox = this->vectorElement(column);
1389
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
231 withSignalsBlocked(spinbox, [&]()
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
232 {
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
233 spinbox->setValue(this->matrixScaling(column));
3fb8ad4d27b1 refactored signal blocking
Teemu Piippo <teemu@hecknology.net>
parents: 1387
diff changeset
234 });
1386
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
235 }
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
236 catch (const std::out_of_range&) {}
c59dac18b06b added scaling vector editing into the subfile editing dialog
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
237 }

mercurial