Dialog edit wrong formula (only for toolendline now).

--HG--
branch : feature
This commit is contained in:
dismine 2014-05-30 11:32:40 +03:00
parent 01ee27d33c
commit 381adf0ba0
17 changed files with 649 additions and 100 deletions

View file

@ -97,14 +97,7 @@ Calculator::Calculator(const QString &formula, bool fromUser)
} }
SetExpr(formula); SetExpr(formula);
try Eval();//Need run for making tokens
{
Eval();//Need run for making tokens
}
catch(qmu::QmuParserError &e)
{
return;//Ignore all warnings
}
} }
Calculator::~Calculator() Calculator::~Calculator()
@ -217,15 +210,13 @@ void Calculator::InitVariables(const VContainer *data)
if (qApp->patternType() == Pattern::Standard) if (qApp->patternType() == Pattern::Standard)
{ {
vVarVal[j] = i.value().GetValue(data->size(), data->height()); vVarVal[j] = i.value().GetValue(data->size(), data->height());
DefineVar(i.key(), &vVarVal[j]);
++j;
} }
else else
{ {
vVarVal[j] = i.value().GetValue(); vVarVal[j] = i.value().GetValue();
DefineVar(i.key(), &vVarVal[j]);
++j;
} }
DefineVar(i.key(), &vVarVal[j]);
++j;
++i; ++i;
} }
} }
@ -237,15 +228,13 @@ void Calculator::InitVariables(const VContainer *data)
if (qApp->patternType() == Pattern::Standard) if (qApp->patternType() == Pattern::Standard)
{ {
vVarVal[j] = i.value().GetValue(data->size(), data->height()); vVarVal[j] = i.value().GetValue(data->size(), data->height());
DefineVar(i.key(), &vVarVal[j]);
++j;
} }
else else
{ {
vVarVal[j] = i.value().GetValue(); vVarVal[j] = i.value().GetValue();
DefineVar(i.key(), &vVarVal[j]);
++j;
} }
DefineVar(i.key(), &vVarVal[j]);
++j;
++i; ++i;
} }
} }

View file

@ -29,7 +29,8 @@ HEADERS += \
dialogs/app/dialogmeasurements.h \ dialogs/app/dialogmeasurements.h \
dialogs/app/dialogstandardmeasurements.h \ dialogs/app/dialogstandardmeasurements.h \
dialogs/app/dialogindividualmeasurements.h \ dialogs/app/dialogindividualmeasurements.h \
dialogs/app/dialogaboutapp.h dialogs/app/dialogaboutapp.h \
dialogs/tools/dialogeditwrongformula.h
SOURCES += \ SOURCES += \
dialogs/tools/dialogtriangle.cpp \ dialogs/tools/dialogtriangle.cpp \
@ -61,7 +62,8 @@ SOURCES += \
dialogs/app/dialogmeasurements.cpp \ dialogs/app/dialogmeasurements.cpp \
dialogs/app/dialogstandardmeasurements.cpp \ dialogs/app/dialogstandardmeasurements.cpp \
dialogs/app/dialogindividualmeasurements.cpp \ dialogs/app/dialogindividualmeasurements.cpp \
dialogs/app/dialogaboutapp.cpp dialogs/app/dialogaboutapp.cpp \
dialogs/tools/dialogeditwrongformula.cpp
FORMS += \ FORMS += \
dialogs/tools/dialogtriangle.ui \ dialogs/tools/dialogtriangle.ui \
@ -90,4 +92,5 @@ FORMS += \
dialogs/app/dialogmeasurements.ui \ dialogs/app/dialogmeasurements.ui \
dialogs/app/dialogstandardmeasurements.ui \ dialogs/app/dialogstandardmeasurements.ui \
dialogs/app/dialogindividualmeasurements.ui \ dialogs/app/dialogindividualmeasurements.ui \
dialogs/app/dialogaboutapp.ui dialogs/app/dialogaboutapp.ui \
dialogs/tools/dialogeditwrongformula.ui

View file

