Moved LDComment and LDEmpty into their own source file pairs.

Thu, 09 Feb 2017 22:46:37 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 09 Feb 2017 22:46:37 +0200
changeset 1117
efcb47c64a72
parent 1116
3b1d2cc6603e
child 1118
3eeb258f1fb9

Moved LDComment and LDEmpty into their own source file pairs.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/dialogs/newpartdialog.cpp file | annotate | diff | comparison | revisions
src/ldDocument.cpp file | annotate | diff | comparison | revisions
src/ldObject.cpp file | annotate | diff | comparison | revisions
src/ldObject.h file | annotate | diff | comparison | revisions
src/linetypes/comment.cpp file | annotate | diff | comparison | revisions
src/linetypes/comment.h file | annotate | diff | comparison | revisions
src/linetypes/empty.cpp file | annotate | diff | comparison | revisions
src/linetypes/empty.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/model.cpp file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
src/toolsets/algorithmtoolset.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Thu Feb 09 21:04:33 2017 +0200
+++ b/CMakeLists.txt	Thu Feb 09 22:46:37 2017 +0200
@@ -71,6 +71,8 @@
 	src/editmodes/magicWandMode.cpp
 	src/editmodes/rectangleMode.cpp
 	src/editmodes/selectMode.cpp
+	src/linetypes/comment.cpp
+	src/linetypes/empty.cpp
 	src/toolsets/algorithmtoolset.cpp
 	src/toolsets/basictoolset.cpp
 	src/toolsets/extprogramtoolset.cpp
@@ -130,6 +132,8 @@
 	src/editmodes/magicWandMode.h
 	src/editmodes/rectangleMode.h
 	src/editmodes/selectMode.h
+	src/linetypes/comment.h
+	src/linetypes/empty.h
 	src/toolsets/algorithmtoolset.h
 	src/toolsets/basictoolset.h
 	src/toolsets/extprogramtoolset.h
--- a/src/dialogs/newpartdialog.cpp	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/dialogs/newpartdialog.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -23,6 +23,8 @@
 #include "../mainwindow.h"
 #include "newpartdialog.h"
 #include "ui_newpartdialog.h"
+#include "../linetypes/comment.h"
+#include "../linetypes/empty.h"
 
 NewPartDialog::NewPartDialog (QWidget *parent) :
 	QDialog (parent),
--- a/src/ldDocument.cpp	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/ldDocument.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -25,6 +25,7 @@
 #include "documentloader.h"
 #include "dialogs/openprogressdialog.h"
 #include "documentmanager.h"
+#include "linetypes/comment.h"
 
 LDDocument::LDDocument (DocumentManager* parent) :
     Model {parent},
@@ -308,7 +309,7 @@
 void LDDocument::objectChanged(int position, QString before, QString after)
 {
 	LDObject* object = static_cast<LDObject*>(sender());
-	addToHistory(new EditHistoryEntry {position, before, after});
+	addToHistory(new EditHistoryEntry {object->lineNumber(), before, after});
 	redoVertices();
 	emit objectModified(object);
 }
--- a/src/ldObject.cpp	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/ldObject.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -67,14 +67,12 @@
 LDSubfileReference::LDSubfileReference (Model* model) :
     LDMatrixObject (model) {}
 
-LDOBJ_DEFAULT_CTOR (LDEmpty, LDObject)
 LDOBJ_DEFAULT_CTOR (LDError, LDObject)
 LDOBJ_DEFAULT_CTOR (LDLine, LDObject)
 LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject)
 LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine)
 LDOBJ_DEFAULT_CTOR (LDQuad, LDObject)
 LDOBJ_DEFAULT_CTOR (LDBfc, LDObject)
-LDOBJ_DEFAULT_CTOR (LDComment, LDObject)
 LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject)
 
 LDObject::~LDObject()
@@ -89,13 +87,6 @@
 
 // =============================================================================
 //
-QString LDComment::asText() const
-{
-	return format ("0 %1", text());
-}
-
-// =============================================================================
-//
 QString LDSubfileReference::asText() const
 {
 	QString val = format ("1 %1 %2 ", color(), position());
@@ -174,13 +165,6 @@
 
 // =============================================================================
 //
-QString LDEmpty::asText() const
-{
-	return "";
-}
-
-// =============================================================================
-//
 QString LDBfc::asText() const
 {
 	return format ("0 BFC %1", statementToString());
@@ -216,6 +200,11 @@
 	return 2;
 }
 
+int LDObject::numVertices() const
+{
+	return 0;
+}
+
 // =============================================================================
 //
 LDLine::LDLine (Vertex v1, Vertex v2, Model* model) :
@@ -351,6 +340,26 @@
 	return data;
 }
 
+LDColor LDObject::defaultColor() const
+{
+	return MainColor;
+}
+
+bool LDObject::isColored() const
+{
+	return true;
+}
+
+bool LDObject::isScemantic() const
+{
+	return true;
+}
+
+bool LDObject::hasMatrix() const
+{
+	return false;
+}
+
 // =============================================================================
 //
 QList<LDPolygon> LDSubfileReference::inlinePolygons()
@@ -476,8 +485,6 @@
 //
 void LDObject::invert() {}
 void LDBfc::invert() {}
-void LDEmpty::invert() {}
-void LDComment::invert() {}
 void LDError::invert() {}
 
 // =============================================================================
@@ -630,35 +637,9 @@
 
 // =============================================================================
 //
-// Hook the set accessors of certain properties to this changeProperty function.
-// It takes care of history management so we can capture low-level changes, this
-// makes history stuff work out of the box.
-//
-template<typename T>
-static void changeProperty(LDObject* object, T* property, const T& value)
-{
-	if (*property == value)
-		return;
-
-	int position = object->lineNumber();
-
-	if (position != -1)
-	{
-		QString before = object->asText();
-		*property = value;
-		emit object->codeChanged(position, before, object->asText());
-	}
-	else
-	{
-		*property = value;
-	}
-}
-
-// =============================================================================
-//
 void LDObject::setColor (LDColor color)
 {
-	changeProperty (this, &m_color, color);
+	changeProperty(&m_color, color);
 }
 
 // =============================================================================
@@ -676,7 +657,7 @@
 //
 void LDObject::setVertex (int i, const Vertex& vert)
 {
-	changeProperty (this, &m_coords[i], vert);
+	changeProperty(&m_coords[i], vert);
 }
 
 LDMatrixObject::LDMatrixObject (Model* model) :
@@ -711,7 +692,7 @@
 //
 void LDMatrixObject::setPosition (const Vertex& a)
 {
-	changeProperty (this, &m_position, a);
+	changeProperty(&m_position, a);
 }
 
 // =============================================================================
@@ -723,7 +704,7 @@
 
 void LDMatrixObject::setTransformationMatrix (const Matrix& val)
 {
-	changeProperty (this, &m_transformationMatrix, val);
+	changeProperty(&m_transformationMatrix, val);
 }
 
 LDError::LDError (QString contents, QString reason, Model* model) :
@@ -751,20 +732,6 @@
 	m_fileReferenced = value;
 }
 
-LDComment::LDComment (QString text, Model* model) :
-    LDObject {model},
-    m_text {text} {}
-
-QString LDComment::text() const
-{
-	return m_text;
-}
-
-void LDComment::setText (QString value)
-{
-	changeProperty (this, &m_text, value);
-}
-
 LDBfc::LDBfc (const BfcStatement type, Model* model) :
     LDObject {model},
     m_statement {type} {}
@@ -871,7 +838,7 @@
 
 void LDSubfileReference::setFileInfo (LDDocument* newReferee)
 {
-	changeProperty (this, &m_fileInfo, newReferee);
+	changeProperty(&m_fileInfo, newReferee);
 
 	if (model())
 		model()->recountTriangles();
@@ -919,11 +886,6 @@
 	}
 }
 
-QString LDEmpty::objectListText() const
-{
-	return "";
-}
-
 QString LDError::objectListText() const
 {
 	return "ERROR: " + asText();
@@ -940,11 +902,6 @@
 	return result;
 }
 
-QString LDComment::objectListText() const
-{
-	return text().simplified();
-}
-
 QString LDBfc::objectListText() const
 {
 	return statementToString();
--- a/src/ldObject.h	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/ldObject.h	Thu Feb 09 22:46:37 2017 +0200
@@ -99,21 +99,21 @@
 public:
 	virtual QString asText() const = 0; // This object as LDraw code
     LDColor color() const;
-	virtual LDColor defaultColor() const = 0; // What color does the object default to?
+	virtual LDColor defaultColor() const; // What color does the object default to?
 	Model* model() const;
 	LDPolygon* getPolygon();
 	virtual void getVertices (QSet<Vertex>& verts) const;
-	virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject)
+	virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject)
 	qint32 id() const;
-	virtual void invert() = 0; // Inverts this object (winding is reversed)
-	virtual bool isColored() const = 0;
+	virtual void invert(); // Inverts this object (winding is reversed)
+	virtual bool isColored() const;
 	bool isHidden() const;
-	virtual bool isScemantic() const = 0; // Does this object have meaning in the part model?
+	virtual bool isScemantic() const; // Does this object have meaning in the part model?
 	bool isSelected() const;
 	int lineNumber() const;
 	void move (Vertex vect);
 	LDObject* next() const;
-	virtual int numVertices() const = 0;
+	virtual int numVertices() const;
 	virtual QString objectListText() const;
 	LDObject* previous() const;
 	bool previousIsInvertnext (LDBfc*& ptr);
@@ -130,7 +130,7 @@
 	static LDObject* fromID(int32 id);
 
 signals:
-	void codeChanged(int position, QString before, QString after);
+	void codeChanged(QString before, QString after);
 
 protected:
 	friend class Model;
@@ -138,6 +138,9 @@
 	virtual ~LDObject();
 	void setDocument(Model* model);
 
+	template<typename T>
+	void changeProperty(T* property, const T& value);
+
 private:
 	bool m_isHidden;
 	bool m_isSelected;
@@ -209,48 +212,6 @@
 
 //
 //
-// Represents an empty line in the LDraw code file.
-//
-class LDEmpty : public LDObject
-{
-	LDOBJ (Empty)
-	LDOBJ_NAME (empty)
-	LDOBJ_VERTICES (0)
-	LDOBJ_UNCOLORED
-	LDOBJ_NON_SCEMANTIC
-	LDOBJ_NO_MATRIX
-
-public:
-	QString objectListText() const override;
-};
-
-//
-//
-// Represents a code-0 comment in the LDraw code file.
-//
-class LDComment : public LDObject
-{
-	LDOBJ (Comment)
-	LDOBJ_NAME (comment)
-	LDOBJ_VERTICES (0)
-	LDOBJ_UNCOLORED
-	LDOBJ_NON_SCEMANTIC
-	LDOBJ_NO_MATRIX
-
-public:
-	QString objectListText() const override;
-	QString text() const;
-	void setText (QString value);
-
-protected:
-	LDComment (QString text, Model* model = nullptr);
-
-private:
-	QString m_text;
-};
-
-//
-//
 // Represents a 0 BFC statement in the LDraw code.
 //
 enum BfcStatement
@@ -438,3 +399,17 @@
 	LowResolution = 16,
 	HighResolution = 48
 };
