|
1 #include "subfilereferenceeditor.h" |
|
2 #include "ui_subfilereferenceeditor.h" |
|
3 #include "../linetypes/modelobject.h" |
|
4 #include "../primitives.h" |
|
5 #include "../guiutilities.h" |
|
6 |
|
7 SubfileReferenceEditor::SubfileReferenceEditor(LDSubfileReference* reference, QWidget* parent) : |
|
8 QDialog {parent}, |
|
9 reference {reference}, |
|
10 ui {*new Ui::SubfileReferenceEditor} |
|
11 { |
|
12 this->ui.setupUi(this); |
|
13 this->ui.referenceName->setText(reference->referenceName()); |
|
14 this->color = reference->color(); |
|
15 this->ui.positionX->setValue(reference->position().x()); |
|
16 this->ui.positionY->setValue(reference->position().y()); |
|
17 this->ui.positionZ->setValue(reference->position().z()); |
|
18 ::setupColorButton(parent, this->ui.colorButton, &this->color); |
|
19 for (int i : {0, 1, 2}) |
|
20 for (int j : {0, 1, 2}) |
|
21 { |
|
22 QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); |
|
23 QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
|
24 spinbox->setValue(reference->transformationMatrix()(i, j)); |
|
25 } |
|
26 connect( |
|
27 this->ui.primitivesTreeView, |
|
28 &QTreeView::clicked, |
|
29 [&](const QModelIndex& index) |
|
30 { |
|
31 QAbstractItemModel* model = this->ui.primitivesTreeView->model(); |
|
32 QVariant primitiveName = model->data(index, PrimitiveManager::PrimitiveNameRole); |
|
33 |
|
34 if (primitiveName.isValid()) |
|
35 this->ui.referenceName->setText(primitiveName.toString()); |
|
36 } |
|
37 ); |
|
38 } |
|
39 |
|
40 void SubfileReferenceEditor::accept() |
|
41 { |
|
42 this->reference->setReferenceName(this->ui.referenceName->text()); |
|
43 Matrix transformationMatrix; |
|
44 for (int i : {0, 1, 2}) |
|
45 for (int j : {0, 1, 2}) |
|
46 { |
|
47 QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); |
|
48 QDoubleSpinBox* spinbox = item ? qobject_cast<QDoubleSpinBox*>(item->widget()) : nullptr; |
|
49 transformationMatrix(i, j) = spinbox->value(); |
|
50 } |
|
51 this->reference->setTransformationMatrix(transformationMatrix); |
|
52 this->reference->setPosition({ |
|
53 this->ui.positionX->value(), |
|
54 this->ui.positionY->value(), |
|
55 this->ui.positionZ->value() |
|
56 }); |
|
57 this->reference->setColor(this->color); |
|
58 QDialog::accept(); |
|
59 } |
|
60 |
|
61 void SubfileReferenceEditor::setPrimitivesTree(PrimitiveManager* primitives) |
|
62 { |
|
63 this->ui.primitivesTreeView->setModel(primitives); |
|
64 } |
|
65 |
|
66 SubfileReferenceEditor::~SubfileReferenceEditor() |
|
67 { |
|
68 delete &this->ui; |
|
69 } |