Gui: Use QDialogButtonBox in DlgExpressionInput

This way the order of buttons is more consistent than using
separate QPushButtons.

This fixes issue 19902
This commit is contained in:
wmayer
2025-02-27 23:17:44 +01:00
committed by Ladislav Michl
parent efe02a8675
commit 87fca2c943
3 changed files with 30 additions and 54 deletions

View File

@@ -25,6 +25,7 @@
#include <QApplication>
#include <QMenu>
#include <QMouseEvent>
#include <QPushButton>
#include <QTreeWidget>
#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<Expression> 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<NumberExpression*>(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.");
}
}