Skip to content
Permalink
Browse files

QgsVectorDataProvider API cleanup

  • Loading branch information
m-kuhn committed Oct 22, 2016
1 parent ec25df1 commit 144564706577a0812bd32e13fc086702c8f767fd
@@ -224,16 +224,24 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
\subsection qgis_api_break_3_0_DataProviders Data Providers

<ul>
<li>Many methods in QgsDataProvider, QgsVectorDataProvider and QgsRasterDataProvider have been made const-correct.
This has no effect on PyQGIS code, but c++ code implementing third-party providers will need to update the
signatures of these methods to match. Affected methods are:
<ul>
<li>QgsDataProvider: crs(), extent(), isValid(), supportsSubsetString(), subsetString()</li>
<li>QgsVectorDataProvider: getFeatures(), minimumValue(), maximumValue(), uniqueValues(), enumValues(), defaultValue(),
attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
<li>QgsRasterInterface: extent()</li>
</ul
</li>
<li>Many methods in QgsDataProvider, QgsVectorDataProvider and QgsRasterDataProvider have been made const-correct.
This has no effect on PyQGIS code, but c++ code implementing third-party providers will need to update the
signatures of these methods to match. Affected methods are:
<ul>
<li>QgsDataProvider: crs(), extent(), isValid(), supportsSubsetString(), subsetString()</li>
<li>QgsVectorDataProvider: getFeatures(), minimumValue(), maximumValue(), uniqueValues(), enumValues(), defaultValue(),
attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
<li>QgsRasterInterface: extent()</li>
</ul>
</li>
<li>Many protected member variables have been wrapped in setter/getter methods.
This should generally only affect 3rd party providers
<ul>
<li>mCacheMinMaxDirty: use clearMinMaxCache()</li>
<li>mNativeTypes: use setNativeTypes()</li>
<li>mAttrPalIndexName: overwrite palAttributeIndexNames()</li>
</ul>
</li>
</ul>

\subsection qgis_api_break_3_0_Qgis Qgis
@@ -343,7 +343,6 @@ class QgsVectorDataProvider : QgsDataProvider
*/
QStringList errors() const;


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

signals:
/** Signals an error in this provider */
void raiseError( const QString& msg );
/**
* Signals an error in this provider
*
* @note Added const in QGIS 3.0
*/
void raiseError( const QString& msg ) const;

protected:
/**
* Invalidates the min/max cache. This will force the provider to recalculate the
* cache the next time it is requested.
*/
void clearMinMaxCache();

//! Populates the cache of minimum and maximum attribute values.
/**
* Populates the cache of minimum and maximum attribute values.
*/
void fillMinMaxCache() const;

/**
* Raises an error message from the provider.
* Push a notification about errors that happened in this providers scope.
* Errors should be translated strings that require the users immediate
* attention.
*
* For general debug information use QgsMessageLog::logMessage() instead.
*
* @note Added in QGIS 3.0
*/
void pushError( const QString& msg ) const;


/** Converts the geometry to the provider type if possible / necessary
@return the converted geometry or nullptr if no conversion was necessary or possible*/
/**
* Converts the geometry to the provider type if possible / necessary
* @return the converted geometry or nullptr if no conversion was necessary or possible
*/
QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const /Factory/;

/**
* Set the list of native types supported by this provider.
* Usually done in the constructor.
*
* @note Added in QGIS 3.0
*/
void setNativeTypes(const QList<QgsVectorDataProvider::NativeType>& nativeTypes);

/**
* Get this providers encoding
*
* @note Added in QGIS 3.0
*/
QTextCodec* textEncoding() const;

};

QFlags<QgsVectorDataProvider::Capability> operator|(QgsVectorDataProvider::Capability f1, QFlags<QgsVectorDataProvider::Capability> f2);
@@ -19,7 +19,6 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgstolerance.h"
#include "qgisapp.h"
@@ -19,7 +19,6 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgstolerance.h"
#include "qgsvertexmarker.h"
@@ -36,7 +36,6 @@
QgsVectorDataProvider::QgsVectorDataProvider( const QString& uri )
: QgsDataProvider( uri )
, mCacheMinMaxDirty( true )
, mAttrPalIndexName( QgsAttrPalIndexNameHash() )
{
QSettings settings;
setEncoding( settings.value( "/UI/encoding", "System" ).toString() );
@@ -280,35 +279,45 @@ QgsAttributeList QgsVectorDataProvider::attributeIndexes() const
return fields().allAttributesList();
}

QgsAttributeList QgsVectorDataProvider::pkAttributeIndexes() const
{
return QgsAttributeList();
}

const QList< QgsVectorDataProvider::NativeType > &QgsVectorDataProvider::nativeTypes() const
{
return mNativeTypes;
}

QgsAttrPalIndexNameHash QgsVectorDataProvider::palAttributeIndexNames() const
{
return QgsAttrPalIndexNameHash();
}

bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
{
int i;
QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
.arg( field.name(),
QVariant::typeToName( field.type() ) )
.arg( field.length() )
.arg( field.precision() ), 2 );
for ( i = 0; i < mNativeTypes.size(); i++ )

Q_FOREACH ( const NativeType& nativeType, mNativeTypes )
{
QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
.arg( QVariant::typeToName( mNativeTypes[i].mType ) )
.arg( mNativeTypes[i].mMinLen )
.arg( mNativeTypes[i].mMaxLen )
.arg( mNativeTypes[i].mMinPrec )
.arg( mNativeTypes[i].mMaxPrec ), 2 );
.arg( QVariant::typeToName( nativeType.mType ) )
.arg( nativeType.mMinLen )
.arg( nativeType.mMaxLen )
.arg( nativeType.mMinPrec )
.arg( nativeType.mMaxPrec ), 2 );

if ( field.type() != mNativeTypes[i].mType )
if ( field.type() != nativeType.mType )
continue;

if ( field.length() == -1 )
{
// source length unlimited
if ( mNativeTypes[i].mMinLen > -1 || mNativeTypes[i].mMaxLen > -1 )
if ( nativeType.mMinLen > -1 || nativeType.mMaxLen > -1 )
{
// destination limited
continue;
@@ -317,8 +326,8 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
else
{
// source length limited
if ( mNativeTypes[i].mMinLen > -1 && mNativeTypes[i].mMaxLen > -1 &&
( field.length() < mNativeTypes[i].mMinLen || field.length() > mNativeTypes[i].mMaxLen ) )
if ( nativeType.mMinLen > -1 && nativeType.mMaxLen > -1 &&
( field.length() < nativeType.mMinLen || field.length() > nativeType.mMaxLen ) )
{
// source length exceeds destination limits
continue;
@@ -328,7 +337,7 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
if ( field.precision() == -1 )
{
// source precision unlimited / n/a
if ( mNativeTypes[i].mMinPrec > -1 || mNativeTypes[i].mMaxPrec > -1 )
if ( nativeType.mMinPrec > -1 || nativeType.mMaxPrec > -1 )
{
// destination limited
continue;
@@ -337,8 +346,8 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
else
{
// source precision unlimited / n/a
if ( mNativeTypes[i].mMinPrec > -1 && mNativeTypes[i].mMaxPrec > -1 &&
( field.precision() < mNativeTypes[i].mMinPrec || field.precision() > mNativeTypes[i].mMaxPrec ) )
if ( nativeType.mMinPrec > -1 && nativeType.mMaxPrec > -1 &&
( field.precision() < nativeType.mMinPrec || field.precision() > nativeType.mMaxPrec ) )
{
// source precision exceeds destination limits
continue;
@@ -523,6 +532,16 @@ QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString
return v;
}

QgsTransaction* QgsVectorDataProvider::transaction() const
{
return nullptr;
}

void QgsVectorDataProvider::forceReload()
{
emit dataChanged();
}

static bool _compareEncodings( const QString& s1, const QString& s2 )
{
return s1.toLower() < s2.toLower();
@@ -606,6 +625,11 @@ QStringList QgsVectorDataProvider::errors() const
return mErrors;
}

bool QgsVectorDataProvider::isSaveAndLoadStyleToDBSupported() const
{
return false;
}

void QgsVectorDataProvider::pushError( const QString& msg ) const
{
QgsDebugMsg( msg );
@@ -717,6 +741,16 @@ QgsGeometry* QgsVectorDataProvider::convertToProviderType( const QgsGeometry& ge
return nullptr;
}

void QgsVectorDataProvider::setNativeTypes( const QList<NativeType>& nativeTypes )
{
mNativeTypes = nativeTypes;
}

QTextCodec* QgsVectorDataProvider::textEncoding() const
{
return mEncoding;
}

QStringList QgsVectorDataProvider::smEncodings;

QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer*, const QList<QgsVectorLayer*>& ) const
@@ -339,12 +339,12 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
/**
* Return list of indexes of fields that make up the primary key
*/
virtual QgsAttributeList pkAttributeIndexes() const { return QgsAttributeList(); }
virtual QgsAttributeList pkAttributeIndexes() const;

/**
* Return list of indexes to names for QgsPalLabeling fix
*/
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const;

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


/**
* It returns false by default.
* Must be implemented by providers that support saving and loading styles to db returning true
*/
virtual bool isSaveAndLoadStyleToDBSupported() const { return false; }
virtual bool isSaveAndLoadStyleToDBSupported() const;

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

/**
* Returns the transaction this data provider is included in, if any.
*/
virtual QgsTransaction* transaction() const { return nullptr; }
virtual QgsTransaction* transaction() const;

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

/**
* 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
virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer* self, const QList<QgsVectorLayer*>& layers ) const;

signals:
/** Signals an error in this provider */
/**
* Signals an error in this provider
*
* @note Added const in QGIS 3.0
*/
void raiseError( const QString& msg ) const;

protected:
/**
* Invalidates the min/max cache. This will force the provider to recalculate the
* cache the next time it is requested.
*/
void clearMinMaxCache();

//! Populates the cache of minimum and maximum attribute values.
/**
* Populates the cache of minimum and maximum attribute values.
*/
void fillMinMaxCache() const;

/**
* Push a notification about errors that happened in this providers scope.
* Errors should be translated strings that require the users immediate
* attention.
*
* For general debug information use QgsMessageLog::logMessage() instead.
*
* @note Added in QGIS 3.0
*/
void pushError( const QString& msg ) const;

/**
* Converts the geometry to the provider type if possible / necessary
* @return the converted geometry or nullptr if no conversion was necessary or possible
*/
QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const;

/**
* Set the list of native types supported by this provider.
* Usually done in the constructor.
*
* @note Added in QGIS 3.0
*/
void setNativeTypes( const QList<NativeType>& nativeTypes );

/**
* Get this providers encoding
*
* @note Added in QGIS 3.0
*/
QTextCodec* textEncoding() const;

private:
mutable bool mCacheMinMaxDirty;
mutable QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;

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

/**
* Raises an error message from the provider.
*/
void pushError( const QString& msg ) const;

/** Old-style mapping of index to name for QgsPalLabeling fix */
QgsAttrPalIndexNameHash mAttrPalIndexName;

/** Converts the geometry to the provider type if possible / necessary
@return the converted geometry or nullptr if no conversion was necessary or possible*/
QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const;

private:
/** Old notation **/
QMap<QString, QVariant::Type> mOldTypeList;

0 comments on commit 1445647

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