Fri, 23 Mar 2018 17:14:46 +0200
ported qOverload to drop minimum Qt requirement down to 5.5
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include "subfilereferenceeditor.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include "ui_subfilereferenceeditor.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | #include "../linetypes/modelobject.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | #include "../primitives.h" |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | #include "../guiutilities.h" |
1298
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
6 | #include "../dialogs/colorselector.h" |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | SubfileReferenceEditor::SubfileReferenceEditor(LDSubfileReference* reference, QWidget* parent) : |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | QDialog {parent}, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | reference {reference}, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | ui {*new Ui::SubfileReferenceEditor} |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | this->ui.setupUi(this); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | this->ui.referenceName->setText(reference->referenceName()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | this->color = reference->color(); |
1299 | 16 | ::setColorButton(this->ui.colorButton, this->color); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | this->ui.positionX->setValue(reference->position().x()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | this->ui.positionY->setValue(reference->position().y()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | 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
|
20 | connect( |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
21 | this->ui.colorButton, |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
22 | &QPushButton::clicked, |
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 | { |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
25 | 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
|
26 | ::setColorButton(this->ui.colorButton, this->color); |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
27 | } |
dbc8bb2a4d84
fixed infinite recursion and integrated the subfilereference editor
Teemu Piippo <teemu@hecknology.net>
parents:
1297
diff
changeset
|
28 | ); |
1297
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | for (int i : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | for (int j : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | spinbox->setValue(reference->transformationMatrix()(i, j)); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | connect( |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | this->ui.primitivesTreeView, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | &QTreeView::clicked, |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | [&](const QModelIndex& index) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | QAbstractItemModel* model = this->ui.primitivesTreeView->model(); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | QVariant primitiveName = model->data(index, PrimitiveManager::PrimitiveNameRole); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | if (primitiveName.isValid()) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | this->ui.referenceName->setText(primitiveName.toString()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | ); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | } |
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 | void SubfileReferenceEditor::accept() |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | this->reference->setReferenceName(this->ui.referenceName->text()); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | Matrix transformationMatrix; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | for (int i : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | for (int j : {0, 1, 2}) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | transformationMatrix(i, j) = spinbox->value(); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | } |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | this->reference->setTransformationMatrix(transformationMatrix); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | this->reference->setPosition({ |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | this->ui.positionX->value(), |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | this->ui.positionY->value(), |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | this->ui.positionZ->value() |
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 | this->reference->setColor(this->color); |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | QDialog::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 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | void SubfileReferenceEditor::setPrimitivesTree(PrimitiveManager* primitives) |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | this->ui.primitivesTreeView->setModel(primitives); |
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 | |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | SubfileReferenceEditor::~SubfileReferenceEditor() |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | { |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | delete &this->ui; |
389516787a4c
added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | } |