maplayer plugin support

git-svn-id: http://svn.osgeo.org/qgis/trunk@237 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2003-07-11 06:01:28 +00:00
parent 3d39959194
commit 9b45300705
8 changed files with 161 additions and 9 deletions

View File

@ -6,7 +6,7 @@
email : sherman at mrcc.com
Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12
***************************************************************************/
/* $Id$ */
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
@ -67,14 +67,19 @@
#include "qgslayerproperties.h"
#include "qgsabout.h"
#include "qgspluginmanager.h"
#include "qgsmaplayerinterface.h"
#include "qgis.h"
#include "qgisapp.h"
#include "qgspluginitem.h"
#include "../plugins/qgisplugin.h"
#include "xpm/qgis.xpm"
#include <ogrsf_frmts.h>
typedef QgsMapLayerInterface* create_it();
typedef QString name_t();
typedef QString description_t();
// version
static const char *qgisVersion = "0.0.11 - June 10, 2003";
static const char *qgisVersion = "0.0.12 pre 1 - July 4, 2003";
static const int qgisVersionInt = 11;
// cursors
static unsigned char zoom_in_bits[] = {
@ -675,13 +680,96 @@ void QgisApp::actionPluginManager_activated(){
QgsPluginManager *pm = new QgsPluginManager(this);
if(pm->exec()){
// load selected plugins
std::vector<QgsPluginItem> pi = pm->getSelectedPlugins();
std::vector<QgsPluginItem>::iterator it = pi.begin();
while(it != pi.end()){
QgsPluginItem plugin = *it;
loadPlugin(plugin.name(), plugin.description(), plugin.fullPath());
it++;
}
}
}
void QgisApp::loadPlugin(QString name, QString description, QString fullPath){
QLibrary *myLib = new QLibrary(fullPath);
std::cout << "Library name is " << myLib->library() << std::endl;
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_it *cf = (create_it *) myLib->resolve("classFactory");
if (cf) {
std::cout << "Getting pointer to a MapLayerInterface object from the library\n";
QgsMapLayerInterface *pl = cf();
if(pl){
std::cout << "Instantiated the maplayer test plugin\n";
// set the main window pointer for the plugin
pl->setQgisMainWindow(this);
std::cout << "getInt returned " << pl->getInt() << " from map layer plugin\n";
// set up the gui
pl->initGui();
}else{
std::cout << "Unable to instantiate the maplayer test plugin\n";
}
}
}else{
std::cout << "Failed to load " << fullPath << "\n";
}
}
void QgisApp::testMapLayerPlugins(){
// map layer plugins live in their own directory (somewhere to be determined)
QDir mlpDir("../plugins/maplayer", "*.so.1.0.0", QDir::Name | QDir::IgnoreCase, QDir::Files );
if(mlpDir.count() == 0){
QMessageBox::information(this,"No MapLayer Plugins", "No MapLayer plugins in ../plugins/maplayer");
}else{
for(unsigned i = 0; i < mlpDir.count(); i++){
std::cout << "Getting information for plugin: " << mlpDir[i] << std::endl;
std::cout << "Attempting to load the plugin using dlopen\n";
void *handle = dlopen("../plugins/maplayer/" + mlpDir[i], RTLD_LAZY);
if (!handle) {
std::cout << "Error in dlopen: " << dlerror() << std::endl;
}else{
std::cout << "dlopen suceeded" << std::endl;
dlclose(handle);
}
QLibrary *myLib = new QLibrary("../plugins/maplayer/" + mlpDir[i]);
std::cout << "Library name is " << myLib->library() << std::endl;
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_it *cf = (create_it *) myLib->resolve("classFactory");
if (cf) {
std::cout << "Getting pointer to a MapLayerInterface object from the library\n";
QgsMapLayerInterface *pl = cf();
if(pl){
std::cout << "Instantiated the maplayer test plugin\n";
// set the main window pointer for the plugin
pl->setQgisMainWindow(this);
std::cout << "getInt returned " << pl->getInt() << " from map layer plugin\n";
// set up the gui
pl->initGui();
}else{
std::cout << "Unable to instantiate the maplayer test plugin\n";
}
}
}else{
std::cout << "Failed to load " << mlpDir[i] << "\n";
}
}
}
}
void QgisApp::testPluginFunctions()
{
// test maplayer plugins first
testMapLayerPlugins();
if(false){
// try to load plugins from the plugin directory and test each one
QDir pluginDir("../plugins", "*.so*", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
@ -746,6 +834,7 @@ void QgisApp::testPluginFunctions()
}
}
}
}
}
void QgisApp::saveWindowState()

