Skip to content

Commit

Permalink
Add driver name to QgsProviderSublayerDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 23, 2021
1 parent 8b1c8d1 commit 6c2d7bd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Expand Up @@ -121,6 +121,22 @@ Returns the layer's description.
Sets the layer's ``description``.

.. seealso:: :py:func:`description`
%End

QString driverName() const;
%Docstring
Returns the layer's driver name.

This is supported only for providers which handle multiple drivers.

.. seealso:: :py:func:`setDriverName`
%End

void setDriverName( const QString &driver );
%Docstring
Sets the layer's ``driver`` name.

.. seealso:: :py:func:`driverName`
%End

QStringList path() const;
Expand Down
3 changes: 2 additions & 1 deletion src/core/providers/qgsprovidersublayerdetails.cpp
Expand Up @@ -37,7 +37,8 @@ bool QgsProviderSublayerDetails::operator==( const QgsProviderSublayerDetails &o
&& mFeatureCount == other.mFeatureCount
&& mGeometryColumnName == other.mGeometryColumnName
&& mPath == other.mPath
&& mWkbType == other.mWkbType;
&& mWkbType == other.mWkbType
&& mDriverName == other.mDriverName;
}

bool QgsProviderSublayerDetails::operator!=( const QgsProviderSublayerDetails &other ) const
Expand Down
17 changes: 17 additions & 0 deletions src/core/providers/qgsprovidersublayerdetails.h
Expand Up @@ -142,6 +142,22 @@ class CORE_EXPORT QgsProviderSublayerDetails
*/
void setDescription( const QString &description ) { mDescription = description; }

/**
* Returns the layer's driver name.
*
* This is supported only for providers which handle multiple drivers.
*
* \see setDriverName()
*/
QString driverName() const { return mDriverName; }

/**
* Sets the layer's \a driver name.
*
* \see driverName()
*/
void setDriverName( const QString &driver ) { mDriverName = driver; }

/**
* Returns the path to the sublayer.
*
Expand Down Expand Up @@ -250,6 +266,7 @@ class CORE_EXPORT QgsProviderSublayerDetails
QString mGeometryColumnName;
QStringList mPath;
QgsWkbTypes::Type mWkbType = QgsWkbTypes::Unknown;
QString mDriverName;

};

Expand Down
16 changes: 14 additions & 2 deletions tests/src/python/test_qgsprovidersublayerdetails.py
Expand Up @@ -69,6 +69,9 @@ def testGettersSetters(self):
d.setLayerNumber(13)
self.assertEqual(d.layerNumber(), 13)

d.setDriverName('drv')
self.assertEqual(d.driverName(), 'drv')

def test_equality(self):
"""
Test equality operator
Expand Down Expand Up @@ -116,10 +119,19 @@ def test_equality(self):
self.assertEqual(d, d2)

d.setGeometryColumnName('geom_col')
self.assertEqual(d.geometryColumnName(), 'geom_col')
self.assertNotEqual(d, d2)
d2.setGeometryColumnName('geom_col')
self.assertEqual(d, d2)

d.setLayerNumber(13)
self.assertEqual(d.layerNumber(), 13)
self.assertNotEqual(d, d2)
d2.setLayerNumber(13)
self.assertEqual(d, d2)

d.setDriverName('drv')
self.assertNotEqual(d, d2)
d2.setDriverName('drv')
self.assertEqual(d, d2)

def test_to_layer(self):
"""
Expand Down

0 comments on commit 6c2d7bd

Please sign in to comment.