Check unique label name in dialog. Fixed catch broken expression.

--HG--
branch : feature
This commit is contained in:
dismine 2014-09-06 11:14:59 +03:00
parent afbc8d8c30
commit 6c784fcdca
31 changed files with 36 additions and 62 deletions

View File

@ -139,15 +139,12 @@ qreal Calculator::EvalFormula(const QString &formula)
} }
// Add variables // Add variables
InitVariables(data, tokens); InitVariables(data, tokens, formula);
return Eval();
result = Eval();
return result;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void Calculator::InitVariables(const VContainer *data, const QMap<int, QString> &tokens) void Calculator::InitVariables(const VContainer *data, const QMap<int, QString> &tokens, const QString &formula)
{ {
if (qApp->patternType() == MeasurementsType::Standard) if (qApp->patternType() == MeasurementsType::Standard)
{ {
@ -156,9 +153,11 @@ void Calculator::InitVariables(const VContainer *data, const QMap<int, QString>
const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables(); const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables();
bool found = false;
QMap<int, QString>::const_iterator i = tokens.constBegin(); QMap<int, QString>::const_iterator i = tokens.constBegin();
while (i != tokens.constEnd()) while (i != tokens.constEnd())
{ {
found = false;
if (vars->contains(i.value())) if (vars->contains(i.value()))
{ {
QSharedPointer<VInternalVariable> var = vars->value(i.value()); QSharedPointer<VInternalVariable> var = vars->value(i.value());
@ -169,6 +168,7 @@ void Calculator::InitVariables(const VContainer *data, const QMap<int, QString>
m->SetValue(data->size(), data->height()); m->SetValue(data->size(), data->height());
} }
DefineVar(i.value(), var->GetValue()); DefineVar(i.value(), var->GetValue());
found = true;
} }
if (qApp->patternType() == MeasurementsType::Standard) if (qApp->patternType() == MeasurementsType::Standard)
@ -177,14 +177,21 @@ void Calculator::InitVariables(const VContainer *data, const QMap<int, QString>
{ {
vVarVal[0] = data->size(); vVarVal[0] = data->size();
DefineVar(data->SizeName(), &vVarVal[0]); DefineVar(data->SizeName(), &vVarVal[0]);
found = true;
} }
if (i.value() == data->HeightName()) if (i.value() == data->HeightName())
{ {
vVarVal[1] = data->height(); vVarVal[1] = data->height();
DefineVar(data->HeightName(), &vVarVal[1]); DefineVar(data->HeightName(), &vVarVal[1]);
found = true;
} }
} }
if (found == false)
{
throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN , i.value(), formula, i.key());
}
++i; ++i;
} }
} }

View File

@ -64,7 +64,7 @@ private:
qreal *vVarVal; qreal *vVarVal;
static int iVal; static int iVal;
const VContainer *data; const VContainer *data;
void InitVariables(const VContainer *data, const QMap<int, QString> &tokens); void InitVariables(const VContainer *data, const QMap<int, QString> &tokens, const QString &formula);
void InitCharacterSets(); void InitCharacterSets();
static qreal* AddVariable(const QString &a_szName, void *a_pUserData); static qreal* AddVariable(const QString &a_szName, void *a_pUserData);
}; };

View File

@ -41,7 +41,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0),
typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0),
line(nullptr) line(nullptr)
{ {

View File

@ -87,9 +87,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;

View File

@ -42,7 +42,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), typeLine(QString()),
formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), thirdPointId(NULL_ID), formulaBaseHeight(0), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), thirdPointId(NULL_ID), formulaBaseHeight(0),
line(nullptr), prepare(false) line(nullptr), prepare(false)
{ {

View File

@ -92,9 +92,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;

View File

@ -42,7 +42,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
: DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), formula(QString()),
arcId(NULL_ID), formulaBaseHeight(0), path(nullptr) arcId(NULL_ID), formulaBaseHeight(0), path(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -78,9 +78,6 @@ private:
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */
Ui::DialogCutArc *ui; Ui::DialogCutArc *ui;
/** @brief pointName name of created point */
QString pointName;
/** @brief formula string with formula */ /** @brief formula string with formula */
QString formula; QString formula;

View File

@ -40,7 +40,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()),
splineId(NULL_ID), formulaBaseHeight(0) splineId(NULL_ID), formulaBaseHeight(0)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -71,9 +71,6 @@ private:
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */
Ui::DialogCutSpline *ui; Ui::DialogCutSpline *ui;
/** @brief pointName name of created point */
QString pointName;
/** @brief formula string with formula */ /** @brief formula string with formula */
QString formula; QString formula;

View File

@ -40,7 +40,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), pointName(QString()), formula(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()),
splinePathId(NULL_ID), formulaBaseHeight(0) splinePathId(NULL_ID), formulaBaseHeight(0)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -71,9 +71,6 @@ private:
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */
Ui::DialogCutSplinePath *ui; Ui::DialogCutSplinePath *ui;
/** @brief pointName name of created point */
QString pointName;
/** @brief formula string with formula */ /** @brief formula string with formula */
QString formula; QString formula;

View File