View File

@ -98,8 +98,12 @@ class QgisApp:public QgisAppBase
void zoomToLayerExtent();
//! test plugin functionality
void testPluginFunctions();
//! test maplayer plugins
void testMapLayerPlugins();
//! plugin manager
void actionPluginManager_activated();
//! plugin loader
void loadPlugin(QString name, QString description, QString fullPath);
//! Save window state
void saveWindowState();
//! Restore the window and toolbar state

View File

@ -0,0 +1,34 @@
/***************************************************************************
begin : Jul 10 2003
copyright : (C) 2003 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#ifndef QGSMAPLAYERINTERFACE_H
#define QGSMAPLAYERINTERFACE_H
/**
* Interface class for map layer plugins
*/
#include <qobject.h>
#include "qgisapp.h"
class QgsMapLayerInterface: public QObject{
Q_OBJECT
public:
virtual void setQgisMainWindow(QMainWindow *qgis) = 0;
// a test function to return an int
virtual int getInt()=0;
// setup the plugin's GUI
virtual void initGui()=0;
virtual void unload()=0;
};
#endif // QGSMAPLAYERINTERFACE_H

View File

@ -10,16 +10,26 @@
// Copyright: See COPYING file that comes with this distribution
//
//
/* $Id$ */
#include <qstring.h>
#include "qgspluginitem.h"
QgsPluginItem::QgsPluginItem(QString _name, QString _description, QString _fullPath) :
name(_name), description(_description), fullPath(_fullPath)
m_name(_name), m_description(_description), m_fullPath(_fullPath)
{
}
QString QgsPluginItem::name(){
return m_name;
}
QString QgsPluginItem::description(){
return m_description;
}
QString QgsPluginItem::fullPath(){
return m_fullPath;
}
QgsPluginItem::~QgsPluginItem()
{
}

View File

@ -10,6 +10,7 @@
// Copyright: See COPYING file that comes with this distribution
//
//
/* $Id$ */
#ifndef QGSPLUGINITEM_H
#define QGSPLUGINITEM_H
class QString;
@ -21,12 +22,14 @@ Class to contain information about a loadable plugin, including its name, descri
class QgsPluginItem{
public:
QgsPluginItem(QString name=0, QString description=0, QString fullPath=0);
QString name();
QString description();
QString fullPath();
~QgsPluginItem();
private:
QString name;
QString description;
QString fullPath;
QString m_name;
QString m_description;
QString m_fullPath;
};

View File

@ -10,6 +10,7 @@
// Copyright: See COPYING file that comes with this distribution
//
//
/* $Id$ */
#include <qfiledialog.h>
#include <qlineedit.h>
#include <qlistview.h>
@ -60,4 +61,14 @@ QDir pluginDir(txtPluginDir->text(), "*.so*", QDir::Name | QDir::IgnoreCase, QDi
}
}
std::vector<QgsPluginItem> QgsPluginManager::getSelectedPlugins(){
std::vector<QgsPluginItem> pis;
QCheckListItem *lvi = (QCheckListItem *)lstPlugins->firstChild();
while(lvi != 0){
if(lvi->isOn()){
pis.push_back(QgsPluginItem(lvi->text(0), lvi->text(1), txtPluginDir->text() + "/" + lvi->text(2)));
}
lvi = (QCheckListItem *)lvi->nextSibling();
}
return pis;
}

View File

@ -5,7 +5,7 @@
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/* $Id$ */
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *

View File

@ -58,7 +58,8 @@ HEADERS += qgisapp.h \
qgsprojectio.h \
qgisiface.h \
qgspluginmanager.h \
qgspluginitem.h
qgspluginitem.h \
qgsmaplayerinterface.h
FORMS += qgisappbase.ui \
qgslegenditembase.ui \
qgsabout.ui \