drop support for a list of QKeySequence in QAction

a single QKeySequence actually is two shortcuts

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-22 04:01:25 +03:00
parent 8f42407b20
commit 1ef52af92e
4 changed files with 5 additions and 129 deletions

View file

@ -124,46 +124,11 @@ void QActionPrivate::redoGrab(QShortcutMap &map)
map.setShortcutAutoRepeat(false, shortcutId, q);
}
void QActionPrivate::redoGrabAlternate(QShortcutMap &map)
{
Q_Q(QAction);
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
if (const int id = alternateShortcutIds.at(i))
map.removeShortcut(id, q);
}
alternateShortcutIds.clear();
if (alternateShortcuts.isEmpty())
return;
for(int i = 0; i < alternateShortcuts.count(); ++i) {
const QKeySequence& alternate = alternateShortcuts.at(i);
if (!alternate.isEmpty())
alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext));
else
alternateShortcutIds.append(0);
}
if (!enabled) {
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
const int id = alternateShortcutIds.at(i);
map.setShortcutEnabled(false, id, q);
}
}
if (!autorepeat) {
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
const int id = alternateShortcutIds.at(i);
map.setShortcutAutoRepeat(false, id, q);
}
}
}
void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
{
Q_Q(QAction);
if (shortcutId)
map.setShortcutEnabled(enable, shortcutId, q);
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
if (const int id = alternateShortcutIds.at(i))
map.setShortcutEnabled(enable, id, q);
}
}
#endif // QT_NO_SHORTCUT
@ -389,52 +354,6 @@ void QAction::setShortcut(const QKeySequence &shortcut)
d->sendDataChanged();
}
/*!
\since 4.2
Sets \a shortcuts as the list of shortcuts that trigger the
action. The first element of the list is the primary shortcut.
\sa shortcut
*/
void QAction::setShortcuts(const QList<QKeySequence> &shortcuts)
{
Q_D(QAction);
QList <QKeySequence> listCopy = shortcuts;
QKeySequence primary;
if (!listCopy.isEmpty())
primary = listCopy.takeFirst();
if (d->shortcut == primary && d->alternateShortcuts == listCopy)
return;
QAPP_CHECK("setShortcuts");
d->shortcut = primary;
d->alternateShortcuts = listCopy;
d->redoGrab(qApp->d_func()->shortcutMap);
d->redoGrabAlternate(qApp->d_func()->shortcutMap);
d->sendDataChanged();
}
/*!
\since 4.2
Sets a platform dependent list of shortcuts based on the \a key.
The result of calling this function will depend on the currently running platform.
Note that more than one shortcut can assigned by this action.
If only the primary shortcut is required, use setShortcut instead.
\sa QKeySequence::keyBindings()
*/
void QAction::setShortcuts(QKeySequence::StandardKey key)
{
QList <QKeySequence> list = QKeySequence::keyBindings(key);
setShortcuts(list);
}
/*!
Returns the primary shortcut.
@ -446,25 +365,6 @@ QKeySequence QAction::shortcut() const
return d->shortcut;
}
/*!
\since 4.2
Returns the list of shortcuts, with the primary shortcut as
the first element of the list.
\sa setShortcuts()
*/
QList<QKeySequence> QAction::shortcuts() const
{
Q_D(const QAction);
QList <QKeySequence> shortcuts;
if (!d->shortcut.isEmpty())
shortcuts << d->shortcut;
if (!d->alternateShortcuts.isEmpty())
shortcuts << d->alternateShortcuts;
return shortcuts;
}
/*!
\property QAction::shortcutContext
\brief the context for the action's shortcut
@ -480,7 +380,6 @@ void QAction::setShortcutContext(Qt::ShortcutContext context)
QAPP_CHECK("setShortcutContext");
d->shortcutContext = context;
d->redoGrab(qApp->d_func()->shortcutMap);
d->redoGrabAlternate(qApp->d_func()->shortcutMap);
d->sendDataChanged();
}
@ -508,7 +407,6 @@ void QAction::setAutoRepeat(bool on)
QAPP_CHECK("setAutoRepeat");
d->autorepeat = on;
d->redoGrab(qApp->d_func()->shortcutMap);
d->redoGrabAlternate(qApp->d_func()->shortcutMap);
d->sendDataChanged();
}
@ -569,10 +467,6 @@ QAction::~QAction()
#ifndef QT_NO_SHORTCUT
if (d->shortcutId && qApp) {
qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this);
for(int i = 0; i < d->alternateShortcutIds.count(); ++i) {
const int id = d->alternateShortcutIds.at(i);
qApp->d_func()->shortcutMap.removeShortcut(id, this);
}
}
#endif
}

View file

@ -112,10 +112,6 @@ public:
void setShortcut(const QKeySequence &shortcut);
QKeySequence shortcut() const;
void setShortcuts(const QList<QKeySequence> &shortcuts);
void setShortcuts(QKeySequence::StandardKey);
QList<QKeySequence> shortcuts() const;
void setShortcutContext(Qt::ShortcutContext context);
Qt::ShortcutContext shortcutContext() const;

View file

@ -61,14 +61,10 @@ public:
QString tooltip;
QString statustip;
QString whatsthis;
#ifndef QT_NO_SHORTCUT
QKeySequence shortcut;
QList<QKeySequence> alternateShortcuts;
#endif
QVariant userData;
#ifndef QT_NO_SHORTCUT
QKeySequence shortcut;
int shortcutId;
QList<int> alternateShortcutIds;
Qt::ShortcutContext shortcutContext;
bool autorepeat;
#endif
@ -89,7 +85,6 @@ public:
#endif
#ifndef QT_NO_SHORTCUT
void redoGrab(QShortcutMap &map);
void redoGrabAlternate(QShortcutMap &map);
void setShortcutEnabled(bool enable, QShortcutMap &map);
#endif // QT_NO_SHORTCUT

View file

@ -209,22 +209,14 @@ void tst_QAction::actionEvent()
QCOMPARE(m_lastAction, &a);
}
//basic testing of standard keys
// basic testing of standard keys
void tst_QAction::setStandardKeys()
{
QAction act(0);
act.setShortcut(QKeySequence("CTRL+L"));
QList<QKeySequence> list;
act.setShortcuts(list);
act.setShortcuts(QKeySequence::Copy);
QVERIFY(act.shortcut() == act.shortcuts().first());
QList<QKeySequence> expected;
expected << QKeySequence("CTRL+C") << QKeySequence("F16") << QKeySequence("CTRL+INSERT");
QVERIFY(act.shortcuts() == expected);
act.setShortcut(QKeySequence("CTRL+C"));
QVERIFY(act.shortcut() == QKeySequence(QKeySequence::Copy));
}
void tst_QAction::alternateShortcuts()
{
//test the alternate shortcuts (by adding more than 1 shortcut)
@ -234,8 +226,7 @@ void tst_QAction::alternateShortcuts()
{
QAction act(wid);
wid->addAction(&act);
QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A");
act.setShortcuts(shlist);
act.setShortcut(QKeySequence("CTRL+A"));
QSignalSpy spy(&act, SIGNAL(triggered()));