Skip to content
Permalink
Browse files

Merge pull request #33259 from signedav/reload_provider

reloadData / forceReload on data providers
  • Loading branch information
m-kuhn committed Jan 9, 2020
2 parents 7240052 + dd0cc93 commit 3a3b430825ed7864d6a05e71140a857556691a42
@@ -265,8 +265,10 @@ databases and servers.

virtual void reloadData();
%Docstring
Reloads the data from the source. Needs to be implemented by providers with data caches to
synchronize with changes in the data source
Reloads the data from the source by calling reloadProviderData() implemented
by providers with data caches to synchronize, changes in the data source, feature
counts and other specific actions.
Emits the `dataChanged` signal
%End

virtual QDateTime timestamp() const;
@@ -546,13 +546,11 @@ providers will return ``None``.
Returns the transaction this data provider is included in, if any.
%End

virtual void forceReload();
virtual void forceReload() /Deprecated/;
%Docstring
Forces a reload of the underlying datasource if the provider implements this
method.
In particular on the OGR provider, a pooled connection will be invalidated.
This forces QGIS to reopen a file or connection.
This can be required if the underlying file is replaced.

.. deprecated::
QGIS 3.12 - will be removed in QGIS 4.0 - use reloadData instead
%End

virtual QSet<QgsMapLayerDependency> dependencies() const;
@@ -573,7 +573,7 @@ void QgsAttributeTableDialog::mActionSaveEdits_triggered()

void QgsAttributeTableDialog::mActionReload_triggered()
{
mMainView->masterModel()->layer()->dataProvider()->forceReload();
mMainView->masterModel()->layer()->dataProvider()->reloadData();
}

void QgsAttributeTableDialog::mActionAddFeature_triggered()
@@ -522,7 +522,7 @@ void QgsGdalProvider::closeDataset()
closeCachedGdalHandlesFor( this );
}

void QgsGdalProvider::reloadData()
void QgsGdalProvider::reloadProviderData()
{
QMutexLocker locker( mpMutex );
closeDataset();
@@ -199,8 +199,6 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
bool setNoDataValue( int bandNo, double noDataValue ) override;
bool remove() override;

void reloadData() override;

QString validateCreationOptions( const QStringList &createOptions, const QString &format ) override;
QString validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
const QStringList &configOptions, const QString &fileFormat ) override;
@@ -335,6 +333,11 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
bool worldToPixel( double x, double y, int &col, int &row ) const;

bool mStatisticsAreReliable = false;

/**
* Closes and reinits dataset
*/
void reloadProviderData() override;
};

/**
@@ -3919,11 +3919,6 @@ QByteArray QgsOgrProvider::quotedIdentifier( const QByteArray &field ) const
return QgsOgrProviderUtils::quotedIdentifier( field, mGDALDriverName );
}

void QgsOgrProvider::forceReload()
{
QgsOgrConnPool::instance()->invalidateConnections( QgsOgrProviderUtils::connectionPoolId( dataSourceUri( true ), mShareSameDatasetAmongLayers ) );
}

QString QgsOgrProviderUtils::connectionPoolId( const QString &dataSourceURI, bool shareSameDatasetAmongLayers )
{
if ( shareSameDatasetAmongLayers )
@@ -4598,11 +4593,11 @@ void QgsOgrProvider::close()
invalidateCachedExtent( false );
}

void QgsOgrProvider::reloadData()
void QgsOgrProvider::reloadProviderData()
{
mFeaturesCounted = QgsVectorDataProvider::Uncounted;
bool wasValid = mValid;
forceReload();
QgsOgrConnPool::instance()->invalidateConnections( QgsOgrProviderUtils::connectionPoolId( dataSourceUri( true ), mShareSameDatasetAmongLayers ) );
close();
open( OpenModeSameAsCurrent );
if ( !mValid && wasValid )
@@ -165,14 +165,6 @@ class QgsOgrProvider : public QgsVectorDataProvider

QByteArray quotedIdentifier( const QByteArray &field ) const;

/**
* A forced reload invalidates the underlying connection.
* E.g. in case a shapefile is replaced, the old file will be closed
* and the new file will be opened.
*/
void forceReload() override;
void reloadData() override;

