2002-10-13 21:35:17 +00:00
|
|
|
/* Test plugin for QGis
|
|
|
|
* This code is a test plugin for QGis and a demonstration of the API
|
|
|
|
* All QGis plugins must inherit from the abstract base class QgisPlugin. A
|
|
|
|
* plugin must implement the virtual functions defined in QgisPlugin:
|
2003-03-09 15:44:11 +00:00
|
|
|
* *name
|
|
|
|
* *version
|
|
|
|
* *description
|
2002-10-13 21:35:17 +00:00
|
|
|
*
|
2003-03-09 15:44:11 +00:00
|
|
|
* This list may grow as the API is expanded.
|
2002-10-13 21:35:17 +00:00
|
|
|
*
|
|
|
|
* In addition, a plugin must implement a the classFactory and unload
|
|
|
|
* functions. Note that these functions must be declared as extern "C"
|
|
|
|
*/
|
2003-03-09 15:44:11 +00:00
|
|
|
#include "qgistestplugin.h"
|
|
|
|
#include <qaction.h>
|
|
|
|
QgisTestPlugin::QgisTestPlugin(QWidget *qgis) : qgisMainWindow(qgis){
|
|
|
|
pName = "Test Plugin";
|
|
|
|
pVersion = "Version 0.0";
|
|
|
|
pDescription = "This test plugin does nothing but tell you its name, version, and description";
|
2002-10-13 21:35:17 +00:00
|
|
|
|
2003-03-09 15:44:11 +00:00
|
|
|
// see if we can popup a message box in qgis on load
|
|
|
|
QMessageBox::information(qgisMainWindow,"Message From Plugin", "This message is from within the test plugin");
|
|
|
|
// add a test menu
|
|
|
|
QPopupMenu *pluginMenu = new QPopupMenu( qgisMainWindow );
|
2003-01-25 00:20:20 +00:00
|
|
|
|
2003-03-09 15:44:11 +00:00
|
|
|
pluginMenu->insertItem("&Open", this, SLOT(open()));
|
|
|
|
pluginMenu->insertItem( "&New" , this, SLOT(newThing()));
|
|
|
|
// a test toolbar
|
|
|
|
QMenuBar *menu = ((QMainWindow *)qgisMainWindow)->menuBar();
|
2002-10-13 21:35:17 +00:00
|
|
|
|
2003-03-09 15:44:11 +00:00
|
|
|
menu->insertItem( "&PluginMenu", pluginMenu );
|
|
|
|
QAction *fileSaveAction = new QAction( "Save File","&Save", CTRL+Key_S, this, "save" );
|
|
|
|
connect( fileSaveAction, SIGNAL( activated() ) , this, SLOT( save() ) );
|
|
|
|
|
|
|
|
QToolBar * fileTools = new QToolBar( (QMainWindow *)qgisMainWindow, "file operations" );
|
|
|
|
fileTools->setLabel( "File Operations" );
|
|
|
|
fileSaveAction->addTo(fileTools);
|
|
|
|
|
2002-10-13 21:35:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
QgisTestPlugin::~QgisTestPlugin(){
|
|
|
|
|
|
|
|
}
|
2002-10-14 15:43:42 +00:00
|
|
|
QString QgisTestPlugin::name(){
|
|
|
|
return pName;
|
2002-10-13 21:35:17 +00:00
|
|
|
}
|
2002-10-14 15:43:42 +00:00
|
|
|
QString QgisTestPlugin::version(){
|
|
|
|
return pVersion;
|
2002-10-13 21:35:17 +00:00
|
|
|
|
|
|
|
}
|
2002-10-14 15:43:42 +00:00
|
|
|
QString QgisTestPlugin::description(){
|
|
|
|
return pDescription;
|
2002-10-13 21:35:17 +00:00
|
|
|
|
|
|
|
}
|
2003-03-09 15:44:11 +00:00
|
|
|
|
|
|
|
void QgisTestPlugin::open(){
|
|
|
|
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the open menu");
|
|
|
|
}
|
|
|
|
void QgisTestPlugin::newThing(){
|
|
|
|
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the new menu");
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgisTestPlugin::save(){
|
|
|
|
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the save toolbar function");
|
2002-10-14 16:03:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-09 15:44:11 +00:00
|
|
|
extern "C" QgisPlugin * classFactory(QWidget *qgis){
|
|
|
|
return new QgisTestPlugin(qgis);
|
2002-10-13 21:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void unload(QgisPlugin *p){
|
|
|
|
delete p;
|
|
|
|
}
|