Refactoring. Delete repetitive code.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-19 14:43:02 +03:00
parent ce19b4ccab
commit ac71fd3cad
15 changed files with 52 additions and 92 deletions

View File

@ -39,32 +39,28 @@
*/ */
DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), typeLine(QString()), :DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), typeLine(QString()),
formula(QString()), firstPointId(0), secondPointId(0), formulaBaseHeight(0) formula(QString()), firstPointId(0), secondPointId(0), formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
labelResultCalculation = ui->labelResultCalculation; InitVariables(ui);
plainTextEditFormula = ui->plainTextEditFormula; InitFormulaUI(ui);
labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight=ui->plainTextEditFormula->height();
InitOkCancelApply(ui);
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
InitOkCancelApply(ui);
CheckState(); CheckState();
FillComboBoxTypeLine(ui->comboBoxLineType);
ui->comboBoxLineType->setCurrentIndex(0);
FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint); FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
ui->comboBoxLineType->setCurrentIndex(0);
labelEditNamePoint = ui->labelEditNamePoint;
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged);
connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit);
InitVariables(ui);
connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal); connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal);
} }

View File

@ -44,7 +44,8 @@
DialogArc::DialogArc(const VContainer *data, QWidget *parent) DialogArc::DialogArc(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false), :DialogTool(data, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false),
timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(0), radius(QString()), f1(QString()), timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(0), radius(QString()), f1(QString()),
f2(QString()), formulaBaseHeight(0), formulaBaseHeightF1(0), formulaBaseHeightF2(0) f2(QString()), formulaBaseHeight(ui->plainTextEditFormula->height()),
formulaBaseHeightF1(ui->plainTextEditF1->height()), formulaBaseHeightF2(ui->plainTextEditF2->height())
{ {
ui->setupUi(this); ui->setupUi(this);
@ -63,10 +64,6 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent)
InitOkCancelApply(ui); InitOkCancelApply(ui);
this->formulaBaseHeight=ui->plainTextEditFormula->height();
this->formulaBaseHeightF1=ui->plainTextEditF1->height();
this->formulaBaseHeightF2=ui->plainTextEditF2->height();
FillComboBoxPoints(ui->comboBoxBasePoint); FillComboBoxPoints(ui->comboBoxBasePoint);
CheckState(); CheckState();

View File

@ -40,17 +40,14 @@
*/ */
DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) DialogBisector::DialogBisector(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), :DialogTool(data, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()),
formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0), formulaBaseHeight(0) formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0),
formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight=ui->plainTextEditFormula->height();
InitOkCancelApply(ui); InitOkCancelApply(ui);
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
@ -58,8 +55,8 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent)
FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint); FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxPoints(ui->comboBoxThirdPoint);
FillComboBoxTypeLine(ui->comboBoxLineType); FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxPoints(ui->comboBoxThirdPoint);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogBisector::PutHere); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogBisector::PutHere);
connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogBisector::PutVal); connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogBisector::PutVal);

View File

@ -40,20 +40,17 @@
*/ */
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),
formulaBaseHeight(0) formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui); InitOkCancelApply(ui);
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
CheckState(); CheckState();
this->formulaBaseHeight=ui->plainTextEditFormula->height();
FillComboBoxArcs(ui->comboBoxArc); FillComboBoxArcs(ui->comboBoxArc);

View File

@ -40,22 +40,18 @@
*/ */
DialogCutSpline::DialogCutSpline(const VContainer *data, QWidget *parent) DialogCutSpline::DialogCutSpline(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), splineId(0), :DialogTool(data, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), splineId(0),
formulaBaseHeight(0) formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui);
InitOkCancel(ui);
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
CheckState(); CheckState();
this->formulaBaseHeight=ui->plainTextEditFormula->height();
FillComboBoxSplines(ui->comboBoxSpline); FillComboBoxSplines(ui->comboBoxSpline);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutSpline::PutHere); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutSpline::PutHere);

View File

@ -40,20 +40,17 @@
*/ */
DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, QWidget *parent) DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogCutSplinePath), pointName(QString()), formula(QString()), :DialogTool(data, parent), ui(new Ui::DialogCutSplinePath), pointName(QString()), formula(QString()),
splinePathId(0), formulaBaseHeight(0) splinePathId(0), formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui); InitOkCancel(ui);
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
CheckState(); CheckState();
this->formulaBaseHeight=ui->plainTextEditFormula->height();
FillComboBoxSplinesPath(ui->comboBoxSplinePath); FillComboBoxSplinesPath(ui->comboBoxSplinePath);

View File