@ -30,6 +30,11 @@
#include "ui_dialogcutarc.h" #include "ui_dialogcutarc.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogCutArc create dialog.
* @param data container with data
* @param parent parent widget
*/
DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) : DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) :
DialogTool(data, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), arcId(0) DialogTool(data, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), arcId(0)
{ {
@ -62,6 +67,11 @@ DialogCutArc::~DialogCutArc()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
* @param id id of point or detail
* @param type type of object
*/
void DialogCutArc::ChoosedObject(quint32 id, const Valentina::Scenes &type) void DialogCutArc::ChoosedObject(quint32 id, const Valentina::Scenes &type)
{ {
if (type == Valentina::Arc) if (type == Valentina::Arc)
@ -74,6 +84,9 @@ void DialogCutArc::ChoosedObject(quint32 id, const Valentina::Scenes &type)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
*/
void DialogCutArc::DialogAccepted() void DialogCutArc::DialogAccepted()
{ {
pointName = ui->lineEditNamePoint->text(); pointName = ui->lineEditNamePoint->text();
@ -83,12 +96,21 @@ void DialogCutArc::DialogAccepted()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief setArcId set id of arc
* @param value id
* @param id don't show this id in list
*/
void DialogCutArc::setArcId(const quint32 &value, const quint32 &id) void DialogCutArc::setArcId(const quint32 &value, const quint32 &id)
{ {
setCurrentArcId(ui->comboBoxArc, arcId, value, id, ComboMode::CutArc); setCurrentArcId(ui->comboBoxArc, arcId, value, id, ComboMode::CutArc);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief setFormula set string with formula length
* @param value string with formula
*/
void DialogCutArc::setFormula(const QString &value) void DialogCutArc::setFormula(const QString &value)
{ {
formula = qApp->FormulaToUser(value); formula = qApp->FormulaToUser(value);
@ -96,8 +118,22 @@ void DialogCutArc::setFormula(const QString &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief setPointName set name point on arc
* @param value name
*/
void DialogCutArc::setPointName(const QString &value) void DialogCutArc::setPointName(const QString &value)
{ {
pointName = value; pointName = value;
ui->lineEditNamePoint->setText(pointName); ui->lineEditNamePoint->setText(pointName);
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getFormula return string with formula length
* @return formula
*/
QString DialogCutArc::getFormula() const
{
return qApp->FormulaFromUser(formula);
}

View file

@ -43,54 +43,17 @@ class DialogCutArc : public DialogTool
{ {
Q_OBJECT Q_OBJECT
public: public:
/**
* @brief DialogCutArc create dialog.
* @param data container with data
* @param parent parent widget
*/
DialogCutArc(const VContainer *data, QWidget *parent = nullptr); DialogCutArc(const VContainer *data, QWidget *parent = nullptr);
~DialogCutArc(); ~DialogCutArc();
/** QString getPointName() const;
* @brief getPointName return name point on arc
* @return name
*/
QString getPointName() const {return pointName;}
/**
* @brief setPointName set name point on arc
* @param value name
*/
void setPointName(const QString &value); void setPointName(const QString &value);
/** QString getFormula() const;
* @brief getFormula return string with formula length
* @return formula
*/
QString getFormula() const {return qApp->FormulaFromUser(formula);}
/**
* @brief setFormula set string with formula length
* @param value string with formula
*/
void setFormula(const QString &value); void setFormula(const QString &value);
/** quint32 getArcId() const;
* @brief getArcId return id of arc
* @return id
*/
quint32 getArcId() const {return arcId;}
/**
* @brief setArcId set id of arc
* @param value id
* @param id don't show this id in list
*/
void setArcId(const quint32 &value, const quint32 &id); void setArcId(const quint32 &value, const quint32 &id);
public slots: public slots:
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
* @param id id of point or detail
* @param type type of object
*/
virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type);
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
*/
virtual void DialogAccepted(); virtual void DialogAccepted();
private: private:
Q_DISABLE_COPY(DialogCutArc) Q_DISABLE_COPY(DialogCutArc)
@ -112,4 +75,24 @@ private:
quint32 arcId; quint32 arcId;
}; };
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getPointName return name point on arc
* @return name
*/
inline QString DialogCutArc::getPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getArcId return id of arc
* @return id
*/
inline quint32 DialogCutArc::getArcId() const
{
return arcId;
}
#endif // DIALOGCUTARC_H #endif // DIALOGCUTARC_H

View file

@ -0,0 +1,95 @@
/************************************************************************
**
** @file dialogeditwrongformula.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 29 5, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "dialogeditwrongformula.h"
#include "ui_dialogeditwrongformula.h"
#include <container/calculator.h>
//---------------------------------------------------------------------------------------------------------------------
DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogEditWrongFormula), formula(QString())
{
ui->setupUi(this);
InitVariables(ui);
labelResultCalculation = ui->labelResult;
lineEditFormula = ui->lineEditFormula;
labelEditFormula = ui->labelFormula;
InitOkCansel(ui);
flagFormula = false;
CheckState();
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEditWrongFormula::PutHere);
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEditWrongFormula::PutVal);
connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEditWrongFormula::EvalFormula);
connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogEditWrongFormula::FormulaChanged);
}
//---------------------------------------------------------------------------------------------------------------------
DialogEditWrongFormula::~DialogEditWrongFormula()
{
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::DialogAccepted()
{
formula = ui->lineEditFormula->text();
emit DialogClosed(QDialog::Accepted);
accepted();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::DialogRejected()
{
emit DialogClosed(QDialog::Rejected);
rejected();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::CheckState()
{
Q_CHECK_PTR(bOk);
bOk->setEnabled(flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::setFormula(const QString &value)
{
formula = qApp->FormulaToUser(value);
ui->lineEditFormula->setText(formula);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogEditWrongFormula::getFormula() const
{
return qApp->FormulaFromUser(formula);
}

View file

@ -0,0 +1,69 @@
/************************************************************************
**
** @file dialogeditwrongformula.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 29 5, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef DIALOGEDITWRONGFORMULA_H
#define DIALOGEDITWRONGFORMULA_H
#include "dialogtool.h"
namespace Ui {
class DialogEditWrongFormula;
}
/**
* @brief The DialogEditWrongFormula class dialog for editing wrong formula.
*
* When math parser find in formula error user can try fix issue. Dialog will show all variables that user can use in
* this formula. Dialog check fixed variant of formula.
*
* Don't implemant button "Apply" for this dialog!!
*/
class DialogEditWrongFormula : public DialogTool
{
Q_OBJECT
public:
explicit DialogEditWrongFormula(const VContainer *data, QWidget *parent = nullptr);
~DialogEditWrongFormula();
QString getFormula() const;
void setFormula(const QString &value);
public slots:
virtual void DialogAccepted();
virtual void DialogRejected();
protected:
virtual void CheckState();
private:
Q_DISABLE_COPY(DialogEditWrongFormula)
Ui::DialogEditWrongFormula *ui;
/**
* @brief formula string with formula
*/
QString formula;
};
#endif // DIALOGEDITWRONGFORMULA_H

View file

@ -0,0 +1,347 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogEditWrongFormula</class>
<widget class="QDialog" name="DialogEditWrongFormula">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>607</width>
<height>535</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit wrong formula</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelFormula">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>159</red>
<green>158</green>
<blue>158</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string>Formula</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditFormula">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>First angle of arc counterclockwise</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonPutHere">
<property name="toolTip">
<string>Insert variable into formula</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../share/resources/icon.qrc">
<normaloff>:/icon/24x24/putHereLeft.png</normaloff>:/icon/24x24/putHereLeft.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonEqual">
<property name="toolTip">
<string>Calculate value</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../share/resources/icon.qrc">
<normaloff>:/icon/24x24/equal.png</normaloff>:/icon/24x24/equal.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelResult">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>87</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Value of first angle</string>
</property>
<property name="text">
<string>_</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Input data</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonSizeGrowth">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Size and height</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonStandardTable">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Standard table</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonIncrements">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Increments</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonLengthLine">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Length of lines</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonLengthArc">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Length of arcs</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonLengthSpline">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Length of curves</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonLineAngles">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Angle of lines</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidget">
<property name="toolTip">
<string>Variables</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelDescription">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../share/resources/icon.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogEditWrongFormula</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogEditWrongFormula</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -333,8 +333,9 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label)
try try
{ {
const QString formula = qApp->FormulaFromUser(edit->text()); const QString formula = qApp->FormulaFromUser(edit->text());
Calculator cal(data); Calculator *cal = new Calculator(data);
const qreal result = cal.EvalFormula(formula); const qreal result = cal->EvalFormula(formula);
delete cal;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName()); QApplication::applicationName());

View file

@ -74,9 +74,8 @@ void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, c
switch (type) switch (type)
{ {
case QtDebugMsg: case QtDebugMsg:
fprintf(stderr, "Debug: %s\n", localMsg.constData()); fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
// fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
// context.function);
return; return;
case QtWarningMsg: case QtWarningMsg:
messageBox.setIcon(QMessageBox::Warning); messageBox.setIcon(QMessageBox::Warning);

View file

@ -1905,7 +1905,14 @@ void MainWindow::LoadPattern(const QString &fileName)
} }
SetEnableWidgets(true); SetEnableWidgets(true);
bool patternModified = doc->isPatternModified();
setCurrentFile(fileName); setCurrentFile(fileName);
if (patternModified)
{
//For situation where was fixed wrong formula need return for document status was modified.
doc->setPatternModified(patternModified);
PatternWasModified();
}
helpLabel->setText(tr("File loaded")); helpLabel->setText(tr("File loaded"));
} }

View file

@ -30,6 +30,7 @@
#include "../../widgets/vmaingraphicsscene.h" #include "../../widgets/vmaingraphicsscene.h"
#include "../../container/calculator.h" #include "../../container/calculator.h"
#include "../../dialogs/tools/dialogendline.h" #include "../../dialogs/tools/dialogendline.h"
#include "../../dialogs/tools/dialogeditwrongformula.h"
const QString VToolEndLine::ToolType = QStringLiteral("endLine"); const QString VToolEndLine::ToolType = QStringLiteral("endLine");
@ -82,15 +83,39 @@ void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatter
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &formula, const qreal &angle, const quint32 &basePointId, QString &formula, const qreal &angle, const quint32 &basePointId,
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation)
{ {
const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId); const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y()));
Calculator cal(data); qreal result = 0;
const qreal result = cal.EvalFormula(formula);
try
{
Calculator *cal = new Calculator(data);
result = cal->EvalFormula(formula);
delete cal;
}
catch(qmu::QmuParserError &e)
{
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data);
dialog->setFormula(formula);
if (dialog->exec() == QDialog::Accepted)
{
formula = dialog->getFormula();
delete dialog;
Calculator *cal = new Calculator(data);
result = cal->EvalFormula(formula);
delete cal;
}
else
{
delete dialog;
throw;
}
}
line.setLength(qApp->toPixel(result)); line.setLength(qApp->toPixel(result));
line.setAngle(angle); line.setAngle(angle);

View file

@ -82,7 +82,7 @@ public:
* @param typeCreation way we create this tool. * @param typeCreation way we create this tool.
*/ */
static void Create(const quint32 _id, const QString &pointName, const QString &typeLine, static void Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &formula, const qreal &angle, const quint32 &basePointId, const qreal &mx, QString &formula, const qreal &angle, const quint32 &basePointId, const qreal &mx,
const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data,
const Document::Documents &parse, const Valentina::Sources &typeCreation); const Document::Documents &parse, const Valentina::Sources &typeCreation);
static const QString ToolType; static const QString ToolType;

View file

@ -1722,23 +1722,10 @@ QString VApplication::FormulaFromUser(const QString &formula)
{ {
QString newFormula = formula; QString newFormula = formula;
QMap<int, QString> tokens; Calculator *cal = new Calculator(formula);
QMap<int, QString> numbers; QMap<int, QString> tokens = cal->GetTokens();
try QMap<int, QString> numbers = cal->GetNumbers();
{ delete cal;
Calculator cal(formula);
tokens = cal.GetTokens();
numbers = cal.GetNumbers();
}
catch(qmu::QmuParserError &e)
{
qDebug() << "\nMath parser error:\n"
<< "--------------------------------------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: " << e.GetExpr() << "\n"
<< "--------------------------------------";
return newFormula;
}
QList<int> tKeys = tokens.keys(); QList<int> tKeys = tokens.keys();
QList<QString> tValues = tokens.values(); QList<QString> tValues = tokens.values();
@ -1799,7 +1786,7 @@ QString VApplication::FormulaFromUser(const QString &formula)
{ {
QList<int> nKeys = numbers.keys(); QList<int> nKeys = numbers.keys();
QList<QString> nValues = numbers.values(); QList<QString> nValues = numbers.values();
for (int i = 0; i < tKeys.size(); ++i) for (int i = 0; i < nKeys.size(); ++i)
{ {
bool ok = false; bool ok = false;
qreal d = loc.toDouble(nValues.at(i), &ok); qreal d = loc.toDouble(nValues.at(i), &ok);
@ -1838,9 +1825,10 @@ QString VApplication::FormulaToUser(const QString &formula)
QMap<int, QString> numbers; QMap<int, QString> numbers;
try try
{ {
Calculator cal(formula, false); Calculator *cal = new Calculator(formula, false);
tokens = cal.GetTokens(); tokens = cal->GetTokens();
numbers = cal.GetNumbers(); numbers = cal->GetNumbers();
delete cal;
} }
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
@ -1917,7 +1905,7 @@ QString VApplication::FormulaToUser(const QString &formula)
{ {
QList<int> nKeys = numbers.keys(); QList<int> nKeys = numbers.keys();
QList<QString> nValues = numbers.values(); QList<QString> nValues = numbers.values();
for (int i = 0; i < tKeys.size(); ++i) for (int i = 0; i < nKeys.size(); ++i)
{ {
QLocale loc = QLocale(QLocale::C); QLocale loc = QLocale(QLocale::C);
bool ok = false; bool ok = false;

View file

@ -656,7 +656,7 @@ void VPattern::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *
const qint32 num = nodeList.size(); const qint32 num = nodeList.size();
for (qint32 i = 0; i < num; ++i) for (qint32 i = 0; i < num; ++i)
{ {
const QDomElement domElement = nodeList.at(i).toElement(); QDomElement domElement = nodeList.at(i).toElement();
if (domElement.isNull() == false) if (domElement.isNull() == false)
{ {
QStringList tags; QStringList tags;
@ -779,7 +779,7 @@ void VPattern::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &domElement, void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElement,
const Document::Documents &parse, const QString &type) const Document::Documents &parse, const QString &type)
{ {
Q_CHECK_PTR(scene); Q_CHECK_PTR(scene);
@ -842,11 +842,19 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, const QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine,
VAbstractTool::TypeLineLine); VAbstractTool::TypeLineLine);
const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0");
QString f = formula;//need for saving fixed formula;
const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0");
const qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); const qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0");
VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, VToolEndLine::Create(id, name, typeLine, f, angle, basePointId,
mx, my, scene, this, data, parse, Valentina::FromFile); mx, my, scene, this, data, parse, Valentina::FromFile);
//Rewrite attribute formula. Need for situation when we have wrong formula.
if (f != formula)
{
SetAttribute(domElement, VToolEndLine::AttrLength, f);
haveLiteChange();
}
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
{ {

View file

@ -334,7 +334,7 @@ private:
* @param type type of point. * @param type type of point.
* @param mode draw mode. * @param mode draw mode.
*/ */
void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElement,
const Document::Documents &parse, const QString &type); const Document::Documents &parse, const QString &type);
/** /**
* @brief ParseLineElement parse line tag. * @brief ParseLineElement parse line tag.

View file

@ -245,9 +245,9 @@ QmuParser::QmuParser():QmuParserBase()
*/ */
void QmuParser::InitCharSets() void QmuParser::InitCharSets()
{ {
DefineNameChars( "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ); DefineNameChars( QStringLiteral("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") );
DefineOprtChars( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*^/?<>=#!$%&|~'_{}" ); DefineOprtChars( QStringLiteral("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*^/?<>=#!$%&|~'_{}") );
DefineInfixOprtChars( "/+-*^?<>=#!$%&|~'_" ); DefineInfixOprtChars( QStringLiteral("/+-*^?<>=#!$%&|~'_") );
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -541,8 +541,7 @@ bool QmuParserTokenReader::IsEOF ( token_type &a_Tok )
} }
catch (qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
qDebug() << "\n " qDebug() << " Code:" << e.GetCode() << "(" << e.GetMsg() << ")";
<< " Code:" << e.GetCode() << "(" << e.GetMsg() << ")";
throw; throw;
} }
} }