forked from qt-creator/qt-creator
Utils: Add a do not show again information message box.
The existent do not ask again question message box isn't suitable for printing out information where the user has no influence on an action. Change-Id: Ief8d2a73b4621e05374ca9a1a4355d9768c69bcc Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -288,6 +288,49 @@ QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButt
|
|||||||
return static_cast<QMessageBox::StandardButton>(int(db));
|
return static_cast<QMessageBox::StandardButton>(int(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool askAgain(QSettings *settings, const QString &settingsSubKey)
|
||||||
|
{
|
||||||
|
QTC_CHECK(settings);
|
||||||
|
if (settings) {
|
||||||
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||||
|
bool shouldNotAsk = settings->value(settingsSubKey, false).toBool();
|
||||||
|
settings->endGroup();
|
||||||
|
if (shouldNotAsk)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DoNotAskAgainType{Question, Information};
|
||||||
|
|
||||||
|
void initDoNotAskAgainMessageBox(CheckableMessageBox &messageBox, const QString &title,
|
||||||
|
const QString &text, QDialogButtonBox::StandardButtons buttons,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton,
|
||||||
|
DoNotAskAgainType type)
|
||||||
|
{
|
||||||
|
messageBox.setWindowTitle(title);
|
||||||
|
messageBox.setIconPixmap(QMessageBox::standardIcon(type == Information
|
||||||
|
? QMessageBox::Information
|
||||||
|
: QMessageBox::Question));
|
||||||
|
messageBox.setText(text);
|
||||||
|
messageBox.setCheckBoxVisible(true);
|
||||||
|
messageBox.setCheckBoxText(type == Information ? CheckableMessageBox::msgDoNotShowAgain()
|
||||||
|
: CheckableMessageBox::msgDoNotAskAgain());
|
||||||
|
messageBox.setChecked(false);
|
||||||
|
messageBox.setStandardButtons(buttons);
|
||||||
|
messageBox.setDefaultButton(defaultButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doNotAskAgain(QSettings *settings, const QString &settingsSubKey)
|
||||||
|
{
|
||||||
|
if (!settings)
|
||||||
|
return;
|
||||||
|
|
||||||
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||||
|
settings->setValue(settingsSubKey, true);
|
||||||
|
settings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Shows a message box with given \a title and \a text, and a \gui {Do not ask again} check box.
|
Shows a message box with given \a title and \a text, and a \gui {Do not ask again} check box.
|
||||||
If the user checks the check box and accepts the dialog with the \a acceptButton,
|
If the user checks the check box and accepts the dialog with the \a acceptButton,
|
||||||
@@ -306,35 +349,44 @@ CheckableMessageBox::doNotAskAgainQuestion(QWidget *parent, const QString &title
|
|||||||
QDialogButtonBox::StandardButton acceptButton)
|
QDialogButtonBox::StandardButton acceptButton)
|
||||||
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(settings);
|
if (!askAgain(settings, settingsSubKey))
|
||||||
if (settings) {
|
|
||||||
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
|
||||||
bool shouldNotAsk = settings->value(settingsSubKey, false).toBool();
|
|
||||||
settings->endGroup();
|
|
||||||
if (shouldNotAsk)
|
|
||||||
return acceptButton;
|
return acceptButton;
|
||||||
|
|
||||||
|
CheckableMessageBox messageBox(parent);
|
||||||
|
initDoNotAskAgainMessageBox(messageBox, title, text, buttons, defaultButton, Question);
|
||||||
|
messageBox.exec();
|
||||||
|
if (messageBox.isChecked() && (messageBox.clickedStandardButton() == acceptButton))
|
||||||
|
doNotAskAgain(settings, settingsSubKey);
|
||||||
|
|
||||||
|
return messageBox.clickedStandardButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckableMessageBox mb(parent);
|
/*!
|
||||||
mb.setWindowTitle(title);
|
Shows a message box with given \a title and \a text, and a \gui {Do not show again} check box.
|
||||||
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
If the user checks the check box and quits the dialog, further invocations of this
|
||||||
mb.setText(text);
|
function with the same \a settings and \a settingsSubKey will not show the dialog, but instantly return.
|
||||||
mb.setCheckBoxVisible(true);
|
|
||||||
mb.setCheckBoxText(CheckableMessageBox::msgDoNotAskAgain());
|
|
||||||
mb.setChecked(false);
|
|
||||||
mb.setStandardButtons(buttons);
|
|
||||||
mb.setDefaultButton(defaultButton);
|
|
||||||
mb.exec();
|
|
||||||
|
|
||||||
if (settings) {
|
Returns the clicked button, or QDialogButtonBox::NoButton if the user rejects the dialog
|
||||||
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
with the escape key, or \a defaultButton if the dialog is suppressed.
|
||||||
if (mb.isChecked() && (mb.clickedStandardButton() == acceptButton))
|
*/
|
||||||
settings->setValue(settingsSubKey, true);
|
QDialogButtonBox::StandardButton
|
||||||
else // clean up doesn't hurt
|
CheckableMessageBox::doNotShowAgainInformation(QWidget *parent, const QString &title,
|
||||||
settings->remove(settingsSubKey);
|
const QString &text, QSettings *settings,
|
||||||
settings->endGroup();
|
const QString &settingsSubKey,
|
||||||
}
|
QDialogButtonBox::StandardButtons buttons,
|
||||||
return mb.clickedStandardButton();
|
QDialogButtonBox::StandardButton defaultButton)
|
||||||
|
|
||||||
|
{
|
||||||
|
if (!askAgain(settings, settingsSubKey))
|
||||||
|
return defaultButton;
|
||||||
|
|
||||||
|
CheckableMessageBox messageBox(parent);
|
||||||
|
initDoNotAskAgainMessageBox(messageBox, title, text, buttons, defaultButton, Information);
|
||||||
|
messageBox.exec();
|
||||||
|
if (messageBox.isChecked())
|
||||||
|
doNotAskAgain(settings, settingsSubKey);
|
||||||
|
|
||||||
|
return messageBox.clickedStandardButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -377,4 +429,13 @@ QString CheckableMessageBox::msgDoNotAskAgain()
|
|||||||
return QApplication::translate("Utils::CheckableMessageBox", "Do not &ask again");
|
return QApplication::translate("Utils::CheckableMessageBox", "Do not &ask again");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the standard \gui {Do not show again} check box text.
|
||||||
|
\sa doNotShowAgainInformation()
|
||||||
|
*/
|
||||||
|
QString CheckableMessageBox::msgDoNotShowAgain()
|
||||||
|
{
|
||||||
|
return QApplication::translate("Utils::CheckableMessageBox", "Do not &show again");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -86,6 +86,15 @@ public:
|
|||||||
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No,
|
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No,
|
||||||
QDialogButtonBox::StandardButton acceptButton = QDialogButtonBox::Yes);
|
QDialogButtonBox::StandardButton acceptButton = QDialogButtonBox::Yes);
|
||||||
|
|
||||||
|
static QDialogButtonBox::StandardButton
|
||||||
|
doNotShowAgainInformation(QWidget *parent,
|
||||||
|
const QString &title,
|
||||||
|
const QString &text,
|
||||||
|
QSettings *settings,
|
||||||
|
const QString &settingsSubKey,
|
||||||
|
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton);
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
void setText(const QString &);
|
void setText(const QString &);
|
||||||
|
|
||||||
@@ -119,6 +128,7 @@ public:
|
|||||||
static void resetAllDoNotAskAgainQuestions(QSettings *settings);
|
static void resetAllDoNotAskAgainQuestions(QSettings *settings);
|
||||||
static bool hasSuppressedQuestions(QSettings *settings);
|
static bool hasSuppressedQuestions(QSettings *settings);
|
||||||
static QString msgDoNotAskAgain();
|
static QString msgDoNotAskAgain();
|
||||||
|
static QString msgDoNotShowAgain();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotClicked(QAbstractButton *b);
|
void slotClicked(QAbstractButton *b);
|
||||||
|
|||||||
Reference in New Issue
Block a user