Skip to content

Commit

Permalink
QgsLayerItem uri/providerKey/mapLayerType better vithout virtual methods
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed May 18, 2011
1 parent b4fde40 commit 0797640
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 32 deletions.
13 changes: 10 additions & 3 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ void QgsDataItem::refresh()

// ---------------------------------------------------------------------

QgsLayerItem::QgsLayerItem(QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType)
: QgsDataItem(Layer, parent, name, path), mUri(uri), mLayerType(layerType)
QgsLayerItem::QgsLayerItem(QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey)
: QgsDataItem(Layer, parent, name, path), mUri(uri), mLayerType(layerType),
mProviderKey(providerKey)
{
if (sIconPoint.isNull())
{
Expand All @@ -218,6 +219,12 @@ QgsLayerItem::QgsLayerItem(QgsDataItem* parent, QString name, QString path, QStr
}
}

QgsMapLayer::LayerType QgsLayerItem::mapLayerType()
{
if ( mLayerType == QgsLayerItem::Raster ) return QgsMapLayer::RasterLayer;
return QgsMapLayer::VectorLayer;
}

bool QgsLayerItem::equal(const QgsDataItem *other)
{
//QgsDebugMsg ( mPath + " x " + other->mPath );
Expand All @@ -227,7 +234,7 @@ bool QgsLayerItem::equal(const QgsDataItem *other)
}
//const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
const QgsLayerItem *o = dynamic_cast<const QgsLayerItem *> ( other );
return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProvider == o->mProvider );
return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProviderKey == o->mProviderKey );
}

// ---------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsdataitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
SetCrs = 1 //Can set CRS on layer or group of layers
};

QgsLayerItem(QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType);
QgsLayerItem(QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey);

// --- reimplemented from QgsDataItem ---

Expand All @@ -149,13 +149,13 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
// --- New virtual methods for layer item derived classes ---

// Returns QgsMapLayer::LayerType
virtual QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::VectorLayer; }
QgsMapLayer::LayerType mapLayerType();

// Returns layer uri or empty string if layer cannot be created
virtual QString uri() { return QString(); }
QString uri() { return mUri; }

// Returns provider key
virtual QString providerKey() { return QString(); }
QString providerKey() { return mProviderKey; }

// This will _write_ selected crs in data source
virtual bool setCrs ( QgsCoordinateReferenceSystem crs ) { return false; }
Expand All @@ -164,7 +164,7 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem

protected:

QString mProvider;
QString mProviderKey;
QString mUri;
LayerType mLayerType;

Expand Down
7 changes: 1 addition & 6 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,19 +1876,14 @@ QGISEXTERN int dataCapabilities () {

QgsGdalLayerItem::QgsGdalLayerItem ( QgsDataItem* parent,
QString name, QString path, QString uri )
: QgsLayerItem ( parent, name, path, uri, QgsLayerItem::Raster )
: QgsLayerItem ( parent, name, path, uri, QgsLayerItem::Raster, "gdal" )
{
}

QgsGdalLayerItem::~QgsGdalLayerItem ()
{
}

QString QgsGdalLayerItem::uri()
{
return mUri;
}

QgsLayerItem::Capability QgsGdalLayerItem::capabilities()
{
// Check if data sour can be opened for update
Expand Down
4 changes: 0 additions & 4 deletions src/providers/gdal/qgsgdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ class QgsGdalLayerItem : public QgsLayerItem
QString name, QString path, QString uri );
~QgsGdalLayerItem ();

QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::RasterLayer; }
QString uri();
QString providerKey() { return "gdal"; }

bool setCrs ( QgsCoordinateReferenceSystem crs );
Capability capabilities();
};
Expand Down
7 changes: 1 addition & 6 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2132,19 +2132,14 @@ QGISEXTERN int dataCapabilities () {

QgsOgrLayerItem::QgsOgrLayerItem ( QgsDataItem* parent,
QString name, QString path, QString uri, LayerType layerType )
: QgsLayerItem ( parent, name, path, uri, layerType )
: QgsLayerItem ( parent, name, path, uri, layerType, "ogr" )
{
}

QgsOgrLayerItem::~QgsOgrLayerItem ()
{
}

QString QgsOgrLayerItem::uri()
{
return mUri;
}

QgsLayerItem::Capability QgsOgrLayerItem::capabilities()
{
QgsDebugMsg( "mPath = " + mPath );
Expand Down
3 changes: 0 additions & 3 deletions src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ class QgsOgrLayerItem : public QgsLayerItem
QgsOgrLayerItem ( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType );
~QgsOgrLayerItem ();

QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::VectorLayer; }
QString uri();
QString providerKey() { return "ogr"; }
bool setCrs ( QgsCoordinateReferenceSystem crs );
Capability capabilities();
};
Expand Down
7 changes: 5 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3104,11 +3104,14 @@ bool QgsWMSConnectionItem::equal(const QgsDataItem *other)
}
// ---------------------------------------------------------------------------
QgsWMSLayerItem::QgsWMSLayerItem ( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
: QgsLayerItem ( parent, name, path, QString(), QgsLayerItem::Raster ),
: QgsLayerItem ( parent, name, path, QString(), QgsLayerItem::Raster, "wms" ),
mCapabilitiesProperty ( capabilitiesProperty ),
mConnInfo ( connInfo ),
mLayerProperty ( layerProperty )
//mProviderKey ("wms"),
//mLayerType ( QgsLayerItem::Raster )
{
mUri = createUri();
// Populate everything, it costs nothing, all info about layers is collected
/*
// TODO
Expand All @@ -3133,7 +3136,7 @@ QgsWMSLayerItem::~QgsWMSLayerItem ()
{
}

QString QgsWMSLayerItem::uri()
QString QgsWMSLayerItem::createUri()
{
QString uri;
if ( mLayerProperty.name.isEmpty() ) return uri; // layer collection
Expand Down
4 changes: 1 addition & 3 deletions src/providers/wms/qgswmsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -990,9 +990,7 @@ class QgsWMSLayerItem : public QgsLayerItem
QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperties );
~QgsWMSLayerItem ();

QgsMapLayer::LayerType mapLayerType() { return QgsMapLayer::RasterLayer; }
QString uri();
QString providerKey() { return "wms"; }
QString createUri();

QgsWmsCapabilitiesProperty mCapabilitiesProperty;
QString mConnInfo;
Expand Down

0 comments on commit 0797640

Please sign in to comment.