implement helper methods to add plugins to the Raster menu and toolbar

This commit is contained in:
Alexander Bruy 2011-12-20 17:53:57 +02:00
parent d4ddf368ba
commit 02555ad2e1
6 changed files with 172 additions and 2 deletions

View File

@ -64,6 +64,13 @@ class QgisInterface : QObject
virtual int addToolBarIcon(QAction *qAction) =0;
//! Remove an action (icon) from the plugin toolbar
virtual void removeToolBarIcon(QAction *qAction) = 0;
//! Add an icon to the Raster toolbar
//! @note added in 2.0
virtual int addRasterToolBarIcon(QAction *qAction) =0;
//! Remove an action (icon) from the Raster toolbar
//! @note added in 2.0
virtual void removeRasterToolBarIcon(QAction *qAction) = 0;
//! Add toolbar with specified name
virtual QToolBar* addToolBar(QString name)=0 /Factory/;
@ -115,6 +122,16 @@ class QgisInterface : QObject
*/
virtual void removePluginDatabaseMenu(QString name, QAction* action)=0;
/** Add action to the Raster menu
* @note added in 2.0
*/
virtual void addPluginToRasterMenu(QString name, QAction* action)=0;
/** Remove action from the Raster menu
* @note added in 2.0
*/
virtual void removePluginRasterMenu(QString name, QAction* action)=0;
/** Add a dock widget to the main window
@note added in 1.7 */
virtual void addDockWidget ( Qt::DockWidgetArea area, QDockWidget * dockwidget )=0;
@ -167,6 +184,8 @@ class QgisInterface : QObject
virtual QMenu *layerMenu() = 0;
virtual QMenu *settingsMenu() = 0;
virtual QMenu *pluginMenu() = 0;
virtual QMenu *rasterMenu() = 0;
virtual QMenu *databaseMenu() = 0;
virtual QMenu *firstRightStandardMenu() = 0;
virtual QMenu *windowMenu() = 0;
virtual QMenu *helpMenu() = 0;

View File

