Skip to content

Commit

Permalink
Implementation of QgsMeshLayer::reload() and QgsMdalProvider::reloadD…
Browse files Browse the repository at this point in the history
…ata()

Implementation of this override method permit to reload mesh end dataset groups when the data changed outside of the QGIS application.
  • Loading branch information
vcloarec authored and PeterPetrik committed May 3, 2019
1 parent 244bb55 commit 109049e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
3 changes: 3 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ QgsMeshLayer cannot be copied.
virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const;


virtual void reload();


QString providerType() const;
%Docstring
Returns the provider type for this layer
Expand Down
21 changes: 21 additions & 0 deletions src/core/mesh/qgsmeshlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,27 @@ bool QgsMeshLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const
return writeSymbology( layer_node, document, errorMsg, context );
}

void QgsMeshLayer::reload()
{
if ( mDataProvider && mDataProvider->isValid() )
{

mDataProvider->reloadData();

//reload the mesh structure
if ( !mNativeMesh )
mNativeMesh.reset( new QgsMesh );

dataProvider()->populateMesh( mNativeMesh.get() );

//clear the TriangularMesh
mTriangularMesh.reset( new QgsTriangularMesh() );

//clear the rendererCache
mRendererCache.reset( new QgsMeshLayerRendererCache() );
}
}

bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options )
{
delete mDataProvider;
Expand Down
2 changes: 2 additions & 0 deletions src/core/mesh/qgsmeshlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;

void reload() override;

//! Returns the provider type for this layer
QString providerType() const;

Expand Down
35 changes: 27 additions & 8 deletions src/providers/mdal/qgsmdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ QgsCoordinateReferenceSystem QgsMdalProvider::crs() const
QgsMdalProvider::QgsMdalProvider( const QString &uri, const ProviderOptions &options )
: QgsMeshDataProvider( uri, options )
{
QByteArray curi = uri.toUtf8();
mMeshH = MDAL_LoadMesh( curi.constData() );
if ( mMeshH )
{
const QString proj = MDAL_M_projection( mMeshH );
if ( !proj.isEmpty() )
mCrs.createFromString( proj );
}
loadData();
}

QgsMdalProvider::~QgsMdalProvider()
Expand Down Expand Up @@ -241,6 +234,32 @@ bool QgsMdalProvider::persistDatasetGroup( const QString &path,
return false;
}

void QgsMdalProvider::loadData()
{
QByteArray curi = dataSourceUri().toUtf8();
mMeshH = MDAL_LoadMesh( curi.constData() );
if ( mMeshH )
{
const QString proj = MDAL_M_projection( mMeshH );
if ( !proj.isEmpty() )
mCrs.createFromString( proj );
}
}

void QgsMdalProvider::reloadData()
{
if ( mMeshH )
MDAL_CloseMesh( mMeshH );

loadData();

if ( mMeshH )
for ( auto uri : mExtraDatasetUris )
{
std::string str = uri.toStdString();
MDAL_M_LoadDatasets( mMeshH, str.c_str() );
}
}

void QgsMdalProvider::fileMeshFilters( QString &fileMeshFiltersString, QString &fileMeshDatasetFiltersString )
{
Expand Down
3 changes: 3 additions & 0 deletions src/providers/mdal/qgsmdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ 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
Expand All @@ -102,6 +104,7 @@ class QgsMdalProvider : public QgsMeshDataProvider
private:
QVector<QgsMeshVertex> vertices( ) const;
QVector<QgsMeshFace> faces( ) const;
void loadData();
MeshH mMeshH;
QStringList mExtraDatasetUris;
QgsCoordinateReferenceSystem mCrs;
Expand Down

0 comments on commit 109049e

Please sign in to comment.