Setter and getter for options VToolArc.

--HG--
branch : feature
This commit is contained in:
dismine 2014-09-01 17:34:45 +03:00
parent 8412cb464a
commit 3d3282ae61
8 changed files with 178 additions and 15 deletions

View File

@ -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"

View File

@ -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();
};

View File

@ -37,6 +37,8 @@
# include <QtMath> // 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;
}

View File

@ -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;

View File

@ -29,8 +29,10 @@
#include "vtoolarc.h"
#include "../../container/calculator.h"
#include "../../dialogs/tools/dialogarc.h"
#include <QKeyEvent>
#include "../../geometry/varc.h"
#include "../container/vformula.h"
#include <QKeyEvent>
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<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(id);
SCASSERT(arc.isNull() == false);
return arc->GetCenter().id();
}
//---------------------------------------------------------------------------------------------------------------------
void VToolArc::setCenter(const quint32 &value)
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VArc> arc = qSharedPointerDynamicCast<VArc>(obj);
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(value);
arc->SetCenter(*point.data());
SaveOption(obj);
}
//---------------------------------------------------------------------------------------------------------------------
VFormula VToolArc::getFormulaRadius() const
{
QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(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<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VArc> arc = qSharedPointerDynamicCast<VArc>(obj);
arc->SetFormulaRadius(value);
SaveOption(obj);
}
}
//---------------------------------------------------------------------------------------------------------------------
VFormula VToolArc::getFormulaF1() const
{
QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(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<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VArc> arc = qSharedPointerDynamicCast<VArc>(obj);
arc->SetFormulaF1(value);
SaveOption(obj);
}
}
//---------------------------------------------------------------------------------------------------------------------
VFormula VToolArc::getFormulaF2() const
{
QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(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<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VArc> arc = qSharedPointerDynamicCast<VArc>(obj);
arc->SetFormulaF2(value);
SaveOption(obj);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FullUpdateFromFile update tool data form file.

View File

@ -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<int>(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:

View File

@ -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());

View File

@ -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();