From 87fca2c943c125e79216b36a2ba595a4175ceae4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 27 Feb 2025 23:17:44 +0100 Subject: [PATCH] Gui: Use QDialogButtonBox in DlgExpressionInput This way the order of buttons is more consistent than using separate QPushButtons. This fixes issue 19902 --- src/Gui/Dialogs/DlgExpressionInput.cpp | 32 +++++++++-------- src/Gui/Dialogs/DlgExpressionInput.h | 2 ++ src/Gui/Dialogs/DlgExpressionInput.ui | 50 ++++++-------------------- 3 files changed, 30 insertions(+), 54 deletions(-) diff --git a/src/Gui/Dialogs/DlgExpressionInput.cpp b/src/Gui/Dialogs/DlgExpressionInput.cpp index 336bbbd2e5..337cc24f02 100644 --- a/src/Gui/Dialogs/DlgExpressionInput.cpp +++ b/src/Gui/Dialogs/DlgExpressionInput.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #endif @@ -66,13 +67,16 @@ DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path, // Setup UI ui->setupUi(this); + okBtn = ui->buttonBox->button(QDialogButtonBox::Ok); + discardBtn = ui->buttonBox->button(QDialogButtonBox::Reset); + discardBtn->setToolTip(tr("Revert to last calculated value (as constant)")); initializeVarSets(); // Connect signal(s) connect(ui->expression, &ExpressionLineEdit::textChanged, this, &DlgExpressionInput::textChanged); - connect(ui->discardBtn, &QPushButton::clicked, + connect(discardBtn, &QPushButton::clicked, this, &DlgExpressionInput::setDiscarded); if (expression) { @@ -280,11 +284,11 @@ void DlgExpressionInput::checkExpression(const QString& text) std::unique_ptr result(expr->eval()); expression = expr; - ui->okBtn->setEnabled(true); + okBtn->setEnabled(true); ui->msg->clear(); //set default palette as we may have read text right now - ui->msg->setPalette(ui->okBtn->palette()); + ui->msg->setPalette(okBtn->palette()); auto * n = freecad_cast(result.get()); if (n) { @@ -325,12 +329,12 @@ static const bool NO_CHECK_EXPR = false; void DlgExpressionInput::textChanged(const QString &text) { if (text.isEmpty()) { - ui->okBtn->setDisabled(true); - ui->discardBtn->setDefault(true); + okBtn->setDisabled(true); + discardBtn->setDefault(true); return; } - ui->okBtn->setDefault(true); + okBtn->setDefault(true); try { //resize the input field according to text size @@ -357,7 +361,7 @@ void DlgExpressionInput::textChanged(const QString &text) QPalette p(ui->msg->palette()); p.setColor(QPalette::WindowText, Qt::red); ui->msg->setPalette(p); - ui->okBtn->setDisabled(true); + okBtn->setDisabled(true); } } @@ -614,7 +618,7 @@ void DlgExpressionInput::setupVarSets() ui->comboBoxVarSet->setModel(treeWidget->model()); ui->comboBoxVarSet->setView(treeWidget.get()); - ui->okBtn->setEnabled(false); + okBtn->setEnabled(false); } std::string DlgExpressionInput::getType() @@ -629,7 +633,7 @@ void DlgExpressionInput::onCheckVarSets(int state) { setupVarSets(); } else { - ui->okBtn->setEnabled(true); // normal expression + okBtn->setEnabled(true); // normal expression } } @@ -719,13 +723,13 @@ void DlgExpressionInput::updateVarSetInfo(bool checkExpr) QString nameGroup = ui->lineEditGroup->text(); if (reportGroup(nameGroup)) { // needed to report something about the group, so disable the button - ui->okBtn->setEnabled(false); + okBtn->setEnabled(false); return; } if (reportName(selected)) { // needed to report something about the name, so disable the button - ui->okBtn->setEnabled(false); + okBtn->setEnabled(false); return; } @@ -744,15 +748,15 @@ void DlgExpressionInput::updateVarSetInfo(bool checkExpr) // We have to check the text of the expression as well try { checkExpression(ui->expression->text()); - ui->okBtn->setEnabled(true); + okBtn->setEnabled(true); } catch (Base::Exception&) { - ui->okBtn->setDisabled(true); + okBtn->setDisabled(true); } } } else { - ui->okBtn->setEnabled(false); + okBtn->setEnabled(false); reportVarSetInfo("Please select a variable set."); } } diff --git a/src/Gui/Dialogs/DlgExpressionInput.h b/src/Gui/Dialogs/DlgExpressionInput.h index 7cb5c8dd92..7f6f20220a 100644 --- a/src/Gui/Dialogs/DlgExpressionInput.h +++ b/src/Gui/Dialogs/DlgExpressionInput.h @@ -120,6 +120,8 @@ private: static bool varSetsVisible; std::unique_ptr treeWidget; + QPushButton* okBtn = nullptr; + QPushButton* discardBtn = nullptr; }; } diff --git a/src/Gui/Dialogs/DlgExpressionInput.ui b/src/Gui/Dialogs/DlgExpressionInput.ui index 8b07b3812a..6b33d3cd25 100644 --- a/src/Gui/Dialogs/DlgExpressionInput.ui +++ b/src/Gui/Dialogs/DlgExpressionInput.ui @@ -249,42 +249,6 @@ - - - - 2 - - - - - Revert to last calculated value (as constant) - - - &Clear - - - true - - - false - - - - - - - &OK - - - true - - - true - - - - - @@ -298,6 +262,13 @@ + + + + QDialogButtonBox::Reset|QDialogButtonBox::Ok + + + @@ -324,15 +295,14 @@ expression - okBtn - discardBtn + buttonBox checkBoxVarSets - okBtn - clicked() + buttonBox + accepted() DlgExpressionInput accept()