fix some issues like subfile references not showing up properly

Mon, 04 Jul 2022 00:19:18 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 04 Jul 2022 00:19:18 +0300
changeset 329
6d75fa09cc0c
parent 328
3ea38fd469ca
child 330
edb6c09cdd3c

fix some issues like subfile references not showing up properly

src/documentmanager.cpp file | annotate | diff | comparison | revisions
src/gl/partrenderer.cpp file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/model.cpp file | annotate | diff | comparison | revisions
--- a/src/documentmanager.cpp	Sun Jul 03 23:54:22 2022 +0300
+++ b/src/documentmanager.cpp	Mon Jul 04 00:19:18 2022 +0300
@@ -335,6 +335,7 @@
 		QObject::connect(model, &Model::dataChanged, modelModified);
 		QObject::connect(model, &Model::rowsInserted, modelModified);
 		QObject::connect(model, &Model::rowsRemoved, modelModified);
+		QObject::connect(model, &Model::modelReset, modelModified);
 	}
 }
 
@@ -403,12 +404,17 @@
 	std::map<QString, QString>& missing)
 {
 	bool repeat = true;
+	const auto olddeps = info->dependencies;
 	info->dependencies.clear();
 	while (repeat) {
 		repeat = false;
 		const std::set<Dependency> dependencies = resolveReferencePaths(info, libraries);
 		for (const Dependency& dep : dependencies) {
-			if (not info->dependencies.contains(dep.name) and not missing.contains(dep.path)) {
+			const ModelId* const idp = findInMap(olddeps, dep.name);
+			if (idp != nullptr) {
+				info->dependencies[dep.name] = *idp;
+			}
+			else if (not info->dependencies.contains(dep.name) and not missing.contains(dep.path)) {
 				QString loadErrorString;
 				QTextStream localErrorStream{&loadErrorString};
 				const std::optional<ModelId> modelIdOpt = documents->openModel(
@@ -417,7 +423,7 @@
 					OpenType::AutomaticallyOpened);
 				if (not modelIdOpt.has_value()) {
 					const QString& errorMessage = QObject::tr("could not load '%1': %2")
-						.arg(dep.path, loadErrorString);
+					.arg(dep.path, loadErrorString);
 					missing[dep.path] = errorMessage;
 				}
 				else {
--- a/src/gl/partrenderer.cpp	Sun Jul 03 23:54:22 2022 +0300
+++ b/src/gl/partrenderer.cpp	Mon Jul 04 00:19:18 2022 +0300
@@ -49,10 +49,11 @@
 	QSurfaceFormat surfaceFormat;
 	surfaceFormat.setSamples(8);
 	this->setFormat(surfaceFormat);
-	connect(model, &Model::rowsInserted, [&]{
-		this->needBuild = true;
-	});
-	connect(model, &Model::rowsRemoved, [&]{ this->needBuild = true; });
+	const auto setNeedBuild = [&]{this->needBuild = true;};
+	connect(model, &Model::rowsInserted, setNeedBuild);
+	connect(model, &Model::rowsRemoved, setNeedBuild);
+	connect(model, &Model::dataChanged, setNeedBuild);
+	connect(model, &Model::modelReset, setNeedBuild);
 	const auto updateLayerMvpMatrix = [this]{
 		const glm::mat4 newMvpMatrix = this->projectionMatrix * this->viewMatrix * this->modelMatrix;
 		for (RenderLayer* layer : this->activeRenderLayers) {
--- a/src/main.cpp	Sun Jul 03 23:54:22 2022 +0300
+++ b/src/main.cpp	Mon Jul 04 00:19:18 2022 +0300
@@ -333,6 +333,15 @@
 	}
 }
 
+static QFont monospace()
+{
+	QFont font{"Monospace"};
+	font.setStyleHint(QFont::TypeWriter);
+	font.setPointSize(10);
+	font.setFixedPitch(true);
+	return font;
+}
+
 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b)
 {
 	return a.row() < b.row();
@@ -429,11 +438,6 @@
 	MessageLog messageLog;
 	Signal settingsChanged;
 	ui.setupUi(&mainWindow);
-	QFont monospace{"Monospace"};
-	monospace.setStyleHint(QFont::TypeWriter);
-	monospace.setPointSize(10);
-	monospace.setFixedPitch(true);
-	ui.modelEdit->setFont(monospace);
 	ToolWidgets toolWidgets{
 		.circleToolOptions = new CircleToolOptionsWidget{&mainWindow},
 		.objectEditor = new ObjectEditor{&mainWindow},
@@ -526,6 +530,7 @@
 			::save(*model, &stream);
 			data->textbuffer = std::make_unique<QTextDocument>();
 			data->textbuffer->setPlainText(modeltext);
+			data->textbuffer->setDefaultFont(monospace());
 			data->textbuffer->setDocumentLayout(new QPlainTextDocumentLayout(data->textbuffer.get()));
 			data->textcursor = std::make_unique<QTextCursor>(data->textbuffer.get());
 			documents.setModelPayload(modelId, data);
@@ -776,6 +781,7 @@
 				QTextStream stream{&text};
 				Parser parser(stream);
 				parser.parseBody(*data->model);
+				documents.loadDependenciesForAllModels(libraries);
 				data->canvas->update();
 			}
 		});
--- a/src/model.cpp	Sun Jul 03 23:54:22 2022 +0300
+++ b/src/model.cpp	Mon Jul 04 00:19:18 2022 +0300
@@ -278,6 +278,8 @@
 {
 	this->beginResetModel();
 	this->body.clear();
+	this->positions.clear();
+	this->runningId = {1};
 	this->endResetModel();
 }
 

mercurial