From 9563604d678f780c02cd304c1ce6d9ac4a967e6f Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 14 Jul 2014 19:28:41 +0300 Subject: [PATCH] Refactoring method PointNameChanged. --HG-- branch : develop --- src/app/dialogs/tools/dialogalongline.cpp | 9 +++++---- src/app/dialogs/tools/dialogbisector.cpp | 12 ++++++------ src/app/dialogs/tools/dialogdetail.cpp | 2 +- src/app/dialogs/tools/dialogheight.cpp | 12 ++++++------ src/app/dialogs/tools/dialogline.cpp | 9 +++++---- src/app/dialogs/tools/dialoglineintersect.cpp | 15 +++++++-------- src/app/dialogs/tools/dialognormal.cpp | 9 +++++---- src/app/dialogs/tools/dialogpointofcontact.cpp | 12 ++++++------ .../dialogs/tools/dialogpointofintersection.cpp | 9 +++++---- src/app/dialogs/tools/dialogshoulderpoint.cpp | 12 ++++++------ src/app/dialogs/tools/dialogspline.cpp | 9 +++++---- src/app/dialogs/tools/dialogtool.cpp | 7 ++++--- src/app/dialogs/tools/dialogtool.h | 2 ++ src/app/dialogs/tools/dialogtriangle.cpp | 15 +++++++-------- 14 files changed, 70 insertions(+), 64 deletions(-) diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 36fb32db5..63c606799 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -78,18 +78,19 @@ void DialogAlongLine::FormulaTextChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogAlongLine::PointChanged() { + QColor color = okColor; if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint)) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 928bd3b3c..b4a418a81 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -88,20 +88,20 @@ void DialogBisector::PointNameChanged() set.insert(getCurrentObjectId(ui->comboBoxSecondPoint)); set.insert(getCurrentObjectId(ui->comboBoxThirdPoint)); + QColor color = okColor; if (set.size() != 3) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); - ChangeColor(ui->labelThirdPoint, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelThirdPoint, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); + ChangeColor(ui->labelThirdPoint, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogdetail.cpp b/src/app/dialogs/tools/dialogdetail.cpp index 2a4b63fdd..6e90a1de2 100644 --- a/src/app/dialogs/tools/dialogdetail.cpp +++ b/src/app/dialogs/tools/dialogdetail.cpp @@ -59,7 +59,7 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent) connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); flagName = true;//We have default name of detail. - ChangeColor(labelEditNamePoint, QColor(76, 76, 76)); + ChangeColor(labelEditNamePoint, okColor); CheckState(); connect(ui.listWidget, &QListWidget::currentRowChanged, this, &DialogDetail::ObjectChanged); diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index 62a3c187d..15a42cf9a 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -193,20 +193,20 @@ void DialogHeight::PointNameChanged() const VPointF *p1Line = data->GeometricObject(p1LineId); const VPointF *p2Line = data->GeometricObject(p2LineId); + QColor color = okColor; if (set.size() != 3 || VAbstractTool::ClosestPoint(QLineF(p1Line->toQPointF(), p2Line->toQPointF()), basePoint->toQPointF()) == QPointF()) { flagError = false; - ChangeColor(ui->labelBasePoint, Qt::red); - ChangeColor(ui->labelFirstLinePoint, Qt::red); - ChangeColor(ui->labelSecondLinePoint, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelBasePoint, QColor(76, 76, 76)); - ChangeColor(ui->labelFirstLinePoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondLinePoint, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelBasePoint, color); + ChangeColor(ui->labelFirstLinePoint, color); + ChangeColor(ui->labelSecondLinePoint, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogline.cpp b/src/app/dialogs/tools/dialogline.cpp index c015a1104..740a2e646 100644 --- a/src/app/dialogs/tools/dialogline.cpp +++ b/src/app/dialogs/tools/dialogline.cpp @@ -111,18 +111,19 @@ void DialogLine::DialogAccepted() //--------------------------------------------------------------------------------------------------------------------- void DialogLine::PointNameChanged() { + QColor color = okColor; if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint)) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 619d090bb..71a763490 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -236,22 +236,21 @@ void DialogLineIntersect::PointNameChanged() QPointF fPoint; QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); + QColor color = okColor; if (set.size() < 3 || intersect == QLineF::NoIntersection) { flagError = false; - ChangeColor(ui->labelP1Line1, Qt::red); - ChangeColor(ui->labelP2Line1, Qt::red); - ChangeColor(ui->labelP1Line2, Qt::red); - ChangeColor(ui->labelP2Line2, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelP1Line1, QColor(76, 76, 76)); - ChangeColor(ui->labelP2Line1, QColor(76, 76, 76)); - ChangeColor(ui->labelP1Line2, QColor(76, 76, 76)); - ChangeColor(ui->labelP2Line2, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelP1Line1, color); + ChangeColor(ui->labelP2Line1, color); + ChangeColor(ui->labelP1Line2, color); + ChangeColor(ui->labelP2Line2, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index ed6c69b67..6091db725 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -78,18 +78,19 @@ void DialogNormal::FormulaTextChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogNormal::PointNameChanged() { + QColor color = okColor; if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint)) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index bf54fb986..a9e43363a 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -101,20 +101,20 @@ void DialogPointOfContact::PointNameChanged() set.insert(getCurrentObjectId(ui->comboBoxSecondPoint)); set.insert(getCurrentObjectId(ui->comboBoxCenter)); + QColor color = okColor; if (set.size() != 3) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); - ChangeColor(ui->labelArcCenter, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelArcCenter, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); + ChangeColor(ui->labelArcCenter, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index 07efa52bd..eaf421563 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -131,18 +131,19 @@ void DialogPointOfIntersection::DialogAccepted() //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfIntersection::PointNameChanged() { + QColor color = okColor; if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint)) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index b16e67dc0..3b3ec9533 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -86,20 +86,20 @@ void DialogShoulderPoint::PointNameChanged() set.insert(getCurrentObjectId(ui->comboBoxP2Line)); set.insert(getCurrentObjectId(ui->comboBoxPShoulder)); + QColor color = okColor; if (set.size() != 3) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); - ChangeColor(ui->labelPointShoulder, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelPointShoulder, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); + ChangeColor(ui->labelPointShoulder, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogspline.cpp b/src/app/dialogs/tools/dialogspline.cpp index bb971d035..e88ff93f1 100644 --- a/src/app/dialogs/tools/dialogspline.cpp +++ b/src/app/dialogs/tools/dialogspline.cpp @@ -140,18 +140,19 @@ void DialogSpline::PointNameChanged() set.insert(getCurrentObjectId(ui->comboBoxP1)); set.insert(getCurrentObjectId(ui->comboBoxP4)); + QColor color = okColor; if (getCurrentObjectId(ui->comboBoxP1) == getCurrentObjectId(ui->comboBoxP4)) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); CheckState(); } diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 36047e1ab..c6e8975b4 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -62,7 +62,8 @@ DialogTool::DialogTool(const VContainer *data, QWidget *parent) listWidget(nullptr), labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), - radioButtonLengthCurve(nullptr), lineStyles(QStringList()), associatedTool(nullptr) + radioButtonLengthCurve(nullptr), lineStyles(QStringList()), okColor(QColor(76, 76, 76)), errorColor(Qt::red), + associatedTool(nullptr) { SCASSERT(data != nullptr); timerFormula = new QTimer(this); @@ -463,7 +464,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); } flag = true; - ChangeColor(labelEditFormula, QColor(76, 76, 76)); + ChangeColor(labelEditFormula, okColor); emit ToolTip(""); } catch (qmu::QmuParserError &e) @@ -669,7 +670,7 @@ void DialogTool::NamePointChanged() else { flagName = true; - ChangeColor(labelEditNamePoint, QColor(76, 76, 76)); + ChangeColor(labelEditNamePoint, okColor); } } CheckState(); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index a15088924..dddffb60f 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -179,6 +179,8 @@ protected: /** @brief lineStyles list supported line styles. */ QStringList lineStyles; + const QColor okColor; + const QColor errorColor; virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index acc550111..972f67326 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -137,22 +137,21 @@ void DialogTriangle::PointNameChanged() set.insert(getCurrentObjectId(ui->comboBoxAxisP1)); set.insert(getCurrentObjectId(ui->comboBoxAxisP2)); + QColor color = okColor; if (set.size() != 4) { flagError = false; - ChangeColor(ui->labelFirstPoint, Qt::red); - ChangeColor(ui->labelSecondPoint, Qt::red); - ChangeColor(ui->labelAxisP1, Qt::red); - ChangeColor(ui->labelAxisP2, Qt::red); + color = errorColor; } else { flagError = true; - ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); - ChangeColor(ui->labelAxisP1, QColor(76, 76, 76)); - ChangeColor(ui->labelAxisP2, QColor(76, 76, 76)); + color = okColor; } + ChangeColor(ui->labelFirstPoint, color); + ChangeColor(ui->labelSecondPoint, color); + ChangeColor(ui->labelAxisP1, color); + ChangeColor(ui->labelAxisP2, color); CheckState(); }