src/document.cpp

changeset 81
62373840e33a
parent 73
97df974b5ed5
child 86
4bec0525ef1b
equal deleted inserted replaced
80:764381756899 81:62373840e33a
29 QWidget{parent}, 29 QWidget{parent},
30 model{model}, 30 model{model},
31 documents{documents}, 31 documents{documents},
32 colorTable{colorTable}, 32 colorTable{colorTable},
33 renderer{new Canvas{model, documents, colorTable, this}}, 33 renderer{new Canvas{model, documents, colorTable, this}},
34 ui{*new Ui::Document} 34 ui{*new Ui::Document},
35 objectEditor{model, ldraw::NULL_ID, this}
35 { 36 {
36 this->ui.setupUi(this); 37 this->ui.setupUi(this);
37 this->ui.listView->setModel(model); 38 this->ui.listView->setModel(model);
38 QVBoxLayout* layout = new QVBoxLayout; 39 this->ui.viewportFrame->setLayout(new QVBoxLayout{this->ui.listView});
39 layout->addWidget(this->renderer); 40 this->ui.viewportFrame->layout()->addWidget(this->renderer);
40 this->ui.viewportFrame->setLayout(layout); 41 this->ui.objectEditorFrame->setLayout(new QVBoxLayout{this->ui.objectEditorFrame});
42 this->ui.objectEditorFrame->layout()->addWidget(&this->objectEditor);
41 this->setMouseTracking(true); 43 this->setMouseTracking(true);
42 connect(this->ui.splitter, &QSplitter::splitterMoved, this, &Document::splitterChanged); 44 connect(this->ui.splitter, &QSplitter::splitterMoved, this, &Document::splitterChanged);
43 connect(this->renderer, &Canvas::newStatusText, this, &Document::newStatusText); 45 connect(this->renderer, &Canvas::newStatusText, this, &Document::newStatusText);
44 connect(this->renderer, &Canvas::selectionChanged, [&](const QSet<ldraw::id_t>& newSelection) 46 connect(this->renderer, &Canvas::selectionChanged, [&](const QSet<ldraw::id_t>& newSelection)
45 { 47 {
51 if (index != QModelIndex{}) 53 if (index != QModelIndex{})
52 { 54 {
53 selection.select(index, index); 55 selection.select(index, index);
54 } 56 }
55 } 57 }
58 QSignalBlocker blocker{this};
56 selectionModel->select(selection, QItemSelectionModel::ClearAndSelect); 59 selectionModel->select(selection, QItemSelectionModel::ClearAndSelect);
60 this->selectionChanged(newSelection);
57 }); 61 });
58 connect(this->ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged, 62 connect(this->ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged,
59 [&](const QItemSelection& selected, const QItemSelection& deselected) 63 [&](const QItemSelection& selected, const QItemSelection& deselected)
60 { 64 {
61 auto resolveIndex = [this](const QModelIndex& index){ return this->model->resolve(index); }; 65 auto resolveIndex = [this](const QModelIndex& index){ return this->model->resolve(index); };
62 auto resolve = [resolveIndex](const QItemSelection& selection) 66 auto resolve = [resolveIndex](const QItemSelection& selection)
63 { 67 {
64 return fn::map<QSet<ldraw::id_t>>(selection.indexes(), resolveIndex); 68 return fn::map<QSet<ldraw::id_t>>(selection.indexes(), resolveIndex);
65 }; 69 };
66 this->renderer->handleSelectionChange(resolve(selected), resolve(deselected)); 70 this->renderer->handleSelectionChange(resolve(selected), resolve(deselected));
71 this->selectionChanged(resolve(this->ui.listView->selectionModel()->selection()));
67 }); 72 });
68 } 73 }
69 74
70 Document::~Document() 75 Document::~Document()
71 { 76 {
84 89
85 void Document::setRenderPreferences(const gl::RenderPreferences& newPreferences) 90 void Document::setRenderPreferences(const gl::RenderPreferences& newPreferences)
86 { 91 {
87 this->renderer->setRenderPreferences(newPreferences); 92 this->renderer->setRenderPreferences(newPreferences);
88 } 93 }
94
95 void Document::selectionChanged(const QSet<ldraw::id_t>& newSelection)
96 {
97 if (newSelection.size() == 1)
98 {
99 this->objectEditor.setObjectId(*newSelection.begin());
100 }
101 else
102 {
103 this->objectEditor.setObjectId(ldraw::NULL_ID);
104 }
105 }

mercurial