Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added Web menu and toolbar for plugins
  • Loading branch information
alexbruy committed Dec 23, 2011
1 parent 42a09af commit 062c160
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python/gui/qgisinterface.sip
Expand Up @@ -82,6 +82,12 @@ class QgisInterface : QObject
//! Remove an action (icon) from the Database toolbar
//! @note added in 2.0
virtual void removeDatabaseToolBarIcon(QAction *qAction) = 0;
//! Add an icon to the Web toolbar
//! @note added in 2.0
virtual int addWebToolBarIcon(QAction *qAction) =0;
//! Remove an action (icon) from the Web toolbar
//! @note added in 2.0
virtual void removeWebToolBarIcon(QAction *qAction) = 0;

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

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

/** Remove action from the Web menu
* @note added in 2.0
*/
virtual void removePluginWebMenu(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 @@ -209,6 +225,8 @@ class QgisInterface : QObject
virtual QMenu *rasterMenu() = 0;
//** @note added in 2.0
virtual QMenu *vectorMenu() = 0;
//** @note added in 2.0
virtual QMenu *webMenu() = 0;
virtual QMenu *databaseMenu() = 0;
virtual QMenu *firstRightStandardMenu() = 0;
virtual QMenu *windowMenu() = 0;
Expand All @@ -228,6 +246,8 @@ class QgisInterface : QObject
virtual QToolBar *vectorToolBar() = 0;
//** @note added in 2.0
virtual QToolBar *databaseToolBar() = 0;
//** @note added in 2.0
virtual QToolBar *webToolBar() = 0;

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

// Help menu
// add What's this button to it
Expand Down Expand Up @@ -1124,6 +1127,7 @@ void QgisApp::createToolBars()
<< mRasterToolBar
<< mVectorToolBar
<< mDatabaseToolBar
<< mWebToolBar
<< mLabelToolBar;

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

QMenu* QgisApp::getWebMenu( 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 = mWebMenu->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 )
mWebMenu->insertMenu( before, menu );
else
mWebMenu->addMenu( menu );

return menu;
}

void QgisApp::insertAddLayerAction( QAction *action )
{
mLayerMenu->insertAction( mActionAddLayerSeparator, action );
Expand Down Expand Up @@ -5453,6 +5496,34 @@ void QgisApp::addPluginToVectorMenu( QString name, QAction* action )
menuBar()->addMenu( mVectorMenu );
}

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

// add the Vector menu to the menuBar if not added yet
if ( mWebMenu->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() == mWebMenu )
return;
if ( actions.at( i )->menu() == mHelpMenu )
{
before = actions.at( i );
break;
}
}

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

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

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

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

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

int QgisApp::addPluginToolBarIcon( QAction * qAction )
{
mPluginToolBar->addAction( qAction );
Expand Down Expand Up @@ -5563,6 +5658,17 @@ void QgisApp::removeDatabaseToolBarIcon( QAction *qAction )
mDatabaseToolBar->removeAction( qAction );
}

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

void QgisApp::removeWebToolBarIcon( QAction *qAction )
{
mWebToolBar->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 @@ -314,6 +314,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QMenu *databaseMenu() { return mDatabaseMenu; }
QMenu *rasterMenu() { return mRasterMenu; }
QMenu *vectorMenu() { return mVectorMenu; }
QMenu *webMenu() { return mWebMenu; }
#ifdef Q_WS_MAC
QMenu *firstRightStandardMenu() { return mWindowMenu; }
QMenu *windowMenu() { return mWindowMenu; }
Expand Down Expand Up @@ -341,6 +342,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QToolBar *rasterToolBar() { return mRasterToolBar; }
QToolBar *vectorToolBar() { return mVectorToolBar; }
QToolBar *databaseToolBar() { return mDatabaseToolBar; }
QToolBar *webToolBar() { return mWebToolBar; }

//! show layer properties
void showLayerProperties( QgsMapLayer *ml );
Expand Down Expand Up @@ -543,6 +545,12 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
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 );
//! Find the QMenu with the given name within the Web menu (ie the user visible text on the menu item)
QMenu* getWebMenu( QString menuName );
//! Add the action to the submenu with the given name under the Web menu
void addPluginToWebMenu( QString name, QAction* action );
//! Remove the action to the submenu with the given name under the Web menu
void removePluginWebMenu( QString name, QAction* action );
//! Add "add layer" action to layer menu
void insertAddLayerAction( QAction* action );
//! Remove "add layer" action to layer menu
Expand All @@ -563,6 +571,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
int addDatabaseToolBarIcon( QAction * qAction );
//! Remove an icon from the Database toolbar
void removeDatabaseToolBarIcon( QAction *qAction );
//! Add an icon to the Web toolbar
int addWebToolBarIcon( QAction * qAction );
//! Remove an icon from the Web toolbar
void removeWebToolBarIcon( QAction *qAction );
//! Save window state
void saveWindowState();
//! Restore the window and toolbar state
Expand Down Expand Up @@ -1015,6 +1027,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QMenu *mDatabaseMenu;
//! Top level vector menu
QMenu *mVectorMenu;
//! Top level web menu
QMenu *mWebMenu;
//! 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 @@ -184,6 +184,16 @@ void QgisAppInterface::removePluginVectorMenu( QString name, QAction* action )
qgis->removePluginVectorMenu( name, action );
}

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

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

