Skip to content
Permalink
Browse files
cleaner fix for #5355: remove shortcuts to destroyed actions automati…
…cally
  • Loading branch information
jef-n committed Apr 15, 2012
1 parent 3f4c11f commit 3c02fe1b26a7372f47e538fb5cd1b553179b0ae9
Showing with 18 additions and 7 deletions.
  1. +1 −0 src/app/CMakeLists.txt
  2. +1 −1 src/app/qgisapp.cpp
  3. +9 −3 src/app/qgsshortcutsmanager.cpp
  4. +7 −3 src/app/qgsshortcutsmanager.h
@@ -186,6 +186,7 @@ SET (QGIS_APP_MOC_HDRS
qgslabelengineconfigdialog.h
qgslabelinggui.h
qgslabelpropertydialog.h
qgsshortcutsmanager.h

qgsmaptooladdfeature.h
qgsmaptoolcapture.h
@@ -640,7 +640,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
//add reacting to long click in android
grabGesture( Qt::TapAndHoldGesture );
#else
//remove mActionTouch button before populuating the shortcuts
//remove mActionTouch button
delete mActionTouch;
mActionTouch = 0;
#endif
@@ -17,22 +17,23 @@

#include <QSettings>

QgsShortcutsManager::QgsShortcutsManager()
QgsShortcutsManager::QgsShortcutsManager( QObject *parent ) : QObject( parent )
{
}

QgsShortcutsManager* QgsShortcutsManager::mInstance = NULL;

QgsShortcutsManager* QgsShortcutsManager::instance()
QgsShortcutsManager* QgsShortcutsManager::instance( QObject *parent )
{
if ( !mInstance )
mInstance = new QgsShortcutsManager;
mInstance = new QgsShortcutsManager( parent );
return mInstance;
}

bool QgsShortcutsManager::registerAction( QAction* action, QString defaultShortcut )
{
mActions.insert( action, defaultShortcut );
connect( action, SIGNAL( destroyed() ), this, SLOT( actionDestroyed() ) );

QString actionText = action->text();
actionText.remove( '&' ); // remove the accelerator
@@ -115,3 +116,8 @@ void QgsShortcutsManager::registerAllChildrenActions( QObject* object )
}
}
}

void QgsShortcutsManager::actionDestroyed()
{
mActions.remove( static_cast<QAction*>( sender() ) );
}
@@ -24,12 +24,13 @@
Shortcuts manager is a singleton class that contains a list of actions from main window
that have been registered and their shortcut can be changed.
*/
class QgsShortcutsManager
class QgsShortcutsManager : public QObject
{
Q_OBJECT;
public:

//! return instance of the manager
static QgsShortcutsManager* instance();
static QgsShortcutsManager* instance( QObject *parent = NULL );

//! register all actions which are children of the passed object
void registerAllChildrenActions( QObject* object );
@@ -55,8 +56,11 @@ class QgsShortcutsManager
// return action by it's name. NULL if nothing found
QAction* actionByName( QString name );

public slots:
void actionDestroyed();

protected:
QgsShortcutsManager();
QgsShortcutsManager( QObject *parent );

typedef QHash<QAction*, QString> ActionsHash;

0 comments on commit 3c02fe1

Please sign in to comment.