From 7cc5167623986ba7bc39951585cfc11b24ee7857 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 20 Aug 2014 16:02:45 +0200 Subject: [PATCH] Sketcher properties feature enhancement: Separated sublist for unnamed datum constraints --- .../Gui/PropertyConstraintListItem.cpp | 80 +++++++++++++++++-- .../Sketcher/Gui/PropertyConstraintListItem.h | 1 + 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp index d960bcd0c1..f458abae47 100644 --- a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp +++ b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp @@ -67,6 +67,9 @@ QVariant PropertyConstraintListItem::value(const App::Property* prop) const int id = 1; QList quantities; + QList subquantities; + bool onlyNamed=true; + const std::vector< Sketcher::Constraint * > &vals = static_cast(prop)->getValues(); for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) { if ((*it)->Type == Sketcher::Distance || // Datum constraint @@ -93,11 +96,31 @@ QVariant PropertyConstraintListItem::value(const App::Property* prop) const name = QString::fromLatin1("Constraint%1").arg(id); PropertyConstraintListItem* self = const_cast(this); + self->blockEvent=true; - self->setProperty(name.toLatin1(), QVariant::fromValue(quant)); + + if((*it)->Name.empty() && !onlyUnnamed){ + onlyNamed=false; + subquantities.append(quant); + PropertyConstraintListItem* unnamednode=static_cast(self->child(self->childCount()-1)); + unnamednode->blockEvent=true; + unnamednode->setProperty(name.toLatin1(), QVariant::fromValue(quant)); + unnamednode->blockEvent=false; + } + else{ + self->setProperty(name.toLatin1(), QVariant::fromValue(quant)); + } + self->blockEvent=false; } } + + if(!onlyUnnamed && !onlyNamed){ + self->blockEvent=true; + self->setProperty(tr("Unnamed").toLatin1(), QVariant::fromValue< QList >(subquantities)); + self->blockEvent=false; + } + return QVariant::fromValue< QList >(quantities); } @@ -116,8 +139,15 @@ bool PropertyConstraintListItem::event (QEvent* ev) QString propName = QString::fromLatin1(ce->propertyName()); Base::Quantity quant = prop.value(); + Sketcher::PropertyConstraintList* item; + int id = 0; - Sketcher::PropertyConstraintList* item = static_cast(getFirstProperty()); + if(this->parent()->getTypeId()==SketcherGui::PropertyConstraintListItem::getClassTypeId()){ + item = static_cast(this->parent()->getFirstProperty()); + } + else { + item = static_cast(getFirstProperty()); + } const std::vector< Sketcher::Constraint * > &vals = item->getValues(); for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) { @@ -173,7 +203,10 @@ void PropertyConstraintListItem::initialize() const std::vector< Sketcher::Constraint * > &vals = item->getValues(); int id = 1; + int iNamed = 0; + std::vector unnamed; + for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) { if ((*it)->Type == Sketcher::Distance || // Datum constraint (*it)->Type == Sketcher::DistanceX || @@ -181,16 +214,49 @@ void PropertyConstraintListItem::initialize() (*it)->Type == Sketcher::Radius || (*it)->Type == Sketcher::Angle) { + PropertyUnitItem* item = static_cast(PropertyUnitItem::create()); + // Get the name QString name = QString::fromStdString((*it)->Name); - if (name.isEmpty()) + if (name.isEmpty()){ name = QString::fromLatin1("Constraint%1").arg(id); - PropertyUnitItem* item = static_cast(PropertyUnitItem::create()); - item->setParent(this); - item->setPropertyName(name); - this->appendChild(item); + item->setPropertyName(name); + unnamed.push_back(item); + } + else{ + iNamed++; + item->setParent(this); + item->setPropertyName(name); + this->appendChild(item); + } + } } + + // now deal with the unnamed + if(iNamed == 0){ + onlyUnnamed = true; + for (std::vector< PropertyUnitItem* >::const_iterator it = unnamed.begin();it != unnamed.end(); ++it) { + (*it)->setParent(this); + this->appendChild((*it)); + } + } + else { + onlyUnnamed = false; + + if(unnamed.size()!=0) { + PropertyConstraintListItem* item = static_cast(PropertyConstraintListItem::create()); + item->setParent(this); + item->setPropertyName(tr("Unnamed")); + this->appendChild(item); + + for (std::vector< PropertyUnitItem* >::const_iterator it = unnamed.begin();it != unnamed.end(); ++it) { + (*it)->setParent(item); + item->appendChild((*it)); + } + } + } + } #include "moc_PropertyConstraintListItem.cpp" diff --git a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h index 212ae6da05..421feaeea3 100644 --- a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h +++ b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h @@ -60,6 +60,7 @@ protected: protected: PropertyConstraintListItem(); bool blockEvent; + bool onlyUnnamed; }; } //namespace SketcherGui