Wed, 17 Feb 2016 02:56:59 +0200
Moved LDObject::moveObjects into MoveToolset
src/ldObject.cpp | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions | |
src/toolsets/movetoolset.cpp | file | annotate | diff | comparison | revisions |
--- a/src/ldObject.cpp Wed Feb 17 00:54:02 2016 +0200 +++ b/src/ldObject.cpp Wed Feb 17 02:56:59 2016 +0200 @@ -463,49 +463,6 @@ // ============================================================================= // -void LDObject::moveObjects (LDObjectList objs, const bool up) -{ - if (objs.isEmpty()) - return; - - // If we move down, we need to iterate the array in reverse order. - long const start = up ? 0 : (objs.size() - 1); - long const end = up ? objs.size() : -1; - long const incr = up ? 1 : -1; - LDObjectList objsToCompile; - LDDocument* file = objs[0]->document(); - - for (long i = start; i != end; i += incr) - { - LDObject* obj = objs[i]; - - long const idx = obj->lineNumber(); - long const target = idx + (up ? -1 : 1); - - if ((up and idx == 0) or (not up and idx == (long) file->objects().size() - 1l)) - { - // One of the objects hit the extrema. If this happens, this should be the first - // object to be iterated on. Thus, nothing has changed yet and it's safe to just - // abort the entire operation. - return; - } - - objsToCompile << obj; - objsToCompile << file->getObject (target); - - obj->swap (file->getObject (target)); - } - - removeDuplicates (objsToCompile); - - // The objects need to be recompiled, otherwise their pick lists are left with - // the wrong index colors which messes up selection. - for (LDObject* obj : objsToCompile) - g_win->renderer()->compileObject (obj); -} - -// ============================================================================= -// // Get type name by enumerator // QString LDObject::typeName (LDObjectType type)
--- a/src/ldObject.h Wed Feb 17 00:54:02 2016 +0200 +++ b/src/ldObject.h Wed Feb 17 02:56:59 2016 +0200 @@ -133,7 +133,6 @@ static QString describeObjects (const LDObjectList& objs); static LDObject* fromID (int id); static LDObject* getDefault (const LDObjectType type); - static void moveObjects (LDObjectList objs, const bool up); // TODO: move this to LDDocument? static QString typeName (LDObjectType type); protected:
--- a/src/toolsets/movetoolset.cpp Wed Feb 17 00:54:02 2016 +0200 +++ b/src/toolsets/movetoolset.cpp Wed Feb 17 02:56:59 2016 +0200 @@ -23,6 +23,7 @@ #include "movetoolset.h" #include "ui_rotpoint.h" #include "../grid.h" +#include "../glRenderer.h" MoveToolset::MoveToolset (MainWindow* parent) : Toolset (parent) {} @@ -30,7 +31,41 @@ void MoveToolset::moveSelection (bool up) { LDObjectList objs = selectedObjects(); - LDObject::moveObjects (objs, up); + if (objs.isEmpty()) + return; + + // If we move down, we need to iterate the array in reverse order. + int start = up ? 0 : (objs.size() - 1); + int end = up ? objs.size() : -1; + int increment = up ? 1 : -1; + QSet<LDObject*> objsToCompile; + LDDocument* file = objs[0]->document(); + + for (int i = start; i != end; i += increment) + { + LDObject* obj = objs[i]; + + int idx = obj->lineNumber(); + int target = idx + (up ? -1 : 1); + + if ((up and idx == 0) or (not up and idx == file->objects().size() - 1)) + { + // One of the objects hit the extrema. If this happens, this should be the first + // object to be iterated on. Thus, nothing has changed yet and it's safe to just + // abort the entire operation. + return; + } + + objsToCompile << obj; + objsToCompile << file->getObject(target); + obj->swap(file->getObject(target)); + } + + // The objects need to be recompiled, otherwise their pick lists are left with + // the wrong index colors which messes up selection. + for (LDObject* obj : objsToCompile) + m_window->renderer()->compileObject(obj); + m_window->buildObjectList(); }