diff --git a/doc/api_break.dox b/doc/api_break.dox index 494461c0fa1..10d9c788060 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -224,16 +224,24 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat \subsection qgis_api_break_3_0_DataProviders Data Providers \subsection qgis_api_break_3_0_Qgis Qgis diff --git a/python/core/qgsvectordataprovider.sip b/python/core/qgsvectordataprovider.sip index d326ec7893e..198b57c5f64 100644 --- a/python/core/qgsvectordataprovider.sip +++ b/python/core/qgsvectordataprovider.sip @@ -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 discoverRelations( const QgsVectorLayer* self, const QList& 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& nativeTypes); + + /** + * Get this providers encoding + * + * @note Added in QGIS 3.0 + */ + QTextCodec* textEncoding() const; + }; QFlags operator|(QgsVectorDataProvider::Capability f1, QFlags f2); diff --git a/src/app/qgsmaptoolmovefeature.cpp b/src/app/qgsmaptoolmovefeature.cpp index 5fdd1ba99be..e4d43d0e60e 100644 --- a/src/app/qgsmaptoolmovefeature.cpp +++ b/src/app/qgsmaptoolmovefeature.cpp @@ -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" diff --git a/src/app/qgsmaptoolrotatefeature.cpp b/src/app/qgsmaptoolrotatefeature.cpp index a240c029669..cb9d597b3e1 100644 --- a/src/app/qgsmaptoolrotatefeature.cpp +++ b/src/app/qgsmaptoolrotatefeature.cpp @@ -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" diff --git a/src/core/qgsvectordataprovider.cpp b/src/core/qgsvectordataprovider.cpp index ddebf456083..da4c0484b5e 100644 --- a/src/core/qgsvectordataprovider.cpp +++ b/src/core/qgsvectordataprovider.cpp @@ -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& nativeTypes ) +{ + mNativeTypes = nativeTypes; +} + +QTextCodec* QgsVectorDataProvider::textEncoding() const +{ + return mEncoding; +} + QStringList QgsVectorDataProvider::smEncodings; QList QgsVectorDataProvider::discoverRelations( const QgsVectorLayer*, const QList& ) const diff --git a/src/core/qgsvectordataprovider.h b/src/core/qgsvectordataprovider.h index df5f1d61fe4..c172f248683 100644 --- a/src/core/qgsvectordataprovider.h +++ b/src/core/qgsvectordataprovider.h @@ -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 discoverRelations( const QgsVectorLayer* self, const QList& 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& nativeTypes ); + + /** + * Get this providers encoding + * + * @note Added in QGIS 3.0 + */ + QTextCodec* textEncoding() const; + + private: mutable bool mCacheMinMaxDirty; mutable QMap 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 mOldTypeList; diff --git a/src/providers/db2/qgsdb2provider.cpp b/src/providers/db2/qgsdb2provider.cpp index ea6af992033..3f83c0c5a3a 100644 --- a/src/providers/db2/qgsdb2provider.cpp +++ b/src/providers/db2/qgsdb2provider.cpp @@ -110,30 +110,30 @@ QgsDb2Provider::QgsDb2Provider( QString uri ) } //fill type names into sets - mNativeTypes - // integer types - << QgsVectorDataProvider::NativeType( tr( "8 Bytes integer" ), "bigint", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "4 Bytes integer" ), "integer", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "2 Bytes integer" ), "smallint", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 31, 0, 31 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 31, 0, 31 ) + setNativeTypes( QList< NativeType >() + // integer types + << QgsVectorDataProvider::NativeType( tr( "8 Bytes integer" ), "bigint", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "4 Bytes integer" ), "integer", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "2 Bytes integer" ), "smallint", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 31, 0, 31 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 31, 0, 31 ) - // floating point - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double", QVariant::Double ) + // floating point + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double", QVariant::Double ) - // date/time types - << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime, -1, -1, -1, -1 ) + // date/time types + << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime, -1, -1, -1, -1 ) - // string types - << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "char", QVariant::String, 1, 254 ) - << QgsVectorDataProvider::NativeType( tr( "Text, variable length (varchar)" ), "varchar", QVariant::String, 1, 32704 ) - << QgsVectorDataProvider::NativeType( tr( "Text, variable length large object (clob)" ), "clob", QVariant::String, 1, 2147483647 ) - //DBCLOB is for 1073741824 double-byte characters, data length should be the same as CLOB (2147483647)? - << QgsVectorDataProvider::NativeType( tr( "Text, variable length large object (dbclob)" ), "dbclob", QVariant::String, 1, 1073741824 ) - ; + // string types + << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "char", QVariant::String, 1, 254 ) + << QgsVectorDataProvider::NativeType( tr( "Text, variable length (varchar)" ), "varchar", QVariant::String, 1, 32704 ) + << QgsVectorDataProvider::NativeType( tr( "Text, variable length large object (clob)" ), "clob", QVariant::String, 1, 2147483647 ) + //DBCLOB is for 1073741824 double-byte characters, data length should be the same as CLOB (2147483647)? + << QgsVectorDataProvider::NativeType( tr( "Text, variable length large object (dbclob)" ), "dbclob", QVariant::String, 1, 1073741824 ) + ); } QgsDb2Provider::~QgsDb2Provider() diff --git a/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp b/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp index 275952c8ce9..ed3714aeecb 100644 --- a/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp +++ b/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp @@ -83,12 +83,12 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( const QString& uri ) { // Add supported types to enable creating expression fields in field calculator - mNativeTypes - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 0, 10 ) - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64 bit)" ), "int8", QVariant::LongLong ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 ) - ; + setNativeTypes( QList< NativeType >() + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 0, 10 ) + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64 bit)" ), "int8", QVariant::LongLong ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 ) + ); QgsDebugMsg( "Delimited text file uri is " + uri ); @@ -1076,7 +1076,7 @@ bool QgsDelimitedTextProvider::setSubsetString( const QString& subset, bool upda } } - mCacheMinMaxDirty = true; + clearMinMaxCache(); emit dataChanged(); return valid; } diff --git a/src/providers/gpx/qgsgpxprovider.cpp b/src/providers/gpx/qgsgpxprovider.cpp index 760c260d2b1..1cffb9b8f3e 100644 --- a/src/providers/gpx/qgsgpxprovider.cpp +++ b/src/providers/gpx/qgsgpxprovider.cpp @@ -74,7 +74,7 @@ QgsGPXProvider::QgsGPXProvider( const QString& uri ) , mValid( false ) // assume that it won't work { // we always use UTF-8 - mEncoding = QTextCodec::codecForName( "utf8" ); + setEncoding( "utf8" ); // get the file name and the type parameter from the URI int fileNameEnd = uri.indexOf( '?' ); diff --git a/src/providers/grass/qgsgrassfeatureiterator.cpp b/src/providers/grass/qgsgrassfeatureiterator.cpp index 3353f3a85d1..7f58a31d84b 100644 --- a/src/providers/grass/qgsgrassfeatureiterator.cpp +++ b/src/providers/grass/qgsgrassfeatureiterator.cpp @@ -757,7 +757,7 @@ QgsGrassFeatureSource::QgsGrassFeatureSource( const QgsGrassProvider* p ) , mGrassType( p->mGrassType ) , mQgisType( p->mQgisType ) , mFields( p->fields() ) - , mEncoding( p->mEncoding ) + , mEncoding( p->textEncoding() ) , mEditing( p->mEditBuffer ) { Q_ASSERT( mLayer ); diff --git a/src/providers/grass/qgsgrassprovider.cpp b/src/providers/grass/qgsgrassprovider.cpp index a8ada401b1d..3865d6bcb22 100644 --- a/src/providers/grass/qgsgrassprovider.cpp +++ b/src/providers/grass/qgsgrassprovider.cpp @@ -261,16 +261,17 @@ QgsGrassProvider::QgsGrassProvider( QString uri ) connect( mLayer->map(), SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); // TODO: types according to database - mNativeTypes - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) + setNativeTypes( QList() + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) #if GRASS_VERSION_MAJOR < 7 - << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), "varchar", QVariant::String, 1, 255, -1, -1 ); + << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), "varchar", QVariant::String, 1, 255, -1, -1 ) #else - << QgsVectorDataProvider::NativeType( tr( "Text" ), "text", QVariant::String ); + << QgsVectorDataProvider::NativeType( tr( "Text" ), "text", QVariant::String ) #endif - // TODO: - // << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, 8, 8 ); + // TODO: + // << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, 8, 8 ); + ); mValid = true; @@ -1020,7 +1021,7 @@ QgsAttributeMap *QgsGrassProvider::attributes( int field, int cat ) dbColumn *column = db_get_table_column( databaseTable, i ); db_convert_column_value_to_string( column, &dbstr ); - QString v = mEncoding->toUnicode( db_get_string( &dbstr ) ); + QString v = textEncoding()->toUnicode( db_get_string( &dbstr ) ); QgsDebugMsg( QString( "Value: %1" ).arg( v ) ); att->insert( i, QVariant( v ) ); } diff --git a/src/providers/memory/qgsmemoryprovider.cpp b/src/providers/memory/qgsmemoryprovider.cpp index 3bb74fd2ee2..88c13aa9f28 100644 --- a/src/providers/memory/qgsmemoryprovider.cpp +++ b/src/providers/memory/qgsmemoryprovider.cpp @@ -64,36 +64,36 @@ QgsMemoryProvider::QgsMemoryProvider( const QString& uri ) mNextFeatureId = 1; - mNativeTypes - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 0, 10 ) - // Decimal number from OGR/Shapefile/dbf may come with length up to 32 and - // precision up to length-2 = 30 (default, if width is not specified in dbf is length = 24 precision = 15) - // We know that double (QVariant::Double) has only 15-16 significant numbers, - // but setting that correct limits would disable the use of memory provider with - // data from Shapefiles. In any case, the data are handled as doubles. - // So the limits set here are not correct but enable use of data from Shapefiles. - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 0, 32, 0, 30 ) - << QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 0, 255 ) + setNativeTypes( QList< NativeType >() + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 0, 10 ) + // Decimal number from OGR/Shapefile/dbf may come with length up to 32 and + // precision up to length-2 = 30 (default, if width is not specified in dbf is length = 24 precision = 15) + // We know that double (QVariant::Double) has only 15-16 significant numbers, + // but setting that correct limits would disable the use of memory provider with + // data from Shapefiles. In any case, the data are handled as doubles. + // So the limits set here are not correct but enable use of data from Shapefiles. + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 0, 32, 0, 30 ) + << QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 0, 255 ) - // date type - << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime, -1, -1, -1, -1 ) + // date type + << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime, -1, -1, -1, -1 ) - // integer types - << QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), "int2", QVariant::Int, -1, -1, 0, 0 ) - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 32bit)" ), "int4", QVariant::Int, -1, -1, 0, 0 ) - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64bit)" ), "int8", QVariant::LongLong, -1, -1, 0, 0 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 20, 0, 20 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 20, 0, 20 ) + // integer types + << QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), "int2", QVariant::Int, -1, -1, 0, 0 ) + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 32bit)" ), "int4", QVariant::Int, -1, -1, 0, 0 ) + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64bit)" ), "int8", QVariant::LongLong, -1, -1, 0, 0 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 20, 0, 20 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 20, 0, 20 ) - // floating point - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) + // floating point + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) - // string types - << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 ) - ; + // string types + << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 ) + ); if ( url.hasQueryItem( "field" ) ) { @@ -477,7 +477,7 @@ bool QgsMemoryProvider::setSubsetString( const QString& theSQL, bool updateFeatu } mSubsetString = theSQL; - mCacheMinMaxDirty = true; + clearMinMaxCache(); emit dataChanged(); return true; diff --git a/src/providers/mssql/qgsmssqlprovider.cpp b/src/providers/mssql/qgsmssqlprovider.cpp index f84bfbf382d..4e3f76ca158 100644 --- a/src/providers/mssql/qgsmssqlprovider.cpp +++ b/src/providers/mssql/qgsmssqlprovider.cpp @@ -147,32 +147,32 @@ QgsMssqlProvider::QgsMssqlProvider( const QString& uri ) } //fill type names into sets - mNativeTypes - // integer types - << QgsVectorDataProvider::NativeType( tr( "8 Bytes integer" ), "bigint", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "4 Bytes integer" ), "int", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "2 Bytes integer" ), "smallint", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "1 Bytes integer" ), "tinyint", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 20, 0, 20 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 20, 0, 20 ) + setNativeTypes( QList() + // integer types + << QgsVectorDataProvider::NativeType( tr( "8 Bytes integer" ), "bigint", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "4 Bytes integer" ), "int", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "2 Bytes integer" ), "smallint", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "1 Bytes integer" ), "tinyint", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 20, 0, 20 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 20, 0, 20 ) - // floating point - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "float", QVariant::Double ) + // floating point + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "float", QVariant::Double ) - // date/time types - << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime, -1, -1, -1, -1 ) + // date/time types + << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime, -1, -1, -1, -1 ) - // string types - << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "char", QVariant::String, 1, 255 ) - << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), "varchar", QVariant::String, 1, 255 ) - << QgsVectorDataProvider::NativeType( tr( "Text, fixed length unicode (nchar)" ), "nchar", QVariant::String, 1, 255 ) - << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length unicode (nvarchar)" ), "nvarchar", QVariant::String, 1, 255 ) - << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String ) - << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length unicode (ntext)" ), "text", QVariant::String ) - ; + // string types + << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "char", QVariant::String, 1, 255 ) + << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), "varchar", QVariant::String, 1, 255 ) + << QgsVectorDataProvider::NativeType( tr( "Text, fixed length unicode (nchar)" ), "nchar", QVariant::String, 1, 255 ) + << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length unicode (nvarchar)" ), "nvarchar", QVariant::String, 1, 255 ) + << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String ) + << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length unicode (ntext)" ), "text", QVariant::String ) + ); } QgsMssqlProvider::~QgsMssqlProvider() diff --git a/src/providers/ogr/qgsogrfeatureiterator.cpp b/src/providers/ogr/qgsogrfeatureiterator.cpp index 5e31dab1f62..646f4aff795 100644 --- a/src/providers/ogr/qgsogrfeatureiterator.cpp +++ b/src/providers/ogr/qgsogrfeatureiterator.cpp @@ -358,7 +358,7 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider* p ) mLayerName = p->layerName(); mLayerIndex = p->layerIndex(); mSubsetString = p->mSubsetString; - mEncoding = p->mEncoding; // no copying - this is a borrowed pointer from Qt + mEncoding = p->textEncoding(); // no copying - this is a borrowed pointer from Qt mFields = p->mAttributeFields; for ( int i = ( p->mFirstFieldIsFid ) ? 1 : 0; i < mFields.size(); i++ ) mFieldsWithoutFid.append( mFields.at( i ) ); diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index d3893666d49..661592ddeff 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -372,22 +372,24 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri ) open( OpenModeInitial ); - mNativeTypes - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 1, 10 ) + setNativeTypes( QList() + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 1, 10 ) #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2000000 - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer 64 bit)" ), "integer64", QVariant::LongLong, 1, 10 ) + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer 64 bit)" ), "integer64", QVariant::LongLong, 1, 10 ) #endif - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 1, 20, 0, 15 ) - << QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 1, 255 ) - << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, 8, 8 ); + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 1, 20, 0, 15 ) + << QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 1, 255 ) + << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, 8, 8 ) + ); // Some drivers do not support datetime type // Please help to fill this list if ( ogrDriverName != "ESRI Shapefile" ) { - mNativeTypes - << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime ); + setNativeTypes( QList() + << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime ) + ); } QgsOgrConnPool::instance()->ref( dataSourceUri() ); @@ -866,7 +868,7 @@ void QgsOgrProvider::loadFields() #ifdef ANDROID QString name = OGR_Fld_GetNameRef( fldDef ); #else - QString name = mEncoding->toUnicode( OGR_Fld_GetNameRef( fldDef ) ); + QString name = textEncoding()->toUnicode( OGR_Fld_GetNameRef( fldDef ) ); #endif if ( mAttributeFields.indexFromName( name ) != -1 ) @@ -893,7 +895,7 @@ void QgsOgrProvider::loadFields() #ifdef ANDROID OGR_GetFieldTypeName( ogrType ), #else - mEncoding->toUnicode( OGR_GetFieldTypeName( ogrType ) ), + textEncoding()->toUnicode( OGR_GetFieldTypeName( ogrType ) ), #endif width, prec ) @@ -1229,8 +1231,8 @@ bool QgsOgrProvider::addFeature( QgsFeature& f ) QgsDebugMsg( QString( "Writing string attribute %1 with %2, encoding %3" ) .arg( qgisAttId ) .arg( attrVal.toString(), - mEncoding->name().constData() ) ); - OGR_F_SetFieldString( feature, ogrAttId, mEncoding->fromUnicode( attrVal.toString() ).constData() ); + textEncoding()->name().data() ) ); + OGR_F_SetFieldString( feature, ogrAttId, textEncoding()->fromUnicode( attrVal.toString() ).constData() ); break; default: @@ -1353,7 +1355,7 @@ bool QgsOgrProvider::addAttributes( const QList &attributes ) continue; } - OGRFieldDefnH fielddefn = OGR_Fld_Create( mEncoding->fromUnicode( iter->name() ).constData(), type ); + OGRFieldDefnH fielddefn = OGR_Fld_Create( textEncoding()->fromUnicode( iter->name() ).constData(), type ); int width = iter->length(); if ( iter->precision() ) width += 1; @@ -1458,7 +1460,7 @@ bool QgsOgrProvider::renameAttributes( const QgsFieldNameMap& renamedAttributes } //type does not matter, it will not be used - OGRFieldDefnH fld = OGR_Fld_Create( mEncoding->fromUnicode( renameIt.value() ), OFTReal ); + OGRFieldDefnH fld = OGR_Fld_Create( textEncoding()->fromUnicode( renameIt.value() ), OFTReal ); if ( OGR_L_AlterFieldDefn( ogrLayer, ogrFieldIndex, fld, ALTER_NAME_FLAG ) != OGRERR_NONE ) { pushError( tr( "OGR error renaming field %1: %2" ).arg( fieldIndex ).arg( CPLGetLastErrorMsg() ) ); @@ -1586,7 +1588,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_ 0 ); break; case OFTString: - OGR_F_SetFieldString( of, f, mEncoding->fromUnicode( it2->toString() ).constData() ); + OGR_F_SetFieldString( of, f, textEncoding()->fromUnicode( it2->toString() ).constData() ); break; default: pushError( tr( "Type %1 of attribute %2 of feature %3 unknown." ).arg( type ).arg( fid ).arg( f ) ); @@ -1720,7 +1722,7 @@ bool QgsOgrProvider::createAttributeIndex( int field ) QByteArray quotedLayerName = quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) ) ); QByteArray dropSql = "DROP INDEX ON " + quotedLayerName; OGR_DS_ExecuteSQL( ogrDataSource, dropSql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), nullptr ); - QByteArray createSql = "CREATE INDEX ON " + quotedLayerName + " USING " + mEncoding->fromUnicode( fields().at( field ).name() ); + QByteArray createSql = "CREATE INDEX ON " + quotedLayerName + " USING " + textEncoding()->fromUnicode( fields().at( field ).name() ); OGR_DS_ExecuteSQL( ogrDataSource, createSql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), nullptr ); QFileInfo fi( mFilePath ); // to get the base name @@ -2792,17 +2794,17 @@ void QgsOgrProvider::uniqueValues( int index, QList &uniqueValues, int // avoid GDAL #4509 return QgsVectorDataProvider::uniqueValues( index, uniqueValues, limit ); #else - QByteArray sql = "SELECT DISTINCT " + quotedIdentifier( mEncoding->fromUnicode( fld.name() ) ); + QByteArray sql = "SELECT DISTINCT " + quotedIdentifier( textEncoding()->fromUnicode( fld.name() ) ); sql += " FROM " + quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrLayer ) ) ); if ( !mSubsetString.isEmpty() ) { - sql += " WHERE " + mEncoding->fromUnicode( mSubsetString ); + sql += " WHERE " + textEncoding()->fromUnicode( mSubsetString ); } - sql += " ORDER BY " + mEncoding->fromUnicode( fld.name() ) + " ASC"; // quoting of fieldname produces a syntax error + sql += " ORDER BY " + textEncoding()->fromUnicode( fld.name() ) + " ASC"; // quoting of fieldname produces a syntax error - QgsDebugMsg( QString( "SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) ); + QgsDebugMsg( QString( "SQL: %1" ).arg( textEncoding()->toUnicode( sql ) ) ); OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, nullptr ); if ( !l ) { @@ -2813,7 +2815,7 @@ void QgsOgrProvider::uniqueValues( int index, QList &uniqueValues, int OGRFeatureH f; while (( f = OGR_L_GetNextFeature( l ) ) ) { - uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) ); + uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) ); OGR_F_Destroy( f ); if ( limit >= 0 && uniqueValues.size() >= limit ) @@ -2833,18 +2835,18 @@ QVariant QgsOgrProvider::minimumValue( int index ) const QgsField fld = mAttributeFields.at( index ); // Don't quote column name (see https://trac.osgeo.org/gdal/ticket/5799#comment:9) - QByteArray sql = "SELECT MIN(" + mEncoding->fromUnicode( fld.name() ); + QByteArray sql = "SELECT MIN(" + textEncoding()->fromUnicode( fld.name() ); sql += ") FROM " + quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrLayer ) ) ); if ( !mSubsetString.isEmpty() ) { - sql += " WHERE " + mEncoding->fromUnicode( mSubsetString ); + sql += " WHERE " + textEncoding()->fromUnicode( mSubsetString ); } OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, nullptr ); if ( !l ) { - QgsDebugMsg( QString( "Failed to execute SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) ); + QgsDebugMsg( QString( "Failed to execute SQL: %1" ).arg( textEncoding()->toUnicode( sql ) ) ); return QgsVectorDataProvider::minimumValue( index ); } @@ -2855,7 +2857,7 @@ QVariant QgsOgrProvider::minimumValue( int index ) const return QVariant(); } - QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ); + QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ); OGR_F_Destroy( f ); OGR_DS_ReleaseResultSet( ogrDataSource, l ); @@ -2872,18 +2874,18 @@ QVariant QgsOgrProvider::maximumValue( int index ) const QgsField fld = mAttributeFields.at( index ); // Don't quote column name (see https://trac.osgeo.org/gdal/ticket/5799#comment:9) - QByteArray sql = "SELECT MAX(" + mEncoding->fromUnicode( fld.name() ); + QByteArray sql = "SELECT MAX(" + textEncoding()->fromUnicode( fld.name() ); sql += ") FROM " + quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrLayer ) ) ); if ( !mSubsetString.isEmpty() ) { - sql += " WHERE " + mEncoding->fromUnicode( mSubsetString ); + sql += " WHERE " + textEncoding()->fromUnicode( mSubsetString ); } OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, nullptr ); if ( !l ) { - QgsDebugMsg( QString( "Failed to execute SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) ); + QgsDebugMsg( QString( "Failed to execute SQL: %1" ).arg( textEncoding()->toUnicode( sql ) ) ); return QgsVectorDataProvider::maximumValue( index ); } @@ -2894,7 +2896,7 @@ QVariant QgsOgrProvider::maximumValue( int index ) const return QVariant(); } - QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ); + QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), textEncoding()->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ); OGR_F_Destroy( f ); OGR_DS_ReleaseResultSet( ogrDataSource, l ); @@ -3230,7 +3232,7 @@ OGRwkbGeometryType QgsOgrProvider::ogrWkbSingleFlatten( OGRwkbGeometryType type OGRLayerH QgsOgrProvider::setSubsetString( OGRLayerH layer, OGRDataSourceH ds ) { - return QgsOgrProviderUtils::setSubsetString( layer, ds, mEncoding, mSubsetString ); + return QgsOgrProviderUtils::setSubsetString( layer, ds, textEncoding(), mSubsetString ); } OGRLayerH QgsOgrProviderUtils::setSubsetString( OGRLayerH layer, OGRDataSourceH ds, QTextCodec* encoding, const QString& subsetString ) diff --git a/src/providers/ogr/qgsogrprovider.h b/src/providers/ogr/qgsogrprovider.h index 9d8c2f6aa87..1c527904575 100644 --- a/src/providers/ogr/qgsogrprovider.h +++ b/src/providers/ogr/qgsogrprovider.h @@ -250,8 +250,6 @@ class QgsOgrProvider : public QgsVectorDataProvider int layerIndex() const { return mLayerIndex; } - QTextCodec* textEncoding() { return mEncoding; } - QByteArray quotedIdentifier( QByteArray field ) const; /** diff --git a/src/providers/oracle/qgsoracleprovider.cpp b/src/providers/oracle/qgsoracleprovider.cpp index 7f1d6ffda42..3f27aa5bef7 100644 --- a/src/providers/oracle/qgsoracleprovider.cpp +++ b/src/providers/oracle/qgsoracleprovider.cpp @@ -142,26 +142,26 @@ QgsOracleProvider::QgsOracleProvider( QString const & uri ) } //fill type names into sets - mNativeTypes - // integer types - << QgsVectorDataProvider::NativeType( tr( "Whole number" ), "number(10,0)", QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "Whole big number" ), "number(20,0)", QVariant::LongLong ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "number", QVariant::Double, 1, 38, 0, 38 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "double precision", QVariant::Double ) + setNativeTypes( QList() + // integer types + << QgsVectorDataProvider::NativeType( tr( "Whole number" ), "number(10,0)", QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "Whole big number" ), "number(20,0)", QVariant::LongLong ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "number", QVariant::Double, 1, 38, 0, 38 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "double precision", QVariant::Double ) - // floating point - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "binary_float", QVariant::Double ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "binary_double", QVariant::Double ) + // floating point + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "binary_float", QVariant::Double ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "binary_double", QVariant::Double ) - // string types - << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "CHAR", QVariant::String, 1, 255 ) - << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar2)" ), "VARCHAR2", QVariant::String, 1, 255 ) - << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (long)" ), "LONG", QVariant::String ) + // string types + << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "CHAR", QVariant::String, 1, 255 ) + << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar2)" ), "VARCHAR2", QVariant::String, 1, 255 ) + << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (long)" ), "LONG", QVariant::String ) - // date type - << QgsVectorDataProvider::NativeType( tr( "Date" ), "DATE", QVariant::Date, 38, 38, 0, 0 ) - << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "TIMESTAMP(6)", QVariant::DateTime, 38, 38, 6, 6 ) - ; + // date type + << QgsVectorDataProvider::NativeType( tr( "Date" ), "DATE", QVariant::Date, 38, 38, 0, 0 ) + << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "TIMESTAMP(6)", QVariant::DateTime, 38, 38, 6, 6 ) + ); QString key; switch ( mPrimaryKeyType ) diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index b304a36bb38..350d5050fc9 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -198,35 +198,35 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri ) #endif //fill type names into sets - mNativeTypes - // integer types - << QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), "int2", QVariant::Int, -1, -1, 0, 0 ) - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 32bit)" ), "int4", QVariant::Int, -1, -1, 0, 0 ) - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64bit)" ), "int8", QVariant::LongLong, -1, -1, 0, 0 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 20, 0, 20 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 20, 0, 20 ) + setNativeTypes( QList() + // integer types + << QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), "int2", QVariant::Int, -1, -1, 0, 0 ) + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 32bit)" ), "int4", QVariant::Int, -1, -1, 0, 0 ) + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64bit)" ), "int8", QVariant::LongLong, -1, -1, 0, 0 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 20, 0, 20 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 20, 0, 20 ) - // floating point - << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) + // floating point + << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) - // string types - << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "char", QVariant::String, 1, 255, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), "varchar", QVariant::String, 1, 255, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 ) + // string types + << QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), "char", QVariant::String, 1, 255, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), "varchar", QVariant::String, 1, 255, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 ) - // date type - << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) - << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "timestamp without time zone", QVariant::DateTime, -1, -1, -1, -1 ) + // date type + << QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Time" ), "time", QVariant::Time, -1, -1, -1, -1 ) + << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "timestamp without time zone", QVariant::DateTime, -1, -1, -1, -1 ) - // complex types - << QgsVectorDataProvider::NativeType( tr( "Map" ), "hstore", QVariant::Map, -1, -1, -1, -1, QVariant::String ) - << QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 32bit)" ), "int4[]", QVariant::List, -1, -1, -1, -1, QVariant::Int ) - << QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 64bit)" ), "int8[]", QVariant::List, -1, -1, -1, -1, QVariant::LongLong ) - << QgsVectorDataProvider::NativeType( tr( "Array of number (double)" ), "double precision[]", QVariant::List, -1, -1, -1, -1, QVariant::Double ) - << QgsVectorDataProvider::NativeType( tr( "Array of text" ), "text[]", QVariant::StringList, -1, -1, -1, -1, QVariant::String ) - ; + // complex types + << QgsVectorDataProvider::NativeType( tr( "Map" ), "hstore", QVariant::Map, -1, -1, -1, -1, QVariant::String ) + << QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 32bit)" ), "int4[]", QVariant::List, -1, -1, -1, -1, QVariant::Int ) + << QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 64bit)" ), "int8[]", QVariant::List, -1, -1, -1, -1, QVariant::LongLong ) + << QgsVectorDataProvider::NativeType( tr( "Array of number (double)" ), "double precision[]", QVariant::List, -1, -1, -1, -1, QVariant::Double ) + << QgsVectorDataProvider::NativeType( tr( "Array of text" ), "text[]", QVariant::StringList, -1, -1, -1, -1, QVariant::String ) + ); QString key; switch ( mPrimaryKeyType ) @@ -4036,6 +4036,11 @@ QList QgsPostgresProvider::discoverRelations( const QgsVectorLayer* return result; } +QgsAttrPalIndexNameHash QgsPostgresProvider::palAttributeIndexNames() const +{ + return mAttrPalIndexName; +} + /** * Class factory to return a pointer to a newly created * QgsPostgresProvider object diff --git a/src/providers/postgres/qgspostgresprovider.h b/src/providers/postgres/qgspostgresprovider.h index c728973c90d..d1c46c808da 100644 --- a/src/providers/postgres/qgspostgresprovider.h +++ b/src/providers/postgres/qgspostgresprovider.h @@ -270,6 +270,11 @@ class QgsPostgresProvider : public QgsVectorDataProvider virtual QList discoverRelations( const QgsVectorLayer* self, const QList& layers ) const override; + /** + * Return list of indexes to names for QgsPalLabeling fix + */ + virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const override; + signals: /** * This is emitted whenever the worker thread has fully calculated the @@ -357,6 +362,9 @@ class QgsPostgresProvider : public QgsVectorDataProvider */ static QList searchLayers( const QList& layers, const QString& connectionInfo, const QString& schema, const QString& tableName ); + /** Old-style mapping of index to name for QgsPalLabeling fix */ + QgsAttrPalIndexNameHash mAttrPalIndexName; + QgsFields mAttributeFields; QString mDataComment; diff --git a/src/providers/spatialite/qgsspatialiteprovider.cpp b/src/providers/spatialite/qgsspatialiteprovider.cpp index e5e6622f718..ef7a49dd5d0 100644 --- a/src/providers/spatialite/qgsspatialiteprovider.cpp +++ b/src/providers/spatialite/qgsspatialiteprovider.cpp @@ -604,16 +604,16 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri ) spatialiteVersion(); //fill type names into sets - mNativeTypes - << QgsVectorDataProvider::NativeType( tr( "Binary object (BLOB)" ), "BLOB", QVariant::ByteArray ) - << QgsVectorDataProvider::NativeType( tr( "Text" ), "TEXT", QVariant::String ) - << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "FLOAT", QVariant::Double ) - << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "INTEGER", QVariant::LongLong ) + setNativeTypes( QList() + << QgsVectorDataProvider::NativeType( tr( "Binary object (BLOB)" ), "BLOB", QVariant::ByteArray ) + << QgsVectorDataProvider::NativeType( tr( "Text" ), "TEXT", QVariant::String ) + << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "FLOAT", QVariant::Double ) + << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "INTEGER", QVariant::LongLong ) - << QgsVectorDataProvider::NativeType( tr( "Array of text" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "TEXT" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::StringList, 0, 0, 0, 0, QVariant::String ) - << QgsVectorDataProvider::NativeType( tr( "Array of decimal numbers (double)" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "REAL" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::List, 0, 0, 0, 0, QVariant::Double ) - << QgsVectorDataProvider::NativeType( tr( "Array of whole numbers (integer)" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "INTEGER" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::List, 0, 0, 0, 0, QVariant::LongLong ) - ; + << QgsVectorDataProvider::NativeType( tr( "Array of text" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "TEXT" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::StringList, 0, 0, 0, 0, QVariant::String ) + << QgsVectorDataProvider::NativeType( tr( "Array of decimal numbers (double)" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "REAL" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::List, 0, 0, 0, 0, QVariant::Double ) + << QgsVectorDataProvider::NativeType( tr( "Array of whole numbers (integer)" ), SPATIALITE_ARRAY_PREFIX.toUpper() + "INTEGER" + SPATIALITE_ARRAY_SUFFIX.toUpper(), QVariant::List, 0, 0, 0, 0, QVariant::LongLong ) + ); mValid = true; } diff --git a/src/providers/virtual/qgsvirtuallayerprovider.cpp b/src/providers/virtual/qgsvirtuallayerprovider.cpp index 85bd4edfc38..015e4b5f556 100644 --- a/src/providers/virtual/qgsvirtuallayerprovider.cpp +++ b/src/providers/virtual/qgsvirtuallayerprovider.cpp @@ -494,7 +494,7 @@ QString QgsVirtualLayerProvider::subsetString() const bool QgsVirtualLayerProvider::setSubsetString( const QString& subset, bool updateFeatureCount ) { mSubset = subset; - mCacheMinMaxDirty = true; + clearMinMaxCache(); if ( updateFeatureCount ) updateStatistics(); return true; diff --git a/src/providers/wfs/qgswfsprovider.cpp b/src/providers/wfs/qgswfsprovider.cpp index 24810e5183d..2f79a5ecc6b 100644 --- a/src/providers/wfs/qgswfsprovider.cpp +++ b/src/providers/wfs/qgswfsprovider.cpp @@ -666,7 +666,7 @@ bool QgsWFSProvider::setSubsetString( const QString& theSQL, bool updateFeatureC mShared->invalidateCache(); mSubsetString = theSQL; - mCacheMinMaxDirty = true; + clearMinMaxCache(); // update URI mShared->mFields = mThisTypenameFields;