mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 10:34:14 +02:00
Merge pull request #584 from ispyisail/fix-potential-selector-cancel
Fix: potential-selector dialog can't actually be cancelled (#581)
This commit is contained in:
@@ -188,8 +188,11 @@ class LinkReportPotentialSelector : public AbstractPotentialSelector
|
||||
//### END PRIVATE CLASS ###//
|
||||
|
||||
|
||||
ConductorProperties PotentialSelectorDialog::chosenProperties(QList<ConductorProperties> list, QWidget *widget)
|
||||
ConductorProperties PotentialSelectorDialog::chosenProperties(QList<ConductorProperties> list, QWidget *widget, bool *cancelled)
|
||||
{
|
||||
if (cancelled)
|
||||
*cancelled = false;
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return ConductorProperties() ;
|
||||
} else if (list.size() == 1) {
|
||||
@@ -222,11 +225,25 @@ ConductorProperties PotentialSelectorDialog::chosenProperties(QList<ConductorPro
|
||||
layout.addWidget(b);
|
||||
H.insert(b, cp);
|
||||
}
|
||||
QDialogButtonBox *button_box = new QDialogButtonBox(QDialogButtonBox::Ok, &dialog);
|
||||
|
||||
// Pre-select the first entry: without this, accepting the dialog without
|
||||
// ever touching a radio button silently returned blank properties too,
|
||||
// the same failure mode as the missing Cancel button below.
|
||||
if (!H.isEmpty())
|
||||
H.constBegin().key()->setChecked(true);
|
||||
|
||||
QDialogButtonBox *button_box = new QDialogButtonBox(
|
||||
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
|
||||
layout.addWidget(button_box);
|
||||
connect(button_box, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
||||
connect(button_box, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted) {
|
||||
if (cancelled)
|
||||
*cancelled = true;
|
||||
return ConductorProperties();
|
||||
}
|
||||
|
||||
dialog.exec();
|
||||
for (QRadioButton *b : H.keys()) {
|
||||
if(b->isChecked()) {
|
||||
return H.value(b);
|
||||
|
||||
@@ -64,7 +64,11 @@ namespace Ui {
|
||||
|
||||
the static function chosenProperties,
|
||||
open a dialog who ask user to make a choice between the given
|
||||
properties
|
||||
properties. If the dialog is cancelled (Cancel button, Escape, or the
|
||||
window's close button) and @a cancelled is non-null, *cancelled is set
|
||||
to true and an empty ConductorProperties() is returned; callers that
|
||||
care about a real cancellation (as opposed to "no properties to choose
|
||||
from") should check it rather than relying on the returned value alone.
|
||||
*/
|
||||
class PotentialSelectorDialog : public QDialog
|
||||
{
|
||||
@@ -73,7 +77,8 @@ class PotentialSelectorDialog : public QDialog
|
||||
public:
|
||||
static ConductorProperties chosenProperties(
|
||||
QList<ConductorProperties> list,
|
||||
QWidget *parent = nullptr);
|
||||
QWidget *parent = nullptr,
|
||||
bool *cancelled = nullptr);
|
||||
|
||||
public:
|
||||
explicit PotentialSelectorDialog(
|
||||
|
||||
@@ -55,7 +55,7 @@ Veuillez choisir les propriétées à appliquer au nouveau potentiel.</string>
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user