src/ldObject.h

changeset 1117
efcb47c64a72
parent 1100
9b2797729c82
child 1123
15e46ea3151f
--- 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());
+	}
+}

mercurial