maintenance fixes

git-svn-id: http://svn.osgeo.org/qgis/trunk@201 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2003-03-09 15:44:11 +00:00
parent 50602c9628
commit 917c05f525
7 changed files with 107 additions and 65 deletions

View File

@ -1,11 +1,13 @@
TEMPLATE = lib
CONFIG += qt thread debug
SOURCES = qgistestplugin.cpp \
qgisplugingui.cpp
HEADERS = qgisplugin.h \
qgisplugingui.h \
qgispluginmenu.h \
qgispluginguielement.h \
qgisplugintoolbar.h
# File generated by kdevelop's qmake manager.
# -------------------------------------------
# Subdir relative project main directory: ./plugins
# Target is a library:
TEMPLATE = lib
CONFIG += debug \
warn_on \
qt \
thread
SOURCES += qgistestplugin.cpp
HEADERS += qgisplugin.h \
qgistestplugin.h

View File

@ -7,7 +7,6 @@
* <ul>name
* <li>version
* <li>description
* <li>gui
* </ul>
*
* All QGis plugins must inherit from the abstract base class QgisPlugin. A
@ -21,14 +20,16 @@
#ifndef qgisplugin_h
#define qgisplugin_h
#include <qstring.h>
#include <qwidget.h>
#include <qmainwindow.h>
#include "qgisplugingui.h"
//#include "qgisplugingui.h"
/*! \class QgisPlugin
* \brief Abstract base class from which all plugins must inherit
*
*/
class QgisPlugin{
class QgisPlugin {
public:
//! Get the name of the plugin
virtual QString name() = 0;
@ -37,7 +38,7 @@ public:
//! A brief description of the plugin
virtual QString description() = 0;
//! Interface to gui element collection object
virtual QgisPluginGui *gui()=0;
//virtual QgisPluginGui *gui()=0;
//! Element types that can be added to the interface
/* enum ELEMENTS {
MENU,
@ -51,7 +52,7 @@ public:
// Typedefs
//! Typedef for function that returns a generic pointer to a plugin object
typedef QgisPlugin* create_t();
typedef QgisPlugin* create_t(QMainWindow *);
//! Typedef for the function to unload a plugin and free its resources
typedef void unload_t(QgisPlugin *);

View File

@ -19,7 +19,7 @@ public:
virtual ~QgisPluginMenu();
private:
//! Map to define slot called when a menu item is activated
std::map<QString menuItemName, QString menuItemSlot> itemSlots;
std::map<QString menuItemName, QString menuItemSlot> itemSlots;
};
#endif QGISPLUGINMENU_H

View File

@ -2,43 +2,41 @@
* 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:
* *pluginName
* *pluginVersion
* *pluginDescription
* *name
* *version
* *description
*
* This list will grow as the API is expanded.
* This list may grow as the API is expanded.
*
* In addition, a plugin must implement a the classFactory and unload
* functions. Note that these functions must be declared as extern "C"
*/
#ifndef qgisplugintest_h
#define qgisplugintest_h
#include "qgisplugin.h"
#include "qgisplugingui.h"
class QgisTestPlugin : public QgisPlugin{
public:
QgisTestPlugin();
virtual QString name();
virtual QString version();
virtual QString description();
virtual QgisPluginGui *gui();
virtual ~QgisTestPlugin();
private:
QString pName;
QString pVersion;
QString pDescription;
QgisPluginGui *guiCollection;
};
#endif
QgisTestPlugin::QgisTestPlugin(){
#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";
guiCollection = new QgisPluginGui();
// 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 );
pluginMenu->insertItem("&Open", this, SLOT(open()));
pluginMenu->insertItem( "&New" , this, SLOT(newThing()));
// a test toolbar
QMenuBar *menu = ((QMainWindow *)qgisMainWindow)->menuBar();
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);
}
QgisTestPlugin::~QgisTestPlugin(){
@ -54,13 +52,20 @@ QString QgisTestPlugin::description(){
return pDescription;
}
QgisPluginGui *QgisTestPlugin::gui(){
// stub
return (0);
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");
}
extern "C" QgisPlugin * classFactory(){
return new QgisTestPlugin();
void QgisTestPlugin::save(){
QMessageBox::information(qgisMainWindow, "Message from plugin", "You chose the save toolbar function");
}
extern "C" QgisPlugin * classFactory(QWidget *qgis){
return new QgisTestPlugin(qgis);
}
extern "C" void unload(QgisPlugin *p){

View File

@ -1,18 +1,35 @@
#ifndef qgisplugintest_h
#define qgisplugintest_h
#include "qgisplugin.h"
#include <qwidget.h>
#include <qmainwindow.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include "qgisplugin.h"
#include "qgistestplugin.h"
#include "qgsworkerclass.h"
class QgisTestPlugin : public QgisPlugin{
class QgisTestPlugin : public QObject, public QgisPlugin{
Q_OBJECT
public:
QgisTestPlugin();
/* virtual QString pluginName();
virtual QString pluginVersion();
virtual QString pluginDescription(); */
QgisTestPlugin(QWidget *qgis);
virtual QString name();
virtual QString version();
virtual QString description();
virtual ~QgisTestPlugin();
public slots:
void open();
void newThing();
void save();
private:
QString name;
QString version;
QString description;
QString pName;
QString pVersion;
QString pDescription;
QWidget *qgisMainWindow;
};
#endif

View File

@ -15,6 +15,8 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include <dlfcn.h>
#include <qapplication.h>
#include <qaction.h>
#include <qmenubar.h>
@ -663,16 +665,29 @@ void QgisApp::testPluginFunctions()
for(unsigned i = 0; i < pluginDir.count(); i++){
std::cout << "Getting information for plugin: " << pluginDir[i] << std::endl;
QLibrary myLib("../plugins/" + pluginDir[i]);
bool loaded = myLib.load();
QLibrary *myLib = new QLibrary("../plugins/" + pluginDir[i]);//"/home/gsherman/development/qgis/plugins/" + pluginDir[i]);
std::cout << "Library name is " << myLib->library() << std::endl;
//QLibrary myLib("../plugins/" + pluginDir[i]);
std::cout << "Attempting to load " << + "../plugins/" + pluginDir[i] << std::endl;
/* void *handle = dlopen("/home/gsherman/development/qgis/plugins/" + pluginDir[i], RTLD_LAZY);
if (!handle) {
std::cout << "Error in dlopen: " << dlerror() << std::endl;
}else{
std::cout << "dlopen suceeded" << std::endl;
dlclose(handle);
}
*/
bool loaded = myLib->load();
if (loaded) {
std::cout << "Loaded test plugin library" << std::endl;
std::cout << "Attempting to resolve the classFactory function" << std::endl;
create_t *cf = (create_t *) myLib.resolve("classFactory");
create_t *cf = (create_t *) myLib->resolve("classFactory");
if (cf) {
std::cout << "Getting pointer to a QgisPlugin object from the library\n";
QgisPlugin *pl = cf();
QgisPlugin *pl = cf(this);
std::cout << "Displaying name, version, and description\n";
std::cout << "Plugin name: " << pl->name() << std::endl;
std::cout << "Plugin version: " << pl->version() << std::endl;
@ -681,6 +696,7 @@ void QgisApp::testPluginFunctions()
+ pl->name() + "\nVersion: " + pl->version() + "\nDescription: " + pl->description());
// unload the plugin (delete it)
std::cout << "Attempting to resolve the unload function" << std::endl;
/*
unload_t *ul = (unload_t *) myLib.resolve("unload");
if (ul) {
ul(pl);
@ -688,10 +704,11 @@ void QgisApp::testPluginFunctions()
} else {
std::cout << "Unable to resolve unload function. Plugin was not unloaded\n";
}
*/
}
} else {
QMessageBox::warning(this, "Unable to Load Plugin",
"QGis was unable to load the plugin from: ../plugins/libqgisplugin.so.1.0.0");
"QGis was unable to load the plugin from: ../plugins/" + pluginDir[i]);
std::cout << "Unable to load library" << std::endl;
}
}

View File

@ -22,7 +22,7 @@ exists ( $(PGSQL)/bin/psql ) {
}
CONFIG += qt thread debug
LIBS += -L$/usr/local/lib -lgdal
LIBS += -L$/usr/local/lib -lgdal.1.1
SOURCES += main.cpp \
qgisapp.cpp \
qgsdatasource.cpp \