Index: python/core/qgsmaplayer.sip =================================================================== --- python/core/qgsmaplayer.sip (revision 12832) +++ python/core/qgsmaplayer.sip (working copy) @@ -35,7 +35,8 @@ enum LayerType { VectorLayer, - RasterLayer + RasterLayer, + PluginLayer }; /** Constructor Index: python/core/core.sip =================================================================== --- python/core/core.sip (revision 12832) +++ python/core/core.sip (working copy) @@ -43,6 +43,7 @@ %Include qgsmarkercatalogue.sip %Include qgsmessageoutput.sip %Include qgsoverlayobject.sip +%Include qgspluginlayerregistry.sip %Include qgspoint.sip %Include qgsproject.sip %Include qgsprovidermetadata.sip Index: python/core/qgspluginlayerregistry.sip =================================================================== --- python/core/qgspluginlayerregistry.sip (revision 0) +++ python/core/qgspluginlayerregistry.sip (revision 0) @@ -0,0 +1,43 @@ +/** callback class for creating plugin specific layers */ +class QgsPluginLayerCreator +{ +%TypeHeaderCode +#include "qgspluginlayerregistry.h" +%End + + public: + + QgsPluginLayerCreator(); + virtual ~QgsPluginLayerCreator(); + + /** return new layer if node data corresponds to the parent plugin, else return NULL */ + virtual QgsMapLayer* createLayer(const QDomNode& layerNode); +}; + +/** a registry of callbacks to create plugin layers */ +class QgsPluginLayerRegistry +{ +%TypeHeaderCode +#include "qgspluginlayerregistry.h" +%End + + public: + + /** means of accessing canonical single instance */ + static QgsPluginLayerRegistry* instance(); + + ~QgsPluginLayerRegistry(); + + /** add plugin layer creator and return unique id */ + unsigned int addCreator(QgsPluginLayerCreator* creator); + /** remove plugin layer creator with id */ + void removeCreator(unsigned int id); + + /** return new layer if corresponding plugin has been found, else return NULL */ + QgsMapLayer* createLayer(const QDomNode& layerNode); + + private: + + /** private since instance() creates it */ + QgsPluginLayerRegistry(); +}; Index: src/app/legend/qgslegendlayer.cpp =================================================================== --- src/app/legend/qgslegendlayer.cpp (revision 12832) +++ src/app/legend/qgslegendlayer.cpp (working copy) @@ -165,7 +165,7 @@ else vectorLayerSymbology( vlayer, widthScale ); // get and change symbology } - else // RASTER + else if ( theMapLayer->type() == QgsMapLayer::RasterLayer ) // RASTER { QgsRasterLayer* rlayer = qobject_cast( theMapLayer ); rasterLayerSymbology( rlayer ); // get and change symbology Index: src/core/qgsproject.cpp =================================================================== --- src/core/qgsproject.cpp (revision 12832) +++ src/core/qgsproject.cpp (working copy) @@ -30,6 +30,7 @@ #include "qgslogger.h" #include "qgsprojectfiletransform.h" #include "qgsprojectversion.h" +#include "qgspluginlayerregistry.h" #include #include @@ -695,6 +696,10 @@ { mapLayer = new QgsRasterLayer; } + else + { + mapLayer = QgsPluginLayerRegistry::instance()->createLayer(node); + } Q_CHECK_PTR( mapLayer ); @@ -885,8 +890,7 @@ } else { - QgsDebugMsg( "bad layer type" ); - return false; + mapLayer = QgsPluginLayerRegistry::instance()->createLayer(layerNode); } if ( !mapLayer ) Index: src/core/qgsmaplayer.cpp =================================================================== --- src/core/qgsmaplayer.cpp (revision 12832) +++ src/core/qgsmaplayer.cpp (working copy) @@ -353,6 +353,11 @@ bool QgsMapLayer::isValid() { + if (type() == PluginLayer) + { + return true; + } + return mValid; } Index: src/core/qgspluginlayerregistry.h =================================================================== --- src/core/qgspluginlayerregistry.h (revision 0) +++ src/core/qgspluginlayerregistry.h (revision 0) @@ -0,0 +1,79 @@ +/*************************************************************************** + qgspluginlayerregistry.cpp - class for + registering plugin layer creators + ------------------- + begin : Mon Nov 30 2009 + copyright : (C) 2009 by Mathias Walker, Sourcepole + email : mwa at sourcepole.ch + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 QGSPLUGINLAYERREGSITRY_H +#define QGSPLUGINLAYERREGSITRY_H + +#include + +#include + +class QgsMapLayer; + +/** \ingroup core + callback class for creating plugin specific layers +*/ +class CORE_EXPORT QgsPluginLayerCreator +{ + public: + + QgsPluginLayerCreator(); + virtual ~QgsPluginLayerCreator(); + + /** return new layer if node data corresponds to the parent plugin, else return NULL */ + virtual QgsMapLayer* createLayer(const QDomNode& layerNode); +}; + +//============================================================================= + +/** \ingroup core + a registry of callbacks to create plugin layers +*/ +class CORE_EXPORT QgsPluginLayerRegistry +{ + public: + + /** means of accessing canonical single instance */ + static QgsPluginLayerRegistry* instance(); + + ~QgsPluginLayerRegistry(); + + /** add plugin layer creator and return unique id */ + unsigned int addCreator(QgsPluginLayerCreator* creator); + /** remove plugin layer creator with id */ + void removeCreator(unsigned int id); + + /** return new layer if corresponding plugin has been found, else return NULL */ + QgsMapLayer* createLayer(const QDomNode& layerNode); + + private: + + typedef std::map PluginLayerCreators; + + /** private since instance() creates it */ + QgsPluginLayerRegistry(); + + /** pointer to canonical Singleton object */ + static QgsPluginLayerRegistry* _instance; + + PluginLayerCreators mPluginLayerCreators; + unsigned int mLastId; +}; + +#endif // QGSPLUGINLAYERREGSITRY_H Index: src/core/qgspluginlayerregistry.cpp =================================================================== --- src/core/qgspluginlayerregistry.cpp (revision 0) +++ src/core/qgspluginlayerregistry.cpp (revision 0) @@ -0,0 +1,92 @@ +/*************************************************************************** + qgspluginlayerregistry.cpp - class for + registering plugin layer creators + ------------------- + begin : Mon Nov 30 2009 + copyright : (C) 2009 by Mathias Walker, Sourcepole + email : mwa at sourcepole.ch + ***************************************************************************/ + +/*************************************************************************** + * * + * 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$ */ + +#include "qgspluginlayerregistry.h" +#include "qgslogger.h" +#include "qgsmaplayer.h" + +QgsPluginLayerCreator::QgsPluginLayerCreator() +{ +} + +QgsPluginLayerCreator::~QgsPluginLayerCreator() +{ +} + +QgsMapLayer* QgsPluginLayerCreator::createLayer(const QDomNode& layerNode) +{ + return NULL; +} + +//============================================================================= + +/** Static calls to enforce singleton behaviour */ +QgsPluginLayerRegistry* QgsPluginLayerRegistry::_instance = NULL; +QgsPluginLayerRegistry* QgsPluginLayerRegistry::instance() +{ + if ( _instance == NULL ) + { + _instance = new QgsPluginLayerRegistry(); + } + return _instance; +} + + +QgsPluginLayerRegistry::QgsPluginLayerRegistry() +{ + mLastId = 0; +} + +QgsPluginLayerRegistry::~QgsPluginLayerRegistry() +{ + if ( !mPluginLayerCreators.empty() ) + { + QgsDebugMsg("QgsPluginLayerRegistry::~QgsPluginLayerRegistry(): creator list not empty"); + } +} + +unsigned int QgsPluginLayerRegistry::addCreator(QgsPluginLayerCreator* creator) +{ + mLastId++; + mPluginLayerCreators[mLastId] = creator; + return mLastId; +} + +void QgsPluginLayerRegistry::removeCreator(unsigned int id) +{ + PluginLayerCreators::iterator iter = mPluginLayerCreators.find(id); + if ( iter != mPluginLayerCreators.end() ) + { + mPluginLayerCreators.erase(id); + } +} + +QgsMapLayer* QgsPluginLayerRegistry::createLayer(const QDomNode& layerNode) +{ + QgsMapLayer* layer = NULL; + for ( PluginLayerCreators::iterator iter = mPluginLayerCreators.begin(); iter != mPluginLayerCreators.end(); ++iter ) + { + layer = iter->second->createLayer(layerNode); + if ( layer != NULL ) + { + break; + } + } + return layer; +} Index: src/core/CMakeLists.txt =================================================================== --- src/core/CMakeLists.txt (revision 12832) +++ src/core/CMakeLists.txt (working copy) @@ -60,6 +60,7 @@ qgsoverlayobject.cpp qgspalgeometry.cpp qgspalobjectpositionmanager.cpp + qgspluginlayerregistry.cpp qgspoint.cpp qgsproject.cpp qgsprojectfiletransform.cpp @@ -388,6 +389,7 @@ qgsmessageoutput.h qgsoverlayobjectpositionmanager.h qgspalobjectpositionmanager.h + qgspluginlayerregistry.h qgspoint.h qgsproject.h qgsprojectfiletransform.h Index: src/core/qgsmaplayer.h =================================================================== --- src/core/qgsmaplayer.h (revision 12832) +++ src/core/qgsmaplayer.h (working copy) @@ -48,7 +48,8 @@ enum LayerType { VectorLayer, - RasterLayer + RasterLayer, + PluginLayer }; /** Constructor