Fri, 30 Mar 2018 14:30:51 +0300
fix warnings
1326 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2018 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
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 | 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; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | spinbox->setValue(reference->transformationMatrix()(i, j)); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | connect( |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | this->ui.primitivesTreeView, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | &QTreeView::clicked, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | [&](const QModelIndex& index) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | QAbstractItemModel* model = this->ui.primitivesTreeView->model(); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | QVariant primitiveName = model->data(index, PrimitiveManager::PrimitiveNameRole); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | if (primitiveName.isValid()) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | this->ui.referenceName->setText(primitiveName.toString()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | ); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | } |
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 | void SubfileReferenceEditor::accept() |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | this->reference->setReferenceName(this->ui.referenceName->text()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | Matrix transformationMatrix; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | for (int i : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | for (int j : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | transformationMatrix(i, j) = spinbox->value(); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | this->reference->setTransformationMatrix(transformationMatrix); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | this->reference->setPosition({ |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | this->ui.positionX->value(), |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | this->ui.positionY->value(), |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | this->ui.positionZ->value() |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | }); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | this->reference->setColor(this->color); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | QDialog::accept(); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
88 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | void SubfileReferenceEditor::setPrimitivesTree(PrimitiveManager* primitives) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
91 | this->ui.primitivesTreeView->setModel(primitives); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
92 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
94 | SubfileReferenceEditor::~SubfileReferenceEditor() |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
95 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | delete &this->ui; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | } |