added Web menu and toolbar for plugins

This commit is contained in:
Alexander Bruy 2011-12-23 20:17:16 +02:00
parent 42a09af84b
commit 062c160c1a
7 changed files with 209 additions and 0 deletions

View File

@ -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/;
@ -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;
@ -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;
@ -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;

View File

@ -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
@ -1124,6 +1127,7 @@ void QgisApp::createToolBars()
<< mRasterToolBar
<< mVectorToolBar
<< mDatabaseToolBar
<< mWebToolBar
<< mLabelToolBar;
QList<QAction*> toolbarMenuActions;
@ -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 );
@ -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 );
@ -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 );
@ -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() );

View File

@ -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; }
@ -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 );
@ -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
@ -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
@ -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

View File

@ -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 );
@ -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 );
@ -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(); }
@ -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(); }

View File

@ -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 );
@ -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 */
@ -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();
@ -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();

View File

@ -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;
@ -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;
@ -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;
@ -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;

View File

@ -407,6 +407,17 @@
<bool>false</bool>
</attribute>
</widget>
<widget class="QToolBar" name="mWebToolBar">
<property name="windowTitle">
<string>Web</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<action name="mActionNewProject">
<property name="icon">
<iconset resource="../../images/images.qrc">