src/document.cpp

changeset 81
62373840e33a
parent 73
97df974b5ed5
child 86
4bec0525ef1b
--- a/src/document.cpp	Wed Mar 11 19:05:34 2020 +0200
+++ b/src/document.cpp	Tue Mar 17 23:13:29 2020 +0200
@@ -31,13 +31,15 @@
 	documents{documents},
 	colorTable{colorTable},
 	renderer{new Canvas{model, documents, colorTable, this}},
-	ui{*new Ui::Document}
+	ui{*new Ui::Document},
+	objectEditor{model, ldraw::NULL_ID, this}
 {
 	this->ui.setupUi(this);
 	this->ui.listView->setModel(model);
-	QVBoxLayout* layout = new QVBoxLayout;
-	layout->addWidget(this->renderer);
-	this->ui.viewportFrame->setLayout(layout);
+	this->ui.viewportFrame->setLayout(new QVBoxLayout{this->ui.listView});
+	this->ui.viewportFrame->layout()->addWidget(this->renderer);
+	this->ui.objectEditorFrame->setLayout(new QVBoxLayout{this->ui.objectEditorFrame});
+	this->ui.objectEditorFrame->layout()->addWidget(&this->objectEditor);
 	this->setMouseTracking(true);
 	connect(this->ui.splitter, &QSplitter::splitterMoved, this, &Document::splitterChanged);
 	connect(this->renderer, &Canvas::newStatusText, this, &Document::newStatusText);
@@ -53,7 +55,9 @@
 				selection.select(index, index);
 			}
 		}
+		QSignalBlocker blocker{this};
 		selectionModel->select(selection, QItemSelectionModel::ClearAndSelect);
+		this->selectionChanged(newSelection);
 	});
 	connect(this->ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged,
 		[&](const QItemSelection& selected, const QItemSelection& deselected)
@@ -64,6 +68,7 @@
 			return fn::map<QSet<ldraw::id_t>>(selection.indexes(), resolveIndex);
 		};
 		this->renderer->handleSelectionChange(resolve(selected), resolve(deselected));
+		this->selectionChanged(resolve(this->ui.listView->selectionModel()->selection()));
 	});
 }
 
@@ -86,3 +91,15 @@
 {
 	this->renderer->setRenderPreferences(newPreferences);
 }
+
+void Document::selectionChanged(const QSet<ldraw::id_t>& newSelection)
+{
+	if (newSelection.size() == 1)
+	{
+		this->objectEditor.setObjectId(*newSelection.begin());
+	}
+	else
+	{
+		this->objectEditor.setObjectId(ldraw::NULL_ID);
+	}
+}

mercurial