Skip to content

Commit 1445647

Browse files
committed
QgsVectorDataProvider API cleanup
1 parent ec25df1 commit 1445647

22 files changed

+364
-252
lines changed

doc/api_break.dox

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,24 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
224224
\subsection qgis_api_break_3_0_DataProviders Data Providers
225225

226226
<ul>
227-
<li>Many methods in QgsDataProvider, QgsVectorDataProvider and QgsRasterDataProvider have been made const-correct.
228-
This has no effect on PyQGIS code, but c++ code implementing third-party providers will need to update the
229-
signatures of these methods to match. Affected methods are:
230-
<ul>
231-
<li>QgsDataProvider: crs(), extent(), isValid(), supportsSubsetString(), subsetString()</li>
232-
<li>QgsVectorDataProvider: getFeatures(), minimumValue(), maximumValue(), uniqueValues(), enumValues(), defaultValue(),
233-
attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
234-
<li>QgsRasterInterface: extent()</li>
235-
</ul
236-
</li>
227+
<li>Many methods in QgsDataProvider, QgsVectorDataProvider and QgsRasterDataProvider have been made const-correct.
228+
This has no effect on PyQGIS code, but c++ code implementing third-party providers will need to update the
229+
signatures of these methods to match. Affected methods are:
230+
<ul>
231+
<li>QgsDataProvider: crs(), extent(), isValid(), supportsSubsetString(), subsetString()</li>
232+
<li>QgsVectorDataProvider: getFeatures(), minimumValue(), maximumValue(), uniqueValues(), enumValues(), defaultValue(),
233+
attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
234+
<li>QgsRasterInterface: extent()</li>
235+
</ul>
236+
</li>
237+
<li>Many protected member variables have been wrapped in setter/getter methods.
238+
This should generally only affect 3rd party providers
239+
<ul>
240+
<li>mCacheMinMaxDirty: use clearMinMaxCache()</li>
241+
<li>mNativeTypes: use setNativeTypes()</li>
242+
<li>mAttrPalIndexName: overwrite palAttributeIndexNames()</li>
243+
</ul>
244+
</li>
237245
</ul>
238246

239247
\subsection qgis_api_break_3_0_Qgis Qgis

python/core/qgsvectordataprovider.sip

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ class QgsVectorDataProvider : QgsDataProvider
343343
*/
344344
QStringList errors() const;
345345

346-
347346
/**
348347
* It returns false by default.
349348
* Must be implemented by providers that support saving and loading styles to db returning true
@@ -381,24 +380,57 @@ class QgsVectorDataProvider : QgsDataProvider
381380
virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer* self, const QList<QgsVectorLayer*>& layers ) const;
382381

383382
signals:
384-
/** Signals an error in this provider */
385-
void raiseError( const QString& msg );
383+
/**
384+
* Signals an error in this provider
385+
*
386+
* @note Added const in QGIS 3.0
387+
*/
388+
void raiseError( const QString& msg ) const;
386389

387390
protected:
391+
/**
392+
* Invalidates the min/max cache. This will force the provider to recalculate the
393+
* cache the next time it is requested.
394+
*/
388395
void clearMinMaxCache();
389396

390-
//! Populates the cache of minimum and maximum attribute values.
397+
/**
398+
* Populates the cache of minimum and maximum attribute values.
399+
*/
391400
void fillMinMaxCache() const;
392401

393402
/**
394-
* Raises an error message from the provider.
403+
* Push a notification about errors that happened in this providers scope.
404+
* Errors should be translated strings that require the users immediate
405+
* attention.
406+
*
407+
* For general debug information use QgsMessageLog::logMessage() instead.
408+
*
409+
* @note Added in QGIS 3.0
395410
*/
396411
void pushError( const QString& msg ) const;
397412

398-
399-
/** Converts the geometry to the provider type if possible / necessary
400-
@return the converted geometry or nullptr if no conversion was necessary or possible*/
413+
/**
414+
* Converts the geometry to the provider type if possible / necessary
415+
* @return the converted geometry or nullptr if no conversion was necessary or possible
416+
*/
401417
QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const /Factory/;
418+
419+
/**
420+
* Set the list of native types supported by this provider.
421+
* Usually done in the constructor.
422+
*
423+
* @note Added in QGIS 3.0
424+
*/
425+
void setNativeTypes(const QList<QgsVectorDataProvider::NativeType>& nativeTypes);
426+
427+
/**
428+
* Get this providers encoding
429+
*
430+
* @note Added in QGIS 3.0
431+
*/
432+
QTextCodec* textEncoding() const;
433+
402434
};
403435

404436
QFlags<QgsVectorDataProvider::Capability> operator|(QgsVectorDataProvider::Capability f1, QFlags<QgsVectorDataProvider::Capability> f2);

src/app/qgsmaptoolmovefeature.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "qgslogger.h"
2020
#include "qgsmapcanvas.h"
2121
#include "qgsrubberband.h"
22-
#include "qgsvectordataprovider.h"
2322
#include "qgsvectorlayer.h"
2423
#include "qgstolerance.h"
2524
#include "qgisapp.h"

src/app/qgsmaptoolrotatefeature.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "qgslogger.h"
2020
#include "qgsmapcanvas.h"
2121
#include "qgsrubberband.h"
22-
#include "qgsvectordataprovider.h"
2322
#include "qgsvectorlayer.h"
2423
#include "qgstolerance.h"
2524
#include "qgsvertexmarker.h"

src/core/qgsvectordataprovider.cpp

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
QgsVectorDataProvider::QgsVectorDataProvider( const QString& uri )
3737
: QgsDataProvider( uri )
3838
, mCacheMinMaxDirty( true )
39-
, mAttrPalIndexName( QgsAttrPalIndexNameHash() )
4039
{
4140
QSettings settings;
4241
setEncoding( settings.value( "/UI/encoding", "System" ).toString() );
@@ -280,35 +279,45 @@ QgsAttributeList QgsVectorDataProvider::attributeIndexes() const
280279
return fields().allAttributesList();
281280
}
282281

282+
QgsAttributeList QgsVectorDataProvider::pkAttributeIndexes() const
283+
{
284+
return QgsAttributeList();
285+
}
286+
283287
const QList< QgsVectorDataProvider::NativeType > &QgsVectorDataProvider::nativeTypes() const
284288
{
285289
return mNativeTypes;
286290
}
287291

292+
QgsAttrPalIndexNameHash QgsVectorDataProvider::palAttributeIndexNames() const
293+
{
294+
return QgsAttrPalIndexNameHash();
295+
}
296+
288297
bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
289298
{
290-
int i;
291299
QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
292300
.arg( field.name(),
293301
QVariant::typeToName( field.type() ) )
294302
.arg( field.length() )
295303
.arg( field.precision() ), 2 );
296-
for ( i = 0; i < mNativeTypes.size(); i++ )
304+
305+
Q_FOREACH ( const NativeType& nativeType, mNativeTypes )
297306
{
298307
QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
299-
.arg( QVariant::typeToName( mNativeTypes[i].mType ) )
300-
.arg( mNativeTypes[i].mMinLen )
301-
.arg( mNativeTypes[i].mMaxLen )
302-
.arg( mNativeTypes[i].mMinPrec )
303-
.arg( mNativeTypes[i].mMaxPrec ), 2 );
308+
.arg( QVariant::typeToName( nativeType.mType ) )
309+
.arg( nativeType.mMinLen )
310+
.arg( nativeType.mMaxLen )
311+
.arg( nativeType.mMinPrec )
312+
.arg( nativeType.mMaxPrec ), 2 );
304313

305-
if ( field.type() != mNativeTypes[i].mType )
314+
if ( field.type() != nativeType.mType )
306315
continue;
307316

