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:
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,8 @@ private:
|
||||
|
||||
static bool varSetsVisible;
|
||||
std::unique_ptr<QTreeWidget> treeWidget;
|
||||
QPushButton* okBtn = nullptr;
|
||||
QPushButton* discardBtn = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -249,42 +249,6 @@
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="discardBtn">
|
||||
<property name="toolTip">
|
||||
<string>Revert to last calculated value (as constant)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Clear</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="okBtn">
|
||||
<property name="text">
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
@@ -298,6 +262,13 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Reset|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@@ -324,15 +295,14 @@
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>expression</tabstop>
|
||||
<tabstop>okBtn</tabstop>
|
||||
<tabstop>discardBtn</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
<tabstop>checkBoxVarSets</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>okBtn</sender>
|
||||
<signal>clicked()</signal>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>DlgExpressionInput</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
|
||||
Reference in New Issue
Block a user