From b4fde40163f853380befdf3bc8646f4388578fd9 Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Wed, 18 May 2011 09:36:40 +0200 Subject: [PATCH] QgsLayerItem::layerInfo replaced by mapLayerType, providerKey and uri methods --- src/browser/qgsbrowser.cpp | 25 +++++++++++++------------ src/core/qgsdataitem.h | 13 +++++++++---- src/providers/gdal/qgsgdalprovider.cpp | 9 ++------- src/providers/gdal/qgsgdalprovider.h | 6 ++++-- src/providers/ogr/qgsogrprovider.cpp | 9 ++------- src/providers/ogr/qgsogrprovider.h | 5 +++-- src/providers/wms/qgswmsprovider.cpp | 11 ++++------- src/providers/wms/qgswmsprovider.h | 5 +++-- 8 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/browser/qgsbrowser.cpp b/src/browser/qgsbrowser.cpp index 6b5c8b36353..39b2554905c 100644 --- a/src/browser/qgsbrowser.cpp +++ b/src/browser/qgsbrowser.cpp @@ -193,11 +193,12 @@ bool QgsBrowser::layerClicked(QgsLayerItem* ptr) { mActionSetProjection->setEnabled ( ptr->capabilities() & QgsLayerItem::SetCrs ); - QgsMapLayer::LayerType type; - QString providerKey; - QString uri; - if ( ptr->layerInfo(type, providerKey, uri) ) + QString uri = ptr->uri(); + if ( !uri.isEmpty() ) { + QgsMapLayer::LayerType type = ptr->mapLayerType(); + QString providerKey = ptr->providerKey(); + QgsDebugMsg ( providerKey + " : " + uri ); if ( type == QgsMapLayer::VectorLayer ) { @@ -214,15 +215,15 @@ bool QgsBrowser::layerClicked(QgsLayerItem* ptr) QString crs; for ( int i = 1 ; i < URIParts.size(); i++ ) { - QString part = URIParts.at( i ); - int pos = part.indexOf( "=" ); - QString field = part.left( pos ); - QString value = part.mid( pos + 1 ); + QString part = URIParts.at( i ); + int pos = part.indexOf( "=" ); + QString field = part.left( pos ); + QString value = part.mid( pos + 1 ); - if ( field == "layers" ) layers = value.split(","); - if ( field == "styles" ) styles = value.split(","); - if ( field == "format" ) format = value; - if ( field == "crs" ) crs = value; + if ( field == "layers" ) layers = value.split(","); + if ( field == "styles" ) styles = value.split(","); + if ( field == "format" ) format = value; + if ( field == "crs" ) crs = value; } QgsDebugMsg ( "rasterLayerPath = " + rasterLayerPath ); QgsDebugMsg ( "layers = " + layers.join(" " ) ); diff --git a/src/core/qgsdataitem.h b/src/core/qgsdataitem.h index ac679498185..42c91c26b72 100644 --- a/src/core/qgsdataitem.h +++ b/src/core/qgsdataitem.h @@ -123,6 +123,7 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem public: enum LayerType { + NoType, Vector, Raster, Point, @@ -147,10 +148,14 @@ public: // --- New virtual methods for layer item derived classes --- - // Sets info about layer which can be created for this item - // returns true if layer can be created - virtual bool layerInfo ( QgsMapLayer::LayerType & type, - QString & providerKey, QString & uri ) { return false; } + // Returns QgsMapLayer::LayerType + virtual QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::VectorLayer; } + + // Returns layer uri or empty string if layer cannot be created + virtual QString uri() { return QString(); } + + // Returns provider key + virtual QString providerKey() { return QString(); } // This will _write_ selected crs in data source virtual bool setCrs ( QgsCoordinateReferenceSystem crs ) { return false; } diff --git a/src/providers/gdal/qgsgdalprovider.cpp b/src/providers/gdal/qgsgdalprovider.cpp index 0d4327e55cd..3e4ffe29473 100644 --- a/src/providers/gdal/qgsgdalprovider.cpp +++ b/src/providers/gdal/qgsgdalprovider.cpp @@ -1884,14 +1884,9 @@ QgsGdalLayerItem::~QgsGdalLayerItem () { } -bool QgsGdalLayerItem::layerInfo(QgsMapLayer::LayerType & type, - QString & providerKey, QString & uri ) +QString QgsGdalLayerItem::uri() { - QgsDebugMsg ( "Entered" ); - type = QgsMapLayer::RasterLayer; - providerKey = "gdal"; - uri = mUri; - return true; + return mUri; } QgsLayerItem::Capability QgsGdalLayerItem::capabilities() diff --git a/src/providers/gdal/qgsgdalprovider.h b/src/providers/gdal/qgsgdalprovider.h index 393ccb75298..2519f59563c 100644 --- a/src/providers/gdal/qgsgdalprovider.h +++ b/src/providers/gdal/qgsgdalprovider.h @@ -293,8 +293,10 @@ class QgsGdalLayerItem : public QgsLayerItem QString name, QString path, QString uri ); ~QgsGdalLayerItem (); - bool layerInfo ( QgsMapLayer::LayerType & type, - QString & providerKey, QString & uri ); + QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::RasterLayer; } + QString uri(); + QString providerKey() { return "gdal"; } + bool setCrs ( QgsCoordinateReferenceSystem crs ); Capability capabilities(); }; diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index fe9bbc0a907..156e401b2c4 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -2140,14 +2140,9 @@ QgsOgrLayerItem::~QgsOgrLayerItem () { } -bool QgsOgrLayerItem::layerInfo ( QgsMapLayer::LayerType & type, - QString & providerKey, QString & uri ) +QString QgsOgrLayerItem::uri() { - QgsDebugMsg ( "Entered" ); - type = QgsMapLayer::VectorLayer; - providerKey = "ogr"; - uri = mUri; - return true; + return mUri; } QgsLayerItem::Capability QgsOgrLayerItem::capabilities() diff --git a/src/providers/ogr/qgsogrprovider.h b/src/providers/ogr/qgsogrprovider.h index 75cfbfa0a31..f1f1da438f0 100644 --- a/src/providers/ogr/qgsogrprovider.h +++ b/src/providers/ogr/qgsogrprovider.h @@ -312,8 +312,9 @@ class QgsOgrLayerItem : public QgsLayerItem QgsOgrLayerItem ( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType ); ~QgsOgrLayerItem (); - bool layerInfo ( QgsMapLayer::LayerType & type, - QString & providerKey, QString & uri ); + QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::VectorLayer; } + QString uri(); + QString providerKey() { return "ogr"; } bool setCrs ( QgsCoordinateReferenceSystem crs ); Capability capabilities(); }; diff --git a/src/providers/wms/qgswmsprovider.cpp b/src/providers/wms/qgswmsprovider.cpp index 5b708032920..7beb571276f 100644 --- a/src/providers/wms/qgswmsprovider.cpp +++ b/src/providers/wms/qgswmsprovider.cpp @@ -3133,13 +3133,10 @@ QgsWMSLayerItem::~QgsWMSLayerItem () { } -bool QgsWMSLayerItem::layerInfo(QgsMapLayer::LayerType & type, - QString & providerKey, QString & uri ) +QString QgsWMSLayerItem::uri() { - if ( mLayerProperty.name.isEmpty() ) return false; // layer collection - - type = QgsMapLayer::RasterLayer; - providerKey = "wms"; + QString uri; + if ( mLayerProperty.name.isEmpty() ) return uri; // layer collection QString rasterLayerPath = mConnInfo; QString baseName = mLayerProperty.name; @@ -3186,7 +3183,7 @@ bool QgsWMSLayerItem::layerInfo(QgsMapLayer::LayerType & type, } uri = rasterLayerPath + "|layers=" + layers.join(",") + "|styles=" + styles.join(",") + "|format=" + format + "|crs=" + crs; - return true; + return uri; } // --------------------------------------------------------------------------- diff --git a/src/providers/wms/qgswmsprovider.h b/src/providers/wms/qgswmsprovider.h index f87a03d3163..11cbc6569a4 100644 --- a/src/providers/wms/qgswmsprovider.h +++ b/src/providers/wms/qgswmsprovider.h @@ -990,8 +990,9 @@ class QgsWMSLayerItem : public QgsLayerItem QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperties ); ~QgsWMSLayerItem (); - bool layerInfo ( QgsMapLayer::LayerType & type, - QString & providerKey, QString & uri ); + QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::RasterLayer; } + QString uri(); + QString providerKey() { return "wms"; } QgsWmsCapabilitiesProperty mCapabilitiesProperty; QString mConnInfo;