From 3d3282ae61118d6717573ddd94953918bd25b651 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 17:34:45 +0300 Subject: [PATCH] Setter and getter for options VToolArc. --HG-- branch : feature --- src/app/container/vformula.cpp | 28 ++++-- src/app/container/vformula.h | 4 +- src/app/geometry/varc.cpp | 29 +++++++ src/app/geometry/varc.h | 11 ++- src/app/tools/drawTools/vtoolarc.cpp | 99 +++++++++++++++++++++- src/app/tools/drawTools/vtoolarc.h | 14 +++ src/app/widgets/vformulaproperty.cpp | 2 +- src/app/widgets/vformulapropertyeditor.cpp | 6 +- 8 files changed, 178 insertions(+), 15 deletions(-) diff --git a/src/app/container/vformula.cpp b/src/app/container/vformula.cpp index 412934508..b9a9719ea 100644 --- a/src/app/container/vformula.cpp +++ b/src/app/container/vformula.cpp @@ -35,13 +35,13 @@ //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula() :formula(QString()), value(QString(tr("Error"))), checkZero(true), data(nullptr), toolId(NULL_ID), - postfix(QStringLiteral("")), _error(true) + postfix(QStringLiteral("")), _error(true), dValue(0) {} //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula(const QString &formula, const VContainer *container) :formula(qApp->FormulaToUser(formula)), value(QString(tr("Error"))), checkZero(true), data(container), toolId(NULL_ID), - postfix(QStringLiteral("")), _error(true) + postfix(QStringLiteral("")), _error(true), dValue(0) { this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist Eval(); @@ -55,29 +55,31 @@ VFormula &VFormula::operator=(const VFormula &formula) return *this; } this->formula = formula.getFormula(); - this->value = formula.getValue(); + this->value = formula.getStringValue(); this->checkZero = formula.getCheckZero(); this->data = formula.getData(); this->toolId = formula.getToolId(); this->postfix = formula.getPostfix(); this->_error = formula.error(); + this->dValue = formula.getDoubleValue(); return *this; } //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula(const VFormula &formula) - :formula(formula.getFormula()), value(formula.getValue()), checkZero(formula.getCheckZero()), - data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()) + :formula(formula.getFormula()), value(formula.getStringValue()), checkZero(formula.getCheckZero()), + data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()), + dValue(formula.getDoubleValue()) {} //--------------------------------------------------------------------------------------------------------------------- bool VFormula::operator==(const VFormula &formula) const { bool isEqual = false; - if (this->formula == formula.getFormula() && this->value == formula.getValue() && + if (this->formula == formula.getFormula() && this->value == formula.getStringValue() && this->checkZero == formula.getCheckZero() && this->data == formula.getData() && this->toolId == formula.getToolId() && this->postfix == formula.getPostfix() && - this->_error == formula.error()) + this->_error == formula.error() && this->dValue == formula.getDoubleValue()) { isEqual = true; } @@ -121,11 +123,17 @@ void VFormula::setFormula(const QString &value, FormulaType type) } //--------------------------------------------------------------------------------------------------------------------- -QString VFormula::getValue() const +QString VFormula::getStringValue() const { return value; } +//--------------------------------------------------------------------------------------------------------------------- +qreal VFormula::getDoubleValue() const +{ + return dValue; +} + //--------------------------------------------------------------------------------------------------------------------- bool VFormula::getCheckZero() const { @@ -209,6 +217,7 @@ void VFormula::Eval() { value = QString(tr("Error")); _error = true; + dValue = 0; } else { @@ -224,6 +233,7 @@ void VFormula::Eval() { value = QString("0"); _error = true; + dValue = 0; } else { @@ -236,6 +246,7 @@ void VFormula::Eval() { loc = QLocale(QLocale::C); } + dValue = result; value = QString(loc.toString(result) + " " + postfix); _error = false; } @@ -244,6 +255,7 @@ void VFormula::Eval() { value = QString(tr("Error")); _error = true; + dValue = 0; qDebug() << "\nMath parser error:\n" << "--------------------------------------\n" << "Message: " << e.GetMsg() << "\n" diff --git a/src/app/container/vformula.h b/src/app/container/vformula.h index c60453de7..222845442 100644 --- a/src/app/container/vformula.h +++ b/src/app/container/vformula.h @@ -49,7 +49,8 @@ public: QString getFormula(FormulaType type = FormulaType::ToUser) const; void setFormula(const QString &value, FormulaType type = FormulaType::ToUser); - QString getValue() const; + QString getStringValue() const; + qreal getDoubleValue() const; bool getCheckZero() const; void setCheckZero(bool value); @@ -74,6 +75,7 @@ private: quint32 toolId; QString postfix; bool _error; + qreal dValue; void Eval(); }; diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index b2773455e..6d97b2c3d 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -37,6 +37,8 @@ # include // for M_PI on Windows #endif /*Q_OS_WIN32*/ +#include "../container/vformula.h" + //--------------------------------------------------------------------------------------------------------------------- /** @@ -247,6 +249,13 @@ QString VArc::GetFormulaF1() const return d->formulaF1; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaF1(const VFormula &value) +{ + d->formulaF1 = value.getFormula(FormulaType::FromUser); + d->f1 = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetF1 return formula for start angle. @@ -267,6 +276,13 @@ QString VArc::GetFormulaF2() const return d->formulaF2; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaF2(const VFormula &value) +{ + d->formulaF2 = value.getFormula(FormulaType::FromUser); + d->f2 = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetF2 return formula for end angle. @@ -287,6 +303,13 @@ QString VArc::GetFormulaRadius() const return d->formulaRadius; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaRadius(const VFormula &value) +{ + d->formulaRadius = value.getFormula(FormulaType::FromUser); + d->radius = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetRadius return formula for radius. @@ -306,3 +329,9 @@ VPointF VArc::GetCenter() const { return d->center; } + +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetCenter(const VPointF &value) +{ + d->center = value; +} diff --git a/src/app/geometry/varc.h b/src/app/geometry/varc.h index bd48b8568..53003724f 100644 --- a/src/app/geometry/varc.h +++ b/src/app/geometry/varc.h @@ -35,6 +35,7 @@ class QPainterPath; class VArcData; +class VFormula; /** * @brief VArc class for anticlockwise arc. @@ -52,13 +53,21 @@ public: virtual ~VArc(); QString GetFormulaF1 () const; + void SetFormulaF1 (const VFormula &value); qreal GetF1 () const; + QString GetFormulaF2 () const; + void SetFormulaF2 (const VFormula &value); qreal GetF2 () const; - qreal GetLength () const; + QString GetFormulaRadius () const; + void SetFormulaRadius (const VFormula &value); qreal GetRadius () const; + VPointF GetCenter () const; + void SetCenter (const VPointF &value); + + qreal GetLength () const; QPointF GetP1() const; QPointF GetP2 () const; qreal AngleArc() const; diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 3fe7d4bae..6a5b1f625 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -29,8 +29,10 @@ #include "vtoolarc.h" #include "../../container/calculator.h" #include "../../dialogs/tools/dialogarc.h" -#include #include "../../geometry/varc.h" +#include "../container/vformula.h" + +#include const QString VToolArc::TagName = QStringLiteral("arc"); const QString VToolArc::ToolType = QStringLiteral("simple"); @@ -170,6 +172,101 @@ QString VToolArc::getTagName() const return VToolArc::TagName; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolArc::getCenter() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + return arc->GetCenter().id(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setCenter(const quint32 &value) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + + QSharedPointer point = VAbstractTool::data.GeometricObject(value); + arc->SetCenter(*point.data()); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaRadius() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula radius(arc->GetFormulaRadius(), getData()); + radius.setCheckZero(true); + radius.setToolId(id); + radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return radius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaRadius(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaRadius(value); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaF1() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula f1(arc->GetFormulaF1(), getData()); + f1.setCheckZero(false); + f1.setToolId(id); + f1.setPostfix(QStringLiteral("°")); + return f1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaF1(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaF1(value); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaF2() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula f2(arc->GetFormulaF2(), getData()); + f2.setCheckZero(false); + f2.setToolId(id); + f2.setPostfix(QStringLiteral("°")); + return f2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaF2(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaF2(value); + SaveOption(obj); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 30a63acfb..a7ba24b52 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -31,6 +31,8 @@ #include "vabstractspline.h" +class VFormula; + /** * @brief The VToolArc class tool for creation arc. */ @@ -49,6 +51,18 @@ public: virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Arc)}; virtual QString getTagName() const; + + quint32 getCenter() const; + void setCenter(const quint32 &value); + + VFormula getFormulaRadius() const; + void setFormulaRadius(const VFormula &value); + + VFormula getFormulaF1() const; + void setFormulaF1(const VFormula &value); + + VFormula getFormulaF2() const; + void setFormulaF2(const VFormula &value); public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/widgets/vformulaproperty.cpp b/src/app/widgets/vformulaproperty.cpp index 752a8103b..d01a91621 100644 --- a/src/app/widgets/vformulaproperty.cpp +++ b/src/app/widgets/vformulaproperty.cpp @@ -181,7 +181,7 @@ void VFormulaProperty::setFormula(const VFormula &formula) value.convert(VFormula::FormulaTypeId()); VProperty::d_ptr->VariantValue = value; - QVariant tmpValue(formula.getValue()); + QVariant tmpValue(formula.getStringValue()); tmpValue.convert(QVariant::String); QVariant tmpFormula(formula.getFormula()); diff --git a/src/app/widgets/vformulapropertyeditor.cpp b/src/app/widgets/vformulapropertyeditor.cpp index f286d6154..b445e9715 100644 --- a/src/app/widgets/vformulapropertyeditor.cpp +++ b/src/app/widgets/vformulapropertyeditor.cpp @@ -58,7 +58,7 @@ VFormulaPropertyEditor::VFormulaPropertyEditor(QWidget *parent) : // Create the text label TextLabel = new QLabel(this); - TextLabel->setText(formula.getValue()); + TextLabel->setText(formula.getStringValue()); // Spacer (this is needed for proper display of the label and button) Spacer = new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored); @@ -78,7 +78,7 @@ void VFormulaPropertyEditor::setFormula(const VFormula& formula) if (this->formula != formula) { this->formula = formula; - TextLabel->setText(this->formula.getValue()); + TextLabel->setText(this->formula.getStringValue()); } } @@ -94,7 +94,7 @@ void VFormulaPropertyEditor::onToolButtonClicked() if (tmpWidget->exec() == QDialog::Accepted) { formula.setFormula(tmpWidget->getFormula(), FormulaType::ToUser); - TextLabel->setText(formula.getValue()); + TextLabel->setText(formula.getStringValue()); delete tmpWidget; emit dataChangedByUser(formula, this); UserChangeEvent *event = new UserChangeEvent();