Skip to content
Permalink
Browse files

QgsLayerItem uri/providerKey/mapLayerType better vithout virtual methods

  • Loading branch information
blazek committed May 18, 2011
1 parent b4fde40 commit 079764059583f3a1c7f1f9b22c880128d6fc8d97
@@ -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())
{
@@ -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 );
@@ -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 );
}

// ---------------------------------------------------------------------
@@ -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 ---

@@ -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; }
@@ -164,7 +164,7 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem

protected:

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

@@ -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
@@ -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();
};
@@ -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 );
@@ -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();
};
@@ -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
@@ -3133,7 +3136,7 @@ QgsWMSLayerItem::~QgsWMSLayerItem ()
{
}

QString QgsWMSLayerItem::uri()
QString QgsWMSLayerItem::createUri()
{
QString uri;
if ( mLayerProperty.name.isEmpty() ) return uri; // layer collection
@@ -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;

0 comments on commit 0797640

Please sign in to comment.
You can’t perform that action at this time.