308317
if ( field.length() == -1 )
309318
{
310319
// source length unlimited
311-
if ( mNativeTypes[i].mMinLen > -1 || mNativeTypes[i].mMaxLen > -1 )
320+
if ( nativeType.mMinLen > -1 || nativeType.mMaxLen > -1 )
312321
{
313322
// destination limited
314323
continue;
@@ -317,8 +326,8 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
317326
else
318327
{
319328
// source length limited
320-
if ( mNativeTypes[i].mMinLen > -1 && mNativeTypes[i].mMaxLen > -1 &&
321-
( field.length() < mNativeTypes[i].mMinLen || field.length() > mNativeTypes[i].mMaxLen ) )
329+
if ( nativeType.mMinLen > -1 && nativeType.mMaxLen > -1 &&
330+
( field.length() < nativeType.mMinLen || field.length() > nativeType.mMaxLen ) )
322331
{
323332
// source length exceeds destination limits
324333
continue;
@@ -328,7 +337,7 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
328337
if ( field.precision() == -1 )
329338
{
330339
// source precision unlimited / n/a
331-
if ( mNativeTypes[i].mMinPrec > -1 || mNativeTypes[i].mMaxPrec > -1 )
340+
if ( nativeType.mMinPrec > -1 || nativeType.mMaxPrec > -1 )
332341
{
333342
// destination limited
334343
continue;
@@ -337,8 +346,8 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
337346
else
338347
{
339348
// source precision unlimited / n/a
340-
if ( mNativeTypes[i].mMinPrec > -1 && mNativeTypes[i].mMaxPrec > -1 &&
341-
( field.precision() < mNativeTypes[i].mMinPrec || field.precision() > mNativeTypes[i].mMaxPrec ) )
349+
if ( nativeType.mMinPrec > -1 && nativeType.mMaxPrec > -1 &&
350+
( field.precision() < nativeType.mMinPrec || field.precision() > nativeType.mMaxPrec ) )
342351
{
343352
// source precision exceeds destination limits
344353
continue;
@@ -523,6 +532,16 @@ QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString
523532
return v;
524533
}
525534

535+
QgsTransaction* QgsVectorDataProvider::transaction() const
536+
{
537+
return nullptr;
538+
}
539+
540+
void QgsVectorDataProvider::forceReload()
541+
{
542+
emit dataChanged();
543+
}
544+
526545
static bool _compareEncodings( const QString& s1, const QString& s2 )
527546
{
528547
return s1.toLower() < s2.toLower();
@@ -606,6 +625,11 @@ QStringList QgsVectorDataProvider::errors() const
606625
return mErrors;
607626
}
608627

628+
bool QgsVectorDataProvider::isSaveAndLoadStyleToDBSupported() const
629+
{
630+
return false;
631+
}
632+
609633
void QgsVectorDataProvider::pushError( const QString& msg ) const
610634
{
611635
QgsDebugMsg( msg );
@@ -717,6 +741,16 @@ QgsGeometry* QgsVectorDataProvider::convertToProviderType( const QgsGeometry& ge
717741
return nullptr;
718742
}
719743

744+
void QgsVectorDataProvider::setNativeTypes( const QList<NativeType>& nativeTypes )
745+
{
746+
mNativeTypes = nativeTypes;
747+
}
748+
749+
QTextCodec* QgsVectorDataProvider::textEncoding() const
750+
{
751+
return mEncoding;
752+
}
753+
720754
QStringList QgsVectorDataProvider::smEncodings;
721755

722756
QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer*, const QList<QgsVectorLayer*>& ) const

src/core/qgsvectordataprovider.h

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
339339
/**
340340
* Return list of indexes of fields that make up the primary key
341341
*/
342-
virtual QgsAttributeList pkAttributeIndexes() const { return QgsAttributeList(); }
342+
virtual QgsAttributeList pkAttributeIndexes() const;
343343

344344
/**
345345
* Return list of indexes to names for QgsPalLabeling fix
346346
*/
347-
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
347+
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const;
348348

349349
/**
350350
* check if provider supports type of field
@@ -403,19 +403,18 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
403403
*/
404404
QStringList errors() const;
405405

406-
407406
/**
408407
* It returns false by default.
409408
* Must be implemented by providers that support saving and loading styles to db returning true
410409
*/
411-
virtual bool isSaveAndLoadStyleToDBSupported() const { return false; }
410+
virtual bool isSaveAndLoadStyleToDBSupported() const;
412411

413412
static QVariant convertValue( QVariant::Type type, const QString& value );
414413

415414
/**
416415
* Returns the transaction this data provider is included in, if any.
417416
*/
418-
virtual QgsTransaction* transaction() const { return nullptr; }
417+
virtual QgsTransaction* transaction() const;
419418

420419
/**
421420
* Forces a reload of the underlying datasource if the provider implements this
@@ -424,10 +423,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
424423
* This forces QGIS to reopen a file or connection.
425424
* This can be required if the underlying file is replaced.
426425
*/
427-
virtual void forceReload()
428-
{
429-
emit dataChanged();
430-
}
426+
virtual void forceReload();
431427

432428
/**
433429
* Get the list of layer ids on which this layer depends. This in particular determines the order of layer loading.
@@ -444,15 +440,58 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
444440
virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer* self, const QList<QgsVectorLayer*>& layers ) const;
445441

446442
signals:
447-
/** Signals an error in this provider */
443+
/**
444+
* Signals an error in this provider
445+
*
446+
* @note Added const in QGIS 3.0
447+
*/
448448
void raiseError( const QString& msg ) const;
449449

450450
protected:
451+
/**
452+
* Invalidates the min/max cache. This will force the provider to recalculate the
453+
* cache the next time it is requested.
454+
*/
451455
void clearMinMaxCache();
452456

453-
//! Populates the cache of minimum and maximum attribute values.
457+
/**
458+
* Populates the cache of minimum and maximum attribute values.
459+
*/
454460
void fillMinMaxCache() const;
455461

462+
/**
463+
* Push a notification about errors that happened in this providers scope.
464+
* Errors should be translated strings that require the users immediate
465+
* attention.
466+
*
467+
* For general debug information use QgsMessageLog::logMessage() instead.
468+
*
469+
* @note Added in QGIS 3.0
470+
*/
471+
void pushError( const QString& msg ) const;
472+
473+
/**
474+
* Converts the geometry to the provider type if possible / necessary
475+
* @return the converted geometry or nullptr if no conversion was necessary or possible
476+
*/
477+
QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const;
478+
479+
/**
480+
* Set the list of native types supported by this provider.
481+
* Usually done in the constructor.
482+
*
483+
* @note Added in QGIS 3.0
484+
*/
485+
void setNativeTypes( const QList<NativeType>& nativeTypes );
486+
487+
/**
488+
* Get this providers encoding
489+
*
490+
* @note Added in QGIS 3.0
491+
*/
492+
QTextCodec* textEncoding() const;
493+
494+
private:
456495
mutable bool mCacheMinMaxDirty;
457496
mutable QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
458497

@@ -465,19 +504,6 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
465504
/** The names of the providers native types*/
466505
QList< NativeType > mNativeTypes;
467506

468-
/**
469-
* Raises an error message from the provider.
470-
*/
471-
void pushError( const QString& msg ) const;
472-
473-
/** Old-style mapping of index to name for QgsPalLabeling fix */
474-
QgsAttrPalIndexNameHash mAttrPalIndexName;
475-
476-
/** Converts the geometry to the provider type if possible / necessary
477-
@return the converted geometry or nullptr if no conversion was necessary or possible*/
478-
QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const;
479-
480-
private:
481507
/** Old notation **/
482508
QMap<QString, QVariant::Type> mOldTypeList;
483509

0 commit comments

Comments
 (0)