protected:
//! Loads fields from input file to member attributeFields
void loadFields();
@@ -335,6 +327,13 @@ class QgsOgrProvider : public QgsVectorDataProvider
QgsOgrTransaction *mTransaction = nullptr;

void setTransaction( QgsTransaction *transaction ) override;

/**
* Invalidates and reopens the file and resets the feature count
* E.g. in case a shapefile is replaced, the old file will be closed
* and the new file will be opened.
*/
void reloadProviderData() override;
};

class QgsOgrDataset;
@@ -24,6 +24,12 @@ QgsDataProvider::QgsDataProvider( const QString &uri, const QgsDataProvider::Pro
{
}

void QgsDataProvider::reloadData()
{
reloadProviderData();
emit dataChanged();
}

void QgsDataProvider::setProviderProperty( QgsDataProvider::ProviderProperty property, const QVariant &value )
{
mProviderProperties.insert( property, value );
@@ -356,10 +356,12 @@ class CORE_EXPORT QgsDataProvider : public QObject
}

/**
* Reloads the data from the source. Needs to be implemented by providers with data caches to
* synchronize with changes in the data source
* Reloads the data from the source by calling reloadProviderData() implemented
* by providers with data caches to synchronize, changes in the data source, feature
* counts and other specific actions.
* Emits the `dataChanged` signal
*/
virtual void reloadData() {}
virtual void reloadData();

//! Time stamp of data source in the moment when data/metadata were loaded by provider
virtual QDateTime timestamp() const { return mTimestamp; }
@@ -614,6 +616,11 @@ class CORE_EXPORT QgsDataProvider : public QObject
*/
mutable QMutex mOptionsMutex;

/**
* Reloads the data according to the provider
* \since QGIS 3.12
*/
virtual void reloadProviderData() {}
};


@@ -596,11 +596,6 @@ 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();
@@ -549,13 +549,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
virtual QgsTransaction *transaction() const;

/**
* Forces a reload of the underlying datasource if the provider implements this
* method.
* In particular on the OGR provider, a pooled connection will be invalidated.
* This forces QGIS to reopen a file or connection.
* This can be required if the underlying file is replaced.
* \deprecated QGIS 3.12 - will be removed in QGIS 4.0 - use reloadData instead
*/
virtual void forceReload();
Q_DECL_DEPRECATED virtual void forceReload() SIP_DEPRECATED { reloadData(); }

/**
* Gets the list of layer ids on which this layer depends. This in particular determines the order of layer loading.
@@ -685,7 +681,6 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
* Includes this data provider in the specified transaction. Ownership of transaction is not transferred.
*/
virtual void setTransaction( QgsTransaction * /*transaction*/ ) {}

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorDataProvider::Capabilities )
@@ -328,7 +328,7 @@ QString QgsAfsProvider::dataComment() const
return mLayerDescription;
}

void QgsAfsProvider::reloadData()
void QgsAfsProvider::reloadProviderData()
{
mSharedData->clearCache();
}
@@ -74,7 +74,6 @@ class QgsAfsProvider : public QgsVectorDataProvider
QString name() const override;
QString description() const override;
QString dataComment() const override;
void reloadData() override;
QgsFeatureRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const override;
QgsAbstractVectorLayerLabeling *createLabeling( const QVariantMap &configuration = QVariantMap() ) const override;
bool renderInPreview( const QgsDataProvider::PreviewContext &context ) override;
@@ -89,6 +88,11 @@ class QgsAfsProvider : public QgsVectorDataProvider
QVariantMap mRendererDataMap;
QVariantList mLabelingDataList;
QgsStringMap mRequestHeaders;

/**
* Clears cache
*/
void reloadProviderData() override;
};

class QgsAfsProviderMetadata: public QgsProviderMetadata
@@ -392,7 +392,7 @@ void QgsAmsProvider::setSubLayerVisibility( const QString &name, bool vis )
}
}

void QgsAmsProvider::reloadData()
void QgsAmsProvider::reloadProviderData()
{
mCachedImage = QImage();
}
@@ -85,7 +85,6 @@ class QgsAmsProvider : public QgsRasterDataProvider
QStringList subLayerStyles() const override;
void setLayerOrder( const QStringList &layers ) override;
void setSubLayerVisibility( const QString &name, bool vis ) override;
void reloadData() override;
bool renderInPreview( const QgsDataProvider::PreviewContext &context ) override;
QgsLayerMetadata layerMetadata() const override;

