diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 411039c70..9fe4bcd0a 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogalongline.h" #include "../../geometry/vpointf.h" #include "exception/vexceptionobjecterror.h" +#include "../undocommands/savetooloptions.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); @@ -122,16 +123,7 @@ void VToolAlongLine::AddToFile() const QSharedPointer point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); + SaveOptions(domElement, *point.data()); AddToCalculation(domElement); } @@ -146,13 +138,11 @@ void VToolAlongLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); + SaveOptions(domElement, *point.data()); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } } @@ -182,6 +172,94 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::SaveOptions(QDomElement &tag, const VPointF &point) +{ + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point.name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point.mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point.my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrFirstPoint, basePointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::SaveOption(const VPointF &point) +{ + QDomElement oldDomElement = doc->elementById(QString().setNum(id)); + if (oldDomElement.isElement()) + { + QDomElement newDomElement = oldDomElement.cloneNode().toElement(); + + SaveOptions(newDomElement, point); + + SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id); + connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree); + qApp->getUndoStack()->push(saveOptions); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolAlongLine::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setSecondPointId(const quint32 &value) +{ + secondPointId = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setName(const QString &name) +{ + VPointF newPoint = VPointF(*VAbstractTool::data.GeometricObject(id).data()); + newPoint.setName(name); + SaveOption(newPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setTypeLine(const QString &value) +{ + typeLine = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setFormulaLength(const VFormula &value) +{ + if (value.error() == false) + { + formulaLength = value.getFormula(FormulaType::FromUser); + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setFirstPointId(const quint32 &value) +{ + basePointId = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDialog set dialog when user want change tool option. diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index 7708abca5..9d4d49e1a 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -51,6 +51,12 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::AlongLine)}; + void setFirstPointId(const quint32 &value); + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + void setName(const QString &name); + void setTypeLine(const QString &value); + void setFormulaLength(const VFormula &value); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); @@ -64,6 +70,8 @@ protected: private: /** @brief secondPointId id second point of line. */ quint32 secondPointId; + void SaveOptions(QDomElement &tag, const VPointF &point); + void SaveOption(const VPointF &point); }; #endif // VTOOLALONGLINE_H diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index cbdf3b2f5..83e9d7133 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -197,7 +197,7 @@ void VToolEndLine::setName(const QString &name) SaveOption(newPoint); } -void VToolEndLine::setBasePointId(const quint32 &value) +void VToolEndLine::setBasePointId(const quint32 &value) { if (value != NULL_ID) { @@ -208,12 +208,15 @@ void VToolEndLine::setBasePointId(const quint32 &value) } } -void VToolEndLine::setFormulaLength(const QString &value) +void VToolEndLine::setFormulaLength(const VFormula &value) { - formulaLength = value; + if (value.error() == false) + { + formulaLength = value.getFormula(FormulaType::FromUser); - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -279,6 +282,10 @@ void VToolEndLine::RefreshDataInFile() { SaveOptions(domElement, *point.data()); } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -313,20 +320,28 @@ void VToolEndLine::SaveOptions(QDomElement &tag, const VPointF &point) } //--------------------------------------------------------------------------------------------------------------------- -QString VToolEndLine::getFormulaAngle() const +VFormula VToolEndLine::getFormulaAngle() const { - return formulaAngle; + VFormula fAngle(formulaAngle, getData()); + fAngle.setCheckZero(false); + fAngle.setToolId(id); + fAngle.setPostfix(QStringLiteral("°")); + return fAngle; } //--------------------------------------------------------------------------------------------------------------------- -void VToolEndLine::setFormulaAngle(const QString &value) +void VToolEndLine::setFormulaAngle(const VFormula &value) { - formulaAngle = value; + if (value.error() == false) + { + formulaAngle = value.getFormula(FormulaType::FromUser); - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); + } } +//--------------------------------------------------------------------------------------------------------------------- void VToolEndLine::setTypeLine(const QString &value) { typeLine = value; diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 2be6d1558..89448b29b 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -52,10 +52,10 @@ public: virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::EndLine)}; void setName(const QString &name); - QString getFormulaAngle() const; - void setFormulaAngle(const QString &value); + VFormula getFormulaAngle() const; + void setFormulaAngle(const VFormula &value); void setTypeLine(const QString &value); - void setFormulaLength(const QString &value); + void setFormulaLength(const VFormula &value); void setBasePointId(const quint32 &value); public slots: virtual void FullUpdateFromFile(); diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 9cd09944a..fb02060e0 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -113,7 +113,12 @@ quint32 VToolLinePoint::getBasePointId() const return basePointId; } -QString VToolLinePoint::getFormulaLength() const +VFormula VToolLinePoint::getFormulaLength() const { - return formulaLength; + VFormula fLength(formulaLength, this->getData()); + fLength.setCheckZero(true); + fLength.setToolId(id); + fLength.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + + return fLength; } diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 1ad64bbf3..4929381d1 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -30,6 +30,7 @@ #define VTOOLLINEPOINT_H #include "vtoolpoint.h" +#include "../container/vformula.h" /** * @brief The VToolLinePoint class parent for all tools what create point with line. @@ -42,7 +43,7 @@ public: const quint32 &basePointId, const qreal &angle, QGraphicsItem * parent = nullptr); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::LinePoint)}; - QString getFormulaLength() const; + VFormula getFormulaLength() const; //void setFormulaLength(const QString &value)=0; quint32 getBasePointId() const; diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index b8d73b06b..ac0c877b2 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -62,27 +62,122 @@ VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) } //--------------------------------------------------------------------------------------------------------------------- -void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) +void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { - if (currentItem == item) + switch (item->type()) { - UpdateOptions(); - return; + case VToolSinglePoint::Type: + { + VToolSinglePoint *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Base point")); + + AddPropertyPointName(i, tr("Point name")); + + VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); + itemPosition->setValue(i->pos()); + AddProperty(itemPosition, QLatin1String("position")); + break; + } + case VToolEndLine::Type: + { + VToolEndLine *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Point at distance and angle")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + AddPropertyFormula(tr("Angle"), i->getFormulaLength(), VAbstractTool::AttrAngle); + break; + } + case VToolAlongLine::Type: + { + VToolAlongLine *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Point at distance along line")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("First point"), i->getBasePointId(), VAbstractTool::AttrFirstPoint); + AddPropertyPointsList(i, tr("Second point"), i->getSecondPointId(), VAbstractTool::AttrSecondPoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + break; + } + case VGraphicsSimpleTextItem::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + case VControlPointSpline::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + default: + break; } +} - PropertyModel->clear(); - propertyToId.clear(); - idToProperty.clear(); - - currentItem = item; - +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptions() +{ if (currentItem == nullptr) { - TreeView->setTitle(tr("")); return; } - ShowItemOptions(currentItem); + switch (currentItem->type()) + { + case VToolSinglePoint::Type: + { + VToolSinglePoint *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[QLatin1String("position")]->setValue(i->pos()); + break; + } + case VToolEndLine::Type: + { + VToolEndLine *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[VAbstractTool::AttrBasePoint]->setValue(i->getBasePointId()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + QVariant valueAngle; + valueAngle.setValue(i->getFormulaAngle()); + idToProperty[VAbstractTool::AttrAngle]->setValue(valueAngle); + + break; + } + case VToolAlongLine::Type: + { + VToolAlongLine *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[VAbstractTool::AttrFirstPoint]->setValue(i->getBasePointId()); + idToProperty[VAbstractTool::AttrSecondPoint]->setValue(i->getSecondPointId()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + break; + } + case VGraphicsSimpleTextItem::Type: + ShowItemOptions(currentItem->parentItem()); + break; + case VControlPointSpline::Type: + ShowItemOptions(currentItem->parentItem()); + break; + default: + break; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -106,62 +201,90 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) return; } - QVariant variant = prop->data(VProperty::DPC_Data, Qt::DisplayRole); - - QString id = propertyToId[prop]; switch (currentItem->type()) { case VToolSinglePoint::Type: - { - if (id == QLatin1String("name")) - { - SetPointName(variant.toString()); - } - else if (id == QLatin1String("position")) - { - currentItem->setPos(variant.toPointF()); - } + ChangeDataToolSinglePoint(prop); break; - } case VToolEndLine::Type: - { - VToolEndLine *i = qgraphicsitem_cast(currentItem); - if (id == QLatin1String("name")) - { - SetPointName(variant.toString()); - } - else if (id == QLatin1String("basePoint")) - { - i->setBasePointId(variant.toUInt()); - } - else if (id == QLatin1String("lineType")) - { - i->setTypeLine(variant.toString()); - } - else if (id == QLatin1String("formulaLength")) - { - VFormula formula = variant.value(); - if (formula.error() == false) - { - i->setFormulaLength(variant.value().getFormula(FormulaType::FromUser)); - } - } - else if (id == QLatin1String("formulaAngle")) - { - VFormula formula = variant.value(); - if (formula.error() == false) - { - i->setFormulaAngle(variant.value().getFormula(FormulaType::FromUser)); - } - } + ChangeDataToolEndLine(prop); + break; + case VToolAlongLine::Type: + ChangeDataToolAlongLine(prop); break; - } default: break; } qApp->getSceneView()->update(); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) +{ + if (currentItem == item) + { + UpdateOptions(); + return; + } + + PropertyModel->clear(); + propertyToId.clear(); + idToProperty.clear(); + + currentItem = item; + + if (currentItem == nullptr) + { + TreeView->setTitle(""); + return; + } + + ShowItemOptions(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::AddPropertyFormula(const QString &propertyName, const VFormula &formula, + const QString &attrName) +{ + VFormulaProperty* itemLength = new VFormulaProperty(propertyName); + itemLength->setFormula(formula); + AddProperty(itemLength, attrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &propertyName) +{ + VProperty* itemName = new VProperty(propertyName); + itemName->setValue(i->name()); + AddProperty(itemName, VAbstractTool::AttrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value, + const QString &attrName) +{ + VObjectProperty *pointsProperty = new VObjectProperty(propertyName); + QMap pointsList = i->PointsList(); + pointsProperty->setObjectsList(pointsList); + pointsProperty->setValue(value); + AddProperty(pointsProperty, attrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName) +{ + VEnumProperty *lineTypeProperty = new VEnumProperty(propertyName); + lineTypeProperty->setLiterals(VAbstractTool::Styles()); + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + lineTypeProperty->setValue(index); + AddProperty(lineTypeProperty, VAbstractTool::AttrTypeLine); +} + +//--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::SetPointName(const QString &name) { @@ -174,7 +297,7 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) if (name.isEmpty()) { - idToProperty[QLatin1String("name")]->setValue(i->name()); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } else { @@ -188,62 +311,6 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolOptionsPropertyBrowser::UpdateOptions() -{ - if (currentItem == nullptr) - { - return; - } - - switch (currentItem->type()) - { - case VToolSinglePoint::Type: - { - VToolSinglePoint *i = qgraphicsitem_cast(currentItem); - idToProperty[QLatin1String("name")]->setValue(i->name()); - idToProperty[QLatin1String("position")]->setValue(i->pos()); - break; - } - case VToolEndLine::Type: - { - VToolEndLine *i = qgraphicsitem_cast(currentItem); - idToProperty[QLatin1String("name")]->setValue(i->name()); - idToProperty[QLatin1String("basePoint")]->setValue(i->getBasePointId()); - - QStringList styles = VAbstractTool::Styles(); - qint32 index = styles.indexOf(i->getLineType()); - idToProperty[QLatin1String("lineType")]->setValue(index); - - VFormula formula(i->getFormulaLength(), i->getData()); - formula.setCheckZero(true); - formula.setToolId(i->getId()); - formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); - QVariant valueFormula; - valueFormula.setValue(formula); - idToProperty[QLatin1String("formulaLength")]->setValue(valueFormula); - - VFormula formulaAngle(i->getFormulaAngle(), i->getData()); - formulaAngle.setCheckZero(false); - formulaAngle.setToolId(i->getId()); - formulaAngle.setPostfix(QStringLiteral("°")); - QVariant valueAngle; - valueAngle.setValue(formulaAngle); - idToProperty[QLatin1String("formulaAngle")]->setValue(valueAngle); - - break; - } - case VGraphicsSimpleTextItem::Type: - ShowItemOptions(currentItem->parentItem()); - break; - case VControlPointSpline::Type: - ShowItemOptions(currentItem->parentItem()); - break; - default: - break; - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString &id) { @@ -253,73 +320,103 @@ void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString } //--------------------------------------------------------------------------------------------------------------------- -void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) +void VToolOptionsPropertyBrowser::ChangeDataToolSinglePoint(VProperty *property) { - switch (item->type()) + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + switch (PropertiesList().indexOf(id)) { - case VToolSinglePoint::Type: - { - VToolSinglePoint *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Base point")); - - VProperty* itemName = new VProperty(tr("Point name")); - itemName->setValue(i->name()); - AddProperty(itemName, QLatin1String("name")); - - VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); - itemPosition->setValue(i->pos()); - AddProperty(itemPosition, QLatin1String("position")); - + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); break; - } - case VToolEndLine::Type: - { - VToolEndLine *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Point at distance and angle")); - - VProperty* itemName = new VProperty(tr("Point name")); - itemName->setValue(i->name()); - AddProperty(itemName, QLatin1String("name")); - - VObjectProperty *pointsProperty = new VObjectProperty(tr("Base point")); - QMap pointsList = i->PointsList(); - pointsProperty->setObjectsList(pointsList); - pointsProperty->setValue(i->getBasePointId()); - AddProperty(pointsProperty, QLatin1String("basePoint")); - - VEnumProperty *lineTypeProperty = new VEnumProperty(tr("Line type")); - lineTypeProperty->setLiterals(VAbstractTool::Styles()); - QStringList styles = VAbstractTool::Styles(); - qint32 index = styles.indexOf(i->getLineType()); - lineTypeProperty->setValue(index); - AddProperty(lineTypeProperty, QLatin1String("lineType")); - - VFormulaProperty* itemLength = new VFormulaProperty(tr("Length")); - VFormula formulaLength(i->getFormulaLength(), i->getData()); - formulaLength.setCheckZero(true); - formulaLength.setToolId(i->getId()); - formulaLength.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); - itemLength->setFormula(formulaLength); - AddProperty(itemLength, QLatin1String("formulaLength")); - - VFormulaProperty* itemAngle = new VFormulaProperty(tr("Angle")); - VFormula formulaAngle(i->getFormulaAngle(), i->getData()); - formulaAngle.setCheckZero(false); - formulaAngle.setToolId(i->getId()); - formulaAngle.setPostfix(QStringLiteral("°")); - itemAngle->setFormula(formulaAngle); - AddProperty(itemAngle, QLatin1String("formulaAngle")); - break; - } - case VGraphicsSimpleTextItem::Type: - currentItem = item->parentItem(); - ShowItemOptions(currentItem); - break; - case VControlPointSpline::Type: - currentItem = item->parentItem(); - ShowItemOptions(currentItem); + case 1: // QLatin1String("position") + currentItem->setPos(value.toPointF()); break; default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolEndLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 2: // VAbstractTool::AttrBasePoint + i->setBasePointId(value.toUInt()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 5: // VAbstractTool::AttrAngle + i->setFormulaAngle(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolAlongLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 6: // VAbstractTool::AttrFirstPoint + i->setFirstPointId(value.toUInt()); + break; + case 7: // VAbstractTool::AttrSecondPoint + i->setSecondPointId(value.toUInt()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "< void SetPointName(const QString &name); + + template + void AddPropertyPointName(Tool *i, const QString &propertyName); + + template + void AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value, const QString &attrName); + + template + void AddPropertyLineType(Tool *i, const QString &propertyName); + + void AddPropertyFormula(const QString &propertyName, const VFormula &formula, const QString &attrName); + + QStringList PropertiesList() const; + + void ChangeDataToolSinglePoint(VProperty *property); + void ChangeDataToolEndLine(VProperty *property); + void ChangeDataToolAlongLine(VProperty *property); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H