diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 07f174f09..36fb32db5 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -63,6 +63,10 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit); connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal); + connect(ui->comboBoxFirstPoint, static_cast(&QComboBox::currentIndexChanged), + this, &DialogAlongLine::PointChanged); + connect(ui->comboBoxSecondPoint, static_cast(&QComboBox::currentIndexChanged), + this, &DialogAlongLine::PointChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -71,6 +75,24 @@ void DialogAlongLine::FormulaTextChanged() this->FormulaChangedPlainText(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::PointChanged() +{ + if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint)) + { + flagError = false; + ChangeColor(ui->labelFirstPoint, Qt::red); + ChangeColor(ui->labelSecondPoint, Qt::red); + } + else + { + flagError = true; + ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76)); + ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76)); + } + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogAlongLine::DeployFormulaTextEdit() { diff --git a/src/app/dialogs/tools/dialogalongline.h b/src/app/dialogs/tools/dialogalongline.h index 478aef06b..f2b7a1db2 100644 --- a/src/app/dialogs/tools/dialogalongline.h +++ b/src/app/dialogs/tools/dialogalongline.h @@ -65,15 +65,16 @@ public slots: /** * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(); + virtual void DialogApply(); /** * @brief DeployFormulaTextEdit grow or shrink formula input */ - void DeployFormulaTextEdit(); + void DeployFormulaTextEdit(); /** * @brief FormulaTextChanged when formula text changes for validation and calc */ - void FormulaTextChanged(); + void FormulaTextChanged(); + void PointChanged(); private: Q_DISABLE_COPY(DialogAlongLine) diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index 41f3e0fd4..d936307f6 100644 --- a/src/app/dialogs/tools/dialogalongline.ui +++ b/src/app/dialogs/tools/dialogalongline.ui @@ -195,7 +195,9 @@ - + + + @@ -268,7 +270,7 @@ - + First point @@ -286,7 +288,7 @@ - + Second point diff --git a/src/app/dialogs/tools/dialogdetail.cpp b/src/app/dialogs/tools/dialogdetail.cpp index 7d8f83e92..2a4b63fdd 100644 --- a/src/app/dialogs/tools/dialogdetail.cpp +++ b/src/app/dialogs/tools/dialogdetail.cpp @@ -59,9 +59,7 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent) connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); flagName = true;//We have default name of detail. - QPalette palette = labelEditNamePoint->palette(); - palette.setColor(labelEditNamePoint->foregroundRole(), QColor(76, 76, 76)); - labelEditNamePoint->setPalette(palette); + ChangeColor(labelEditNamePoint, QColor(76, 76, 76)); CheckState(); connect(ui.listWidget, &QListWidget::currentRowChanged, this, &DialogDetail::ObjectChanged); diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 9505096a6..661e4db12 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -57,8 +57,8 @@ * @param parent parent widget */ DialogTool::DialogTool(const VContainer *data, QWidget *parent) - :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(nullptr), - bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), plainTextEditFormula(nullptr), + :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), flagError(true), + timerFormula(nullptr), bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), plainTextEditFormula(nullptr), listWidget(nullptr), labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), @@ -401,9 +401,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) { flag = false; CheckState(); - QPalette palette = labelEditFormula->palette(); - palette.setColor(labelEditFormula->foregroundRole(), Qt::red); - labelEditFormula->setPalette(palette); + ChangeColor(labelEditFormula, Qt::red); return; } timer->start(1000); @@ -418,9 +416,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim { flag = false; CheckState(); - QPalette palette = labelEditFormula->palette(); - palette.setColor(labelEditFormula->foregroundRole(), Qt::red); - labelEditFormula->setPalette(palette); + ChangeColor(labelEditFormula, Qt::red); return; } timer->start(1000); @@ -439,11 +435,10 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la SCASSERT(timer != nullptr); SCASSERT(label != nullptr); SCASSERT(labelEditFormula != nullptr); - QPalette palette = labelEditFormula->palette(); if (text.isEmpty()) { flag = false; - palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + ChangeColor(labelEditFormula, Qt::red); } else { @@ -468,14 +463,14 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); } flag = true; - palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); + ChangeColor(labelEditFormula, QColor(76, 76, 76)); emit ToolTip(""); } catch (qmu::QmuParserError &e) { label->setText(tr("Error")); flag = false; - palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + ChangeColor(labelEditFormula, Qt::red); emit ToolTip("Parser error: "+e.GetMsg()); qDebug() << "\nMath parser error:\n" << "--------------------------------------\n" @@ -486,7 +481,6 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la } CheckState(); timer->stop(); - labelEditFormula->setPalette(palette); } //--------------------------------------------------------------------------------------------------------------------- @@ -636,11 +630,11 @@ void DialogTool::FillList(QComboBox *box, const QMap &list) co void DialogTool::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(flagFormula && flagName); + bOk->setEnabled(flagFormula && flagName && flagError); // In case dialog hasn't apply button if ( bApply != nullptr) { - bApply->setEnabled(flagFormula && flagName); + bApply->setEnabled(bOk->isEnabled()); } } @@ -670,21 +664,26 @@ void DialogTool::NamePointChanged() if (name.isEmpty() || name.contains(" ")) { flagName = false; - QPalette palette = labelEditNamePoint->palette(); - palette.setColor(labelEditNamePoint->foregroundRole(), Qt::red); - labelEditNamePoint->setPalette(palette); + ChangeColor(labelEditNamePoint, Qt::red); } else { flagName = true; - QPalette palette = labelEditNamePoint->palette(); - palette.setColor(labelEditNamePoint->foregroundRole(), QColor(76, 76, 76)); - labelEditNamePoint->setPalette(palette); + ChangeColor(labelEditNamePoint, QColor(76, 76, 76)); } } CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::ChangeColor(QWidget *widget, const QColor &color) +{ + SCASSERT(widget != nullptr); + QPalette palette = widget->palette(); + palette.setColor(widget->foregroundRole(), color); + widget->setPalette(palette); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogAccepted save data and emit signal about closed dialog. diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 7e9bfb451..737418c6d 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -122,6 +122,13 @@ protected: /** @brief flagFormula true if formula correct */ bool flagFormula; + /** @brief flagError use this flag if for you do not enought @see flagName and @see flagFormula. + * + * In many cases you will need more flags fore checking if all data are valid. + * By default this flag is true. + */ + bool flagError; + /** @brief timerFormula timer for check formula */ QTimer *timerFormula; @@ -292,6 +299,7 @@ protected: * @brief associatedTool vdrawtool associated with opened dialog. */ VAbstractTool* associatedTool; + void ChangeColor(QWidget *widget, const QColor &color); private: void FillList(QComboBox *box, const QMap &list)const; };