@ -42,7 +42,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), typeLine(QString()),
formulaLength(QString()), formulaAngle(QString()), basePointId(NULL_ID), formulaBaseHeight(0), formulaLength(QString()), formulaAngle(QString()), basePointId(NULL_ID), formulaBaseHeight(0),
formulaBaseHeightAngle(0), line(nullptr) formulaBaseHeightAngle(0), line(nullptr)
{ {

View File

@ -89,9 +89,6 @@ private:
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */
Ui::DialogEndLine *ui; Ui::DialogEndLine *ui;
/** @brief pointName name of point */
QString pointName;
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;

View File

@ -42,7 +42,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0), pointName(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0),
typeLine(QString()), basePointId(NULL_ID), p1LineId(NULL_ID), p2LineId(NULL_ID), line(nullptr) typeLine(QString()), basePointId(NULL_ID), p1LineId(NULL_ID), p2LineId(NULL_ID), line(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -81,9 +81,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;

View File

@ -42,7 +42,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0),
p1Line1(NULL_ID), p2Line1(NULL_ID), p1Line2(NULL_ID), p2Line2(NULL_ID), flagPoint(true), line(nullptr) p1Line1(NULL_ID), p2Line1(NULL_ID), p1Line2(NULL_ID), p2Line2(NULL_ID), flagPoint(true), line(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -85,9 +85,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief p1Line1 id first point of first line */ /** @brief p1Line1 id first point of first line */
quint32 p1Line1; quint32 p1Line1;

View File

@ -39,7 +39,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), typeLine(QString()),
formula(QString()), angle(0), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr) formula(QString()), angle(0), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -91,9 +91,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;

View File

@ -41,7 +41,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0),
radius(QString()), center(NULL_ID), firstPoint(NULL_ID), secondPoint(NULL_ID), formulaBaseHeight(0), line(nullptr) radius(QString()), center(NULL_ID), firstPoint(NULL_ID), secondPoint(NULL_ID), formulaBaseHeight(0), line(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -89,9 +89,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief radius radius of arc */ /** @brief radius radius of arc */
QString radius; QString radius;

View File

@ -42,7 +42,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), pointName(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0),
firstPointId(NULL_ID), secondPointId(NULL_ID), line(nullptr) firstPointId(NULL_ID), secondPointId(NULL_ID), line(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -75,9 +75,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief firstPointId id first point of line */ /** @brief firstPointId id first point of line */
quint32 firstPointId; quint32 firstPointId;

View File

@ -42,7 +42,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), :DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0),
typeLine(QString()), formula(QString()), p1Line(NULL_ID), p2Line(NULL_ID), pShoulder(NULL_ID), formulaBaseHeight(0), typeLine(QString()), formula(QString()), p1Line(NULL_ID), p2Line(NULL_ID), pShoulder(NULL_ID), formulaBaseHeight(0),
line (nullptr) line (nullptr)
{ {

View File

@ -91,9 +91,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;

View File

@ -63,7 +63,8 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p
labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr),
radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr),
radioButtonLengthCurve(nullptr), radioButtonAngleLine(nullptr), lineStyles(VAbstractTool::Styles()), radioButtonLengthCurve(nullptr), radioButtonAngleLine(nullptr), lineStyles(VAbstractTool::Styles()),
okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false) okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false),
pointName(QString())
{ {
SCASSERT(data != nullptr); SCASSERT(data != nullptr);
timerFormula = new QTimer(this); timerFormula = new QTimer(this);
@ -659,7 +660,8 @@ void DialogTool::NamePointChanged()
if (edit) if (edit)
{ {
QString name = edit->text(); QString name = edit->text();
if (name.isEmpty() || name.contains(" ")) name.replace(" ", "");
if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false))
{ {
flagName = false; flagName = false;
ChangeColor(labelEditNamePoint, Qt::red); ChangeColor(labelEditNamePoint, Qt::red);

View File

@ -200,6 +200,9 @@ protected:
/** @brief prepare show if we prepare. Show dialog after finish working with visual part of tool*/ /** @brief prepare show if we prepare. Show dialog after finish working with visual part of tool*/
bool prepare; bool prepare;
/** @brief pointName name of point */
QString pointName;
virtual void closeEvent ( QCloseEvent * event ); virtual void closeEvent ( QCloseEvent * event );
virtual void showEvent( QShowEvent *event ); virtual void showEvent( QShowEvent *event );
void FillComboBoxPoints(QComboBox *box)const; void FillComboBoxPoints(QComboBox *box)const;

View File

@ -41,7 +41,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent) DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), pointName(QString()), axisP1Id(NULL_ID), :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), axisP1Id(NULL_ID),
axisP2Id(NULL_ID), firstPointId(NULL_ID), secondPointId(NULL_ID), line (nullptr) axisP2Id(NULL_ID), firstPointId(NULL_ID), secondPointId(NULL_ID), line (nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -80,9 +80,6 @@ private:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
/** @brief pointName name of point */
QString pointName;
/** @brief axisP1Id id first point of axis */ /** @brief axisP1Id id first point of axis */
quint32 axisP1Id; quint32 axisP1Id;

View File

@ -1139,7 +1139,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem
//Rewrite attribute formula. Need for situation when we have wrong formula. //Rewrite attribute formula. Need for situation when we have wrong formula.
if (f != formula || angleFix != angle) if (f != formula || angleFix != angle)
{ {
SetAttribute(domElement, VAbstractTool::AttrRadius, f); SetAttribute(domElement, VAbstractTool::AttrLength, f);
SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix); SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix);
haveLiteChange(); haveLiteChange();
} }
@ -2452,6 +2452,7 @@ void VPattern::PrepareForParse(const Document &parse)
else if (parse == Document::LiteParse) else if (parse == Document::LiteParse)
{ {
data->ClearUniqueNames(); data->ClearUniqueNames();
data->ClearVariables();
} }
} }