Renamed modeleditcontext.cpp -> modeleditor.cpp

Fri, 04 Mar 2022 11:40:19 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 04 Mar 2022 11:40:19 +0200
changeset 153
2f79053c2e9a
parent 152
03f8e6d42e13
child 154
47cb50cfa9ad

Renamed modeleditcontext.cpp -> modeleditor.cpp

CMakeLists.txt file | annotate | diff | comparison | revisions
src/document.cpp file | annotate | diff | comparison | revisions
src/documentmanager.cpp file | annotate | diff | comparison | revisions
src/edithistory.cpp file | annotate | diff | comparison | revisions
src/linetypes/object.cpp file | annotate | diff | comparison | revisions
src/linetypes/polygonobject.h file | annotate | diff | comparison | revisions
src/model.cpp file | annotate | diff | comparison | revisions
src/modeleditcontext.cpp file | annotate | diff | comparison | revisions
src/modeleditcontext.h file | annotate | diff | comparison | revisions
src/modeleditor.cpp file | annotate | diff | comparison | revisions
src/modeleditor.h file | annotate | diff | comparison | revisions
src/parser.h file | annotate | diff | comparison | revisions
src/tools/drawtool.cpp file | annotate | diff | comparison | revisions
src/tools/transformtool.cpp file | annotate | diff | comparison | revisions
src/ui/polygonobjecteditor.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Fri Mar 04 11:37:50 2022 +0200
+++ b/CMakeLists.txt	Fri Mar 04 11:40:19 2022 +0200
@@ -26,7 +26,7 @@
 source_group("3.2 Widgets" REGULAR_EXPRESSION "src/(ui|widgets)/.+\\.(cpp|h|ui)")
 source_group("3.1 Settings editor" REGULAR_EXPRESSION "src/settingseditor/.+\\.(cpp|h|ui)")
 source_group("3 User interface" REGULAR_EXPRESSION "src/(mainwindow|document|documentmanager|uiutilities)\\.(cpp|h|ui)")
