Skip to content
Permalink
Browse files

Add sourceName() method to QgsFeatureSource

Sometimes it's necessary to retrieve the name of a source...
  • Loading branch information
nyalldawson committed Jun 26, 2017
1 parent d88d52b commit 7ae1ee975d979e262670520382de206325bd7328
@@ -33,6 +33,12 @@ class QgsFeatureSource
:rtype: QgsFeatureIterator
%End

virtual QString sourceName() const = 0;
%Docstring
Returns a friendly display name for the source. The returned value can be an empty string.
:rtype: str
%End

virtual QgsCoordinateReferenceSystem sourceCrs() const = 0;
%Docstring
Returns the coordinate reference system for features in the source.
@@ -128,6 +128,7 @@ Bitmask of all provider's editing capabilities

virtual QgsRectangle sourceExtent() const;

virtual QString sourceName() const;

virtual QString dataComment() const;
%Docstring
@@ -700,6 +700,8 @@ Return the provider type for this layer

virtual QgsCoordinateReferenceSystem sourceCrs() const;

virtual QString sourceName() const;


virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
%Docstring
@@ -168,11 +168,19 @@ class QgsVectorLayerSelectedFeatureSource : QgsFeatureSource
%End

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const;

virtual QgsCoordinateReferenceSystem sourceCrs() const;

virtual QgsFields fields() const;

virtual QgsWkbTypes::Type wkbType() const;

virtual long featureCount() const;

virtual QString sourceName() const;



};

/************************************************************************
@@ -137,7 +137,7 @@ def processAlgorithm(self, parameters, context, feedback):
if table:
table.strip()
if not table or table == '':
table = layer.name()
table = source.name()
table = table.replace('.', '_')
table = table.replace(' ', '').lower()[0:62]
providerName = 'postgres'
@@ -508,3 +508,9 @@ long QgsProcessingFeatureSource::featureCount() const
{
return mSource->featureCount();
}

QString QgsProcessingFeatureSource::sourceName() const
{
return mSource->sourceName();

}
@@ -244,11 +244,12 @@ class QgsProcessingFeatureSource : public QgsFeatureSource

~QgsProcessingFeatureSource();

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
virtual QgsCoordinateReferenceSystem sourceCrs() const override;
virtual QgsFields fields() const override;
virtual QgsWkbTypes::Type wkbType() const override;
virtual long featureCount() const override;
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
QgsCoordinateReferenceSystem sourceCrs() const override;
QgsFields fields() const override;
QgsWkbTypes::Type wkbType() const override;
long featureCount() const override;
QString sourceName() const override;

private:

@@ -46,6 +46,11 @@ class CORE_EXPORT QgsFeatureSource
*/
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const = 0;

/**
* Returns a friendly display name for the source. The returned value can be an empty string.
*/
virtual QString sourceName() const = 0;

/**
* Returns the coordinate reference system for features in the source.
*/
@@ -161,6 +161,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat

QgsCoordinateReferenceSystem sourceCrs() const override;
QgsRectangle sourceExtent() const override;
QString sourceName() const override { return QString(); }

/**
* Return a short comment for the data that this provider is
@@ -312,6 +312,11 @@ QgsCoordinateReferenceSystem QgsVectorLayer::sourceCrs() const
return crs();
}

QString QgsVectorLayer::sourceName() const
{
return name();
}

void QgsVectorLayer::reload()
{
if ( mDataProvider )
@@ -698,6 +698,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
QString providerType() const;

QgsCoordinateReferenceSystem sourceCrs() const override;
QString sourceName() const override;

/** Reads vector layer specific state from project file Dom node.
* \note Called by QgsMapLayer::readXml().
@@ -1064,6 +1064,7 @@ QgsVectorLayerSelectedFeatureSource::QgsVectorLayerSelectedFeatureSource( QgsVec
: mSource( layer )
, mSelectedFeatureIds( layer->selectedFeatureIds() )
, mWkbType( layer->wkbType() )
, mName( layer->name() )
{}

QgsFeatureIterator QgsVectorLayerSelectedFeatureSource::getFeatures( const QgsFeatureRequest &request ) const
@@ -1103,3 +1104,8 @@ long QgsVectorLayerSelectedFeatureSource::featureCount() const
{
return mSelectedFeatureIds.count();
}

QString QgsVectorLayerSelectedFeatureSource::sourceName() const
{
return mName;
}
@@ -282,18 +282,21 @@ class CORE_EXPORT QgsVectorLayerSelectedFeatureSource : public QgsFeatureSource
*/
QgsVectorLayerSelectedFeatureSource( QgsVectorLayer *layer );

virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
virtual QgsCoordinateReferenceSystem sourceCrs() const override;
virtual QgsFields fields() const override;
virtual QgsWkbTypes::Type wkbType() const override;
virtual long featureCount() const override;
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
QgsCoordinateReferenceSystem sourceCrs() const override;
QgsFields fields() const override;
QgsWkbTypes::Type wkbType() const override;
long featureCount() const override;
QString sourceName() const override;


private:

// ideally this wouldn't be mutable, but QgsVectorLayerFeatureSource has non-const getFeatures()
mutable QgsVectorLayerFeatureSource mSource;
QgsFeatureIds mSelectedFeatureIds;
QgsWkbTypes::Type mWkbType = QgsWkbTypes::Unknown;
QString mName;

};

0 comments on commit 7ae1ee9

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