From 8aab8ccc0ffba504078deb7b4371d2f98c834df3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 7 Nov 2013 13:43:02 +0100 Subject: Dialogs: provide the StandardButton->ButtonRole mapping in QPA As the QPlatformMessageDialogHelper will be implemented repeatedly, it's useful to have this mapping in one place for reuse. Also, since we do not guarantee that either accepted() or rejected() will be emitted for every possible button on a QtQuick MessageDialog, it's useful for the QtQuick.Dialogs module to have access to this mapping to interpret individual button presses and emit the role-specific signals such as yes(), apply(), help(), etc. Change-Id: I7be753080794adabb784df9b95ac04aa1c29151c Reviewed-by: BogDan Vatra --- src/widgets/widgets/qdialogbuttonbox.cpp | 43 +++----------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 9789c453f3..6b183d3759 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include "qdialogbuttonbox.h" @@ -166,46 +167,8 @@ enum { static QDialogButtonBox::ButtonRole roleFor(QDialogButtonBox::StandardButton button) { - switch (button) { - case QDialogButtonBox::Ok: - case QDialogButtonBox::Save: - case QDialogButtonBox::Open: - case QDialogButtonBox::SaveAll: - case QDialogButtonBox::Retry: - case QDialogButtonBox::Ignore: - return QDialogButtonBox::AcceptRole; - - case QDialogButtonBox::Cancel: - case QDialogButtonBox::Close: - case QDialogButtonBox::Abort: - return QDialogButtonBox::RejectRole; - - case QDialogButtonBox::Discard: - return QDialogButtonBox::DestructiveRole; - - case QDialogButtonBox::Help: - return QDialogButtonBox::HelpRole; - - case QDialogButtonBox::Apply: - return QDialogButtonBox::ApplyRole; - - case QDialogButtonBox::Yes: - case QDialogButtonBox::YesToAll: - return QDialogButtonBox::YesRole; - - case QDialogButtonBox::No: - case QDialogButtonBox::NoToAll: - return QDialogButtonBox::NoRole; - - case QDialogButtonBox::RestoreDefaults: - case QDialogButtonBox::Reset: - return QDialogButtonBox::ResetRole; - - case QDialogButtonBox::NoButton: // NoButton means zero buttons, not "No" button - ; - } - - return QDialogButtonBox::InvalidRole; + return static_cast(QMessageDialogOptions::buttonRole( + static_cast(button))); } static const uint layouts[2][5][14] = -- cgit v1.2.3