Skip to content

Commit 109049e

Browse files
vcloarecPeterPetrik
authored andcommitted
Implementation of QgsMeshLayer::reload() and QgsMdalProvider::reloadData()
Implementation of this override method permit to reload mesh end dataset groups when the data changed outside of the QGIS application.
1 parent 244bb55 commit 109049e

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

python/core/auto_generated/mesh/qgsmeshlayer.sip.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ QgsMeshLayer cannot be copied.
133133
virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
134134

135135

136+
virtual void reload();
137+
138+
136139
QString providerType() const;
137140
%Docstring
138141
Returns the provider type for this layer

src/core/mesh/qgsmeshlayer.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,27 @@ bool QgsMeshLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const
457457
return writeSymbology( layer_node, document, errorMsg, context );
458458
}
459459

460+
void QgsMeshLayer::reload()
461+
{
462+
if ( mDataProvider && mDataProvider->isValid() )
463+
{
464+
465+
mDataProvider->reloadData();
466+
467+
//reload the mesh structure
468+
if ( !mNativeMesh )
469+
mNativeMesh.reset( new QgsMesh );
470+
471+
dataProvider()->populateMesh( mNativeMesh.get() );
472+
473+
//clear the TriangularMesh
474+
mTriangularMesh.reset( new QgsTriangularMesh() );
475+
476+
//clear the rendererCache
477+
mRendererCache.reset( new QgsMeshLayerRendererCache() );
478+
}
479+
}
480+
460481
bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options )
461482
{
462483
delete mDataProvider;

src/core/mesh/qgsmeshlayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
146146
bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
147147
bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
148148

149+
void reload() override;
150+
149151
//! Returns the provider type for this layer
150152
QString providerType() const;
151153

src/providers/mdal/qgsmdalprovider.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ QgsCoordinateReferenceSystem QgsMdalProvider::crs() const
5454
QgsMdalProvider::QgsMdalProvider( const QString &uri, const ProviderOptions &options )
5555
: QgsMeshDataProvider( uri, options )
5656
{
57-
QByteArray curi = uri.toUtf8();
58-
mMeshH = MDAL_LoadMesh( curi.constData() );
59-
if ( mMeshH )
60-
{
61-
const QString proj = MDAL_M_projection( mMeshH );
62-
if ( !proj.isEmpty() )
63-
mCrs.createFromString( proj );
64-
}
57+
loadData();
6558
}
6659

6760
QgsMdalProvider::~QgsMdalProvider()
@@ -241,6 +234,32 @@ bool QgsMdalProvider::persistDatasetGroup( const QString &path,
241234
return false;
242235
}
243236

237+
void QgsMdalProvider::loadData()
238+
{
239+
QByteArray curi = dataSourceUri().toUtf8();
240+
mMeshH = MDAL_LoadMesh( curi.constData() );
241+
if ( mMeshH )
242+
{
243+
const QString proj = MDAL_M_projection( mMeshH );
244+
if ( !proj.isEmpty() )
245+
mCrs.createFromString( proj );
246+
}
247+
}
248+
249+
void QgsMdalProvider::reloadData()
250+
{
251+
if ( mMeshH )
252+
MDAL_CloseMesh( mMeshH );
253+
254+
loadData();
255+
256+
if ( mMeshH )
257+
for ( auto uri : mExtraDatasetUris )
258+
{
259+
std::string str = uri.toStdString();
260+
MDAL_M_LoadDatasets( mMeshH, str.c_str() );
261+
}
262+
}
244263

245264
void QgsMdalProvider::fileMeshFilters( QString &fileMeshFiltersString, QString &fileMeshDatasetFiltersString )
246265
{

src/providers/mdal/qgsmdalprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class QgsMdalProvider : public QgsMeshDataProvider
7777
const QVector<double> &times
7878
) override;
7979

80+
void reloadData() override;
81+
8082
/**
8183
* Returns file filters for meshes and datasets to be used in Open File Dialogs
8284
* \param fileMeshFiltersString file mesh filters
@@ -102,6 +104,7 @@ class QgsMdalProvider : public QgsMeshDataProvider
102104
private:
103105
QVector<QgsMeshVertex> vertices( ) const;
104106
QVector<QgsMeshFace> faces( ) const;
107+
void loadData();
105108
MeshH mMeshH;
106109
QStringList mExtraDatasetUris;
107110
QgsCoordinateReferenceSystem mCrs;

0 commit comments

Comments
 (0)