Mon, 02 Jun 2014 13:35:41 +0300
- made select by color/type no longer require uniform selection
changelog.txt | file | annotate | diff | comparison | revisions | |
src/actions.cc | file | annotate | diff | comparison | revisions | |
src/actionsEdit.cc | file | annotate | diff | comparison | revisions | |
src/ldObject.cc | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions | |
src/mainWindow.cc | file | annotate | diff | comparison | revisions | |
src/mainWindow.h | file | annotate | diff | comparison | revisions |
--- a/changelog.txt Mon Jun 02 13:16:14 2014 +0300 +++ b/changelog.txt Mon Jun 02 13:35:41 2014 +0300 @@ -69,6 +69,7 @@ ! - Moved the uncolorize action into the color toolbar, replacing Main and Edge colors there. ! - Changed `<anonymous>` to `untitled`. ! - Grids now have a single coordinate snap value instead of individual X, Y and Z values. +! - Select by color and type now consider an object matching if one of the color/types match. The color/type of the existing selection does not need to be uniform anymore.
--- a/src/actions.cc Mon Jun 02 13:16:14 2014 +0300 +++ b/src/actions.cc Mon Jun 02 13:35:41 2014 +0300 @@ -289,24 +289,35 @@ obj->select(); ui->objectList->selectAll(); + refresh(); } // ============================================================================= // DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) { - int colnum = getSelectedColor(); + if (selection().isEmpty()) + return; + + QList<int> colors; - if (colnum == -1) - return; // no consensus on color + for (LDObjectPtr obj : selection()) + { + if (obj->isColored()) + colors << obj->color(); + } + removeDuplicates (colors); getCurrentDocument()->clearSelection(); for (LDObjectPtr obj : getCurrentDocument()->objects()) - if (obj->color() == colnum) + { + if (colors.contains (obj->color())) obj->select(); + } updateSelection(); + refresh(); } // ============================================================================= @@ -316,38 +327,37 @@ if (selection().isEmpty()) return; - LDObjectType type = getUniformSelectedType(); - - if (type == OBJ_Unknown) - return; + QList<LDObjectType> types; + QStringList subfilenames; - // If we're selecting subfile references, the reference filename must also - // be uniform. - String refName; - - if (type == OBJ_Subfile) + for (LDObjectPtr obj : selection()) { - refName = selection()[0].staticCast<LDSubfile>()->fileInfo()->name(); + types << obj->type(); - for (LDObjectPtr obj : selection()) - if (obj.staticCast<LDSubfile>()->fileInfo()->name() != refName) - return; + if (types.last() == OBJ_Subfile) + subfilenames << obj.staticCast<LDSubfile>()->fileInfo()->name(); } + removeDuplicates (types); + removeDuplicates (subfilenames); getCurrentDocument()->clearSelection(); for (LDObjectPtr obj : getCurrentDocument()->objects()) { - if (obj->type() != type) + LDObjectType type = obj->type(); + + if (not types.contains (type)) continue; - if (type == OBJ_Subfile && obj.staticCast<LDSubfile>()->fileInfo()->name() != refName) + // For subfiles, type check is not enough, we check the name of the document as well. + if (type == OBJ_Subfile && not subfilenames.contains (obj.staticCast<LDSubfile>()->fileInfo()->name())) continue; obj->select(); } updateSelection(); + refresh(); } // =============================================================================
--- a/src/actionsEdit.cc Mon Jun 02 13:16:14 2014 +0300 +++ b/src/actionsEdit.cc Mon Jun 02 13:35:41 2014 +0300 @@ -54,7 +54,7 @@ for (LDObjectPtr obj : objs) { - if (data.length() > 0) + if (not data.isEmpty()) data += "\n"; data += obj->asText(); @@ -160,10 +160,9 @@ // DEFINE_ACTION (SplitQuads, 0) { - LDObjectList objs = selection(); int num = 0; - for (LDObjectPtr obj : objs) + for (LDObjectPtr obj : selection()) { if (obj->type() != OBJ_Quad) continue; @@ -239,10 +238,8 @@ { for (LDObjectPtr obj : objs) { - if (not obj->isColored()) - continue; - - obj->setColor (colnum); + if (obj->isColored()) + obj->setColor (colnum); } refresh(); @@ -407,9 +404,7 @@ // DEFINE_ACTION (Invert, CTRL_SHIFT (W)) { - LDObjectList sel = selection(); - - for (LDObjectPtr obj : sel) + for (LDObjectPtr obj : selection()) obj->invert(); refresh();
--- a/src/ldObject.cc Mon Jun 02 13:16:14 2014 +0300 +++ b/src/ldObject.cc Mon Jun 02 13:35:41 2014 +0300 @@ -606,11 +606,10 @@ case OBJ_Subfile: return spawn<LDSubfile>(); case OBJ_Triangle: return spawn<LDTriangle>(); case OBJ_Quad: return spawn<LDQuad>(); - case OBJ_Empty: return spawn<LDEmpty>(); - case OBJ_Error: return spawn<LDError>(); + case OBJ_Empty: return spawn<LDEmpty>(); + case OBJ_Error: return spawn<LDError>(); case OBJ_Vertex: return spawn<LDVertex>(); case OBJ_Overlay: return spawn<LDOverlay>(); - case OBJ_Unknown: assert (false); case OBJ_NumTypes: assert (false); } return LDObjectPtr();
--- a/src/ldObject.h Mon Jun 02 13:16:14 2014 +0300 +++ b/src/ldObject.h Mon Jun 02 13:35:41 2014 +0300 @@ -72,7 +72,6 @@ OBJ_Comment, // Object represents a comment OBJ_Error, // Object is the result of failed parsing OBJ_Empty, // Object represents an empty line - OBJ_Unknown, // Unknown object type (some functions return this; TODO: they probably should not) OBJ_NumTypes, // Amount of object types OBJ_FirstType = OBJ_Subfile
--- a/src/mainWindow.cc Mon Jun 02 13:16:14 2014 +0300 +++ b/src/mainWindow.cc Mon Jun 02 13:35:41 2014 +0300 @@ -599,24 +599,6 @@ // ============================================================================= // -LDObjectType MainWindow::getUniformSelectedType() -{ - LDObjectType result = OBJ_Unknown; - - for (LDObjectPtr obj : selection()) - { - if (result != OBJ_Unknown && obj->color() != result) - return OBJ_Unknown; - - if (result == OBJ_Unknown) - result = obj->type(); - } - - return result; -} - -// ============================================================================= -// void MainWindow::closeEvent (QCloseEvent* ev) { // Check whether it's safe to close all files.
--- a/src/mainWindow.h Mon Jun 02 13:16:14 2014 +0300 +++ b/src/mainWindow.h Mon Jun 02 13:35:41 2014 +0300 @@ -135,11 +135,6 @@ //! red), -1 if there is no such consensus. int getSelectedColor(); - //! \returns the uniform selected type (i.e. \c OBJ_Line if everything - //! selected is a line), \c OBJ_Unknown if there is no such - //! consensus. - LDObjectType getUniformSelectedType(); - //! Automatically scrolls the object list so that it points to the first //! selected object. void scrollToSelection();