Thu, 09 Feb 2017 01:08:57 +0200
Cleaned up code in LDDocument and removed unnecessary flags and methods. Flags turned into bools.
src/ldDocument.cpp | file | annotate | diff | comparison | revisions | |
src/ldDocument.h | file | annotate | diff | comparison | revisions |
--- a/src/ldDocument.cpp Thu Feb 09 01:00:31 2017 +0200 +++ b/src/ldDocument.cpp Thu Feb 09 01:08:57 2017 +0200 @@ -30,15 +30,14 @@ QObject (parent), Model {parent}, HierarchyElement (parent), - m_history (new EditHistory (this)), - m_flags(IsFrozen | VerticesOutdated | NeedsVertexMerge | NeedsRecache), + m_history (new EditHistory (this)), m_savePosition(-1), m_tabIndex(-1), m_manager (parent) {} LDDocument::~LDDocument() { - m_flags |= IsBeingDestroyed; + m_isBeingDestroyed = true; delete m_history; } @@ -104,15 +103,12 @@ void LDDocument::setFrozen(bool value) { - if (value) - m_flags |= IsFrozen; - else - m_flags &= ~IsFrozen; + m_isFrozen = value; } bool LDDocument::isFrozen() const { - return !!(m_flags & IsFrozen); + return m_isFrozen; } void LDDocument::addHistoryStep() @@ -144,7 +140,7 @@ { if (not isFrozen()) { - m_flags |= IsFrozen; + setFrozen(true); m_manager->documentClosed(this); } } @@ -290,7 +286,7 @@ replaceWithFromString(obj, static_cast<LDError*> (obj)->contents()); } - m_flags |= NeedsRecache; + m_needsRecache = true; if (this == m_window->currentDocument()) m_window->buildObjectList(); @@ -319,26 +315,11 @@ m_window->currentDocument()->redoVertices(); } -// ============================================================================= -// -void LDDocument::addKnownVertices (LDObject* obj) -{ - auto it = m_objectVertices.find (obj); - - if (it == m_objectVertices.end()) - it = m_objectVertices.insert (obj, QSet<Vertex>()); - else - it->clear(); - - obj->getVertices (*it); - needVertexMerge(); -} - LDObject* LDDocument::withdrawAt(int position) { LDObject* object = getObject(position); - if (not isFrozen() and not checkFlag(IsBeingDestroyed)) + if (not isFrozen() and not m_isBeingDestroyed) { history()->add(new DelHistoryEntry {position, object}); m_objectVertices.remove(object); @@ -372,7 +353,7 @@ // void LDDocument::initializeCachedData() { - if (checkFlag(NeedsRecache)) + if (m_needsRecache) { m_vertices.clear(); Model model {m_documents}; @@ -397,36 +378,34 @@ } } - unsetFlag(NeedsRecache); + m_needsRecache = false; } - if (checkFlag(VerticesOutdated)) + if (m_verticesOutdated) { m_objectVertices.clear(); Model model {m_documents}; inlineContents(model, true, false); - for (LDObject* obj : model) - addKnownVertices (obj); + for (LDObject* object : model) + { + auto iterator = m_objectVertices.find (object); - mergeVertices(); - unsetFlag(VerticesOutdated); - } - - if (checkFlag(NeedsVertexMerge)) - mergeVertices(); -} + if (iterator == m_objectVertices.end()) + iterator = m_objectVertices.insert (object, QSet<Vertex>()); + else + iterator->clear(); -// ============================================================================= -// -void LDDocument::mergeVertices() -{ - m_vertices.clear(); + object->getVertices (*iterator); + } + + m_vertices.clear(); - for (const QSet<Vertex>& vertices : m_objectVertices) - m_vertices.unite(vertices); + for (const QSet<Vertex>& vertices : m_objectVertices) + m_vertices.unite(vertices); - unsetFlag(NeedsVertexMerge); + m_verticesOutdated = false; + } } // ============================================================================= @@ -548,11 +527,5 @@ void LDDocument::redoVertices() { - setFlag(VerticesOutdated); + m_verticesOutdated = true; } - -void LDDocument::needVertexMerge() -{ - setFlag(NeedsVertexMerge); -} -
--- a/src/ldDocument.h Thu Feb 09 01:00:31 2017 +0200 +++ b/src/ldDocument.h Thu Feb 09 01:08:57 2017 +0200 @@ -42,17 +42,6 @@ Q_OBJECT public: - enum Flag - { - IsFrozen = (1 << 0), // Document may not be modified - VerticesOutdated = (1 << 1), - NeedsVertexMerge = (1 << 2), - IsBeingDestroyed = (1 << 3), - NeedsRecache = (1 << 4), // The next polygon inline of this document rebuilds stored polygon data. - }; - - Q_DECLARE_FLAGS(Flags, Flag) - LDDocument (DocumentManager* parent); ~LDDocument(); @@ -76,7 +65,6 @@ bool isFrozen() const; bool isSafeToClose(); QString name() const; - void needVertexMerge(); void objectRemoved(LDObject* object, int index); const QList<LDPolygon>& polygonData() const; void recountTriangles(); @@ -110,7 +98,10 @@ QString m_fullPath; QString m_defaultName; EditHistory* m_history; - Flags m_flags; + bool m_isFrozen = true; // Document may not be modified + bool m_verticesOutdated = true; + bool m_isBeingDestroyed = true; + bool m_needsRecache = true; // The next polygon inline of this document rebuilds stored polygon data. long m_savePosition; int m_tabIndex; int m_triangleCount; @@ -119,13 +110,7 @@ QSet<Vertex> m_vertices; QSet<LDObject*> m_selection; DocumentManager* m_manager; - - DEFINE_FLAG_ACCESS_METHODS(m_flags) - void addKnownVertices (LDObject* obj); - void mergeVertices(); }; -Q_DECLARE_OPERATORS_FOR_FLAGS(LDDocument::Flags) - // Parses a string line containing an LDraw object and returns the object parsed. LDObject* ParseLine (QString line);