Show dialog "Fix broken formula" only in GUI mode.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-12-22 20:12:09 +02:00
parent 8b7602e223
commit d227ce68c2
9 changed files with 100 additions and 27 deletions

View file

@ -322,6 +322,15 @@ bool MApplication::IsTestMode() const
return testMode;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class.
*/
bool MApplication::IsAppInGUIMode() const
{
return IsTestMode();
}
//---------------------------------------------------------------------------------------------------------------------
TMainWindow *MApplication::MainWindow()
{

View file

@ -57,6 +57,7 @@ public:
virtual bool notify(QObject * receiver, QEvent * event) Q_DECL_OVERRIDE;
bool IsTestMode() const;
virtual bool IsAppInGUIMode() const;
TMainWindow *MainWindow();
QList<TMainWindow*> MainWindows();

View file

@ -671,6 +671,15 @@ bool VApplication::IsGUIMode()
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsGuiEnabled();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class.
*/
bool VApplication::IsAppInGUIMode() const
{
return IsGUIMode();
}
//---------------------------------------------------------------------------------------------------------------------
const VCommandLinePtr VApplication::CommandLine() const
{

View file

@ -78,6 +78,7 @@ public:
void CollectReports() const;
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
bool static IsGUIMode();
virtual bool IsAppInGUIMode() const;
virtual void OpenSettings() Q_DECL_OVERRIDE;
VSettings *ValentinaSettings();

View file

@ -94,6 +94,8 @@ public:
QUndoStack *getUndoStack() const;
virtual bool IsAppInGUIMode()const =0;
protected slots:
void SyncSettings();

View file

@ -299,46 +299,54 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine
<< "--------------------------------------";
delete cal;
DialogUndo *dialogUndo = new DialogUndo(qApp->getMainWindow());
forever
if (qApp->IsAppInGUIMode())
{
if (dialogUndo->exec() == QDialog::Accepted)
DialogUndo *dialogUndo = new DialogUndo(qApp->getMainWindow());
forever
{
const UndoButton resultUndo = dialogUndo->Result();
if (resultUndo == UndoButton::Fix)
if (dialogUndo->exec() == QDialog::Accepted)
{
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow());
dialog->setWindowTitle(tr("Edit wrong formula"));
dialog->SetFormula(formula);
if (dialog->exec() == QDialog::Accepted)
const UndoButton resultUndo = dialogUndo->Result();
if (resultUndo == UndoButton::Fix)
{
formula = dialog->GetFormula();
/* Need delete dialog here because parser in dialog don't allow use correct separator for
* parsing here. */
delete dialog;
Calculator *cal1 = new Calculator();
result = cal1->EvalFormula(data->PlainVariables(), formula);
delete cal1; /* Here can be memory leak, but dialog already check this formula and probability
* very low. */
break;
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId,
qApp->getMainWindow());
dialog->setWindowTitle(tr("Edit wrong formula"));
dialog->SetFormula(formula);
if (dialog->exec() == QDialog::Accepted)
{
formula = dialog->GetFormula();
/* Need delete dialog here because parser in dialog don't allow use correct separator for
* parsing here. */
delete dialog;
Calculator *cal1 = new Calculator();
result = cal1->EvalFormula(data->PlainVariables(), formula);
delete cal1; /* Here can be memory leak, but dialog already check this formula and
probability very low. */
break;
}
else
{
delete dialog;
}
}
else
{
delete dialog;
throw VExceptionUndo(QString("Undo wrong formula %1").arg(formula));
}
}
else
{
throw VExceptionUndo(QString("Undo wrong formula %1").arg(formula));
delete dialogUndo;
throw;
}
}
else
{
delete dialogUndo;
throw;
}
delete dialogUndo;
}
else
{
throw;
}
delete dialogUndo;
}
return result;
}

View file

@ -245,7 +245,8 @@ VALENTINA_TEST_FILES += \
tst_valentina/issue_256_correct.vit \
tst_valentina/issue_256_wrong.vit \
tst_valentina/issue_256_correct.vst \
tst_valentina/issue_256_wrong.vit
tst_valentina/issue_256_wrong.vit \
tst_valentina/wrong_formula.val
COLLECTION_FILES += \
$${PWD}/../../app/share/tables/standard/GOST_man_ru.vst \

View file

@ -0,0 +1,37 @@
<?xml version='1.0' encoding='UTF-8'?>
<pattern>
<!--Pattern created with Valentina (http://www.valentina-project.org/).-->
<version>0.2.2</version>
<unit>cm</unit>
<author/>
<description/>
<notes/>
<measurements>issue_256_correct.vit</measurements>
<increments/>
<draw name="Pattern piece 1">
<calculation>
<point type="single" x="1.34938" y="1.24354" id="1" name="A" mx="0.132292" my="0.264583"/>
<point type="endLine" typeLine="hair" id="2" name="A1" basePoint="1" mx="0.175422" lineColor="black" angle="0" my="0.27896" length="height_scapula/10+"/>
<point type="endLine" typeLine="hair" id="3" name="A2" basePoint="1" mx="0.132292" lineColor="black" angle="269.719" my="0.264583" length="Line_A_A1"/>
<point type="pointOfIntersection" id="4" name="A3" firstPoint="2" secondPoint="3" mx="0.132292" my="0.264583"/>
<line typeLine="hair" id="5" firstPoint="3" secondPoint="4" lineColor="black"/>
<line typeLine="hair" id="6" firstPoint="2" secondPoint="4" lineColor="black"/>
</calculation>
<modeling>
<point type="modeling" id="7" idObject="1" mx="0.0264587" my="0.291041"/>
<point type="modeling" id="8" idObject="2" mx="-1.85208" my="0.264583"/>
<point type="modeling" id="9" idObject="4" mx="-2.03729" my="-1.71979"/>
<point type="modeling" id="10" idObject="3" mx="0.47625" my="-1.95792"/>
<point type="modeling" id="11" idObject="1" mx="0.0264587" my="0.291041"/>
</modeling>
<details>
<detail closed="1" id="12" name="Detail" supplement="1" width="1" mx="0.185208" my="-0.079375">
<node type="NodePoint" nodeType="Contour" idObject="7" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="8" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="9" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="10" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="11" mx="0" my="0"/>
</detail>
</details>
</draw>
</pattern>

View file

@ -220,6 +220,11 @@ void TST_ValentinaCommandLine::TestMode_data() const
QLatin1Literal("issue_256_wrong.vst"))
<< false
<< V_EX_NOINPUT;
QTest::newRow("Wrong formula.")<< "wrong_formula.val"
<< QString("--test")
<< false
<< V_EX_DATAERR;
}
//---------------------------------------------------------------------------------------------------------------------