Navigation Menu

Skip to content

Commit

Permalink
add Vector menu and toolbar to improve plugins organization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 20, 2011
1 parent 0f41da3 commit 2e5aa32
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 1 deletion.
18 changes: 18 additions & 0 deletions python/gui/qgisinterface.sip
Expand Up @@ -70,6 +70,12 @@ class QgisInterface : QObject
//! Remove an action (icon) from the Raster toolbar
//! @note added in 2.0
virtual void removeRasterToolBarIcon(QAction *qAction) = 0;
//! Add an icon to the Vector toolbar
//! @note added in 2.0
virtual int addVectorToolBarIcon(QAction *qAction) =0;
//! Remove an action (icon) from the Vector toolbar
//! @note added in 2.0
virtual void removeVectorToolBarIcon(QAction *qAction) = 0;

//! Add toolbar with specified name
virtual QToolBar* addToolBar(QString name)=0 /Factory/;
Expand Down Expand Up @@ -132,6 +138,16 @@ class QgisInterface : QObject
*/
virtual void removePluginRasterMenu(QString name, QAction* action)=0;

/** Add action to the Vector menu
* @note added in 2.0
*/
virtual void addPluginToVectorMenu(QString name, QAction* action)=0;

/** Remove action from the Vector menu
* @note added in 2.0
*/
virtual void removePluginVectorMenu(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;
Expand Down Expand Up @@ -185,6 +201,7 @@ class QgisInterface : QObject
virtual QMenu *settingsMenu() = 0;
virtual QMenu *pluginMenu() = 0;
virtual QMenu *rasterMenu() = 0;
virtual QMenu *vectorMenu() = 0;
virtual QMenu *databaseMenu() = 0;
virtual QMenu *firstRightStandardMenu() = 0;
virtual QMenu *windowMenu() = 0;
Expand All @@ -200,6 +217,7 @@ class QgisInterface : QObject
virtual QToolBar *pluginToolBar() = 0;
virtual QToolBar *helpToolBar() = 0;
virtual QToolBar *rasterToolBar() = 0;
virtual QToolBar *vectorToolBar() = 0;

//! File menu actions
virtual QAction *actionNewProject() = 0;
Expand Down
106 changes: 106 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1090,6 +1090,9 @@ void QgisApp::createMenus()
// Database Menu
// don't add it yet, wait for a plugin
mDatabaseMenu = new QMenu( tr( "&Database" ) );
// Vector Menu
// don't add it yet, wait for a plugin
mVectorMenu = new QMenu( tr( "Vect&or" ) );

// Help menu
// add What's this button to it
Expand Down Expand Up @@ -1117,6 +1120,7 @@ void QgisApp::createToolBars()
<< mPluginToolBar
<< mHelpToolBar
<< mRasterToolBar
<< mVectorToolBar
<< mLabelToolBar;

QList<QAction*> toolbarMenuActions;
Expand Down Expand Up @@ -5335,6 +5339,45 @@ QMenu* QgisApp::getRasterMenu( QString menuName )
return menu;
}

QMenu* QgisApp::getVectorMenu( QString menuName )
{
#ifdef Q_WS_MAC
// Mac doesn't have '&' keyboard shortcuts.
menuName.remove( QChar( '&' ) );
#endif
QString dst = menuName;
dst.remove( QChar( '&' ) );

QAction *before = NULL;
QList<QAction*> actions = mVectorMenu->actions();
for ( int i = 0; 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 )
mVectorMenu->insertMenu( before, menu );
else
mVectorMenu->addMenu( menu );

return menu;
}

void QgisApp::insertAddLayerAction( QAction *action )
{
mLayerMenu->insertAction( mActionAddLayerSeparator, action );
Expand Down Expand Up @@ -5379,6 +5422,34 @@ void QgisApp::addPluginToRasterMenu( QString name, QAction* action )
menu->addAction( action );
}

void QgisApp::addPluginToVectorMenu( QString name, QAction* action )
{
QMenu* menu = getVectorMenu( name );
menu->addAction( action );

// add the Vector menu to the menuBar if not added yet
if ( mVectorMenu->actions().count() != 1 )
return;

QAction* before = NULL;
QList<QAction*> actions = menuBar()->actions();
for ( int i = 0; i < actions.count(); i++ )
{
if ( actions.at( i )->menu() == mVectorMenu )
return;
if ( actions.at( i )->menu() == mRasterMenu )
{
before = actions.at( i );
break;
}
}

if ( before )
menuBar()->insertMenu( before, mVectorMenu );
else
menuBar()->addMenu( mVectorMenu );
}

void QgisApp::removePluginDatabaseMenu( QString name, QAction* action )
{
QMenu* menu = getDatabaseMenu( name );
Expand Down Expand Up @@ -5421,6 +5492,30 @@ void QgisApp::removePluginRasterMenu( QString name, QAction* action )
}
}