-source_group("2 Model handling" REGULAR_EXPRESSION "src/(model|modeleditcontext|libraries|colors|parser|vertexmap|edithistory|polygoncache)\\.(cpp|h|ui)")
+source_group("2 Model handling" REGULAR_EXPRESSION "src/(model|modeleditor|libraries|colors|parser|vertexmap|edithistory|polygoncache)\\.(cpp|h|ui)")
 source_group("6 Editing tools" REGULAR_EXPRESSION "src/tools/.+\\.(cpp|h|ui)")
 
 set (LDFORGE_SOURCES
@@ -42,7 +42,7 @@
 	src/main.cpp
 	src/mainwindow.cpp
 	src/model.cpp
-	src/modeleditcontext.cpp
+	src/modeleditor.cpp
 	src/parser.cpp
 	src/polygoncache.cpp
 	src/uiutilities.cpp
@@ -97,7 +97,7 @@
 	src/mainwindow.h
 	src/maths.h
 	src/model.h
-	src/modeleditcontext.h
+	src/modeleditor.h
 	src/parser.h
 	src/polygoncache.h
 	src/ring.h
--- a/src/document.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/document.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -21,7 +21,7 @@
 #include "document.h"
 #include "ui_document.h"
 #include "model.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 #include "tools/basetool.h"
 #include "tools/drawtool.h"
 #include "tools/selecttool.h"
--- a/src/documentmanager.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/documentmanager.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -21,7 +21,7 @@
 #include <QFileInfo>
 #include <QSaveFile>
 #include "documentmanager.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 #include "linetypes/comment.h"
 #include "linetypes/subfilereference.h"
 #include "parser.h"
--- a/src/edithistory.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/edithistory.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -17,7 +17,7 @@
  */
 
 #include "edithistory.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 
 EditHistory::EditHistory()
 {
--- a/src/linetypes/object.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/linetypes/object.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -2,7 +2,7 @@
 #include <QFont>
 #include "object.h"
 #include "widgets/vec3editor.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 
 static std::int32_t getIdForNewObject()
 {
--- a/src/linetypes/polygonobject.h	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/linetypes/polygonobject.h	Fri Mar 04 11:40:19 2022 +0200
@@ -2,7 +2,7 @@
 #include "object.h"
 #include "widgets/vec3editor.h"
 #include "model.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 
 namespace ldraw
 {
--- a/src/model.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/model.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -22,7 +22,7 @@
 #include <QFont>
 #include <QSaveFile>
 #include "model.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 #include "documentmanager.h"
 
 /**
--- a/src/modeleditcontext.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- *  LDForge: LDraw parts authoring CAD
- *  Copyright (C) 2013 - 2020 Teemu Piippo
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "modeleditcontext.h"
-#include "linetypes/triangle.h"
-#include "linetypes/quadrilateral.h"
-
-ModelEditor::ModelEditor(Model& model) :
-	storedModel{model}
-{
-}
-
-ModelEditor::~ModelEditor()
-{
-	for (ldraw::id_t id : this->modifiedObjects)
-	{
-		const QModelIndex index = this->model().find(id);
-		if (index.isValid())
-		{
-			Q_EMIT this->objectModified(index.row());
-		}
-	}
-}
-
-ldraw::id_t ModelEditor::append(std::unique_ptr<ldraw::Object>&& object)
-{
-	this->storedModel.append(std::move(object));
-	Q_EMIT this->objectAdded(this->model().size() - 1);
-	return object->id;
-}
-
-void ModelEditor::remove(int position)
-{
-	this->storedModel.remove(position);
-}
-
-auto ModelEditor::setObjectProperty(
-	const ldraw::id_t id,
-	const ldraw::Property property,
-	const QVariant& value)
-	-> ldraw::Object::SetPropertyResult
-{
-	ldraw::Object* const object = this->storedModel.findObjectById(id);
-	if (object != nullptr)
-	{
-		const ldraw::Object::SetPropertyResult result = object->setProperty(ldraw::PropertyKeyValue{property, value});
-		modifiedObjects.insert(id);
-		return result;
-	}
-	else
-	{
-		return ldraw::Object::SetPropertyResult::PropertyNotHandled;
-	}
-}
-
-void ModelEditor::setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value)
-{
-	ldraw::Object* object = this->storedModel.findObjectById(id);
-	if (object != nullptr)
-	{
-		object->setProperty(ldraw::PropertyKeyValue{ldraw::pointProperty(pointId), QVariant::fromValue(value)});
-		modifiedObjects.insert(id);
-	}
-}
-
-const Model &ModelEditor::model()
-{
-	return this->storedModel;
-}
-
--- a/src/modeleditcontext.h	Fri Mar 04 11:37:50 2022 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- *  LDForge: LDraw parts authoring CAD
- *  Copyright (C) 2013 - 2020 Teemu Piippo
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-#include "model.h"
-
-/**
- * @brief Provides an interface for editing a model such that signals are emitted for each edit done.
- * User edits to models should always be done through this class.
- */
-class ModelEditor : public QObject
-{
-	Q_OBJECT
-public:
-	ModelEditor(Model& model);
-	~ModelEditor();
-	template<typename T, typename... Args>
-	ldraw::Id<T> append(Args&&... args);
-	ldraw::id_t append(std::unique_ptr<ldraw::Object>&& object);
-	template<typename T, typename... Args>
-	ldraw::Id<T> insert(int position, Args&&... args);
-	void remove(int position);
-	template<ldraw::Property property>
-	void setObjectProperty(ldraw::id_t id, const ldraw::PropertyType<property>& value);
-	auto setObjectProperty(ldraw::id_t id, ldraw::Property property, const QVariant& value)
-		-> ldraw::Object::SetPropertyResult;
-	void setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value);
-	template<typename T, typename Fn>
-	bool modifyObject(ldraw::Id<T> id, Fn&& function);
-	template<typename T, typename Fn>
-	bool modifyObjectAt(int position, Fn&& function);
-	const Model& model();
-Q_SIGNALS:
-	void objectAdded(int position);
-	void objectModified(int position);
-	void objectRemoved(ldraw::id_t id);
-private:
-	QSet<ldraw::id_t> modifiedObjects;
-	Model& storedModel;
-};
-
-template<ldraw::Property Property>
-void ModelEditor::setObjectProperty(const ldraw::id_t id, const ldraw::PropertyType<Property>& value)
-{
-	this->modifyObject(id, [&](ldraw::Object* object){
-		object->setProperty<Property>(value);
-	});
-}
-
-template<typename T, typename... Args>
-ldraw::Id<T> ModelEditor::append(Args&&... args)
-{
-	return this->storedModel.append<T>(args...);
-}
-
-template<typename T, typename... Args>
-ldraw::Id<T> ModelEditor::insert(int position, Args&&... args)
-{
-	return this->storedModel.insert<T>(position, args...);
-}
-
-template<typename T, typename Fn>
-bool ModelEditor::modifyObject(ldraw::Id<T> id, Fn&& function)
-{
-	QModelIndex index = this->model().find(id);
-	return this->modifyObjectAt<T>(index.row(), function);
-}
-
-template<typename T, typename Fn>
-bool ModelEditor::modifyObjectAt(int position, Fn&& function)
-{
-	if (position >= 0 and position < this->model().size())
-	{
-		T* object = dynamic_cast<T*>(this->storedModel[position]);
-		if (object != nullptr)
-		{
-			Q_EMIT this->objectModified(position);
-			function(object);
-			return true;
-		}
-	}
-	return false;
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/modeleditor.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -0,0 +1,85 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2020 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "modeleditor.h"
+#include "linetypes/triangle.h"
+#include "linetypes/quadrilateral.h"
+
+ModelEditor::ModelEditor(Model& model) :
+	storedModel{model}
+{
+}
+
+ModelEditor::~ModelEditor()
+{
+	for (ldraw::id_t id : this->modifiedObjects)
+	{
+		const QModelIndex index = this->model().find(id);
+		if (index.isValid())
+		{
+			Q_EMIT this->objectModified(index.row());
+		}
+	}
+}
+
+ldraw::id_t ModelEditor::append(std::unique_ptr<ldraw::Object>&& object)
+{
+	this->storedModel.append(std::move(object));
+	Q_EMIT this->objectAdded(this->model().size() - 1);
+	return object->id;
+}
+
+void ModelEditor::remove(int position)
+{
+	this->storedModel.remove(position);
+}
+
+auto ModelEditor::setObjectProperty(
+	const ldraw::id_t id,
+	const ldraw::Property property,
+	const QVariant& value)
+	-> ldraw::Object::SetPropertyResult
+{
+	ldraw::Object* const object = this->storedModel.findObjectById(id);
+	if (object != nullptr)
+	{
+		const ldraw::Object::SetPropertyResult result = object->setProperty(ldraw::PropertyKeyValue{property, value});
+		modifiedObjects.insert(id);
+		return result;
+	}
+	else
+	{
+		return ldraw::Object::SetPropertyResult::PropertyNotHandled;
+	}
+}
+
+void ModelEditor::setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value)
+{
+	ldraw::Object* object = this->storedModel.findObjectById(id);
+	if (object != nullptr)
+	{
+		object->setProperty(ldraw::PropertyKeyValue{ldraw::pointProperty(pointId), QVariant::fromValue(value)});
+		modifiedObjects.insert(id);
+	}
+}
+
+const Model &ModelEditor::model()
+{
+	return this->storedModel;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/modeleditor.h	Fri Mar 04 11:40:19 2022 +0200
@@ -0,0 +1,98 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2020 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include "model.h"
+
+/**
+ * @brief Provides an interface for editing a model such that signals are emitted for each edit done.
+ * User edits to models should always be done through this class.
+ */
+class ModelEditor : public QObject
+{
+	Q_OBJECT
+public:
+	ModelEditor(Model& model);
+	~ModelEditor();
+	template<typename T, typename... Args>
+	ldraw::Id<T> append(Args&&... args);
+	ldraw::id_t append(std::unique_ptr<ldraw::Object>&& object);
+	template<typename T, typename... Args>
+	ldraw::Id<T> insert(int position, Args&&... args);
+	void remove(int position);
+	template<ldraw::Property property>
+	void setObjectProperty(ldraw::id_t id, const ldraw::PropertyType<property>& value);
+	auto setObjectProperty(ldraw::id_t id, ldraw::Property property, const QVariant& value)
+		-> ldraw::Object::SetPropertyResult;
+	void setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value);
+	template<typename T, typename Fn>
+	bool modifyObject(ldraw::Id<T> id, Fn&& function);
+	template<typename T, typename Fn>
+	bool modifyObjectAt(int position, Fn&& function);
+	const Model& model();
+Q_SIGNALS:
+	void objectAdded(int position);
+	void objectModified(int position);
+	void objectRemoved(ldraw::id_t id);
+private:
+	QSet<ldraw::id_t> modifiedObjects;
+	Model& storedModel;
+};
+
+template<ldraw::Property Property>
+void ModelEditor::setObjectProperty(const ldraw::id_t id, const ldraw::PropertyType<Property>& value)
+{
+	this->modifyObject(id, [&](ldraw::Object* object){
+		object->setProperty<Property>(value);
+	});
+}
+
+template<typename T, typename... Args>
+ldraw::Id<T> ModelEditor::append(Args&&... args)
+{
+	return this->storedModel.append<T>(args...);
+}
+
+template<typename T, typename... Args>
+ldraw::Id<T> ModelEditor::insert(int position, Args&&... args)
+{
+	return this->storedModel.insert<T>(position, args...);
+}
+
+template<typename T, typename Fn>
+bool ModelEditor::modifyObject(ldraw::Id<T> id, Fn&& function)
+{
+	QModelIndex index = this->model().find(id);
+	return this->modifyObjectAt<T>(index.row(), function);
+}
+
+template<typename T, typename Fn>
+bool ModelEditor::modifyObjectAt(int position, Fn&& function)
+{
+	if (position >= 0 and position < this->model().size())
+	{
+		T* object = dynamic_cast<T*>(this->storedModel[position]);
+		if (object != nullptr)
+		{
+			Q_EMIT this->objectModified(position);
+			function(object);
+			return true;
+		}
+	}
+	return false;
+}
\ No newline at end of file
--- a/src/parser.h	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/parser.h	Fri Mar 04 11:40:19 2022 +0200
@@ -20,7 +20,7 @@
 #include "main.h"
 #include "linetypes/object.h"
 #include "model.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 #include "header.h"
 
 class Parser : public QObject
--- a/src/tools/drawtool.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/tools/drawtool.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -4,7 +4,7 @@
 #include "linetypes/triangle.h"
 #include "linetypes/quadrilateral.h"
 #include "drawtool.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 
 static const QBrush pointBrush = {Qt::white};
 static const QPen polygonPen = {QBrush{Qt::black}, 2.0, Qt::DashLine};
--- a/src/tools/transformtool.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/tools/transformtool.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -1,6 +1,6 @@
 #include <QHBoxLayout>
 #include "model.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 #include "linetypes/object.h"
 #include "transformtool.h"
 #include "document.h"
--- a/src/ui/polygonobjecteditor.cpp	Fri Mar 04 11:37:50 2022 +0200
+++ b/src/ui/polygonobjecteditor.cpp	Fri Mar 04 11:40:19 2022 +0200
@@ -1,7 +1,7 @@
 #include <QFormLayout>
 #include <QSplitter>
 #include "document.h"
-#include "modeleditcontext.h"
+#include "modeleditor.h"
 #include "widgets/vec3editor.h"
 #include "ui/polygonobjecteditor.h"
 

mercurial