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.pushButtonRot, &QPushButton::clicked, this, &DialogDetail::EditFormula);
connect(ui.pushButtonLen, &QPushButton::clicked, this, &DialogDetail::EditFormula);
connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue);
connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue);
connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues);
connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues);
connect(ui.pushButtonShowRot, &QPushButton::clicked, this, &DialogDetail::DeployRotation);
connect(ui.pushButtonShowLen, &QPushButton::clicked, this, &DialogDetail::DeployLength);
@ -484,11 +484,8 @@ VDetail DialogDetail::CreateDetail() const
detail.GetGrainlineGeometry() = m_oldGrainline;
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;
}
@ -835,58 +832,80 @@ void DialogDetail::ClearFields()
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDetail::SetValue(QObject *pobjSender)
void DialogDetail::UpdateValues()
{
QPlainTextEdit* pleSender = qobject_cast<QPlainTextEdit*>(pobjSender);
SCASSERT(pleSender != 0);
QPlainTextEdit* apleSender[2];
apleSender[0] = ui.lineEditRotFormula;
apleSender[1] = ui.lineEditLenFormula;
bool bFormulasOK = true;
QString qsFormula = pleSender->toPlainText().simplified();
Calculator cal;
QString qsVal;
try
for (int i = 0; i < 2; ++i)
{
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)
QLabel* plbVal;
QLabel* plbText;
QString qsUnit;
if (i == 0)
{
qsVal.clear();
plbVal = ui.labelRot;
plbText = ui.labelEditRot;
QChar ch(0x00b0);
qsUnit = ch;
}
else
{
qsVal.setNum(dVal, 'f', 5);
plbVal = ui.labelLen;
plbText = ui.labelEditLen;
qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit());
}
}
catch (...)
{
qsVal.clear();
QString qsFormula = apleSender[i]->toPlainText().simplified();
Calculator cal;
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;
QString qsUnit;
if (pobjSender == ui.lineEditLenFormula)
bOk->setEnabled(bFormulasOK);
if (bFormulasOK == false)
{
plbVal = ui.labelLen;
qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit());
}
else if (pobjSender == ui.lineEditRotFormula)
{
plbVal = ui.labelRot;
QChar ch(0x00b0);
qsUnit = ch;
QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png");
ui.tabWidget->setTabIcon(2, icon);
}
else
{
// should not get here
return;
QIcon icon;
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.pushButtonShowLen->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();
qsFormula.replace("\n", " ");
pleFormula->setPlainText(qsFormula);
SetValue(pleFormula);
UpdateValues();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDetail::UpdateValue()
{
SetValue(sender());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDetail::DeployRotation()
{

View File

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

View File

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