void QgisApp::removePluginVectorMenu( QString name, QAction* action )
{
QMenu* menu = getVectorMenu( name );
menu->removeAction( action );
if ( menu->actions().count() == 0 )
{
mVectorMenu->removeAction( menu->menuAction() );
}

// remove the Vector menu from the menuBar if there are no more actions
if ( mVectorMenu->actions().count() > 0 )
return;

QList<QAction*> actions = menuBar()->actions();
for ( int i = 0; i < actions.count(); i++ )
{
if ( actions.at( i )->menu() == mVectorMenu )
{
menuBar()->removeAction( actions.at( i ) );
return;
}
}
}

int QgisApp::addPluginToolBarIcon( QAction * qAction )
{
mPluginToolBar->addAction( qAction );
Expand All @@ -5443,6 +5538,17 @@ void QgisApp::removeRasterToolBarIcon( QAction *qAction )
mRasterToolBar->removeAction( qAction );
}

int QgisApp::addVectorToolBarIcon( QAction * qAction )
{
mVectorToolBar->addAction( qAction );
return 0;
}

void QgisApp::removeVectorToolBarIcon( QAction *qAction )
{
mVectorToolBar->removeAction( qAction );
}

void QgisApp::updateCRSStatusBar()
{
mOnTheFlyProjectionStatusLabel->setText( mMapCanvas->mapRenderer()->destinationCrs().authid() );
Expand Down
14 changes: 14 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -313,6 +313,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QMenu *pluginMenu() { return mPluginMenu; }
QMenu *databaseMenu() { return mDatabaseMenu; }
QMenu *rasterMenu() { return mRasterMenu; }
QMenu *vectorMenu() { return mVectorMenu; }
#ifdef Q_WS_MAC
QMenu *firstRightStandardMenu() { return mWindowMenu; }
QMenu *windowMenu() { return mWindowMenu; }
Expand All @@ -338,6 +339,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QToolBar *pluginToolBar() { return mPluginToolBar; }
QToolBar *helpToolBar() { return mHelpToolBar; }
QToolBar *rasterToolBar() { return mRasterToolBar; }
QToolBar *vectorToolBar() { return mVectorToolBar; }

//! show layer properties
void showLayerProperties( QgsMapLayer *ml );
Expand Down Expand Up @@ -534,6 +536,12 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
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 );
//! Find the QMenu with the given name within the Vector menu (ie the user visible text on the menu item)
QMenu* getVectorMenu( QString menuName );
//! Add the action to the submenu with the given name under the Vector menu
void addPluginToVectorMenu( QString name, QAction* action );
//! Remove the action to the submenu with the given name under the Vector menu
void removePluginVectorMenu( QString name, QAction* action );
//! Add "add layer" action to layer menu
void insertAddLayerAction( QAction* action );
//! Remove "add layer" action to layer menu
Expand All @@ -546,6 +554,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
int addRasterToolBarIcon( QAction * qAction );
//! Remove an icon from the Raster toolbar
void removeRasterToolBarIcon( QAction *qAction );
//! Add an icon to the Vector toolbar
int addVectorToolBarIcon( QAction * qAction );
//! Remove an icon from the Vector toolbar
void removeVectorToolBarIcon( QAction *qAction );
//! Save window state
void saveWindowState();
//! Restore the window and toolbar state
Expand Down Expand Up @@ -996,6 +1008,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QMenu * mPopupMenu;
//! Top level database menu
QMenu *mDatabaseMenu;
//! Top level vector menu
QMenu *mVectorMenu;
//! Popup menu for the map overview tools
QMenu *toolPopupOverviews;
//! Popup menu for the display tools
Expand Down
22 changes: 22 additions & 0 deletions src/app/qgisappinterface.cpp
Expand Up @@ -174,6 +174,16 @@ void QgisAppInterface::removePluginRasterMenu( QString name, QAction* action )
qgis->removePluginRasterMenu( name, action );
}

void QgisAppInterface::addPluginToVectorMenu( QString name, QAction* action )
{
qgis->addPluginToVectorMenu( name, action );
}

void QgisAppInterface::removePluginVectorMenu( QString name, QAction* action )
{
qgis->removePluginVectorMenu( name, action );
}

int QgisAppInterface::addToolBarIcon( QAction * qAction )
{
return qgis->addPluginToolBarIcon( qAction );
Expand All @@ -194,6 +204,16 @@ void QgisAppInterface::removeRasterToolBarIcon( QAction *qAction )
qgis->removeRasterToolBarIcon( qAction );
}

int QgisAppInterface::addVectorToolBarIcon( QAction * qAction )
{
return qgis->addVectorToolBarIcon( qAction );
}

void QgisAppInterface::removeVectorToolBarIcon( QAction *qAction )
{
qgis->removeVectorToolBarIcon( qAction );
}

