mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
plugin api tweaks
git-svn-id: http://svn.osgeo.org/qgis/trunk@208 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
7b77ca7306
commit
0c7305d9fa
@ -22,6 +22,7 @@
|
||||
#include <qstring.h>
|
||||
#include <qwidget.h>
|
||||
#include <qmainwindow.h>
|
||||
#include "../src/qgisapp.h"
|
||||
|
||||
//#include "qgisplugingui.h"
|
||||
|
||||
@ -52,7 +53,7 @@ public:
|
||||
// Typedefs
|
||||
|
||||
//! Typedef for function that returns a generic pointer to a plugin object
|
||||
typedef QgisPlugin* create_t(QMainWindow *);
|
||||
typedef QgisPlugin* create_t(QgisApp *, QgisInterface *);
|
||||
//! Typedef for the function to unload a plugin and free its resources
|
||||
typedef void unload_t(QgisPlugin *);
|
||||
|
||||
|
@ -11,9 +11,12 @@
|
||||
* In addition, a plugin must implement a the classFactory and unload
|
||||
* functions. Note that these functions must be declared as extern "C"
|
||||
*/
|
||||
#include <iostream>
|
||||
#include "../src/qgisapp.h"
|
||||
#include "qgistestplugin.h"
|
||||
#include <qaction.h>
|
||||
QgisTestPlugin::QgisTestPlugin(QWidget *qgis) : qgisMainWindow(qgis){
|
||||
QgisTestPlugin::QgisTestPlugin(QgisApp *qgis, QgisIface *_qI)
|
||||
: qgisMainWindow(qgis), qI(_qI){
|
||||
pName = "Test Plugin";
|
||||
pVersion = "Version 0.0";
|
||||
pDescription = "This test plugin does nothing but tell you its name, version, and description";
|
||||
@ -29,13 +32,29 @@ QgisTestPlugin::QgisTestPlugin(QWidget *qgis) : qgisMainWindow(qgis){
|
||||
QMenuBar *menu = ((QMainWindow *)qgisMainWindow)->menuBar();
|
||||
|
||||
menu->insertItem( "&PluginMenu", pluginMenu );
|
||||
QAction *fileSaveAction = new QAction( "Save File","&Save", CTRL+Key_S, this, "save" );
|
||||
QAction *fileSaveAction = new QAction( "Save File","&Save", CTRL+Key_S, qgisMainWindow, "save" );
|
||||
connect( fileSaveAction, SIGNAL( activated() ) , this, SLOT( save() ) );
|
||||
|
||||
QToolBar * fileTools = new QToolBar( (QMainWindow *)qgisMainWindow, "file operations" );
|
||||
fileTools->setLabel( "File Operations" );
|
||||
fileSaveAction->addTo(fileTools);
|
||||
|
||||
|
||||
//int foo = qgisMainWindow->getInt();
|
||||
/*
|
||||
QgisInterface *qI = qgisMainWindow->getInterface();
|
||||
if(qI)
|
||||
std::cout << "qI pointer is good" << std::endl;
|
||||
else
|
||||
std::cout << "qI pointer is bad" << std::endl;
|
||||
*/
|
||||
//zoomFullX();
|
||||
qI->zoomFull2();
|
||||
// qgisMainWindow->zoomFull();
|
||||
QMessageBox::information(qgisMainWindow,"Message From Plugin", "Click Ok to zoom previous");
|
||||
|
||||
qI->zoomPrevious();
|
||||
|
||||
// std::cout << "Result of getInt is: " << foo << std::endl;
|
||||
|
||||
}
|
||||
QgisTestPlugin::~QgisTestPlugin(){
|
||||
@ -62,10 +81,11 @@ void QgisTestPlugin::newThing(){
|
||||
|
||||
void QgisTestPlugin::save(){
|
||||
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the save toolbar function");
|
||||
qI->zoomPrevious();
|
||||
}
|
||||
|
||||
extern "C" QgisPlugin * classFactory(QWidget *qgis){
|
||||
return new QgisTestPlugin(qgis);
|
||||
extern "C" QgisPlugin * classFactory(QgisApp *qgis, QgisIface *qI){
|
||||
return new QgisTestPlugin(qgis, qI);
|
||||
}
|
||||
|
||||
extern "C" void unload(QgisPlugin *p){
|
||||
|
@ -10,11 +10,13 @@
|
||||
#include "qgisplugin.h"
|
||||
#include "qgistestplugin.h"
|
||||
#include "qgsworkerclass.h"
|
||||
#include "../src/qgisapp.h"
|
||||
|
||||
|
||||
class QgisTestPlugin : public QObject, public QgisPlugin{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgisTestPlugin(QWidget *qgis);
|
||||
QgisTestPlugin(QgisApp *qgis, QgisIface *qI);
|
||||
virtual QString name();
|
||||
virtual QString version();
|
||||
virtual QString description();
|
||||
@ -29,7 +31,8 @@ private:
|
||||
QString pVersion;
|
||||
QString pDescription;
|
||||
|
||||
QWidget *qgisMainWindow;
|
||||
QgisApp *qgisMainWindow;
|
||||
QgisIface *qI;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -170,7 +170,9 @@ QgisApp::QgisApp(QWidget * parent, const char *name, WFlags fl):QgisAppBase(pare
|
||||
popMenu->insertSeparator();
|
||||
popMenu->insertItem("&Remove", this, SLOT(removeLayer()));
|
||||
mapCursor = 0;
|
||||
|
||||
// create the interfce
|
||||
qgisInterface = new QgisIface(this);
|
||||
///qgisInterface->setParent(this);
|
||||
// set the legend control for the map canvas
|
||||
mapCanvas->setLegend(mapLegend);
|
||||
// disable functions based on build type
|
||||
@ -651,7 +653,12 @@ void QgisApp::rightClickLegendMenu(QListViewItem * lvi, const QPoint & pt, int)
|
||||
popMenu->exec(pt);
|
||||
}
|
||||
|
||||
|
||||
QgisInterface * QgisApp::getInterface(){
|
||||
return qgisInterface;
|
||||
}
|
||||
int QgisApp::getInt(){
|
||||
return 99;
|
||||
}
|
||||
void QgisApp::testPluginFunctions()
|
||||
{
|
||||
// try to load plugins from the plugin directory and test each one
|
||||
@ -687,7 +694,7 @@ void QgisApp::testPluginFunctions()
|
||||
|
||||
if (cf) {
|
||||
std::cout << "Getting pointer to a QgisPlugin object from the library\n";
|
||||
QgisPlugin *pl = cf(this);
|
||||
QgisPlugin *pl = cf(this, qgisInterface);
|
||||
std::cout << "Displaying name, version, and description\n";
|
||||
std::cout << "Plugin name: " << pl->name() << std::endl;
|
||||
std::cout << "Plugin version: " << pl->version() << std::endl;
|
||||
|
@ -30,7 +30,7 @@ class QListView;
|
||||
class QListViewItem;
|
||||
class QgsMapLayer;
|
||||
#include "qgisappbase.h"
|
||||
|
||||
#include "qgisiface.h"
|
||||
class QgsMapCanvas;
|
||||
/*! \class QgisApp
|
||||
* \brief Main window for the Qgis application
|
||||
@ -42,6 +42,10 @@ class QgisApp:public QgisAppBase
|
||||
QgisApp(QWidget * parent = 0, const char *name = 0, WFlags fl = WType_TopLevel);
|
||||
|
||||
~QgisApp();
|
||||
private:
|
||||
QgisInterface *getInterface();
|
||||
int getInt();
|
||||
//private:
|
||||
//public slots:
|
||||
//! Add a layer to the map
|
||||
void addLayer();
|
||||
@ -77,7 +81,7 @@ class QgisApp:public QgisAppBase
|
||||
//! About QGis
|
||||
void about();
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
//! Slot to show the map coordinate position of the mouse cursor
|
||||
void showMouseCoordinate(QgsPoint &);
|
||||
//! Show layer properties for the selected layer
|
||||
@ -124,6 +128,8 @@ class QgisApp:public QgisAppBase
|
||||
QString startupPath;
|
||||
//! full path name of the current map file (if it has been saved or loaded)
|
||||
QString fullPath;
|
||||
QgisIface *qgisInterface;
|
||||
friend class QgisIface;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
18
src/qgisiface.cpp
Normal file
18
src/qgisiface.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
#include "qgisinterface.h"
|
||||
#include "qgisapp.h"
|
||||
|
||||
QgisIface::QgisIface(QgisApp *_qgis, const char * name) : qgis(_qgis) {
|
||||
|
||||
|
||||
}
|
||||
QgisIface::~QgisIface(){
|
||||
}
|
||||
|
||||
void QgisIface::zoomFull2(){
|
||||
qgis->zoomFull();
|
||||
}
|
||||
void QgisIface::zoomPrevious(){
|
||||
qgis->zoomPrevious();
|
||||
}
|
||||
|
15
src/qgisiface.h
Normal file
15
src/qgisiface.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef QGISIFACE_H
|
||||
#define QGISIFACE_H
|
||||
#include "qgisinterface.h"
|
||||
class QgisIface : public QgisInterface{
|
||||
public:
|
||||
QgisIface(QgisApp *qgis=0, const char *name=0);
|
||||
~QgisIface();
|
||||
void zoomFull2();
|
||||
void zoomPrevious();
|
||||
private:
|
||||
QgisApp *qgis;
|
||||
};
|
||||
|
||||
|
||||
#endif //#define QGISIFACE_H
|
18
src/qgisinterface.cpp
Normal file
18
src/qgisinterface.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
#include "qgisinterface.h"
|
||||
#include "qgisapp.h"
|
||||
|
||||
QgisInterface::QgisInterface(QgisApp *_qgis, const char * name) : QWidget(_qgis, name){
|
||||
|
||||
|
||||
}
|
||||
QgisInterface::~QgisInterface(){
|
||||
}
|
||||
|
||||
void QgisInterface::zoomFull2(){
|
||||
|
||||
}
|
||||
void QgisInterface::zoomPrevious(){
|
||||
|
||||
}
|
||||
|
25
src/qgisinterface.h
Normal file
25
src/qgisinterface.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef QGISINTERFACE_H
|
||||
#define QGISINTERFACE_H
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
//#include "qgisapp.h"
|
||||
#include <qwidget.h>
|
||||
class QgisApp;
|
||||
|
||||
|
||||
// interface class for plugins
|
||||
class QgisInterface : public QWidget{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgisInterface(QgisApp *qgis=0, const char *name=0);
|
||||
virtual ~QgisInterface();
|
||||
public slots:
|
||||
virtual void zoomFull2()=0;
|
||||
virtual void zoomPrevious()=0;
|
||||
private:
|
||||
//QgisApp *qgis;
|
||||
};
|
||||
|
||||
#endif //#ifndef QGISINTERFACE_H
|
||||
|
@ -25,6 +25,7 @@ CONFIG += qt thread debug
|
||||
LIBS += -L$/usr/local/lib -lgdal.1.1
|
||||
SOURCES += main.cpp \
|
||||
qgisapp.cpp \
|
||||
qgisinterface.cpp \
|
||||
qgsdatasource.cpp \
|
||||
qgsmapcanvas.cpp \
|
||||
qgsmaplayer.cpp \
|
||||
@ -45,8 +46,10 @@ SOURCES += main.cpp \
|
||||
qgsattributetabledisplay.cpp \
|
||||
qgsrenderer.cpp \
|
||||
qgsrenderitem.cpp \
|
||||
qgsprojectio.cpp
|
||||
qgsprojectio.cpp \
|
||||
qgisiface.cpp
|
||||
HEADERS += qgisapp.h \
|
||||
qgisinterface.h \
|
||||
qgisappbase.ui.h \
|
||||
qgsdatasource.h \
|
||||
qgsmapcanvas.h \
|
||||
@ -69,7 +72,8 @@ HEADERS += qgisapp.h \
|
||||
qgsattributetabledisplay.h \
|
||||
qgsrenderer.h \
|
||||
qgsrenderitem.h \
|
||||
qgsprojectio.h
|
||||
qgsprojectio.h \
|
||||
qgisiface.h
|
||||
FORMS += qgisappbase.ui \
|
||||
qgslegenditembase.ui \
|
||||
qgsabout.ui \
|
||||
|
Loading…
x
Reference in New Issue
Block a user