From 291c19d5a27cb545527cd93a0ca8d6eaa0b0f073 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 18 May 2016 14:32:51 +0300 Subject: [PATCH] Property browser for tool Rotation. --HG-- branch : feature --- .../core/vtooloptionspropertybrowser.cpp | 79 ++++++++++++++++- .../core/vtooloptionspropertybrowser.h | 6 ++ .../drawTools/operation/vtoolrotation.cpp | 88 +++++++++++++++++-- .../tools/drawTools/operation/vtoolrotation.h | 32 ++++--- 4 files changed, 185 insertions(+), 20 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 1a901204d..cdbc80c06 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -490,7 +490,6 @@ void VToolOptionsPropertyBrowser::AddPropertyObjectName(Tool *i, const QString & AddProperty(itemName, AttrName); } - //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyPointName1(Tool *i, const QString &propertyName) @@ -511,6 +510,17 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName2(Tool *i, const QString & AddProperty(itemName, AttrName2); } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyOperationSuffix(Tool *i, const QString &propertyName, bool readOnly) +{ + auto itemSuffix = new VStringProperty(propertyName); + itemSuffix->setClearButtonEnable(true); + itemSuffix->setValue(i->Suffix()); + itemSuffix->setReadOnly(readOnly); + AddProperty(itemSuffix, AttrSuffix); +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyCrossPoint(Tool *i, const QString &propertyName) @@ -654,6 +664,43 @@ void VToolOptionsPropertyBrowser::SetPointName2(const QString &name) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetOperationSuffix(const QString &suffix) +{ + if (Tool *item = qgraphicsitem_cast(currentItem)) + { + if (suffix == item->Suffix()) + { + return; + } + + if (suffix.isEmpty()) + { + idToProperty[AttrSuffix]->setValue(item->Suffix()); + return; + } + + QRegularExpression rx(NameRegExp()); + const QVector names = item->GetNames(suffix); + for (int i=0; i < names.size(); ++i) + { + if (not rx.match(names.at(i)).hasMatch() || not VContainer::IsUnique(names.at(i))) + { + idToProperty[AttrSuffix]->setValue(item->Suffix()); + } + else + { + item->SetSuffix(suffix); + } + } + } + else + { + qWarning()<<"Can't cast item"; + } +} + //--------------------------------------------------------------------------------------------------------------------- template Type VToolOptionsPropertyBrowser::GetCrossPoint(const QVariant &value) @@ -1538,6 +1585,24 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCurveIntersectAxis(VProperty *pr void VToolOptionsPropertyBrowser::ChangeDataToolRotation(VProperty *property) { SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolRotation *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + case 5: // AttrAngle + i->SetFormulaAngle(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<(item); i->ShowVisualization(true); + formView->setTitle(tr("Tool rotation")); + + AddPropertyOperationSuffix(i, tr("Suffix")); + AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle); } //--------------------------------------------------------------------------------------------------------------------- @@ -2390,7 +2459,12 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCurveIntersectAxis() //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation() { + VToolRotation *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrSuffix]->setValue(i->Suffix()); + QVariant valueAngle; + valueAngle.setValue(i->GetFormulaAngle()); + idToProperty[AttrAngle]->setValue(valueAngle); } //--------------------------------------------------------------------------------------------------------------------- @@ -2433,6 +2507,7 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const << AttrVCrossPoint /* 34 */ << AttrHCrossPoint /* 35 */ << AttrLength1 /* 36 */ - << AttrLength2; /* 37 */ + << AttrLength2 /* 37 */ + << AttrSuffix; /* 38 */ return attr; } diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index a0e44fef0..e8ba646e1 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -74,6 +74,9 @@ private: template void SetPointName2(const QString &name); + template + void SetOperationSuffix(const QString &suffix); + template Type GetCrossPoint(const QVariant &value); @@ -95,6 +98,9 @@ private: template void AddPropertyPointName2(Tool *i, const QString &propertyName); + template + void AddPropertyOperationSuffix(Tool *i, const QString &propertyName, bool readOnly = false); + template void AddPropertyCrossPoint(Tool *i, const QString &propertyName); diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index ec1aaa9d0..4837ba21b 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -39,6 +39,7 @@ #include "../vwidgets/vsimplepoint.h" #include "../vwidgets/vsimplecurve.h" #include "../../../undocommands/label/rotationmovelabel.h" +#include "../vpatterndb/vformula.h" const QString VToolRotation::ToolType = QStringLiteral("rotation"); const QString VToolRotation::TagItem = QStringLiteral("item"); @@ -53,7 +54,7 @@ VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id : VDrawTool(doc, data, id), QGraphicsItem(parent), origPointId(origPointId), - angle(angle), + formulaAngle(angle), suffix(suffix), source(source), destination(destination), @@ -142,7 +143,7 @@ void VToolRotation::setDialog() DialogRotation *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); dialogTool->SetOrigPointId(origPointId); - dialogTool->SetAngle(angle); + dialogTool->SetAngle(formulaAngle); dialogTool->SetSuffix(suffix); } @@ -350,6 +351,52 @@ void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domEle } } +//--------------------------------------------------------------------------------------------------------------------- +QVector VToolRotation::GetNames(const QString &suffix) const +{ + QVector names; + for (int i = 0; i < source.size(); ++i) + { + const QSharedPointer obj = VAbstractTool::data.GetGObject(source.at(i)); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +#if defined(Q_CC_GNU) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch-default" +#endif + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer point = VAbstractTool::data.GeometricObject(source.at(i)); + names.append(point->name() + suffix); + break; + } + case GOType::Arc: + case GOType::EllipticalArc: + case GOType::Spline: + case GOType::SplinePath: + case GOType::CubicBezier: + case GOType::CubicBezierPath: + { + const QSharedPointer curve = + VAbstractTool::data.GeometricObject(source.at(i)); + names.append(curve->name() + suffix); + break; + } + case GOType::Unknown: + break; + } +#if defined(Q_CC_GNU) +#pragma GCC diagnostic pop +#endif + } + + return names; +} + //--------------------------------------------------------------------------------------------------------------------- QString VToolRotation::getTagName() const { @@ -362,12 +409,43 @@ void VToolRotation::SetEnabled(bool enabled) this->setEnabled(enabled); } +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolRotation::GetFormulaAngle() const +{ + VFormula fAngle(formulaAngle, getData()); + fAngle.setCheckZero(false); + fAngle.setToolId(id); + fAngle.setPostfix(degreeSymbol); + return fAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetFormulaAngle(const VFormula &value) +{ + if (value.error() == false) + { + formulaAngle = value.GetFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + //--------------------------------------------------------------------------------------------------------------------- QString VToolRotation::Suffix() const { return suffix; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetSuffix(const QString &suffix) +{ + // Don't know if need check name here. + this->suffix = suffix; + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::GroupVisibility(quint32 object, bool visible) { @@ -620,7 +698,7 @@ void VToolRotation::SetVisualization() visual->SetObjects(source); visual->SetOriginPointId(origPointId); - visual->SetAngle(qApp->TrVars()->FormulaToUser(angle)); + visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle)); visual->RefreshGeometry(); } } @@ -718,7 +796,7 @@ void VToolRotation::SaveDialog(QDomElement &domElement) void VToolRotation::ReadToolAttributes(const QDomElement &domElement) { origPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); - angle = doc->GetParametrString(domElement, AttrAngle, "0"); + formulaAngle = doc->GetParametrString(domElement, AttrAngle, "0"); suffix = doc->GetParametrString(domElement, AttrSuffix); } @@ -729,7 +807,7 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId)); - doc->SetAttribute(tag, AttrAngle, angle); + doc->SetAttribute(tag, AttrAngle, formulaAngle); doc->SetAttribute(tag, AttrSuffix, suffix); QDomElement tagObjects = doc->createElement(TagSource); diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h index 740d0c2ba..9556b7d03 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -40,6 +40,7 @@ struct DestinationItem class VAbstractSimple; class VSimpleCurve; +class VFormula; class VToolRotation : public VDrawTool, public QGraphicsItem { @@ -52,12 +53,13 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolRotation* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix, + static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &formulaAngle, const QString &suffix, const QVector &source, const QVector &destination, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, QVector &destination); + QVector GetNames(const QString &suffix) const; static const QString ToolType; static const QString TagItem; static const QString TagSource; @@ -68,7 +70,11 @@ public: void SetEnabled(bool enabled); + VFormula GetFormulaAngle() const; + void SetFormulaAngle(const VFormula &value); + QString Suffix() const; + void SetSuffix(const QString &suffix); virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; @@ -118,7 +124,7 @@ private slots: private: Q_DISABLE_COPY(VToolRotation) quint32 origPointId; - QString angle; + QString formulaAngle; QString suffix; QVector source; @@ -127,39 +133,39 @@ private: QMap rObjects; VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, - const QString &angle, const QString &suffix, const QVector &source, + const QString &formulaAngle, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent = nullptr); void UpdateNamePosition(quint32 id); - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); template - static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); - static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); - static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); template - static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id); - static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id); template