33 , mSettingsPath( settingsRoot )
48 Q_FOREACH (
QAction* a, actions )
57 if (
QAction* a = qobject_cast<QAction*>( child ) )
79 if (
QShortcut* s = qobject_cast<QShortcut*>( child ) )
95 mActions.
insert( action, defaultSequence );
118 mShortcuts.
insert( shortcut, defaultSequence );
119 connect( shortcut, SIGNAL(
destroyed() ),
this, SLOT( shortcutDestroyed() ) );
125 QString keySequence = settings.
value( mSettingsPath + shortcutName, defaultSequence ).
toString();
127 shortcut->
setKey( keySequence );
137 mActions.
remove( action );
143 if ( !mShortcuts.
contains( shortcut ) )
146 mShortcuts.
remove( shortcut );
152 return mActions.
keys();
157 return mShortcuts.
keys();
163 ActionsHash::const_iterator actionIt = mActions.
constBegin();
164 for ( ; actionIt != mActions.
constEnd(); ++actionIt )
166 list << actionIt.key();
168 ShortcutsHash::const_iterator shortcutIt = mShortcuts.
constBegin();
169 for ( ; shortcutIt != mShortcuts.
constEnd(); ++shortcutIt )
171 list << shortcutIt.key();
178 if (
QAction* action = qobject_cast< QAction* >(
object ) )
180 else if (
QShortcut* shortcut = qobject_cast< QShortcut* >(
object ) )
208 if (
QAction* action = qobject_cast< QAction* >(
object ) )
210 else if (
QShortcut* shortcut = qobject_cast< QShortcut* >(
object ) )
225 settings.
setValue( mSettingsPath + actionText, sequence );
231 shortcut->
setKey( sequence );
237 settings.
setValue( mSettingsPath + shortcutText, sequence );
256 for ( ActionsHash::const_iterator it = mActions.
constBegin(); it != mActions.
constEnd(); ++it )
258 if ( it.key()->shortcut() == sequence )
270 for ( ShortcutsHash::const_iterator it = mShortcuts.
constBegin(); it != mShortcuts.
constEnd(); ++it )
272 if ( it.key()->key() == sequence )
281 for ( ActionsHash::const_iterator it = mActions.
constBegin(); it != mActions.
constEnd(); ++it )
283 if ( it.key()->text() ==
name )
292 for ( ShortcutsHash::const_iterator it = mShortcuts.
constBegin(); it != mShortcuts.
constEnd(); ++it )
294 if ( it.key()->objectName() ==
name )
301 void QgsShortcutsManager::actionDestroyed()
306 void QgsShortcutsManager::shortcutDestroyed()
308 mShortcuts.
remove( qobject_cast<QShortcut*>(
sender() ) );
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
QString objectDefaultKeySequence(QObject *object) const
Returns the default sequence for an object (either a QAction or QShortcut).
QList< QObject * > listAll() const
Returns a list of both actions and shortcuts in the manager.
iterator insert(const Key &key, const T &value)
bool unregisterShortcut(QShortcut *shortcut)
Removes a shortcut from the manager.
QShortcut * shortcutForSequence(const QKeySequence &sequence) const
Returns the shortcut which is associated for a key sequence, or nullptr if no shortcut is associated...
static void warning(const QString &msg)
Goes to qWarning.
void registerAllChildActions(QObject *object, bool recursive=false)
Automatically registers all QActions which are children of the passed object.
const QObjectList & children() const
QList< QAction * > listActions() const
Returns a list of all actions in the manager.
Shortcuts manager is a class that contains a list of QActions and QShortcuts that have been registere...
bool setObjectKeySequence(QObject *object, const QString &sequence)
Modifies an object's (either a QAction or a QShortcut) key sequence.
QString & remove(int position, int n)
void registerAllChildShortcuts(QObject *object, bool recursive=false)
Automatically registers all QShortcuts which are children of the passed object.
static QgsShortcutsManager * instance()
Return the singleton instance of the manager.
QList< QShortcut * > listShortcuts() const
Returns a list of shortcuts in the manager.
void setValue(const QString &key, const QVariant &value)
const char * name() const
bool setKeySequence(const QString &name, const QString &sequence)
Modifies an action or shortcut's key sequence.
const_iterator constEnd() const
bool registerShortcut(QShortcut *shortcut, const QString &defaultSequence=QString())
Registers a QShortcut with the manager so the shortcut can be configured in GUI.
QAction * actionForSequence(const QKeySequence &sequence) const
Returns the action which is associated for a shortcut sequence, or nullptr if no action is associated...
QString defaultKeySequence(QAction *action) const
Returns the default sequence for an action.
int remove(const Key &key)
QList< Key > keys() const
const T value(const Key &key) const
QShortcut * shortcutByName(const QString &name) const
Returns a shortcut by its name, or nullptr if nothing found.
bool registerAction(QAction *action, const QString &defaultShortcut=QString())
Registers an action with the manager so the shortcut can be configured in GUI.
void registerAllChildren(QObject *object, bool recursive=false)
Automatically registers all QActions and QShortcuts which are children of the passed object...
QVariant value(const QString &key, const QVariant &defaultValue) const
const_iterator constBegin() const
QAction * actionByName(const QString &name) const
Returns an action by its name, or nullptr if nothing found.
bool unregisterAction(QAction *action)
Removes an action from the manager.
bool contains(const Key &key) const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QgsShortcutsManager(QObject *parent=nullptr, const QString &settingsRoot="/shortcuts/")
Constructor for QgsShortcutsManager.
void destroyed(QObject *obj)
QObject * objectForSequence(const QKeySequence &sequence) const
Returns the object (QAction or QShortcut) matching the specified key sequence,.