Skip to content

Commit

Permalink
QgsLayerItem::layerInfo replaced by mapLayerType, providerKey and uri…
Browse files Browse the repository at this point in the history
… methods
  • Loading branch information
blazek committed May 18, 2011
1 parent 022be6e commit b4fde40
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 44 deletions.
27 changes: 14 additions & 13 deletions src/browser/qgsbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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 );

if ( field == "layers" ) layers = value.split(",");
if ( field == "styles" ) styles = value.split(",");
if ( field == "format" ) format = value;
if ( field == "crs" ) crs = value;
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;
}
QgsDebugMsg ( "rasterLayerPath = " + rasterLayerPath );
QgsDebugMsg ( "layers = " + layers.join(" " ) );
Expand Down
13 changes: 9 additions & 4 deletions src/core/qgsdataitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
public:
enum LayerType
{
NoType,
Vector,
Raster,
Point,
Expand All @@ -147,10 +148,14 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem

// --- 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; }
Expand Down
9 changes: 2 additions & 7 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions src/providers/gdal/qgsgdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
9 changes: 2 additions & 7 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
11 changes: 4 additions & 7 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

// ---------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/providers/wms/qgswmsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b4fde40

Please sign in to comment.