Skip to content
Permalink
Browse files
Fix for ticket #112
Moved the plugin add/remove menu item api and mechanism to Qt4 QActions.
Plugin menu items are now ordered alphabetically

Was unable to test the grass plugin, so that may no work until yet :)


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5450 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed May 14, 2006
1 parent afcb258 commit 2e9bd8ff9b72ea1357a7112165e3ede881e77893
@@ -48,13 +48,13 @@ lib_LTLIBRARIES = libqgis_gui.la

qgis_SOURCES = main.cpp

qgis_LDADD = ../raster/libqgis_raster.la ../legend/libqgis_legend.la ../composer/libqgis_composer.la $(LDADD) $(QT_LDADD) $(GDAL_LDADD) $(PG_LIB) $(GEOS_LDADD) $(PYTHON_LIB) -lproj -lsqlite3 libqgis_gui.la ../core/libqgis_core.la
qgis_LDADD = ../raster/libqgis_raster.la ../legend/libqgis_legend.la ../composer/libqgis_composer.la $(GEOS_LDADD) $(GDAL_LDADD) $(LDADD) $(QT_LDADD) $(PG_LIB) $(PYTHON_LIB) -lproj -lsqlite3 libqgis_gui.la ../core/libqgis_core.la
if HAVE_QTMAC
qgis_LDFLAGS = -framework ApplicationServices
else
qgis_LDFLAGS = -rdynamic
endif
qgis_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(PG_INC) $(DEBUG_QGIS) $(HAVE_PYTHON) $(GEOS_CFLAGS) $(PYTHON_INCLUDE_DIR) -I../ui/ -I../widgets/projectionselector/ -I../legend/ -I../raster/ -I../composer/ -I../core/ -I../plugins/
qgis_CXXFLAGS = $(GEOS_CFLAGS) $(GDAL_CFLAGS) $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(PG_INC) $(DEBUG_QGIS) $(HAVE_PYTHON) $(PYTHON_INCLUDE_DIR) -I../ui/ -I../widgets/projectionselector/ -I../legend/ -I../raster/ -I../composer/ -I../core/ -I../plugins/


##
@@ -294,10 +294,10 @@ nodist_libqgis_gui_la_SOURCES = $(libqgis_gui_la_MOC)
BUILT_SOURCES = $(libqgis_gui_la_MOC) $(qgis_YACC) $(postgresMOC)


libqgis_gui_la_LIBADD = ../core/libqgis_core.la ../raster/libqgis_raster.la ../legend/libqgis_legend.la ../composer/libqgis_composer.la ../widgets/projectionselector/libqgsprojectionselector.la $(QT_LDADD) $(GEOS_LDADD) $(GDAL_LDADD) $(PYTHON_LIB) -lsqlite3
libqgis_gui_la_LIBADD = ../core/libqgis_core.la ../raster/libqgis_raster.la ../legend/libqgis_legend.la ../composer/libqgis_composer.la ../widgets/projectionselector/libqgsprojectionselector.la $(QT_LDADD) $(GEOS_LDADD) $(GDAL_LDADD) $(PYTHON_LIB) -lsqlite3
libqgis_gui_la_LDFLAGS = -version-info $(INTERFACE_VERSION)

libqgis_gui_la_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(PG_INC) $(DEBUG_QGIS) $(GEOS_CFLAGS) $(PYTHON_INCLUDE_DIR) $(HAVE_PYTHON) -I../ui/ -I../widgets/projectionselector/ -I../legend/ -I../raster/ -I../composer/ -I../core/ -I../plugins/
libqgis_gui_la_CXXFLAGS = $(GDAL_CFLAGS) $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(PG_INC) $(DEBUG_QGIS) $(GEOS_CFLAGS) $(PYTHON_INCLUDE_DIR) $(HAVE_PYTHON) -I../ui/ -I../widgets/projectionselector/ -I../legend/ -I../raster/ -I../composer/ -I../core/ -I../plugins/

