Cleanup short-cut id deprecation

Wasn't marked deprecated in documentation, and was needed for user
construction of QShortcutEvents.

Fixes: QTBUG-109090
Change-Id: Ibf0ad83a57de724d9b88a7e610ba04c2c662983b
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2022-12-02 13:49:18 +01:00
parent 10b5b4cbba
commit d4eb5d1110
3 changed files with 37 additions and 0 deletions

View File

@ -22,6 +22,10 @@
#include <private/qdnd_p.h> #include <private/qdnd_p.h>
#endif #endif
#if QT_CONFIG(shortcut)
#include <private/qshortcut_p.h>
#endif
#include <private/qdebug_p.h> #include <private/qdebug_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -3682,6 +3686,8 @@ Q_IMPL_EVENT_COMMON(QToolBarChangeEvent)
Constructs a shortcut event for the given \a key press, Constructs a shortcut event for the given \a key press,
associated with the QShortcut ID \a id. associated with the QShortcut ID \a id.
\deprecated use the other constructor
\a ambiguous specifies whether there is more than one QShortcut \a ambiguous specifies whether there is more than one QShortcut
for the same key sequence. for the same key sequence.
*/ */
@ -3690,6 +3696,27 @@ QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
{ {
} }
/*!
Constructs a shortcut event for the given \a key press,
associated with the QShortcut \a shortcut.
\a ambiguous specifies whether there is more than one QShortcut
for the same key sequence.
*/
QShortcutEvent::QShortcutEvent(const QKeySequence &key, const QShortcut *shortcut, bool ambiguous)
: QEvent(Shortcut), m_sequence(key), m_shortcutId(0), m_ambiguous(ambiguous)
{
if (shortcut) {
auto priv = static_cast<const QShortcutPrivate *>(QShortcutPrivate::get(shortcut));
auto index = priv->sc_sequences.indexOf(key);
if (index < 0) {
qWarning() << "Given QShortcut does not contain key-sequence " << key;
return;
}
m_shortcutId = priv->sc_ids[index];
}
}
Q_IMPL_EVENT_COMMON(QShortcutEvent) Q_IMPL_EVENT_COMMON(QShortcutEvent)
#endif // QT_CONFIG(shortcut) #endif // QT_CONFIG(shortcut)
@ -4233,6 +4260,8 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
/*! /*!
\fn int QShortcutEvent::shortcutId() const \fn int QShortcutEvent::shortcutId() const
\deprecated
Returns the ID of the QShortcut object for which this event was Returns the ID of the QShortcut object for which this event was
generated. generated.

View File

@ -36,6 +36,9 @@ class QAction;
class QMouseEvent; class QMouseEvent;
class QPointerEvent; class QPointerEvent;
class QScreen; class QScreen;
#if QT_CONFIG(shortcut)
class QShortcut;
#endif
class QTabletEvent; class QTabletEvent;
class QTouchEvent; class QTouchEvent;
#if QT_CONFIG(gestures) #if QT_CONFIG(gestures)
@ -873,9 +876,12 @@ class Q_GUI_EXPORT QShortcutEvent : public QEvent
{ {
Q_DECL_EVENT_COMMON(QShortcutEvent) Q_DECL_EVENT_COMMON(QShortcutEvent)
public: public:
// Note this is publicly deprecated, but should remain as internal constructor:
QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false); QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false);
QShortcutEvent(const QKeySequence &key, const QShortcut *shortcut = nullptr, bool ambiguous = false);
inline const QKeySequence &key() const { return m_sequence; } inline const QKeySequence &key() const { return m_sequence; }
// Note this is publicly deprecated, but should remain as internal getter:
inline int shortcutId() const { return m_shortcutId; } inline int shortcutId() const { return m_shortcutId; }
inline bool isAmbiguous() const { return m_ambiguous; } inline bool isAmbiguous() const { return m_ambiguous; }
protected: protected:

View File

@ -536,6 +536,8 @@ QString QShortcut::whatsThis() const
/*! /*!
Returns the primary key binding's ID. Returns the primary key binding's ID.
\deprecated
\sa QShortcutEvent::shortcutId() \sa QShortcutEvent::shortcutId()
*/ */
int QShortcut::id() const int QShortcut::id() const