QToolBar* QgisAppInterface::addToolBar( QString name )
{
return qgis->addToolBar( name );
Expand Down Expand Up @@ -299,6 +319,7 @@ 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::vectorMenu() { return qgis->vectorMenu(); }
QMenu *QgisAppInterface::databaseMenu() { return qgis->databaseMenu(); }
QMenu *QgisAppInterface::firstRightStandardMenu() { return qgis->firstRightStandardMenu(); }
QMenu *QgisAppInterface::windowMenu() { return qgis->windowMenu(); }
Expand All @@ -314,6 +335,7 @@ QToolBar *QgisAppInterface::attributesToolBar() { return qgis->attributesToolBar
QToolBar *QgisAppInterface::pluginToolBar() { return qgis->pluginToolBar(); }
QToolBar *QgisAppInterface::helpToolBar() { return qgis->helpToolBar(); }
QToolBar *QgisAppInterface::rasterToolBar() { return qgis->rasterToolBar(); }
QToolBar *QgisAppInterface::vectorToolBar() { return qgis->vectorToolBar(); }

//! File menu actions
QAction *QgisAppInterface::actionNewProject() { return qgis->actionNewProject(); }
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisappinterface.h
Expand Up @@ -86,6 +86,10 @@ class QgisAppInterface : public QgisInterface
int addRasterToolBarIcon( QAction *qAction );
//! Remove an icon (action) from the Raster toolbar
void removeRasterToolBarIcon( QAction *qAction );
//! Add an icon to the Vector toolbar
int addVectorToolBarIcon( QAction *qAction );
//! Remove an icon (action) from the Vector toolbar
void removeVectorToolBarIcon( QAction *qAction );

//! Add toolbar with specified name
QToolBar* addToolBar( QString name );
Expand Down Expand Up @@ -126,6 +130,11 @@ class QgisAppInterface : public QgisInterface
/** Remove action from the Raster menu */
void removePluginRasterMenu( QString name, QAction* action );

/** Add action to the Vector menu */
void addPluginToVectorMenu( QString name, QAction* action );
/** Remove action from the Raster menu */
void removePluginVectorMenu( QString name, QAction* action );

/** Add "add layer" action to the layer menu */
void insertAddLayerAction( QAction *action );
/** remove "add layer" action from the layer menu */
Expand Down Expand Up @@ -178,6 +187,7 @@ class QgisAppInterface : public QgisInterface
virtual QMenu *settingsMenu();
virtual QMenu *pluginMenu();
virtual QMenu *rasterMenu();
virtual QMenu *vectorMenu();
virtual QMenu *databaseMenu();
virtual QMenu *firstRightStandardMenu();
virtual QMenu *windowMenu();
Expand All @@ -193,6 +203,7 @@ class QgisAppInterface : public QgisInterface
virtual QToolBar *pluginToolBar();
virtual QToolBar *helpToolBar();
virtual QToolBar *rasterToolBar();
virtual QToolBar *vectorToolBar();

//! File menu actions
virtual QAction *actionNewProject();
Expand Down
24 changes: 24 additions & 0 deletions src/gui/qgisinterface.h
Expand Up @@ -125,6 +125,14 @@ class GUI_EXPORT QgisInterface : public QObject
//! @note added in 2.0
virtual void removeRasterToolBarIcon( QAction *qAction ) = 0;

//! Add an icon to the Vector toolbar
//! @note added in 2.0
virtual int addVectorToolBarIcon( QAction *qAction ) = 0;

//! Remove an action (icon) from the Vector toolbar
//! @note added in 2.0
virtual void removeVectorToolBarIcon( QAction *qAction ) = 0;

//! Add toolbar with specified name
virtual QToolBar * addToolBar( QString name ) = 0;

Expand Down Expand Up @@ -173,6 +181,16 @@ class GUI_EXPORT QgisInterface : public QObject
*/
virtual void removePluginRasterMenu( QString name, QAction* action ) = 0;

/** Add action to the Vector menu
* @note added in 2.0
*/
virtual void addPluginToVectorMenu( QString name, QAction* action ) = 0;

/** Remove action from the Vector menu
* @note added in 2.0
*/
virtual void removePluginVectorMenu( QString name, QAction* action ) = 0;

/** Add a dock widget to the main window */
virtual void addDockWidget( Qt::DockWidgetArea area, QDockWidget * dockwidget ) = 0;

Expand Down Expand Up @@ -246,6 +264,9 @@ class GUI_EXPORT QgisInterface : public QObject
/** \note added in 1.7
*/
virtual QMenu *databaseMenu() = 0;
/** \note added in 2.0
*/
virtual QMenu *vectorMenu() = 0;
virtual QMenu *firstRightStandardMenu() = 0;
virtual QMenu *windowMenu() = 0;
virtual QMenu *helpMenu() = 0;
Expand All @@ -262,6 +283,9 @@ class GUI_EXPORT QgisInterface : public QObject
/** \note added in 1.7
*/
virtual QToolBar *rasterToolBar() = 0;
/** \note added in 2.0
*/
virtual QToolBar *vectorToolBar() = 0;

//! File menu actions
virtual QAction *actionNewProject() = 0;
Expand Down

0 comments on commit 2e5aa32

Please sign in to comment.