int QgisAppInterface::addToolBarIcon( QAction * qAction )
{
return qgis->addPluginToolBarIcon( qAction );
Expand Down Expand Up @@ -224,6 +234,16 @@ void QgisAppInterface::removeDatabaseToolBarIcon( QAction *qAction )
qgis->removeDatabaseToolBarIcon( qAction );
}

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

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

QToolBar* QgisAppInterface::addToolBar( QString name )
{
return qgis->addToolBar( name );
Expand Down Expand Up @@ -331,6 +351,7 @@ 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::webMenu() { return qgis->webMenu(); }
QMenu *QgisAppInterface::firstRightStandardMenu() { return qgis->firstRightStandardMenu(); }
QMenu *QgisAppInterface::windowMenu() { return qgis->windowMenu(); }
QMenu *QgisAppInterface::helpMenu() { return qgis->helpMenu(); }
Expand All @@ -347,6 +368,7 @@ QToolBar *QgisAppInterface::helpToolBar() { return qgis->helpToolBar(); }
QToolBar *QgisAppInterface::rasterToolBar() { return qgis->rasterToolBar(); }
QToolBar *QgisAppInterface::vectorToolBar() { return qgis->vectorToolBar(); }
QToolBar *QgisAppInterface::databaseToolBar() { return qgis->databaseToolBar(); }
QToolBar *QgisAppInterface::webToolBar() { return qgis->webToolBar(); }

//! File menu actions
QAction *QgisAppInterface::actionNewProject() { return qgis->actionNewProject(); }
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisappinterface.h
Expand Up @@ -94,6 +94,10 @@ class QgisAppInterface : public QgisInterface
int addDatabaseToolBarIcon( QAction *qAction );
//! Remove an icon (action) from the Database toolbar
void removeDatabaseToolBarIcon( QAction *qAction );
//! Add an icon to the Web toolbar
int addWebToolBarIcon( QAction *qAction );
//! Remove an icon (action) from the Web toolbar
void removeWebToolBarIcon( QAction *qAction );

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

/** Add action to the Web menu */
void addPluginToWebMenu( QString name, QAction* action );
/** Remove action from the Web menu */
void removePluginWebMenu( 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 @@ -193,6 +202,7 @@ class QgisAppInterface : public QgisInterface
virtual QMenu *rasterMenu();
virtual QMenu *vectorMenu();
virtual QMenu *databaseMenu();
virtual QMenu *webMenu();
virtual QMenu *firstRightStandardMenu();
virtual QMenu *windowMenu();
virtual QMenu *helpMenu();
Expand All @@ -209,6 +219,7 @@ class QgisAppInterface : public QgisInterface
virtual QToolBar *rasterToolBar();
virtual QToolBar *vectorToolBar();
virtual QToolBar *databaseToolBar();
virtual QToolBar *webToolBar();

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

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

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

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

Expand Down Expand Up @@ -199,6 +207,17 @@ class GUI_EXPORT QgisInterface : public QObject
*/
virtual void removePluginVectorMenu( QString name, QAction* action ) = 0;

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

/** Remove action from the Web menu
* @note added in 2.0
*/
virtual void removePluginWebMenu( 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 @@ -275,6 +294,9 @@ class GUI_EXPORT QgisInterface : public QObject
/** \note added in 2.0
*/
virtual QMenu *vectorMenu() = 0;
/** \note added in 2.0
*/
virtual QMenu *webMenu() = 0;
virtual QMenu *firstRightStandardMenu() = 0;
virtual QMenu *windowMenu() = 0;
virtual QMenu *helpMenu() = 0;
Expand All @@ -297,6 +319,9 @@ class GUI_EXPORT QgisInterface : public QObject
/** \note added in 2.0
*/
virtual QToolBar *databaseToolBar() = 0;
/** \note added in 2.0
*/
virtual QToolBar *webToolBar() = 0;

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

0 comments on commit 062c160

Please sign in to comment.