+
+/*
+ * Changes a property in a manner that emits the appropriate signal to notify that the object changed.
+ */
+template<typename T>
+void LDObject::changeProperty(T* property, const T& value)
+{
+	if (*property != value)
+	{
+		QString before = asText();
+		*property = value;
+		emit codeChanged(before, asText());
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/linetypes/comment.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -0,0 +1,66 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2017 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 "comment.h"
+
+LDComment::LDComment(Model* model) :
+    LDObject {model} {}
+
+LDComment::LDComment(QString text, Model* model) :
+    LDObject {model},
+    m_text {text} {}
+
+LDObjectType LDComment::type() const
+{
+	return OBJ_Comment;
+}
+
+QString LDComment::typeName() const
+{
+	return "comment";
+}
+
+bool LDComment::isScemantic() const
+{
+	return false;
+}
+
+bool LDComment::isColored() const
+{
+	return false;
+}
+
+QString LDComment::text() const
+{
+	return m_text;
+}
+
+void LDComment::setText (QString value)
+{
+	changeProperty(&m_text, value);
+}
+
+QString LDComment::objectListText() const
+{
+	return text().simplified();
+}
+
+QString LDComment::asText() const
+{
+	return format ("0 %1", text());
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/linetypes/comment.h	Thu Feb 09 22:46:37 2017 +0200
@@ -0,0 +1,46 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2017 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 "../ldObject.h"
+
+/*
+ * Represents a line type 0 comment in the LDraw model.
+ */
+class LDComment : public LDObject
+{
+public:
+	static constexpr LDObjectType SubclassType = OBJ_Comment;
+
+	QString asText() const override;
+	bool isColored() const override;
+	bool isScemantic() const override;
+	QString objectListText() const override;
+	QString text() const;
+	LDObjectType type() const override;
+	QString typeName() const override;
+	void setText(QString value);
+
+protected:
+	LDComment(QString text, Model* model);
+	LDComment(Model* model);
+	friend class Model;
+
+private:
+	QString m_text;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/linetypes/empty.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -0,0 +1,43 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2017 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 "empty.h"
+
+LDEmpty::LDEmpty(Model* model) :
+    LDObject{model} {}
+
+QString LDEmpty::typeName() const
+{
+	return "empty";
+}
+
+LDObjectType LDEmpty::type() const
+{
+	return OBJ_Empty;
+}
+
+QString LDEmpty::objectListText() const
+{
+	return "";
+}
+
+QString LDEmpty::asText() const
+{
+	return "";
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/linetypes/empty.h	Thu Feb 09 22:46:37 2017 +0200
@@ -0,0 +1,38 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2017 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 "../ldObject.h"
+
+/*
+ * Represents an empty line in the LDraw code file.
+ */
+class LDEmpty : public LDObject
+{
+public:
+	static const LDObjectType SubclassType = OBJ_Empty;
+
+	QString asText() const override;
+	QString objectListText() const override;
+	LDObjectType type() const override;
+	QString typeName() const override;
+
+protected:
+	friend class Model;
+	LDEmpty(Model* model);
+};
--- a/src/mainwindow.cpp	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/mainwindow.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -33,6 +33,7 @@
 #include "editmodes/abstractEditMode.h"
 #include "toolsets/toolset.h"
 #include "dialogs/configdialog.h"
+#include "linetypes/comment.h"
 #include "guiutilities.h"
 #include "glCompiler.h"
 #include "documentmanager.h"
--- a/src/model.cpp	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/model.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -19,6 +19,8 @@
 #include "model.h"
 #include "ldObject.h"
 #include "documentmanager.h"
+#include "linetypes/empty.h"
+#include "linetypes/comment.h"
 
 Model::Model(DocumentManager* manager) :
     QObject {manager},
--- a/src/primitives.cpp	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/primitives.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -24,6 +24,8 @@
 #include "colors.h"
 #include "ldpaths.h"
 #include "documentmanager.h"
+#include "linetypes/comment.h"
+#include "linetypes/empty.h"
 
 
 PrimitiveManager::PrimitiveManager(QObject* parent) :
--- a/src/toolsets/algorithmtoolset.cpp	Thu Feb 09 21:04:33 2017 +0200
+++ b/src/toolsets/algorithmtoolset.cpp	Thu Feb 09 22:46:37 2017 +0200
@@ -32,6 +32,8 @@
 #include "../mathfunctions.h"
 #include "../ldobjectiterator.h"
 #include "../documentmanager.h"
+#include "../linetypes/comment.h"
+#include "../linetypes/empty.h"
 #include "ui_replcoords.h"
 #include "ui_editraw.h"
 #include "ui_flip.h"

mercurial