Wed, 17 Feb 2016 19:54:21 +0200
removed removeDuplicates in favor of QSet, and the unused ObjectList class
--- a/src/basics.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/basics.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -362,4 +362,9 @@ const Vertex& BoundingBox::vertex1() const { return m_vertex1; -} \ No newline at end of file +} + +uint qHash(const Vertex& key) +{ + return qHash(static_cast<const QVector3D&>(key)); +}
--- a/src/basics.h Wed Feb 17 03:24:07 2016 +0200 +++ b/src/basics.h Wed Feb 17 19:54:21 2016 +0200 @@ -85,6 +85,7 @@ } Q_DECLARE_METATYPE (Vertex) +uint qHash(const Vertex& key); // // A mathematical 3 x 3 matrix @@ -211,13 +212,6 @@ return (qAbs (a - floor(a)) < 0.00001) or (qAbs (a - ceil(a)) < 0.00001); } -template<typename T> -void removeDuplicates (T& a) -{ - std::sort (a.begin(), a.end()); - a.erase (std::unique (a.begin(), a.end()), a.end()); -} - // // Returns true if first arg is equal to any of the other args //
--- a/src/colors.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/colors.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -132,6 +132,11 @@ return index() >= 0x02000000; } +uint qHash(LDColor color) +{ + return color.index(); +} + int luma (const QColor& col) { return (0.2126f * col.red()) + (0.7152f * col.green()) + (0.0722f * col.blue());
--- a/src/colors.h Wed Feb 17 03:24:07 2016 +0200 +++ b/src/colors.h Wed Feb 17 19:54:21 2016 +0200 @@ -83,6 +83,8 @@ qint32 m_index; }; +uint qHash(LDColor color); + // // Parses ldconfig.ldr //
--- a/src/editmodes/abstractEditMode.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/editmodes/abstractEditMode.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -103,7 +103,7 @@ Vertex cursorPosition = renderer()->convert2dTo3d (data.ev->pos(), false); QPoint cursorPosition2D (data.ev->pos()); const Axis relZ = renderer()->getRelativeZ(); - QVector<Vertex> vertices = renderer()->document()->inlineVertices(); + QList<Vertex> vertices = renderer()->document()->inlineVertices().toList(); // Sort the vertices in order of distance to camera std::sort (vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool
--- a/src/editmodes/magicWandMode.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/editmodes/magicWandMode.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -40,7 +40,7 @@ return EditModeType::MagicWand; } -void MagicWandMode::fillBoundaries (LDObject* obj, QVector<BoundaryType>& boundaries, QVector<LDObject*>& candidates) +void MagicWandMode::fillBoundaries (LDObject* obj, QVector<BoundaryType>& boundaries, QSet<LDObject*>& candidates) { // All boundaries obviously share vertices with the object, therefore they're all in the list // of candidates. @@ -110,15 +110,13 @@ return; } - QVector<LDObject*> candidates; + QSet<LDObject*> candidates; // Get the list of objects that touch this object, i.e. share a vertex // with this. for (int i = 0; i < obj->numVertices(); ++i) candidates += m_vertices[obj->vertex (i)]; - removeDuplicates (candidates); - // If we're dealing with surfaces, get a list of boundaries. if (matchesneeded > 1) fillBoundaries (obj, boundaries, candidates);
--- a/src/editmodes/magicWandMode.h Wed Feb 17 03:24:07 2016 +0200 +++ b/src/editmodes/magicWandMode.h Wed Feb 17 19:54:21 2016 +0200 @@ -24,7 +24,7 @@ class MagicWandMode : public AbstractSelectMode { - QMap<Vertex, QVector<LDObject*>> m_vertices; + QMap<Vertex, QSet<LDObject*>> m_vertices; QVector<LDObject*> m_selection; DEFINE_CLASS (MagicWandMode, AbstractSelectMode) @@ -45,5 +45,5 @@ virtual bool mouseReleased (MouseEventData const& data) override; private: - void fillBoundaries (LDObject* obj, QVector<BoundaryType>& boundaries, QVector<LDObject*>& candidates); + void fillBoundaries (LDObject* obj, QVector<BoundaryType>& boundaries, QSet<LDObject *> &candidates); };
--- a/src/ldDocument.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/ldDocument.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -649,7 +649,7 @@ auto it = m_objectVertices.find (obj); if (it == m_objectVertices.end()) - it = m_objectVertices.insert (obj, QVector<Vertex>()); + it = m_objectVertices.insert (obj, QSet<Vertex>()); else it->clear(); @@ -792,10 +792,9 @@ { m_vertices.clear(); - for (QVector<Vertex> const& verts : m_objectVertices) - m_vertices << verts; + for (const QSet<Vertex>& vertices : m_objectVertices) + m_vertices.unite(vertices); - removeDuplicates (m_vertices); unsetFlag(NeedsVertexMerge); } @@ -908,7 +907,7 @@ // ============================================================================= // -QVector<Vertex> const& LDDocument::inlineVertices() +const QSet<Vertex>& LDDocument::inlineVertices() { initializeCachedData(); return m_vertices;
--- a/src/ldDocument.h Wed Feb 17 03:24:07 2016 +0200 +++ b/src/ldDocument.h Wed Feb 17 19:54:21 2016 +0200 @@ -81,7 +81,7 @@ void initializeCachedData(); LDObjectList inlineContents (bool deep, bool renderinline); QList<LDPolygon> inlinePolygons(); - const QVector<Vertex>& inlineVertices(); + const QSet<Vertex>& inlineVertices(); void insertObject (int pos, LDObject* obj); bool isCache() const; bool isSafeToClose(); @@ -122,8 +122,8 @@ int m_tabIndex; int m_triangleCount; QList<LDPolygon> m_polygonData; - QMap<LDObject*, QVector<Vertex>> m_objectVertices; - QVector<Vertex> m_vertices; + QMap<LDObject*, QSet<Vertex>> m_objectVertices; + QSet<Vertex> m_vertices; LDObjectList m_sel; LDGLData* m_gldata; DocumentManager* m_manager;
--- a/src/ldObject.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/ldObject.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -1166,13 +1166,13 @@ } }; -void LDObject::getVertices (QVector<Vertex>& verts) const +void LDObject::getVertices (QSet<Vertex>& verts) const { for (int i = 0; i < numVertices(); ++i) - verts << vertex (i); + verts.insert(vertex(i)); } -void LDSubfileReference::getVertices (QVector<Vertex>& verts) const +void LDSubfileReference::getVertices (QSet<Vertex>& verts) const { - verts << fileInfo()->inlineVertices(); + verts.unite(fileInfo()->inlineVertices()); } \ No newline at end of file
--- a/src/ldObject.h Wed Feb 17 03:24:07 2016 +0200 +++ b/src/ldObject.h Wed Feb 17 19:54:21 2016 +0200 @@ -101,7 +101,7 @@ void destroy(); LDDocument* document() const; LDPolygon* getPolygon(); - virtual void getVertices (QVector<Vertex>& verts) const; + virtual void getVertices (QSet<Vertex>& verts) const; virtual bool hasMatrix() const = 0; // Does this object have a matrix and position? (see LDMatrixObject) qint32 id() const; virtual void invert() = 0; // Inverts this object (winding is reversed) @@ -318,7 +318,7 @@ public: // Inlines this subfile. LDDocument* fileInfo() const; - virtual void getVertices (QVector<Vertex>& verts) const override; + virtual void getVertices (QSet<Vertex>& verts) const override; LDObjectList inlineContents (bool deep, bool render); QList<LDPolygon> inlinePolygons(); void setFileInfo (LDDocument* fileInfo);
--- a/src/main.h Wed Feb 17 03:24:07 2016 +0200 +++ b/src/main.h Wed Feb 17 19:54:21 2016 +0200 @@ -25,6 +25,7 @@ #include <stdlib.h> #include <stdint.h> #include <stdarg.h> +#include <QSet> #include <QString> #include <QTextFormat> #include "macros.h"
--- a/src/mainwindow.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/mainwindow.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -519,7 +519,7 @@ if (m_isSelectionLocked == true or m_currentDocument == nullptr) return; - LDObjectList priorSelection = selectedObjects(); + QSet<LDObject*> priorSelection = selectedObjects().toSet(); // Get the objects from the object list selection m_currentDocument->clearSelection(); @@ -542,10 +542,7 @@ updateSelection(); // Update the GL renderer - LDObjectList compound = priorSelection + selectedObjects(); - removeDuplicates (compound); - - for (LDObject* obj : compound) + for (LDObject* obj : (priorSelection + selectedObjects().toSet())) renderer()->compileObject (obj); renderer()->update(); @@ -720,7 +717,7 @@ // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::spawnContextMenu (const QPoint pos) +void MainWindow::spawnContextMenu (const QPoint& position) { const bool single = (selectedObjects().size() == 1); LDObject* singleObj = single ? selectedObjects().first() : nullptr; @@ -781,7 +778,7 @@ contextMenu->addAction (ui.actionSetDrawDepth); } - contextMenu->exec (pos); + contextMenu->exec(position); } // --------------------------------------------------------------------------------------------------------------------- @@ -890,15 +887,6 @@ m_renderer->messageLog()->addLine (msg); } -// ============================================================================ -void ObjectList::contextMenuEvent (QContextMenuEvent* ev) -{ - MainWindow* mainWindow = qobject_cast<MainWindow*>(parent()); - - if (mainWindow) - mainWindow->spawnContextMenu (ev->globalPos()); -} - // --------------------------------------------------------------------------------------------------------------------- // QPixmap GetIcon (QString iconName)
--- a/src/mainwindow.h Wed Feb 17 03:24:07 2016 +0200 +++ b/src/mainwindow.h Wed Feb 17 19:54:21 2016 +0200 @@ -58,15 +58,6 @@ QToolButton* m_toolButton; }; -// Object list class for MainWindow -class ObjectList : public QListWidget -{ - Q_OBJECT - -protected: - void contextMenuEvent (QContextMenuEvent* ev); -}; - // LDForge's main GUI class. class MainWindow : public QMainWindow { @@ -112,7 +103,7 @@ void scrollToSelection(); const LDObjectList& selectedObjects(); void setQuickColors (const QList<ColorToolbarItem>& colors); - void spawnContextMenu (const QPoint pos); + void spawnContextMenu (const QPoint& position); int suggestInsertPoint(); void syncSettings(); Q_SLOT void updateActions();
--- a/src/toolsets/viewtoolset.cpp Wed Feb 17 03:24:07 2016 +0200 +++ b/src/toolsets/viewtoolset.cpp Wed Feb 17 19:54:21 2016 +0200 @@ -43,7 +43,7 @@ if (selectedObjects().isEmpty()) return; - QList<LDColor> colors; + QSet<LDColor> colors; for (LDObject* obj : selectedObjects()) { @@ -51,7 +51,6 @@ colors << obj->color(); } - removeDuplicates (colors); currentDocument()->clearSelection(); for (LDObject* obj : currentDocument()->objects()) @@ -66,19 +65,17 @@ if (selectedObjects().isEmpty()) return; - QList<LDObjectType> types; - QStringList subfilenames; + QSet<LDObjectType> types; + QSet<QString> subfilenames; for (LDObject* obj : selectedObjects()) { types << obj->type(); - if (types.last() == OBJ_SubfileReference) + if (obj->type() == OBJ_SubfileReference) subfilenames << static_cast<LDSubfileReference*> (obj)->fileInfo()->name(); } - removeDuplicates (types); - removeDuplicates (subfilenames); currentDocument()->clearSelection(); for (LDObject* obj : currentDocument()->objects())