diff --git a/src/Mod/Sketcher/App/PropertyConstraintList.cpp b/src/Mod/Sketcher/App/PropertyConstraintList.cpp index 15fcaaeda..d0943c4f5 100644 --- a/src/Mod/Sketcher/App/PropertyConstraintList.cpp +++ b/src/Mod/Sketcher/App/PropertyConstraintList.cpp @@ -386,7 +386,7 @@ bool PropertyConstraintList::scanGeometry(const std::vector &G string PropertyConstraintList::getConstraintName(const std::string & name, int i) { - if (name != "") + if (!name.empty()) return name; else return getConstraintName(i); diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index a480c27b7..328e0fe0b 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -355,11 +355,14 @@ PyObject* SketchObjectPy::renameConstraint(PyObject *args) } } - Constraint* copy = this->getSketchObjectPtr()->Constraints[Index]->clone(); - copy->Name = Name; - this->getSketchObjectPtr()->Constraints.set1Value(Index, copy); - delete copy; - + // only change the constraint item if the names are different + const Constraint* item = this->getSketchObjectPtr()->Constraints[Index]; + if (item->Name != Name) { + Constraint* copy = item->clone(); + copy->Name = Name; + this->getSketchObjectPtr()->Constraints.set1Value(Index, copy); + delete copy; + } Py_Return; } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index cf59bd57a..90b095c6f 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -476,8 +476,19 @@ void ConstraintView::swapNamedOfSelectedItems() std::string escapedstr1 = Base::Tools::escapedUnicodeFromUtf8(item1->sketch->Constraints[item1->ConstraintNbr]->Name.c_str()); ConstraintItem * item2 = static_cast(items[1]); std::string escapedstr2 = Base::Tools::escapedUnicodeFromUtf8(item2->sketch->Constraints[item2->ConstraintNbr]->Name.c_str()); - std::stringstream ss; + // In commit 67800ec8c (21 Jul 2015) the implementation of on_listWidgetConstraints_itemChanged() + // has changed ensuring that a name of a constraint cannot be reset any more. + // This leads to some inconsistencies when trying to swap "empty" names. + // + // If names are empty then nothing should be done + if (escapedstr1.empty() || escapedstr2.empty()) { + QMessageBox::warning(Gui::MainWindow::getInstance(), tr("Unnamed constraint"), + tr("Only the names of named constraints can be swapped.")); + return; + } + + std::stringstream ss; ss << "DummyConstraint" << rand(); std::string tmpname = ss.str(); @@ -673,7 +684,7 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemChanged(QListWidgetIte catch (const Base::Exception & e) { Gui::Command::abortCommand(); - QMessageBox::critical(Gui::MainWindow::getInstance(), QString::fromLatin1("Error"), + QMessageBox::critical(Gui::MainWindow::getInstance(), tr("Error"), QString::fromLatin1(e.what()), QMessageBox::Ok, QMessageBox::Ok); } }