Skip to content
Permalink
Browse files

Implementation of QgsMeshLayer::reload() and QgsMdalProvider::reloadD…

…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 109049ea86e4c133f4e230267659809d5b89d675
@@ -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
@@ -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;
@@ -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;

@@ -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()
@@ -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 )
{
@@ -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
@@ -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;

0 comments on commit 109049e

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