@ -31,20 +31,17 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, QWidget *parent) DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0) :DialogTool(data, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()),
formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResult; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelFormula;
InitOkCancel(ui); InitOkCancel(ui);
flagFormula = false; flagFormula = false;
CheckState(); CheckState();
this->formulaBaseHeight=ui->plainTextEditFormula->height();
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEditWrongFormula::PutHere); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEditWrongFormula::PutHere);
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEditWrongFormula::PutVal); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEditWrongFormula::PutVal);

View File

@ -17,7 +17,7 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QLabel" name="labelFormula"> <widget class="QLabel" name="labelEditFormula">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -88,7 +88,7 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../share/resources/icon.qrc"> <iconset>
<normaloff>:/icon/24x24/putHereLeft.png</normaloff>:/icon/24x24/putHereLeft.png</iconset> <normaloff>:/icon/24x24/putHereLeft.png</normaloff>:/icon/24x24/putHereLeft.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -120,7 +120,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labelResult"> <widget class="QLabel" name="labelResultCalculation">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>

View File

@ -40,17 +40,13 @@
*/ */
DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), formula(QString()), :DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), formula(QString()),
angle(0), basePointId(0), formulaBaseHeight(0) angle(0), basePointId(0), formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight=ui->plainTextEditFormula->height();
InitOkCancelApply(ui); InitOkCancelApply(ui);
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;

View File

@ -37,18 +37,15 @@
*/ */
DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) DialogNormal::DialogNormal(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()), :DialogTool(data, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()),
formula(QString()), angle(0), firstPointId(0), secondPointId(0), formulaBaseHeight(0) formula(QString()), angle(0), firstPointId(0), secondPointId(0),
formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui); InitOkCancelApply(ui);
this->formulaBaseHeight=ui->plainTextEditFormula->height();
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
CheckState(); CheckState();

View File

@ -39,40 +39,21 @@
*/ */
DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *parent) DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), radius(QString()), :DialogTool(data, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), radius(QString()),
center(0), firstPoint(0), secondPoint(0), formulaBaseHeight(0) center(0), firstPoint(0), secondPoint(0), formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
listWidget = ui->listWidget; InitFormulaUI(ui);
labelResultCalculation = ui->labelResultCalculation;
labelDescription = ui->labelDescription;
radioButtonSizeGrowth = ui->radioButtonSizeGrowth;
radioButtonStandardTable = ui->radioButtonStandardTable;
radioButtonIncrements = ui->radioButtonIncrements;
radioButtonLengthLine = ui->radioButtonLengthLine;
radioButtonLengthArc = ui->radioButtonLengthArc;
radioButtonLengthCurve = ui->radioButtonLengthSpline;
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight=ui->plainTextEditFormula->height();
InitOkCancelApply(ui); InitOkCancelApply(ui);
/* bOk = ui.buttonBox->button(QDialogButtonBox::Ok);
SCASSERT(bOk != nullptr);
connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted);
QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel);
SCASSERT(bCansel != nullptr);
connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected);
*/
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
CheckState(); CheckState();
FillComboBoxPoints(ui->comboBoxCenter);
FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint); FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxPoints(ui->comboBoxCenter);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogPointOfContact::PutHere); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogPointOfContact::PutHere);
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogPointOfContact::PutVal); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogPointOfContact::PutVal);

View File

@ -44,6 +44,7 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, QWi
{ {
ui->setupUi(this); ui->setupUi(this);
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui); InitOkCancel(ui);
flagName = false; flagName = false;
CheckState(); CheckState();

View File

@ -40,19 +40,15 @@
*/ */
DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent) DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), :DialogTool(data, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()),
typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0), formulaBaseHeight(0) typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0),
formulaBaseHeight(ui->plainTextEditFormula->height())
{ {
ui->setupUi(this); ui->setupUi(this);
number = 0;
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; InitFormulaUI(ui);
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui); InitOkCancelApply(ui);
this->formulaBaseHeight=ui->plainTextEditFormula->height();
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
CheckState(); CheckState();

View File

@ -276,6 +276,17 @@ protected:
SCASSERT(bCancel != nullptr); SCASSERT(bCancel != nullptr);
connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected);
} }
template <typename T>
/**
* @brief InitFormulaUI initialise ui object for formula fild
* @param ui Dialog container
*/
void InitFormulaUI(T *ui)
{
labelResultCalculation = ui->labelResultCalculation;
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
}
/** /**
* @brief associatedTool vdrawtool associated with opened dialog. * @brief associatedTool vdrawtool associated with opened dialog.
*/ */

View File

@ -43,6 +43,7 @@ DialogTriangle::DialogTriangle(const VContainer *data, QWidget *parent)
{ {
ui->setupUi(this); ui->setupUi(this);
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancel(ui); InitOkCancel(ui);
flagName = false; flagName = false;
CheckState(); CheckState();