32 const QString &baseName,
33 const QString &providerKey,
36 , mProviderKey( providerKey )
40 setDataProvider( providerKey, providerOptions );
43 mRendererNativeMeshSettings.
setEnabled(
true );
75 return mDataProvider->
extent();
91 return mNativeMesh.get();
97 return mTriangularMesh.get();
103 return mRendererNativeMeshSettings;
108 mRendererNativeMeshSettings = settings;
114 return mRendererTriangularMeshSettings;
119 mRendererTriangularMeshSettings = settings;
125 return mRendererScalarSettings;
130 mRendererScalarSettings = settings;
137 return mRendererVectorSettings;
142 mRendererVectorSettings = settings;
149 if ( index == mActiveScalarDataset )
152 if ( ( index >= 0 ) && ( index <
dataProvider()->datasetCount() ) )
153 mActiveScalarDataset = index;
162 if ( index == mActiveVectorDataset )
165 if ( ( index < 0 ) || ( index >=
dataProvider()->datasetCount() ) )
173 mActiveVectorDataset = index;
181 void QgsMeshLayer::fillNativeMesh()
183 Q_ASSERT( !mNativeMesh );
185 mNativeMesh.reset(
new QgsMesh() );
190 mNativeMesh->vertices.resize(
dataProvider()->vertexCount() );
196 mNativeMesh->faces.resize(
dataProvider()->faceCount() );
211 if ( !mTriangularMesh )
214 mTriangularMesh->update( mNativeMesh.get(), &rendererContext );
221 Q_UNUSED( errorMessage );
230 Q_UNUSED( errorMessage );
237 QString src( source );
238 if ( provider == QLatin1String(
"mdal" ) )
247 QString src( source );
262 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
264 if ( pkeyNode.isNull() )
266 mProviderKey.clear();
270 QDomElement pkeyElt = pkeyNode.toElement();
271 mProviderKey = pkeyElt.text();
275 if ( !setDataProvider( mProviderKey, providerOptions ) )
286 QDomElement mapLayerNode = layer_node.toElement();
288 if ( mapLayerNode.isNull() || ( QLatin1String(
"maplayer" ) != mapLayerNode.nodeName() ) )
294 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"mesh" ) );
299 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
300 QDomText providerText = document.createTextNode(
providerType() );
301 provider.appendChild( providerText );
302 layer_node.appendChild( provider );
313 delete mDataProvider;
315 mProviderKey = provider;
319 if ( !mDataProvider )
321 QgsDebugMsgLevel( QStringLiteral(
"Unable to get mesh data provider" ), 2 );
325 mDataProvider->setParent(
this );
326 QgsDebugMsgLevel( QStringLiteral(
"Instantiated the mesh data provider plugin" ), 2 );
335 if ( provider == QStringLiteral(
"mesh_memory" ) )
QgsMeshRendererVectorSettings rendererVectorSettings() const
Returns renderer settings.
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
Base class for all map layer types.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const override
Write the symbology for the layer into the docment provided.
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context) override
Read the symbology for the current layer from the Dom node supplied.
QgsMeshRendererMeshSettings rendererTriangularMeshSettings() const
Returns renderer settings.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
void setRendererNativeMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new renderer settings, triggers repaint.
virtual int faceCount() const =0
Returns number of faces in the native mesh.
void setActiveScalarDataset(int index=NO_ACTIVE_MESH_DATASET)
Sets active scalar dataset for rendering.
Represents a mesh renderer settings for mesh object.
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns dataset metadata.
Represents a mesh renderer settings for scalar datasets.
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
Setting options for loading mesh layers.
bool isValid() const
Returns the status of the layer.
void setRendererVectorSettings(const QgsMeshRendererVectorSettings &settings)
Sets new renderer settings, triggers repaint.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering)
const int NO_ACTIVE_MESH_DATASET
Implementation of threaded rendering for mesh layers.
QgsRectangle extent() const override
Returns the extent of the layer.
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Creates a new instance of a provider.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsRectangle extent() const override
Returns the extent of the layer.
Represents a mesh renderer settings for vector datasets.
QString providerType() const
Returns the provider type for this layer.
void setRendererTriangularMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new renderer settings, triggers repaint.
QgsMeshRendererMeshSettings rendererNativeMeshSettings() const
Returns renderer settings.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted...
#define QgsDebugMsgLevel(str, level)
virtual bool isValid() const =0
Returns true if this is a valid layer.
void setRendererScalarSettings(const QgsMeshRendererScalarSettings &settings)
Sets new renderer settings, triggers repaint.
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider.
bool mValid
Indicates if the layer is valid and can be drawn.
void setEnabled(bool enabled)
Sets whether mesh structure rendering is enabled.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Base class for providing data for QgsMeshLayer.
virtual QgsMeshVertex vertex(int index) const =0
Returns the mesh vertex at index.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files...
Contains information about the context of a rendering operation.
Setting options for creating vector data providers.
QString name() const
Returns the display name of the layer.
virtual QgsMeshFace face(int index) const =0
Returns the mesh face at index.
Mesh - vertices and faces.
QString mDataSource
Data source description string, varies by layer type.
QString source() const
Returns the source for the layer.
void setActiveVectorDataset(int index=NO_ACTIVE_MESH_DATASET)
Sets active vector dataset for rendering.
QgsMeshLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QgsMeshRendererScalarSettings rendererScalarSettings() const
Returns renderer settings.
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files...
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
QgsMeshLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib="mesh_memory", const QgsMeshLayer::LayerOptions &options=QgsMeshLayer::LayerOptions())
Constructor - creates a mesh layer.