forked from qt-creator/qt-creator
Utils: Allow async CheckableMsgBox without guard
Change-Id: I76cb8dcb5aa89cc9b98410daeeeba668279c6e45 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <QCheckBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPointer>
|
||||
#include <QPushButton>
|
||||
#include <QStyle>
|
||||
#include <QTextEdit>
|
||||
@@ -122,25 +123,38 @@ static void show(QWidget *parent,
|
||||
if (decider.shouldAskAgain && !decider.shouldAskAgain()) {
|
||||
if (callback) {
|
||||
QMetaObject::invokeMethod(
|
||||
guard, [callback, acceptButton] { callback(acceptButton); }, Qt::QueuedConnection);
|
||||
guard ? guard : qApp,
|
||||
[callback, acceptButton] { callback(acceptButton); },
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox *msgBox = new QMessageBox(parent);
|
||||
prepare(icon, title, text, decider, buttons, defaultButton, buttonTextOverrides, msg, *msgBox);
|
||||
|
||||
QObject::connect(msgBox, &QMessageBox::finished, guard, [msgBox, callback, decider, acceptButton] {
|
||||
QMessageBox::StandardButton clickedBtn = msgBox->standardButton(msgBox->clickedButton());
|
||||
std::optional<QPointer<QObject>> guardPtr;
|
||||
if (guard)
|
||||
guardPtr = guard;
|
||||
|
||||
if (decider.doNotAskAgain && msgBox->checkBox()->isChecked()
|
||||
&& (acceptButton == QMessageBox::NoButton || clickedBtn == acceptButton))
|
||||
decider.doNotAskAgain();
|
||||
if (callback)
|
||||
callback(clickedBtn);
|
||||
QObject::connect(msgBox,
|
||||
&QMessageBox::finished,
|
||||
[guardPtr, msgBox, callback, decider, acceptButton] {
|
||||
QMessageBox::StandardButton clickedBtn = msgBox->standardButton(
|
||||
msgBox->clickedButton());
|
||||
|
||||
msgBox->deleteLater();
|
||||
});
|
||||
if (decider.doNotAskAgain && msgBox->checkBox()->isChecked()
|
||||
&& (acceptButton == QMessageBox::NoButton
|
||||
|| clickedBtn == acceptButton)) {
|
||||
decider.doNotAskAgain();
|
||||
}
|
||||
|
||||
if (callback && (!guardPtr || *guardPtr))
|
||||
callback(clickedBtn);
|
||||
|
||||
msgBox->deleteLater();
|
||||
});
|
||||
|
||||
msgBox->show();
|
||||
}
|
||||
|
@@ -60,7 +60,7 @@ public:
|
||||
const QString &text,
|
||||
const CheckableDecider &decider,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton,
|
||||
QMessageBox::StandardButton defaultButton = QMessageBox::Ok,
|
||||
QMap<QMessageBox::StandardButton, QString> buttonTextOverrides = {},
|
||||
const QString &msg = {});
|
||||
|
||||
@@ -71,8 +71,8 @@ public:
|
||||
const CheckableDecider &decider,
|
||||
QObject *guard = nullptr,
|
||||
std::function<void(QMessageBox::StandardButton choosenBtn)> callback = nullptr,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
QMessageBox::StandardButton defaultButton = QMessageBox::Ok,
|
||||
QMap<QMessageBox::StandardButton, QString> buttonTextOverrides = {},
|
||||
const QString &msg = {});
|
||||
|
||||
|
Reference in New Issue
Block a user