##
## ----------------------------------------------------------------------
@@ -4388,41 +4388,57 @@ void QgisApp::populateMenuMaps()
}
while(menuId != -1);
}
int QgisApp::addPluginMenu(QString menuText, QMenu *menu)
{
return mPluginMenu->insertItem(menuText, menu);
}

QMenu* QgisApp::getPluginMenu(QString menuName)
{
for (unsigned int i = 0; i < mPluginMenu->count(); ++i)
if (mPluginMenu->text(mPluginMenu->idAt(i)) == menuName)
// This is going to record the menu item that the potentially new
// menu item is going to be inserted before. A value of 0 will a new
// menu item to be appended.
QAction* before = 0;

QList<QAction*> actions = mPluginMenu->actions();
// Avoid 1 because the first item (number 0) is 'Plugin Manager',
// which we want to stay first. Search in reverse order as that
// makes it easier to find out where which item a new menu item
// should go before (since the insertMenu() function requires a
// 'before' argument).
for (unsigned int i = actions.count()-1; i > 0; --i)
{
if (actions.at(i)->text() == menuName)
{
QMenuItem* item = mPluginMenu->findItem(mPluginMenu->idAt(i));
return item->menu();
return actions.at(i)->menu();
}
// Find out where to put the menu item, assuming that it is a new one
//
// This bit of code assumes that the menu items are already in
// alphabetical order, which they will be if the menus are all
// created using this function.
if (QString::localeAwareCompare(menuName, actions.at(i)->text()) <= 0)
before = actions.at(i);
}

// It doesn't exist, so create
QMenu* menu = new QMenu(menuName, this);
// Where to put it? - we worked that out above...
mPluginMenu->insertMenu(before, menu);

// It doesn't exist, so create one
Q3PopupMenu* menu = new Q3PopupMenu(mPluginMenu);
mPluginMenu->insertItem(menuName, menu);
return menu;
}

void QgisApp::removePluginMenuItem(QString name, int menuId)
void QgisApp::addPluginMenu(QString name, QAction* action)
{
// TODO: Qt4 will have to do this a different way...
#if QT_VERSION < 0x040000
for (int i = 0; i < mPluginMenu->count(); ++i)
if (mPluginMenu->text(mPluginMenu->idAt(i)) == name)
QMenu* menu = getPluginMenu(name);
menu->addAction(action);
}

void QgisApp::removePluginMenu(QString name, QAction* action)
{
QMenu* menu = getPluginMenu(name);
menu->removeAction(action);
if (menu->actions().count() == 0)
{
QMenuItem* item = mPluginMenu->findItem(mPluginMenu->idAt(i));
Q3PopupMenu* popup = item->popup();
popup->removeItem(menuId);
if (popup->count() == 0)
mPluginMenu->removeItem(mPluginMenu->idAt(i));
break;
mPluginMenu->removeAction(menu->menuAction());
}
#endif
}

int QgisApp::addPluginToolBarIcon (QAction * qAction)
@@ -198,12 +198,12 @@ public slots:
void showPluginManager();
//! plugin loader
void loadPlugin(QString name, QString description, QString mFullPath);
//! Add a plugin menu to the main Plugins menu
int addPluginMenu(QString menuText, QMenu *menu);
//! Get the menu that holds teh list of loaded plugins
//! Find the QMenu with the given name (ie the user visible text on the menu item)
QMenu* getPluginMenu(QString menuName);
//! Remove an item from the qgis main app menus
void removePluginMenuItem(QString name, int menuId);
//! Add the action to the submenu with the given name under the plugin menu
void addPluginMenu(QString name, QAction* action);
//! Remove the action to the submenu with the given name under the plugin menu
void removePluginMenu(QString name, QAction* action);
//! Add an icon to the plugin toolbar
int addPluginToolBarIcon (QAction * qAction);
//! Remove an icon from the plugin toolbar
@@ -89,14 +89,14 @@ QString QgisIface::activeLayerSource()
return qgis->activeLayerSource();
}

QMenu* QgisIface::getPluginMenu(QString menuName)
void QgisIface::addPluginMenu(QString name, QAction* action)
{
return qgis->getPluginMenu(menuName);
qgis->addPluginMenu(name, action);
}

void QgisIface::removePluginMenuItem(QString name, int menuId)
void QgisIface::removePluginMenu(QString name, QAction* action)
{
qgis->removePluginMenuItem(name, menuId);
qgis->removePluginMenu(name, action);
}

int QgisIface::addToolBarIcon(QAction * qAction)
@@ -63,7 +63,8 @@ class QgisIface : public QgisInterface
//! Get source of the active layer
QString activeLayerSource();

QMenu* getPluginMenu(QString menuName);
void addPluginMenu(QString name, QAction* action);
void removePluginMenu(QString name, QAction* action);

void removePluginMenuItem(QString name, int menuId);

@@ -82,13 +82,8 @@ QgsCopyrightLabelPlugin::~QgsCopyrightLabelPlugin()
*/
void QgsCopyrightLabelPlugin::initGui()
{
QMenu *pluginMenu = qGisInterface->getPluginMenu(tr("&Decorations"));
menuId = pluginMenu->insertItem(QIcon(icon),tr("&CopyrightLabel"), this, SLOT(run()));

pluginMenu->setWhatsThis(menuId, tr("Creates a copyright label that is displayed on the map canvas."));

// Create the action for tool
myQActionPointer = new QAction(QIcon(icon), tr("Copyright Label"), this);
myQActionPointer = new QAction(QIcon(icon), tr("&Copyright Label"), this);
myQActionPointer->setWhatsThis(tr("Creates a copyright label that is displayed on the map canvas."));
// Connect the action to the run
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
@@ -99,6 +94,7 @@ void QgsCopyrightLabelPlugin::initGui()

// Add the icon to the toolbar
qGisInterface->addToolBarIcon(myQActionPointer);
qGisInterface->addPluginMenu(tr("&Decorations"), myQActionPointer);
//initialise default values in the gui
projectRead();
}
@@ -208,7 +204,7 @@ void QgsCopyrightLabelPlugin::renderLabel(QPainter * theQPainter)
void QgsCopyrightLabelPlugin::unload()
{
// remove the GUI
qGisInterface->removePluginMenuItem(tr("&Decorations"),menuId);
qGisInterface->removePluginMenu(tr("&Decorations"),myQActionPointer);
qGisInterface->removeToolBarIcon(myQActionPointer);
// remove the copyright from the canvas
disconnect(qGisInterface->getMapCanvas(), SIGNAL(renderComplete(QPainter *)),
@@ -83,8 +83,6 @@ class QgsCopyrightLabelPlugin:public QObject, public QgisPlugin
bool mEnable;

int pluginType;
//! Id of the plugin's menu. Used for unloading
int menuId;
//! Pionter to QGIS main application object
QgisApp *qgisMainWindowPointer;
//! Pointer to the QGIS interface object
@@ -101,15 +101,8 @@ void QgsDelimitedTextPlugin::help()
*/
void QgsDelimitedTextPlugin::initGui()
{
QMenu *pluginMenu = qGisInterface->getPluginMenu(tr("&Delimited text"));
menuId = pluginMenu->insertItem(QIcon(icon),tr("&Add Delimited Text Layer"), this, SLOT(run()));

pluginMenu->setWhatsThis(menuId, tr("Add a delimited text file as a map layer. ")+
tr("The file must have a header row containing the field names. ")+
tr("X and Y fields are required and must contain coordinates in decimal units."));

// Create the action for tool
myQActionPointer = new QAction(QIcon(icon), tr("Add Delimited Text Layer"), this);
myQActionPointer = new QAction(QIcon(icon), tr("&Add Delimited Text Layer"), this);

myQActionPointer->setWhatsThis(tr("Add a delimited text file as a map layer. ")+
tr("The file must have a header row containing the field names. ")+
@@ -118,6 +111,7 @@ void QgsDelimitedTextPlugin::initGui()
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
// Add the icon to the toolbar
qGisInterface->addToolBarIcon(myQActionPointer);
qGisInterface->addPluginMenu(tr("&Delimited text"), myQActionPointer);

}

@@ -154,7 +148,7 @@ void QgsDelimitedTextPlugin::drawVectorLayer(QString thePathNameQString,
void QgsDelimitedTextPlugin::unload()
{
// remove the GUI
qGisInterface->removePluginMenuItem(tr("&Delimited text"),menuId);
qGisInterface->removePluginMenu(tr("&Delimited text"),myQActionPointer);
qGisInterface->removeToolBarIcon(myQActionPointer);
delete myQActionPointer;
}
@@ -80,8 +80,6 @@ class QgsDelimitedTextPlugin:public QObject, public QgisPlugin, private Ui::QgsD
QString pluginDescriptionQString;
//! Plugin type as defined in Plugin::PLUGINTYPE
int pluginType;
//! Id of the plugin's menu. Used for unloading
int menuId;
//! Pionter to QGIS main application object
QgisApp *qgisMainWindowPointer;
//! Pointer to the QGIS interface object
@@ -72,21 +72,16 @@ QgsPgGeoprocessing::~QgsPgGeoprocessing()
*/
void QgsPgGeoprocessing::initGui()
{
QMenu *pluginMenu = qI->getPluginMenu(tr("&Geoprocessing"));
menuId = pluginMenu->insertItem(QIcon(icon_buffer),tr("&Buffer Features"), this, SLOT(buffer()));

pluginMenu->setWhatsThis(menuId, tr("Create a buffer for a PostgreSQL layer. " +
tr("A new layer is created in the database with the buffered features.")));

// Create the action for tool
bufferAction = new QAction(QIcon(icon_buffer), tr("Buffer features"), this);
bufferAction = new QAction(QIcon(icon_buffer), tr("&Buffer features"), this);
bufferAction->setWhatsThis(tr("Create a buffer for a PostgreSQL layer. " +
tr("A new layer is created in the database with the buffered features.")));
// Connect the action to the buffer slot
connect(bufferAction, SIGNAL(activated()), this, SLOT(buffer()));

// Add the icon to the toolbar
qI->addToolBarIcon(bufferAction);
qI->addPluginMenu(tr("&Geoprocessing"), bufferAction);

}

@@ -416,7 +411,7 @@ bool QgsPgGeoprocessing::hasPROJ(PGconn *connection){
void QgsPgGeoprocessing::unload()
{
// remove the GUI
qI->removePluginMenuItem(tr("&Geoprocessing"),menuId);
qI->removePluginMenu(tr("&Geoprocessing"),bufferAction);
qI->removeToolBarIcon(bufferAction);
delete bufferAction;
}
@@ -73,8 +73,6 @@ class QgsPgGeoprocessing:public QObject, public QgisPlugin
bool gistAvailable;
bool projAvailable;

//! Id of the plugin's menu. Used for unloading
int menuId;
//! Pionter to QGIS main application object
QgisApp *qgisMainWindow;
//! Pointer to the QGIS interface object
@@ -113,12 +113,9 @@ void QgsGeorefPlugin::initGui()
// Connect the action to the run
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));

// add to the plugin menu
QMenu *pluginMenu = mQGisIface->getPluginMenu(tr("&Georeferencer"));
pluginMenu->addAction(mQActionPointer);

// Add to the toolbar
// Add to the toolbar & menu
mQGisIface->addToolBarIcon(mQActionPointer);
mQGisIface->addPluginMenu(tr("&Georeferencer"), mQActionPointer);

}
//method defined in interface
@@ -137,9 +134,8 @@ void QgsGeorefPlugin::run()
// Unload the plugin by cleaning up the GUI
void QgsGeorefPlugin::unload()
{
// TODO: make it work in Qt4 way
// remove the GUI
mQGisIface->removePluginMenuItem(tr("&Georeferencer"),mMenuId);
mQGisIface->removePluginMenu(tr("&Georeferencer"),mQActionPointer);
mQGisIface->removeToolBarIcon(mQActionPointer);
delete mQActionPointer;
}
@@ -103,8 +103,6 @@ public slots:
////////////////////////////////////////////////////////////////////

int mPluginType;
//! Id of the plugin's menu. Used for unloading
int mMenuId;
//! Pointer to our toolbar
Q3ToolBar *mToolBarPointer;
//! Pionter to QGIS main application object
@@ -103,18 +103,18 @@ QgsGPSPlugin::~QgsGPSPlugin()
*/
void QgsGPSPlugin::initGui()
{
QMenu *pluginMenu = mQGisInterface->getPluginMenu(tr("&Gps"));
mMenuIdGPS = pluginMenu->insertItem(QIcon(icon),tr("&Gps Tools"), this, SLOT(run()));
mMenuIdGPX = pluginMenu->insertItem(QIcon(icon),tr("&Create new GPX layer"), this, SLOT(createGPX()));

pluginMenu->setWhatsThis(mMenuIdGPX, tr("Creates a new GPX layer and displays it on the map canvas"));

// add an action to the toolbar
mQActionPointer = new QAction(QIcon(icon), tr("Gps Tools"), this);
mQActionPointer = new QAction(QIcon(icon), tr("&Gps Tools"), this);
mCreateGPXAction = new QAction(QIcon(icon), tr("&Create new GPX layer"), this);

mQActionPointer->setWhatsThis(tr("Creates a new GPX layer and displays it on the map canvas"));
mCreateGPXAction->setWhatsThis(tr("Creates a new GPX layer and displays it on the map canvas"));
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
connect(mCreateGPXAction, SIGNAL(activated()), this, SLOT(createGPX()));

mQGisInterface->addToolBarIcon(mQActionPointer);
mQGisInterface->addPluginMenu(tr("&Gps"), mQActionPointer);
mQGisInterface->addPluginMenu(tr("&Gps"), mCreateGPXAction);
}

//method defined in interface
@@ -202,8 +202,8 @@ void QgsGPSPlugin::drawVectorLayer(QString thePathNameQString,
void QgsGPSPlugin::unload()
{
// remove the GUI
mQGisInterface->removePluginMenuItem(tr("&Gps"),mMenuIdGPS);
mQGisInterface->removePluginMenuItem(tr("&Gps"),mMenuIdGPX);
mQGisInterface->removePluginMenu(tr("&Gps"),mQActionPointer);
mQGisInterface->removePluginMenu(tr("&Gps"),mCreateGPXAction);
mQGisInterface->removeToolBarIcon(mQActionPointer);
delete mQActionPointer;
}
@@ -80,15 +80,14 @@ public slots:
//! Initializes all variables needed to run GPSBabel.
void setupBabel();

//! Id of the plugin's menu. Used for unloading
int mMenuIdGPS, mMenuIdGPX;
//! Pointer to our menu
QgisApp *mMainWindowPointer;
//! Pointer to the QGIS interface object
QgisIface *mQGisInterface;
//! Pointer to the QAction object used in the menu and toolbar
QAction *mQActionPointer;

//! Pointer to the QAction used for creating a new GPX layer
QAction *mCreateGPXAction;
//! The path to the GPSBabel program
QString mBabelPath;
//! Importers for external GPS data file formats

0 comments on commit 2e9bd8f

Please sign in to comment.