Mon, 30 Jan 2017 02:30:26 +0200
Split object list representation into virtual methods
src/ldObject.cpp | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions |
--- a/src/ldObject.cpp Mon Jan 30 02:18:42 2017 +0200 +++ b/src/ldObject.cpp Mon Jan 30 02:30:26 2017 +0200 @@ -18,6 +18,7 @@ #include <assert.h> #include "main.h" +#include "documentmanager.h" #include "ldObject.h" #include "ldDocument.h" #include "miscallenous.h" @@ -955,7 +956,7 @@ { newReferee->initializeCachedData(); } -}; +} void LDObject::getVertices (QSet<Vertex>& verts) const { @@ -967,3 +968,61 @@ { verts.unite(fileInfo()->inlineVertices()); } + +QString LDObject::objectListText() const +{ + if (numVertices() > 0) + { + QString result; + + for (int i = 0; i < numVertices(); ++i) + { + if (i != 0) + result += ", "; + + result += vertex(i).toString (true); + } + + return result; + } + else + { + return typeName(); + } +} + +QString LDEmpty::objectListText() const +{ + return ""; +} + +QString LDError::objectListText() const +{ + return "ERROR: " + asText(); +} + +QString LDSubfileReference::objectListText() const +{ + QString result = format ("%1 %2, (", fileInfo()->getDisplayName(), position().toString(true)); + + for (int i = 0; i < 9; ++i) + result += format("%1%2", transformationMatrix().value(i), (i != 8) ? " " : ""); + + result += ')'; + return result; +} + +QString LDOverlay::objectListText() const +{ + return format("[%1] %2 (%3, %4), %5 x %6", static_cast<int>(camera()), Basename(fileName()), x(), y(), width(), height()); +} + +QString LDComment::objectListText() const +{ + return text().simplified(); +} + +QString LDBfc::objectListText() const +{ + return statementToString(); +}
--- a/src/ldObject.h Mon Jan 30 02:18:42 2017 +0200 +++ b/src/ldObject.h Mon Jan 30 02:30:26 2017 +0200 @@ -114,6 +114,7 @@ void move (Vertex vect); LDObject* next() const; virtual int numVertices() const = 0; + virtual QString objectListText() const; LDObject* previous() const; bool previousIsInvertnext (LDBfc*& ptr); QColor randomColor() const; @@ -195,6 +196,7 @@ QString contents() const; QString fileReferenced() const; void setFileReferenced (QString value); + QString objectListText() const override; protected: LDError (QString contents, QString reason, Model* model = nullptr); @@ -217,6 +219,9 @@ LDOBJ_UNCOLORED LDOBJ_NON_SCEMANTIC LDOBJ_NO_MATRIX + +public: + QString objectListText() const override; }; // @@ -233,6 +238,7 @@ LDOBJ_NO_MATRIX public: + QString objectListText() const override; QString text() const; void setText (QString value); @@ -274,6 +280,7 @@ LDOBJ_NO_MATRIX public: + QString objectListText() const override; BfcStatement statement() const; void setStatement (BfcStatement value); QString statementToString() const; @@ -308,6 +315,7 @@ virtual void getVertices (QSet<Vertex>& verts) const override; void inlineContents(Model& model, bool deep, bool render); QList<LDPolygon> inlinePolygons(); + QString objectListText() const override; void setFileInfo (LDDocument* fileInfo); int triangleCount() const override; @@ -424,6 +432,7 @@ int camera() const; QString fileName() const; int height() const; + QString objectListText() const override; void setCamera (int value); void setFileName (QString value); void setHeight (int value);
--- a/src/mainwindow.cpp Mon Jan 30 02:18:42 2017 +0200 +++ b/src/mainwindow.cpp Mon Jan 30 02:30:26 2017 +0200 @@ -387,82 +387,7 @@ for (LDObject* obj : m_currentDocument->objects()) { - QString descr; - - switch (obj->type()) - { - case OBJ_Comment: - { - descr = static_cast<LDComment*> (obj)->text(); - - // Remove leading whitespace - while (descr[0] == ' ') - descr.remove (0, 1); - - break; - } - - case OBJ_Empty: - break; // leave it empty - - case OBJ_Line: - case OBJ_Triangle: - case OBJ_Quad: - case OBJ_CondLine: - case OBJ_BezierCurve: - { - for (int i = 0; i < obj->numVertices(); ++i) - { - if (i != 0) - descr += ", "; - - descr += obj->vertex (i).toString (true); - } - break; - } - - case OBJ_Error: - { - descr = format ("ERROR: %1", obj->asText()); - break; - } - - case OBJ_SubfileReference: - { - LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj); - - descr = format ("%1 %2, (", ref->fileInfo()->getDisplayName(), ref->position().toString (true)); - - for (int i = 0; i < 9; ++i) - descr += format ("%1%2", ref->transformationMatrix().value(i), (i != 8) ? " " : ""); - - descr += ')'; - break; - } - - case OBJ_Bfc: - { - descr = static_cast<LDBfc*> (obj)->statementToString(); - break; - } - - case OBJ_Overlay: - { - LDOverlay* ovl = static_cast<LDOverlay*> (obj); - descr = format ("[%1] %2 (%3, %4), %5 x %6", renderer()->cameraName ((Camera) ovl->camera()), - Basename (ovl->fileName()), ovl->x(), ovl->y(), - ovl->width(), ovl->height()); - break; - } - - default: - { - descr = obj->typeName(); - break; - } - } - - QListWidgetItem* item = new QListWidgetItem (descr); + QListWidgetItem* item = new QListWidgetItem {obj->objectListText()}; item->setIcon (GetIcon (obj->typeName())); // Use italic font if hidden