src/dialogs/subfilereferenceeditor.cpp

Sun, 18 Mar 2018 12:00:39 +0200

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

added subfile reference editor

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"
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 SubfileReferenceEditor::SubfileReferenceEditor(LDSubfileReference* reference, QWidget* parent) :
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 QDialog {parent},
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 reference {reference},
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 ui {*new Ui::SubfileReferenceEditor}
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 this->ui.setupUi(this);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 this->ui.referenceName->setText(reference->referenceName());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 this->color = reference->color();
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 this->ui.positionX->setValue(reference->position().x());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 this->ui.positionY->setValue(reference->position().y());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 this->ui.positionZ->setValue(reference->position().z());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 ::setupColorButton(parent, this->ui.colorButton, &this->color);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 for (int i : {0, 1, 2})
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 for (int j : {0, 1, 2})
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr;
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 spinbox->setValue(reference->transformationMatrix()(i, j));
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 connect(
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 this->ui.primitivesTreeView,
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 &QTreeView::clicked,
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 [&](const QModelIndex& index)
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 QAbstractItemModel* model = this->ui.primitivesTreeView->model();
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 QVariant primitiveName = model->data(index, PrimitiveManager::PrimitiveNameRole);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 if (primitiveName.isValid())
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 this->ui.referenceName->setText(primitiveName.toString());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 );
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 void SubfileReferenceEditor::accept()
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 this->reference->setReferenceName(this->ui.referenceName->text());
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 Matrix transformationMatrix;
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 for (int i : {0, 1, 2})
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 for (int j : {0, 1, 2})
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 QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr;
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 transformationMatrix(i, j) = spinbox->value();
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 }
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 this->reference->setTransformationMatrix(transformationMatrix);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 this->reference->setPosition({
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 this->ui.positionX->value(),
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 this->ui.positionY->value(),
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 this->ui.positionZ->value()
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 this->reference->setColor(this->color);
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 QDialog::accept();
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 }
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 void SubfileReferenceEditor::setPrimitivesTree(PrimitiveManager* primitives)
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 this->ui.primitivesTreeView->setModel(primitives);
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 SubfileReferenceEditor::~SubfileReferenceEditor()
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 delete &this->ui;
389516787a4c added subfile reference editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 }

mercurial