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 <bogdan@kde.org>
This commit is contained in:
parent
42670c7c45
commit
8aab8ccc0f
@ -693,6 +693,48 @@ QMessageDialogOptions::StandardButtons QMessageDialogOptions::standardButtons()
|
||||
return d->buttons;
|
||||
}
|
||||
|
||||
QMessageDialogOptions::ButtonRole QMessageDialogOptions::buttonRole(QMessageDialogOptions::StandardButton button)
|
||||
{
|
||||
switch (button) {
|
||||
case Ok:
|
||||
case Save:
|
||||
case Open:
|
||||
case SaveAll:
|
||||
case Retry:
|
||||
case Ignore:
|
||||
return AcceptRole;
|
||||
|
||||
case Cancel:
|
||||
case Close:
|
||||
case Abort:
|
||||
return RejectRole;
|
||||
|
||||
case Discard:
|
||||
return DestructiveRole;
|
||||
|
||||
case Help:
|
||||
return HelpRole;
|
||||
|
||||
case Apply:
|
||||
return ApplyRole;
|
||||
|
||||
case Yes:
|
||||
case YesToAll:
|
||||
return YesRole;
|
||||
|
||||
case No:
|
||||
case NoToAll:
|
||||
return NoRole;
|
||||
|
||||
case RestoreDefaults:
|
||||
case Reset:
|
||||
return ResetRole;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return InvalidRole;
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QPlatformMessageDialogHelper
|
||||
|
@ -361,6 +361,21 @@ public:
|
||||
|
||||
Q_DECLARE_FLAGS(StandardButtons, StandardButton)
|
||||
|
||||
enum ButtonRole {
|
||||
InvalidRole = -1,
|
||||
AcceptRole,
|
||||
RejectRole,
|
||||
DestructiveRole,
|
||||
ActionRole,
|
||||
HelpRole,
|
||||
YesRole,
|
||||
NoRole,
|
||||
ResetRole,
|
||||
ApplyRole,
|
||||
|
||||
NRoles
|
||||
};
|
||||
|
||||
QMessageDialogOptions();
|
||||
QMessageDialogOptions(const QMessageDialogOptions &rhs);
|
||||
QMessageDialogOptions &operator=(const QMessageDialogOptions &rhs);
|
||||
@ -386,6 +401,8 @@ public:
|
||||
void setStandardButtons(StandardButtons buttons);
|
||||
StandardButtons standardButtons() const;
|
||||
|
||||
static ButtonRole buttonRole(StandardButton button);
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QMessageDialogOptionsPrivate> d;
|
||||
};
|
||||
@ -400,7 +417,8 @@ public:
|
||||
void setOptions(const QSharedPointer<QMessageDialogOptions> &options);
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked(QMessageDialogOptions::StandardButton button);
|
||||
void clicked(QMessageDialogOptions::StandardButton button); // TODO remove before 5.2
|
||||
void clicked(QMessageDialogOptions::StandardButton button, QMessageDialogOptions::ButtonRole role);
|
||||
|
||||
private:
|
||||
QSharedPointer<QMessageDialogOptions> m_options;
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <QtWidgets/qdialog.h>
|
||||
#include <QtWidgets/qapplication.h>
|
||||
#include <private/qwidget_p.h>
|
||||
#include <QtGui/qpa/qplatformdialoghelper.h>
|
||||
#include <QtWidgets/qaction.h>
|
||||
|
||||
#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<QDialogButtonBox::ButtonRole>(QMessageDialogOptions::buttonRole(
|
||||
static_cast<QMessageDialogOptions::StandardButton>(button)));
|
||||
}
|
||||
|
||||
static const uint layouts[2][5][14] =
|
||||
|
Loading…
Reference in New Issue
Block a user