# HG changeset patch # User Teemu Piippo # Date 1455731661 -7200 # Node ID 55c0d3beea0d35225ee45a387da03bad285ceebe # Parent d931a7547578d9080111b2d8ce1b649768ccd45a removed removeDuplicates in favor of QSet, and the unused ObjectList class diff -r d931a7547578 -r 55c0d3beea0d src/basics.cpp --- 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(key)); +} diff -r d931a7547578 -r 55c0d3beea0d src/basics.h --- 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 -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 // diff -r d931a7547578 -r 55c0d3beea0d src/colors.cpp --- 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()); diff -r d931a7547578 -r 55c0d3beea0d src/colors.h --- 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 // diff -r d931a7547578 -r 55c0d3beea0d src/editmodes/abstractEditMode.cpp --- 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 vertices = renderer()->document()->inlineVertices(); + QList 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 diff -r d931a7547578 -r 55c0d3beea0d src/editmodes/magicWandMode.cpp --- 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& boundaries, QVector& candidates) +void MagicWandMode::fillBoundaries (LDObject* obj, QVector& boundaries, QSet& candidates) { // All boundaries obviously share vertices with the object, therefore they're all in the list // of candidates. @@ -110,15 +110,13 @@ return; } - QVector candidates; + QSet 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); diff -r d931a7547578 -r 55c0d3beea0d src/editmodes/magicWandMode.h --- 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> m_vertices; + QMap> m_vertices; QVector m_selection; DEFINE_CLASS (MagicWandMode, AbstractSelectMode) @@ -45,5 +45,5 @@ virtual bool mouseReleased (MouseEventData const& data) override; private: - void fillBoundaries (LDObject* obj, QVector& boundaries, QVector& candidates); + void fillBoundaries (LDObject* obj, QVector& boundaries, QSet &candidates); }; diff -r d931a7547578 -r 55c0d3beea0d src/ldDocument.cpp --- 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()); + it = m_objectVertices.insert (obj, QSet()); else it->clear(); @@ -792,10 +792,9 @@ { m_vertices.clear(); - for (QVector const& verts : m_objectVertices) - m_vertices << verts; + for (const QSet& vertices : m_objectVertices) + m_vertices.unite(vertices); - removeDuplicates (m_vertices); unsetFlag(NeedsVertexMerge); } @@ -908,7 +907,7 @@ // ============================================================================= // -QVector const& LDDocument::inlineVertices() +const QSet& LDDocument::inlineVertices() { initializeCachedData(); return m_vertices; diff -r d931a7547578 -r 55c0d3beea0d src/ldDocument.h --- 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 inlinePolygons(); - const QVector& inlineVertices(); + const QSet& inlineVertices(); void insertObject (int pos, LDObject* obj); bool isCache() const; bool isSafeToClose(); @@ -122,8 +122,8 @@ int m_tabIndex; int m_triangleCount; QList m_polygonData; - QMap> m_objectVertices; - QVector m_vertices; + QMap> m_objectVertices; + QSet m_vertices; LDObjectList m_sel; LDGLData* m_gldata; DocumentManager* m_manager; diff -r d931a7547578 -r 55c0d3beea0d src/ldObject.cpp --- 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& verts) const +void LDObject::getVertices (QSet& verts) const { for (int i = 0; i < numVertices(); ++i) - verts << vertex (i); + verts.insert(vertex(i)); } -void LDSubfileReference::getVertices (QVector& verts) const +void LDSubfileReference::getVertices (QSet& verts) const { - verts << fileInfo()->inlineVertices(); + verts.unite(fileInfo()->inlineVertices()); } \ No newline at end of file diff -r d931a7547578 -r 55c0d3beea0d src/ldObject.h --- 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& verts) const; + virtual void getVertices (QSet& 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& verts) const override; + virtual void getVertices (QSet& verts) const override; LDObjectList inlineContents (bool deep, bool render); QList inlinePolygons(); void setFileInfo (LDDocument* fileInfo); diff -r d931a7547578 -r 55c0d3beea0d src/main.h --- 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 #include #include +#include #include #include #include "macros.h" diff -r d931a7547578 -r 55c0d3beea0d src/mainwindow.cpp --- 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 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(parent()); - - if (mainWindow) - mainWindow->spawnContextMenu (ev->globalPos()); -} - // --------------------------------------------------------------------------------------------------------------------- // QPixmap GetIcon (QString iconName) diff -r d931a7547578 -r 55c0d3beea0d src/mainwindow.h --- 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& colors); - void spawnContextMenu (const QPoint pos); + void spawnContextMenu (const QPoint& position); int suggestInsertPoint(); void syncSettings(); Q_SLOT void updateActions(); diff -r d931a7547578 -r 55c0d3beea0d src/toolsets/viewtoolset.cpp --- 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 colors; + QSet 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 types; - QStringList subfilenames; + QSet types; + QSet subfilenames; for (LDObject* obj : selectedObjects()) { types << obj->type(); - if (types.last() == OBJ_SubfileReference) + if (obj->type() == OBJ_SubfileReference) subfilenames << static_cast (obj)->fileInfo()->name(); } - removeDuplicates (types); - removeDuplicates (subfilenames); currentDocument()->clearSelection(); for (LDObject* obj : currentDocument()->objects())