@@ -158,6 +157,11 @@ class QgsAmsProvider : public QgsRasterDataProvider
int mMaxImageHeight = 4096;
QgsLayerMetadata mLayerMetadata;
QList< double > mResolutions;

/**
* Resets cached image
*/
void reloadProviderData() override;
};

//! Handler for tiled MapServer requests, the data are written to the given image
@@ -275,7 +275,7 @@ void QgsMdalProvider::loadData()
}
}

void QgsMdalProvider::reloadData()
void QgsMdalProvider::reloadProviderData()
{
if ( mMeshH )
MDAL_CloseMesh( mMeshH );
@@ -83,8 +83,6 @@ class QgsMdalProvider : public QgsMeshDataProvider
const QVector<double> &times
) override;

void reloadData() override;

/**
* Returns file filters for meshes and datasets to be used in Open File Dialogs
* \param fileMeshFiltersString file mesh filters
@@ -114,6 +112,11 @@ class QgsMdalProvider : public QgsMeshDataProvider
MeshH mMeshH;
QStringList mExtraDatasetUris;
QgsCoordinateReferenceSystem mCrs;

/**
* Closes and reloads dataset
*/
void reloadProviderData() override;
};

class QgsMdalProviderMetadata: public QgsProviderMetadata
@@ -343,6 +343,13 @@ void QgsPostgresProvider::setListening( bool isListening )
}
}

void QgsPostgresProvider::reloadProviderData()
{
mShared->setFeaturesCounted( -1 );
mLayerExtent.setMinimal();
}


QgsPostgresConn *QgsPostgresProvider::connectionRW()
{
if ( mTransaction )
@@ -3323,11 +3330,13 @@ bool QgsPostgresProvider::setSubsetString( const QString &theSQL, bool updateFea

if ( updateFeatureCount )
{
mShared->setFeaturesCounted( -1 );
reloadData();
}
else
{
mLayerExtent.setMinimal();
emit dataChanged();
}
mLayerExtent.setMinimal();

emit dataChanged();

return true;
}
@@ -240,6 +240,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
*/
void setListening( bool isListening ) override;


private:
Relkind relkind() const;

@@ -325,6 +326,14 @@ class QgsPostgresProvider : public QgsVectorDataProvider
*/
static QList<QgsVectorLayer *> searchLayers( const QList<QgsVectorLayer *> &layers, const QString &connectionInfo, const QString &schema, const QString &tableName );

/**
* Effect a reload including resetting the feature count
* and setting the layer extent to minimal
*
* \since QGIS 3.12
*/
void reloadProviderData() override;

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

@@ -96,7 +96,7 @@ QgsVirtualLayerProvider::QgsVirtualLayerProvider( QString const &uri, const QgsD
}
}

void QgsVirtualLayerProvider::reloadData()
void QgsVirtualLayerProvider::reloadProviderData()
{
if ( mDefinition.sourceLayers().empty() && !mDefinition.filePath().isEmpty() && mDefinition.query().isEmpty() )
{
@@ -60,7 +60,6 @@ class QgsVirtualLayerProvider: public QgsVectorDataProvider
QgsAttributeList pkAttributeIndexes() const override;
QSet<QgsMapLayerDependency> dependencies() const override;
bool cancelReload() override;
void reloadData() override;

private:

@@ -118,6 +117,11 @@ class QgsVirtualLayerProvider: public QgsVectorDataProvider
bool loadSourceLayers();
void createVirtualTable( QgsVectorLayer *vlayer, const QString &name );

/**
* Opens or creates file
*/
void reloadProviderData() override;

friend class QgsVirtualLayerFeatureSource;

private slots:
@@ -1592,7 +1592,7 @@ QString QgsWcsProvider::description() const
return WCS_DESCRIPTION;
}

void QgsWcsProvider::reloadData()
void QgsWcsProvider::reloadProviderData()
{
clearCache();
}

0 comments on commit 3a3b430

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