From cccaa6d4dc42911b8c59d03c24546462ee53e59b Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 16 Dec 2017 15:58:57 +0100 Subject: [PATCH] Sketcher: Extension of Constraints Widget to support checkboxes for Virtual Space ================================================================================= The checkboxes enable a constraint to swap virtual space. If checked the constraint is visible in the selected space and hidden in the other space (Real Space or Virtual Space). If unchecked the constraint is visible in the other space and hidden in the selected space. --- .../Sketcher/Gui/TaskSketcherConstrains.cpp | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index 49db314f08..5c8aa06067 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -83,7 +83,9 @@ public: sketch(s), ConstraintNbr(ConstNbr) { - this->setFlags(this->flags() | Qt::ItemIsEditable); + this->setFlags(this->flags() | Qt::ItemIsEditable | Qt::ItemIsUserCheckable); + + this->setCheckState(this->isInVirtualSpace()?Qt::Unchecked:Qt::Checked); } ~ConstraintItem() { @@ -299,6 +301,12 @@ public: return sketch->Constraints[ConstraintNbr]->isDriving; } + bool isInVirtualSpace() const { + assert(ConstraintNbr >= 0 && ConstraintNbr < sketch->Constraints.getSize()); + + return sketch->Constraints[ConstraintNbr]->isInVirtualSpace; + } + const Sketcher::SketchObject * sketch; int ConstraintNbr; QVariant value; @@ -686,15 +694,24 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemChanged(QListWidgetIte return; inEditMode = true; + + assert(sketchView); const Sketcher::SketchObject * sketch = sketchView->getSketchObject(); const std::vector< Sketcher::Constraint * > &vals = sketch->Constraints.getValues(); const Sketcher::Constraint* v = vals[it->ConstraintNbr]; const std::string currConstraintName = v->Name; - std::string newName(Sketcher::PropertyConstraintList::getConstraintName(Base::Tools::toStdString(it->data(Qt::EditRole).toString()), it->ConstraintNbr)); + const std::string basename = Base::Tools::toStdString(it->data(Qt::EditRole).toString()); + + std::string newName(Sketcher::PropertyConstraintList::getConstraintName(basename, it->ConstraintNbr)); - if (newName != currConstraintName) { + // we only start a rename if we are really sure the name has changed, which is: + // a) that the name generated by the constraints is different from the text in the widget item + // b) that the text in the widget item, basename, is not "" + // otherwise a checkbox change will trigger a rename on the first execution, bloating the constraint icons with the + // default constraint name "constraint1, constraint2" + if (newName != currConstraintName && !basename.empty()) { std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(newName.c_str()); Gui::Command::openCommand("Rename sketch constraint"); @@ -712,6 +729,10 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemChanged(QListWidgetIte } } + const_cast(v)->isInVirtualSpace = !(item->checkState() == Qt::Checked); // update constraint virtual space status + + sketchView->updateVirtualSpace(); + inEditMode = false; }