@ -759,7 +759,7 @@ void QgisApp::createActions()
{
mActionPluginSeparator1 = NULL; // plugin list separator will be created when the first plugin is loaded
mActionPluginSeparator2 = NULL; // python separator will be created only if python is found
mActionRasterSeparator = NULL; // raster plugins list separator will be created when the first plugin is loaded
// File Menu Items
connect( mActionNewProject, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
@ -5286,6 +5286,55 @@ QMenu* QgisApp::getDatabaseMenu( QString menuName )
return menu;
}
QMenu* QgisApp::getRasterMenu( QString menuName )
{
#ifdef Q_WS_MAC
// Mac doesn't have '&' keyboard shortcuts.
menuName.remove( QChar( '&' ) );
#endif
QAction *before = NULL;
if ( !mActionRasterSeparator )
{
// First plugin - create plugin list separator
mActionRasterSeparator = mRasterMenu->insertSeparator( before );
}
else
{
QString dst = menuName;
dst.remove( QChar( '&' ) );
// Plugins exist - search between plugin separator and python separator or end of list
QList<QAction*> actions = mRasterMenu->actions();
for ( int i = actions.indexOf( mActionRasterSeparator ) + 1; i < actions.count(); i++ )
{
QString src = actions.at( i )->text();
src.remove( QChar( '&' ) );
int comp = dst.localeAwareCompare( src );
if ( comp < 0 )
{
// Add item before this one
before = actions.at( i );
break;
}
else if ( comp == 0 )
{
// Plugin menu item already exists
return actions.at( i )->menu();
}
}
}
// It doesn't exist, so create
QMenu *menu = new QMenu( menuName, this );
if ( before )
mRasterMenu->insertMenu( before, menu );
else
mRasterMenu->addMenu( menu );
return menu;
}
void QgisApp::insertAddLayerAction( QAction *action )
{
mLayerMenu->insertAction( mActionAddLayerSeparator, action );
@ -5324,6 +5373,12 @@ void QgisApp::addPluginToDatabaseMenu( QString name, QAction* action )
menuBar()->addMenu( mDatabaseMenu );
}
void QgisApp::addPluginToRasterMenu( QString name, QAction* action )
{
QMenu* menu = getRasterMenu( name );
menu->addAction( action );
}
void QgisApp::removePluginDatabaseMenu( QString name, QAction* action )
{
QMenu* menu = getDatabaseMenu( name );
@ -5348,16 +5403,46 @@ void QgisApp::removePluginDatabaseMenu( QString name, QAction* action )
}
}
void QgisApp::removePluginRasterMenu( QString name, QAction* action )
{
QMenu* menu = getRasterMenu( name );
menu->removeAction( action );
if ( menu->actions().count() == 0 )
{
mRasterMenu->removeAction( menu->menuAction() );
}
// Remove separator above plugins in Raster menu if no plugins remain
QList<QAction*> actions = mRasterMenu->actions();
if ( actions.indexOf( mActionRasterSeparator ) + 1 == actions.count() )
{
mRasterMenu->removeAction( mActionRasterSeparator );
mActionRasterSeparator = NULL;
}
}
int QgisApp::addPluginToolBarIcon( QAction * qAction )
{
mPluginToolBar->addAction( qAction );
return 0;
}
void QgisApp::removePluginToolBarIcon( QAction *qAction )
{
mPluginToolBar->removeAction( qAction );
}
int QgisApp::addRasterToolBarIcon( QAction * qAction )
{
mRasterToolBar->addAction( qAction );
return 0;
}
void QgisApp::removeRasterToolBarIcon( QAction *qAction )
{
mRasterToolBar->removeAction( qAction );
}
void QgisApp::updateCRSStatusBar()
{
mOnTheFlyProjectionStatusLabel->setText( mMapCanvas->mapRenderer()->destinationCrs().authid() );

View File

@ -528,6 +528,12 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void addPluginToDatabaseMenu( QString name, QAction* action );
//! Remove the action to the submenu with the given name under the Database menu
void removePluginDatabaseMenu( QString name, QAction* action );
//! Find the QMenu with the given name within the Raster menu (ie the user visible text on the menu item)
QMenu* getRasterMenu( QString menuName );
//! Add the action to the submenu with the given name under the Raster menu
void addPluginToRasterMenu( QString name, QAction* action );
//! Remove the action to the submenu with the given name under the Raster menu
void removePluginRasterMenu( QString name, QAction* action );
//! Add "add layer" action to layer menu
void insertAddLayerAction( QAction* action );
//! Remove "add layer" action to layer menu
@ -536,6 +542,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
int addPluginToolBarIcon( QAction * qAction );
//! Remove an icon from the plugin toolbar
void removePluginToolBarIcon( QAction *qAction );
//! Add an icon to the Raster toolbar
int addRasterToolBarIcon( QAction * qAction );
//! Remove an icon from the Raster toolbar
void removeRasterToolBarIcon( QAction *qAction );
//! Save window state
void saveWindowState();
//! Restore the window and toolbar state
@ -893,6 +903,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QAction* mActionPluginSeparator1;
QAction* mActionPluginSeparator2;
QAction* mActionRasterSeparator;
// action groups ----------------------------------
QActionGroup *mMapToolGroup;

View File

@ -164,15 +164,36 @@ void QgisAppInterface::removePluginDatabaseMenu( QString name, QAction* action )
qgis->removePluginDatabaseMenu( name, action );
}
void QgisAppInterface::addPluginToRasterMenu( QString name, QAction* action )
{
qgis->addPluginToRasterMenu( name, action );
}
void QgisAppInterface::removePluginRasterMenu( QString name, QAction* action )
{
qgis->removePluginRasterMenu( name, action );
}
int QgisAppInterface::addToolBarIcon( QAction * qAction )
{
// add the menu to the master Plugins menu
return qgis->addPluginToolBarIcon( qAction );
}
void QgisAppInterface::removeToolBarIcon( QAction *qAction )
{
qgis->removePluginToolBarIcon( qAction );
}
int QgisAppInterface::addRasterToolBarIcon( QAction * qAction )
{
return qgis->addRasterToolBarIcon( qAction );
}
void QgisAppInterface::removeRasterToolBarIcon( QAction *qAction )
{
qgis->removeRasterToolBarIcon( qAction );
}
QToolBar* QgisAppInterface::addToolBar( QString name )
{
return qgis->addToolBar( name );
@ -277,6 +298,7 @@ QMenu *QgisAppInterface::viewMenu() { return qgis->viewMenu(); }
QMenu *QgisAppInterface::layerMenu() { return qgis->layerMenu(); }
QMenu *QgisAppInterface::settingsMenu() { return qgis->settingsMenu(); }
QMenu *QgisAppInterface::pluginMenu() { return qgis->pluginMenu(); }
QMenu *QgisAppInterface::rasterMenu() { return qgis->rasterMenu(); }
QMenu *QgisAppInterface::databaseMenu() { return qgis->databaseMenu(); }
QMenu *QgisAppInterface::firstRightStandardMenu() { return qgis->firstRightStandardMenu(); }
QMenu *QgisAppInterface::windowMenu() { return qgis->windowMenu(); }

View File

@ -82,6 +82,11 @@ class QgisAppInterface : public QgisInterface
int addToolBarIcon( QAction *qAction );
//! Remove an icon (action) from the plugin toolbar
void removeToolBarIcon( QAction *qAction );
//! Add an icon to the Raster toolbar
int addRasterToolBarIcon( QAction *qAction );
//! Remove an icon (action) from the Raster toolbar
void removeRasterToolBarIcon( QAction *qAction );
//! Add toolbar with specified name
QToolBar* addToolBar( QString name );
@ -116,6 +121,11 @@ class QgisAppInterface : public QgisInterface
/** Remove action from the Database menu */
void removePluginDatabaseMenu( QString name, QAction* action );
/** Add action to the Raster menu */
void addPluginToRasterMenu( QString name, QAction* action );
/** Remove action from the Raster menu */
void removePluginRasterMenu( QString name, QAction* action );
/** Add "add layer" action to the layer menu */
void insertAddLayerAction( QAction *action );
/** remove "add layer" action from the layer menu */
@ -167,6 +177,7 @@ class QgisAppInterface : public QgisInterface
virtual QMenu *layerMenu();
virtual QMenu *settingsMenu();
virtual QMenu *pluginMenu();
virtual QMenu *rasterMenu();
virtual QMenu *databaseMenu();
virtual QMenu *firstRightStandardMenu();
virtual QMenu *windowMenu();

View File

@ -117,6 +117,14 @@ class GUI_EXPORT QgisInterface : public QObject
//! Remove an action (icon) from the plugin toolbar
virtual void removeToolBarIcon( QAction *qAction ) = 0;
//! Add an icon to the Raster toolbar
//! @note added in 2.0
virtual int addRasterToolBarIcon( QAction *qAction ) = 0;
//! Remove an action (icon) from the Raster toolbar
//! @note added in 2.0
virtual void removeRasterToolBarIcon( QAction *qAction ) = 0;
//! Add toolbar with specified name
virtual QToolBar * addToolBar( QString name ) = 0;
@ -155,6 +163,16 @@ class GUI_EXPORT QgisInterface : public QObject
*/
virtual void removePluginDatabaseMenu( QString name, QAction* action ) = 0;
/** Add action to the Raster menu
* @note added in 2.0
*/
virtual void addPluginToRasterMenu( QString name, QAction* action ) = 0;
/** Remove action from the Raster menu
* @note added in 2.0
*/
virtual void removePluginRasterMenu( QString name, QAction* action ) = 0;
/** Add a dock widget to the main window */
virtual void addDockWidget( Qt::DockWidgetArea area, QDockWidget * dockwidget ) = 0;
@ -224,6 +242,10 @@ class GUI_EXPORT QgisInterface : public QObject
virtual QMenu *layerMenu() = 0;
virtual QMenu *settingsMenu() = 0;
virtual QMenu *pluginMenu() = 0;
virtual QMenu *rasterMenu() = 0;
/** \note added in 1.7
*/
virtual QMenu *databaseMenu() = 0;
virtual QMenu *firstRightStandardMenu() = 0;
virtual QMenu *windowMenu() = 0;
virtual QMenu *helpMenu() = 0;