Skip to content

Commit

Permalink
cleaner fix for #5355: remove shortcuts to destroyed actions automati…
Browse files Browse the repository at this point in the history
…cally
  • Loading branch information
jef-n committed Apr 15, 2012
1 parent 3f4c11f commit 3c02fe1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -186,6 +186,7 @@ SET (QGIS_APP_MOC_HDRS
qgslabelengineconfigdialog.h
qgslabelinggui.h
qgslabelpropertydialog.h
qgsshortcutsmanager.h

qgsmaptooladdfeature.h
qgsmaptoolcapture.h
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/app/qgsshortcutsmanager.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -115,3 +116,8 @@ void QgsShortcutsManager::registerAllChildrenActions( QObject* object )
}
}
}

void QgsShortcutsManager::actionDestroyed()
{
mActions.remove( static_cast<QAction*>( sender() ) );
}
10 changes: 7 additions & 3 deletions src/app/qgsshortcutsmanager.h
Expand Up @@ -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 );
Expand All @@ -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;

Expand Down

0 comments on commit 3c02fe1

Please sign in to comment.