Fixed the Grainline tab in detail dialog and also length/rotation formulas checking

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-10-06 23:39:57 +02:00
parent 520995a90c
commit 5562e46790
3 changed files with 324 additions and 114 deletions

View File

@ -159,8 +159,8 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge
connect(ui.checkBoxGrainline, &QCheckBox::toggled, this, &DialogDetail::EnableGrainlineRotation); connect(ui.checkBoxGrainline, &QCheckBox::toggled, this, &DialogDetail::EnableGrainlineRotation);
connect(ui.pushButtonRot, &QPushButton::clicked, this, &DialogDetail::EditFormula); connect(ui.pushButtonRot, &QPushButton::clicked, this, &DialogDetail::EditFormula);
connect(ui.pushButtonLen, &QPushButton::clicked, this, &DialogDetail::EditFormula); connect(ui.pushButtonLen, &QPushButton::clicked, this, &DialogDetail::EditFormula);
connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues);
connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues);
connect(ui.pushButtonShowRot, &QPushButton::clicked, this, &DialogDetail::DeployRotation); connect(ui.pushButtonShowRot, &QPushButton::clicked, this, &DialogDetail::DeployRotation);
connect(ui.pushButtonShowLen, &QPushButton::clicked, this, &DialogDetail::DeployLength); connect(ui.pushButtonShowLen, &QPushButton::clicked, this, &DialogDetail::DeployLength);
@ -484,11 +484,8 @@ VDetail DialogDetail::CreateDetail() const
detail.GetGrainlineGeometry() = m_oldGrainline; detail.GetGrainlineGeometry() = m_oldGrainline;
detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked()); detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked());
if (ui.checkBoxGrainline->isChecked() == true) detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText());
{ detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText());
detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText());
detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText());
}
return detail; return detail;
} }
@ -835,58 +832,80 @@ void DialogDetail::ClearFields()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogDetail::SetValue(QObject *pobjSender) void DialogDetail::UpdateValues()
{ {
QPlainTextEdit* pleSender = qobject_cast<QPlainTextEdit*>(pobjSender); QPlainTextEdit* apleSender[2];
SCASSERT(pleSender != 0); apleSender[0] = ui.lineEditRotFormula;
apleSender[1] = ui.lineEditLenFormula;
bool bFormulasOK = true;
QString qsFormula = pleSender->toPlainText().simplified(); for (int i = 0; i < 2; ++i)
Calculator cal;
QString qsVal;
try
{ {
qsFormula.replace("\n", " "); QLabel* plbVal;
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); QLabel* plbText;
qreal dVal; QString qsUnit;
dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); if (i == 0)
if (qIsInf(dVal) == true || qIsNaN(dVal) == true)
{ {
qsVal.clear(); plbVal = ui.labelRot;
plbText = ui.labelEditRot;
QChar ch(0x00b0);
qsUnit = ch;
} }
else else
{ {
qsVal.setNum(dVal, 'f', 5); plbVal = ui.labelLen;
plbText = ui.labelEditLen;
qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit());
} }
}
catch (...) QString qsFormula = apleSender[i]->toPlainText().simplified();
{ Calculator cal;
qsVal.clear(); QString qsVal;
try
{
qsFormula.replace("\n", " ");
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
qreal dVal;
dVal = cal.EvalFormula(data->PlainVariables(), qsFormula);
if (qIsInf(dVal) == true || qIsNaN(dVal) == true)
{
throw qmu::QmuParserError(tr("Infinite/undefined result"));
}
else if (i == 1 && dVal <= 0.0)
{
throw qmu::QmuParserError(tr("Length should be positive"));
}
else
{
qsVal.setNum(dVal, 'f', 2);
ChangeColor(plbText, okColor);
}
}
catch (...)
{
qsVal.clear();
ChangeColor(plbText, Qt::red);
bFormulasOK = false;
}
if (qsVal.isEmpty() == false)
{
qsVal += qsUnit;
}
plbVal->setText(qsVal);
} }
QLabel* plbVal; bOk->setEnabled(bFormulasOK);
QString qsUnit; if (bFormulasOK == false)
if (pobjSender == ui.lineEditLenFormula)
{ {
plbVal = ui.labelLen; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png");
qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit()); ui.tabWidget->setTabIcon(2, icon);
}
else if (pobjSender == ui.lineEditRotFormula)
{
plbVal = ui.labelRot;
QChar ch(0x00b0);
qsUnit = ch;
} }
else else
{ {
// should not get here QIcon icon;
return; ui.tabWidget->setTabIcon(2, icon);
} }
if (qsVal.isEmpty() == false)
{
qsVal += qsUnit;
}
plbVal->setText(qsVal);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -945,6 +964,17 @@ void DialogDetail::EnableGrainlineRotation()
ui.pushButtonLen->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonLen->setEnabled(ui.checkBoxGrainline->isChecked());
ui.pushButtonShowLen->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonShowLen->setEnabled(ui.checkBoxGrainline->isChecked());
ui.pushButtonShowRot->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonShowRot->setEnabled(ui.checkBoxGrainline->isChecked());
if (ui.checkBoxGrainline->isChecked() == true)
{
UpdateValues();
}
else
{
ChangeColor(ui.labelEditLen, okColor);
ChangeColor(ui.labelEditRot, okColor);
bOk->setEnabled(true);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -977,16 +1007,10 @@ void DialogDetail::EditFormula()
QString qsFormula = dlg.GetFormula(); QString qsFormula = dlg.GetFormula();
qsFormula.replace("\n", " "); qsFormula.replace("\n", " ");
pleFormula->setPlainText(qsFormula); pleFormula->setPlainText(qsFormula);
SetValue(pleFormula); UpdateValues();
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogDetail::UpdateValue()
{
SetValue(sender());
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogDetail::DeployRotation() void DialogDetail::DeployRotation()
{ {

View File

@ -127,14 +127,12 @@ private:
quint32 RowId(int i) const; quint32 RowId(int i) const;
void SetValue(QObject* pobjSender);
private slots: private slots:
void UpdateValues();
void SetAddMode(); void SetAddMode();
void SetEditMode(); void SetEditMode();
void EnableGrainlineRotation(); void EnableGrainlineRotation();
void EditFormula(); void EditFormula();
void UpdateValue();
void DeployRotation(); void DeployRotation();
void DeployLength(); void DeployLength();
}; };

View File

@ -538,9 +538,9 @@
<widget class="QWidget" name="horizontalLayoutWidget"> <widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>10</x>
<y>20</y> <y>10</y>
<width>351</width> <width>541</width>
<height>41</height> <height>41</height>
</rect> </rect>
</property> </property>
@ -554,32 +554,68 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget_2"> <widget class="QWidget" name="layoutWidget_2">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>10</x>
<y>70</y> <y>60</y>
<width>351</width> <width>541</width>
<height>41</height> <height>41</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_11">
<item> <item alignment="Qt::AlignLeft">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="labelEditRot">
<property name="font"> <property name="sizePolicy">
<font> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<pointsize>11</pointsize> <horstretch>0</horstretch>
<weight>75</weight> <verstretch>0</verstretch>
<bold>true</bold> </sizepolicy>
</font> </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>
<property name="text"> <property name="text">
<string>Rotation</string> <string>Rotation:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_4">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -591,10 +627,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item alignment="Qt::AlignRight">
<widget class="QPushButton" name="pushButtonRot"> <widget class="QToolButton" name="pushButtonRot">
<property name="toolTip">
<string>Formula wizard</string>
</property>
<property name="text"> <property name="text">
<string/> <string notr="true">...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../../vmisc/share/resources/icon.qrc"> <iconset resource="../../../vmisc/share/resources/icon.qrc">
@ -608,8 +647,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item alignment="Qt::AlignRight">
<widget class="QLabel" name="label_10"> <widget class="QLabel" name="labelEqual">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
@ -618,79 +657,171 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item alignment="Qt::AlignRight">
<widget class="QLabel" name="labelRot"> <widget class="QLabel" name="labelRot">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>87</width> <width>87</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Value</string>
</property>
<property name="text"> <property name="text">
<string/> <string notr="true">_</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget_3"> <widget class="QWidget" name="layoutWidget_3">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>10</x>
<y>120</y> <y>110</y>
<width>351</width> <width>541</width>
<height>41</height> <height>41</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_12">
<item> <item>
<widget class="QPlainTextEdit" name="lineEditRotFormula"> <widget class="QPlainTextEdit" name="lineEditRotFormula">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
<height>28</height> <height>28</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Calculation</string>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="plainText">
<string notr="true"/>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButtonShowRot"> <widget class="QPushButton" name="pushButtonShowRot">
<property name="maximumSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show full calculation in message box&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text"> <property name="text">
<string/> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="go-down"/> <iconset theme="go-down">
<normaloff/>
</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget_4"> <widget class="QWidget" name="layoutWidget_4">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>10</x>
<y>180</y> <y>160</y>
<width>351</width> <width>541</width>
<height>41</height> <height>41</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_9"> <layout class="QHBoxLayout" name="horizontalLayout_13">
<item> <item alignment="Qt::AlignLeft">
<widget class="QLabel" name="label_11"> <widget class="QLabel" name="labelEditLen">
<property name="font"> <property name="sizePolicy">
<font> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<pointsize>11</pointsize> <horstretch>0</horstretch>
<weight>75</weight> <verstretch>0</verstretch>
<bold>true</bold> </sizepolicy>
</font> </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>
<property name="text"> <property name="text">
<string>Length</string> <string>Length:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_5">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -702,10 +833,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item alignment="Qt::AlignRight">
<widget class="QPushButton" name="pushButtonLen"> <widget class="QToolButton" name="pushButtonLen">
<property name="toolTip">
<string>Formula wizard</string>
</property>
<property name="text"> <property name="text">
<string/> <string notr="true">...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../../vmisc/share/resources/icon.qrc"> <iconset resource="../../../vmisc/share/resources/icon.qrc">
@ -719,8 +853,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item alignment="Qt::AlignRight">
<widget class="QLabel" name="label_12"> <widget class="QLabel" name="labelEqual_2">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
@ -729,51 +863,105 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item alignment="Qt::AlignRight">
<widget class="QLabel" name="labelLen"> <widget class="QLabel" name="labelLen">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>87</width> <width>87</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Value</string>
</property>
<property name="text"> <property name="text">
<string/> <string notr="true">_</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget_5"> <widget class="QWidget" name="layoutWidget_5">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>10</x>
<y>230</y> <y>210</y>
<width>351</width> <width>541</width>
<height>41</height> <height>41</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_10"> <layout class="QHBoxLayout" name="horizontalLayout_14">
<item> <item>
<widget class="QPlainTextEdit" name="lineEditLenFormula"> <widget class="QPlainTextEdit" name="lineEditLenFormula">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
<height>28</height> <height>28</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Calculation</string>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="plainText">
<string notr="true"/>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButtonShowLen"> <widget class="QPushButton" name="pushButtonShowLen">
<property name="maximumSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show full calculation in message box&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text"> <property name="text">
<string/> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="go-down"> <iconset theme="go-down">
<normaloff/> <normaloff/>
</iconset> </iconset>
</property> </property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>