QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsmeshlayer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshlayer.cpp
3  ----------------
4  begin : April 2018
5  copyright : (C) 2018 by Peter Petrik
6  email : zilolv at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include <cstddef>
19 #include <limits>
20 
21 #include <QUuid>
22 
23 #include "qgscolorramp.h"
24 #include "qgslogger.h"
25 #include "qgsmaplayerlegend.h"
26 #include "qgsmeshdataprovider.h"
27 #include "qgsmeshlayer.h"
28 #include "qgsmeshlayerrenderer.h"
29 #include "qgsmeshlayerutils.h"
30 #include "qgsmeshtimesettings.h"
31 #include "qgspainting.h"
32 #include "qgsproviderregistry.h"
33 #include "qgsreadwritecontext.h"
34 #include "qgsstyle.h"
35 #include "qgstriangularmesh.h"
36 
37 
38 
39 QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,
40  const QString &baseName,
41  const QString &providerKey,
42  const QgsMeshLayer::LayerOptions &options )
43  : QgsMapLayer( QgsMapLayerType::MeshLayer, baseName, meshLayerPath )
44 {
46 
47  setProviderType( providerKey );
48  // if we’re given a provider type, try to create and bind one to this layer
49  if ( !meshLayerPath.isEmpty() && !providerKey.isEmpty() )
50  {
51  QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
52  setDataProvider( providerKey, providerOptions );
53  }
54 
56  setDefaultRendererSettings();
57 } // QgsMeshLayer ctor
58 
59 
60 void QgsMeshLayer::setDefaultRendererSettings()
61 {
62  if ( mDataProvider && mDataProvider->datasetGroupCount() > 0 )
63  {
64  // show data from the first dataset group
65  mRendererSettings.setActiveScalarDataset( QgsMeshDatasetIndex( 0, 0 ) );
66  }
67  else
68  {
69  // show at least the mesh by default
70  QgsMeshRendererMeshSettings meshSettings;
71  meshSettings.setEnabled( true );
72  mRendererSettings.setNativeMeshSettings( meshSettings );
73  }
74 }
75 
77 {
78  delete mDataProvider;
79 }
80 
82 {
83  return mDataProvider;
84 }
85 
87 {
88  return mDataProvider;
89 }
90 
92 {
94  if ( mDataProvider )
95  {
96  options.transformContext = mDataProvider->transformContext();
97  }
98  QgsMeshLayer *layer = new QgsMeshLayer( source(), name(), mProviderKey, options );
99  QgsMapLayer::clone( layer );
100  return layer;
101 }
102 
104 {
105  if ( mDataProvider )
106  return mDataProvider->extent();
107  else
108  {
109  QgsRectangle rec;
110  rec.setMinimal();
111  return rec;
112  }
113 }
114 
116 {
117  return mProviderKey;
118 }
119 
121 {
122  return mNativeMesh.get();
123 }
124 
126 {
127  return mNativeMesh.get();
128 }
129 
131 {
132  return mTriangularMesh.get();
133 }
134 
136 {
137  return mTriangularMesh.get();
138 }
139 
140 QgsMeshLayerRendererCache *QgsMeshLayer::rendererCache()
141 {
142  return mRendererCache.get();
143 }
144 
146 {
147  return mRendererSettings;
148 }
149 
151 {
152  mRendererSettings = settings;
153  emit rendererChanged();
154  triggerRepaint();
155 }
156 
158 {
159  return mTimeSettings;
160 }
161 
163 {
164  mTimeSettings = settings;
165  emit timeSettingsChanged();
166 }
167 
168 QString QgsMeshLayer::formatTime( double hours )
169 {
170  return QgsMeshLayerUtils::formatTime( hours, mTimeSettings );
171 }
172 
174 {
175  QgsMeshDatasetValue value;
176 
177  if ( mTriangularMesh && dataProvider() && dataProvider()->isValid() && index.isValid() )
178  {
179  int faceIndex = mTriangularMesh->faceIndexForPoint( point ) ;
180  if ( faceIndex >= 0 )
181  {
182  int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex );
183  if ( dataProvider()->isFaceActive( index, nativeFaceIndex ) )
184  {
185 
186  if ( dataProvider()->datasetGroupMetadata( index ).dataType() == QgsMeshDatasetGroupMetadata::DataOnFaces )
187  {
188  int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex );
189  value = dataProvider()->datasetValue( index, nativeFaceIndex );
190  }
191  else
192  {
193  const QgsMeshFace &face = mTriangularMesh->triangles()[faceIndex];
194  const int v1 = face[0], v2 = face[1], v3 = face[2];
195  const QgsPoint p1 = mTriangularMesh->vertices()[v1], p2 = mTriangularMesh->vertices()[v2], p3 = mTriangularMesh->vertices()[v3];
196  const QgsMeshDatasetValue val1 = dataProvider()->datasetValue( index, v1 );
197  const QgsMeshDatasetValue val2 = dataProvider()->datasetValue( index, v2 );
198  const QgsMeshDatasetValue val3 = dataProvider()->datasetValue( index, v3 );
199  const double x = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.x(), val2.x(), val3.x(), point );
200  double y = std::numeric_limits<double>::quiet_NaN();
201  bool isVector = dataProvider()->datasetGroupMetadata( index ).isVector();
202  if ( isVector )
203  y = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.y(), val2.y(), val3.y(), point );
204 
205  value = QgsMeshDatasetValue( x, y );
206  }
207 
208  }
209  }
210  }
211 
212  return value;
213 }
214 
216 {
217  if ( mDataProvider )
218  mDataProvider->setTransformContext( transformContext );
219 }
220 
221 void QgsMeshLayer::fillNativeMesh()
222 {
223  Q_ASSERT( !mNativeMesh );
224 
225  mNativeMesh.reset( new QgsMesh() );
226 
227  if ( !( dataProvider() && dataProvider()->isValid() ) )
228  return;
229 
230  dataProvider()->populateMesh( mNativeMesh.get() );
231 }
232 
233 void QgsMeshLayer::onDatasetGroupsAdded( int count )
234 {
235  // assign default style to new dataset groups
236  int newDatasetGroupCount = mDataProvider->datasetGroupCount();
237  for ( int i = newDatasetGroupCount - count; i < newDatasetGroupCount; ++i )
238  assignDefaultStyleToDatasetGroup( i );
239 }
240 
241 static QgsColorRamp *_createDefaultColorRamp()
242 {
243  QgsColorRamp *ramp = QgsStyle::defaultStyle()->colorRamp( QStringLiteral( "Plasma" ) );
244  if ( ramp )
245  return ramp;
246 
247  // definition of "Plasma" color ramp (in case it is not available in the style for some reason)
248  QgsStringMap props;
249  props["color1"] = "13,8,135,255";
250  props["color2"] = "240,249,33,255";
251  props["stops"] =
252  "0.0196078;27,6,141,255:0.0392157;38,5,145,255:0.0588235;47,5,150,255:0.0784314;56,4,154,255:0.0980392;65,4,157,255:"
253  "0.117647;73,3,160,255:0.137255;81,2,163,255:0.156863;89,1,165,255:0.176471;97,0,167,255:0.196078;105,0,168,255:"
254  "0.215686;113,0,168,255:0.235294;120,1,168,255:0.254902;128,4,168,255:0.27451;135,7,166,255:0.294118;142,12,164,255:"
255  "0.313725;149,17,161,255:0.333333;156,23,158,255:0.352941;162,29,154,255:0.372549;168,34,150,255:0.392157;174,40,146,255:"
256  "0.411765;180,46,141,255:0.431373;186,51,136,255:0.45098;191,57,132,255:0.470588;196,62,127,255:0.490196;201,68,122,255:"
257  "0.509804;205,74,118,255:0.529412;210,79,113,255:0.54902;214,85,109,255:0.568627;218,91,105,255:0.588235;222,97,100,255:"
258  "0.607843;226,102,96,255:0.627451;230,108,92,255:0.647059;233,114,87,255:0.666667;237,121,83,255:0.686275;240,127,79,255:"
259  "0.705882;243,133,75,255:0.72549;245,140,70,255:0.745098;247,147,66,255:0.764706;249,154,62,255:0.784314;251,161,57,255:"
260  "0.803922;252,168,53,255:0.823529;253,175,49,255:0.843137;254,183,45,255:0.862745;254,190,42,255:0.882353;253,198,39,255:"
261  "0.901961;252,206,37,255:0.921569;251,215,36,255:0.941176;248,223,37,255:0.960784;246,232,38,255:0.980392;243,240,39,255";
262  return QgsGradientColorRamp::create( props );
263 }
264 
265 void QgsMeshLayer::assignDefaultStyleToDatasetGroup( int groupIndex )
266 {
267  const QgsMeshDatasetGroupMetadata metadata = mDataProvider->datasetGroupMetadata( groupIndex );
268  double groupMin = metadata.minimum();
269  double groupMax = metadata.maximum();
270 
271  QgsColorRampShader fcn( groupMin, groupMax, _createDefaultColorRamp() );
272  fcn.classifyColorRamp( 5, -1, QgsRectangle(), nullptr );
273 
274  QgsMeshRendererScalarSettings scalarSettings;
275  scalarSettings.setClassificationMinimumMaximum( groupMin, groupMax );
276  scalarSettings.setColorRampShader( fcn );
277  mRendererSettings.setScalarSettings( groupIndex, scalarSettings );
278 }
279 
281 {
282  // Native mesh
283  if ( !mNativeMesh )
284  {
285  // lazy loading of mesh data
286  fillNativeMesh();
287  }
288 
289  // Triangular mesh
290  if ( !mTriangularMesh )
291  mTriangularMesh.reset( new QgsTriangularMesh() );
292 
293  mTriangularMesh->update( mNativeMesh.get(), &rendererContext );
294 
295  // Cache
296  if ( !mRendererCache )
297  mRendererCache.reset( new QgsMeshLayerRendererCache() );
298 
299  return new QgsMeshLayerRenderer( this, rendererContext );
300 }
301 
302 bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
303  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
304 {
305  Q_UNUSED( errorMessage )
306  // TODO: implement categories for raster layer
307 
308  QDomElement elem = node.toElement();
309 
310  readCommonStyle( elem, context, categories );
311 
312  QDomElement elemRendererSettings = elem.firstChildElement( "mesh-renderer-settings" );
313  if ( !elemRendererSettings.isNull() )
314  mRendererSettings.readXml( elemRendererSettings );
315 
316  QDomElement elemTimeSettings = elem.firstChildElement( "mesh-time-settings" );
317  if ( !elemTimeSettings.isNull() )
318  mTimeSettings.readXml( elemTimeSettings, context );
319 
320  // get and set the blend mode if it exists
321  QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
322  if ( !blendModeNode.isNull() )
323  {
324  QDomElement e = blendModeNode.toElement();
325  setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
326  }
327 
328  return true;
329 }
330 
331 bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
332  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
333 {
334  Q_UNUSED( errorMessage )
335  // TODO: implement categories for raster layer
336 
337  QDomElement elem = node.toElement();
338 
339  writeCommonStyle( elem, doc, context, categories );
340 
341  QDomElement elemRendererSettings = mRendererSettings.writeXml( doc );
342  elem.appendChild( elemRendererSettings );
343 
344  QDomElement elemTimeSettings = mTimeSettings.writeXml( doc, context );
345  elem.appendChild( elemTimeSettings );
346 
347  // add blend mode node
348  QDomElement blendModeElement = doc.createElement( QStringLiteral( "blendMode" ) );
349  QDomText blendModeText = doc.createTextNode( QString::number( QgsPainting::getBlendModeEnum( blendMode() ) ) );
350  blendModeElement.appendChild( blendModeText );
351  node.appendChild( blendModeElement );
352 
353  return true;
354 }
355 
356 QString QgsMeshLayer::decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const
357 {
358  QString src( source );
359  if ( provider == QLatin1String( "mdal" ) )
360  {
361  src = context.pathResolver().readPath( src );
362  }
363  return src;
364 }
365 
366 QString QgsMeshLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
367 {
368  QString src( source );
369  if ( providerType() == QLatin1String( "mdal" ) )
370  {
371  src = context.pathResolver().writePath( src );
372  }
373  return src;
374 }
375 
376 bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
377 {
378  QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsMeshLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 );
379 
380  //process provider key
381  QDomNode pkeyNode = layer_node.namedItem( QStringLiteral( "provider" ) );
382 
383  if ( pkeyNode.isNull() )
384  {
385  mProviderKey.clear();
386  }
387  else
388  {
389  QDomElement pkeyElt = pkeyNode.toElement();
390  mProviderKey = pkeyElt.text();
391  }
392 
394  {
395  return false;
396  }
397 
398  QgsDataProvider::ProviderOptions providerOptions;
399  if ( !setDataProvider( mProviderKey, providerOptions ) )
400  {
401  return false;
402  }
403 
404  QDomElement elemExtraDatasets = layer_node.firstChildElement( QStringLiteral( "extra-datasets" ) );
405  if ( !elemExtraDatasets.isNull() )
406  {
407  QDomElement elemUri = elemExtraDatasets.firstChildElement( QStringLiteral( "uri" ) );
408  while ( !elemUri.isNull() )
409  {
410  QString uri = context.pathResolver().readPath( elemUri.text() );
411 
412  bool res = mDataProvider->addDataset( uri );
413 #ifdef QGISDEBUG
414  QgsDebugMsg( QStringLiteral( "extra dataset (res %1): %2" ).arg( res ).arg( uri ) );
415 #else
416  ( void )res; // avoid unused warning in release builds
417 #endif
418 
419  elemUri = elemUri.nextSiblingElement( QStringLiteral( "uri" ) );
420  }
421  }
422 
423  QString errorMsg;
424  readSymbology( layer_node, errorMsg, context );
425 
426  return mValid; // should be true if read successfully
427 }
428 
429 bool QgsMeshLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const
430 {
431  // first get the layer element so that we can append the type attribute
432  QDomElement mapLayerNode = layer_node.toElement();
433 
434  if ( mapLayerNode.isNull() || ( QLatin1String( "maplayer" ) != mapLayerNode.nodeName() ) )
435  {
436  QgsDebugMsgLevel( QStringLiteral( "can't find <maplayer>" ), 2 );
437  return false;
438  }
439 
440  mapLayerNode.setAttribute( QStringLiteral( "type" ), QStringLiteral( "mesh" ) );
441 
442  // add provider node
443  if ( mDataProvider )
444  {
445  QDomElement provider = document.createElement( QStringLiteral( "provider" ) );
446  QDomText providerText = document.createTextNode( providerType() );
447  provider.appendChild( providerText );
448  layer_node.appendChild( provider );
449 
450  const QStringList extraDatasetUris = mDataProvider->extraDatasets();
451  QDomElement elemExtraDatasets = document.createElement( QStringLiteral( "extra-datasets" ) );
452  for ( const QString &uri : extraDatasetUris )
453  {
454  QString path = context.pathResolver().writePath( uri );
455  QDomElement elemUri = document.createElement( QStringLiteral( "uri" ) );
456  elemUri.appendChild( document.createTextNode( path ) );
457  elemExtraDatasets.appendChild( elemUri );
458  }
459  layer_node.appendChild( elemExtraDatasets );
460  }
461 
462  // renderer specific settings
463  QString errorMsg;
464  return writeSymbology( layer_node, document, errorMsg, context );
465 }
466 
468 {
469  if ( mDataProvider && mDataProvider->isValid() )
470  {
471 
472  mDataProvider->reloadData();
473 
474  //reload the mesh structure
475  if ( !mNativeMesh )
476  mNativeMesh.reset( new QgsMesh );
477 
478  dataProvider()->populateMesh( mNativeMesh.get() );
479 
480  //clear the TriangularMesh
481  mTriangularMesh.reset( new QgsTriangularMesh() );
482 
483  //clear the rendererCache
484  mRendererCache.reset( new QgsMeshLayerRendererCache() );
485  }
486 }
487 
488 bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options )
489 {
490  delete mDataProvider;
491 
492  mProviderKey = provider;
493  QString dataSource = mDataSource;
494 
495  mDataProvider = qobject_cast<QgsMeshDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options ) );
496  if ( !mDataProvider )
497  {
498  QgsDebugMsgLevel( QStringLiteral( "Unable to get mesh data provider" ), 2 );
499  return false;
500  }
501 
502  mDataProvider->setParent( this );
503  QgsDebugMsgLevel( QStringLiteral( "Instantiated the mesh data provider plugin" ), 2 );
504 
505  mValid = mDataProvider->isValid();
506  if ( !mValid )
507  {
508  QgsDebugMsgLevel( QStringLiteral( "Invalid mesh provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ), 2 );
509  return false;
510  }
511 
512  setCrs( mDataProvider->crs() );
513 
514  if ( provider == QStringLiteral( "mesh_memory" ) )
515  {
516  // required so that source differs between memory layers
517  mDataSource = mDataSource + QStringLiteral( "&uid=%1" ).arg( QUuid::createUuid().toString() );
518  }
519 
520  for ( int i = 0; i < mDataProvider->datasetGroupCount(); ++i )
521  assignDefaultStyleToDatasetGroup( i );
522 
523  connect( mDataProvider, &QgsMeshDataProvider::dataChanged, this, &QgsMeshLayer::dataChanged );
524  connect( mDataProvider, &QgsMeshDataProvider::datasetGroupsAdded, this, &QgsMeshLayer::onDatasetGroupsAdded );
525 
526  return true;
527 }
void setClassificationMinimumMaximum(double minimum, double maximum)
Sets min/max values used for creation of the color ramp shader.
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:79
Triangular/Derived Mesh is mesh with vertices in map coordinates.
QgsCoordinateTransformContext transformContext
Definition: qgsmeshlayer.h:109
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:151
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void setRendererSettings(const QgsMeshRendererSettings &settings)
Sets new renderer settings.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
bool mShouldValidateCrs
true if the layer&#39;s CRS should be validated and invalid CRSes are not permitted.
Definition: qgsmaplayer.h:1541
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1529
Represents a mesh renderer settings for mesh object.
A class to represent a 2D point.
Definition: qgspointxy.h:43
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
virtual bool addDataset(const QString &uri)=0
Associate dataset with the mesh.
Represents a mesh renderer settings for scalar datasets.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by derived classes to encode provider&#39;s specific data source to proje...
double maximum() const
Returns maximum scalar value/vector magnitude present for whole dataset group.
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer&#39;s metadata store.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from the given DOM element.
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:98
bool isValid() const
Returns the status of the layer.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
Definition: qgsstyle.cpp:356
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void setScalarSettings(int groupIndex, const QgsMeshRendererScalarSettings &settings)
Sets new renderer settings.
static QgsMapLayerLegend * defaultMeshLegend(QgsMeshLayer *ml)
Create new legend implementation for mesh layer.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:612
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering)
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:74
Implementation of threaded rendering for mesh layers.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
double y() const
Returns y value.
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Creates a new instance of a provider.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider&#39;...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Represents all mesh renderer settings.
QgsRectangle extent() const override
Returns the extent of the layer.
QString providerType() const
Returns the provider type for this layer.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
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)
Definition: qgslogger.h:39
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer&#39;s spatial reference system.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
void setColorRampShader(const QgsColorRampShader &shader)
Sets color ramp shader function.
~QgsMeshLayer() override
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
void datasetGroupsAdded(int count)
Emitted when some new dataset groups have been added.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Definition: qgsmeshlayer.h:124
Don&#39;t resolve layer paths or create data providers for layers.
Definition: qgsmaplayer.h:531
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider&#39;s specific data source from proj...
void setTimeSettings(const QgsMeshTimeSettings &settings)
Sets time format settings.
QgsMeshDataProvider * dataProvider() override
Returns the layer&#39;s data provider, it may be nullptr.
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
void rendererChanged()
Signal emitted when renderer is changed.
Contains information about the context in which a coordinate transform is executed.
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:1480
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
Represents a mesh time settings for mesh datasets.
QgsMeshDatasetValue datasetValue(const QgsMeshDatasetIndex &index, const QgsPointXY &point) const
Interpolates the value on the given point from given dataset.
virtual void populateMesh(QgsMesh *mesh) const =0
Populates the mesh vertices and faces.
void setEnabled(bool enabled)
Sets whether mesh structure rendering is enabled.
void reload() override
Synchronises with changes in the datasource.
void classifyColorRamp(int classes=0, int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
Classify color ramp shader.
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.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsColorRamp from a map of properties.
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.
Mesh - vertices and faces.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a new DOM element.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1483
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
QString source() const
Returns the source for the layer.
QgsMeshLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
void setNativeMeshSettings(const QgsMeshRendererMeshSettings &settings)
Sets new renderer settings, triggers repaint.
virtual void reloadData()
Reloads the data from the source.
bool isVector() const
Returns whether dataset group has vector data.
QVector< int > QgsMeshFace
List of vertex indexes.
void setActiveScalarDataset(QgsMeshDatasetIndex index=QgsMeshDatasetIndex())
Sets active scalar dataset for rendering.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
virtual QStringList extraDatasets() const =0
Returns list of additional dataset file URIs added using addDataset() calls.
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering)
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
void dataChanged()
Data of layer changed.
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.
Definition: qgsmeshlayer.h:90
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:66
QgsMeshTimeSettings timeSettings() const
Returns time format settings.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
QgsMeshDatasetValue represents single dataset value.
virtual QgsMeshDatasetValue datasetValue(QgsMeshDatasetIndex index, int valueIndex) const =0
Returns vector/scalar value associated with the index from the dataset To read multiple continuous va...
double minimum() const
Returns minimum scalar value/vector magnitude present for whole dataset group.
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
void timeSettingsChanged()
Emitted when time format is changed.
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files...
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
double x() const
Returns x value.
QgsMeshLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib=QStringLiteral("mesh_memory"), const QgsMeshLayer::LayerOptions &options=QgsMeshLayer::LayerOptions())
Constructor - creates a mesh layer.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It&#39;s up to the subclass to respect these when restoring state from XML.
Definition: qgsmaplayer.h:1534
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
QString formatTime(double hours)
Returns (date) time in hours formatted to human readable form.