QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsmeshrenderersettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshrenderersettings.cpp
3 ---------------------------
4 begin : May 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
19
20#include "qgscolorramp.h"
21#include "qgscolorutils.h"
22#include "qgsunittypes.h"
23
24#include <QString>
25
26using namespace Qt::StringLiterals;
27
29{
30 return mEnabled;
31}
32
34{
35 mEnabled = on;
36}
37
39{
40 return mLineWidth;
41}
42
44{
45 mLineWidth = lineWidth;
46}
47
49{
50 return mColor;
51}
52
54{
55 mColor = color;
56}
57
59{
60 return mLineWidthUnit;
61}
62
67
68QDomElement QgsMeshRendererMeshSettings::writeXml( QDomDocument &doc ) const
69{
70 QDomElement elem = doc.createElement( u"mesh-settings"_s );
71 elem.setAttribute( u"enabled"_s, mEnabled ? u"1"_s : u"0"_s );
72 elem.setAttribute( u"line-width"_s, mLineWidth );
73 elem.setAttribute( u"color"_s, QgsColorUtils::colorToString( mColor ) );
74 elem.setAttribute( u"line-width-unit"_s, QgsUnitTypes::encodeUnit( mLineWidthUnit ) );
75 return elem;
76}
77
78void QgsMeshRendererMeshSettings::readXml( const QDomElement &elem )
79{
80 mEnabled = elem.attribute( u"enabled"_s ).toInt();
81 mLineWidth = elem.attribute( u"line-width"_s ).toDouble();
82 mColor = QgsColorUtils::colorFromString( elem.attribute( u"color"_s ) );
83 mLineWidthUnit = QgsUnitTypes::decodeRenderUnit( elem.attribute( u"line-width-unit"_s ) );
84}
85// ---------------------------------------------------------------------
86
88{
89 return mColorRampShader;
90}
91
93{
94 mColorRampShader = shader;
95}
96
97double QgsMeshRendererScalarSettings::classificationMinimum() const { return mClassificationMinimum; }
98
99double QgsMeshRendererScalarSettings::classificationMaximum() const { return mClassificationMaximum; }
100
102{
103 mClassificationMinimum = minimum;
104 mClassificationMaximum = maximum;
105 updateShader();
106}
107
108double QgsMeshRendererScalarSettings::opacity() const { return mOpacity; }
109
111
116
118{
119 mDataResamplingMethod = dataInterpolationMethod;
120}
121
122QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
123{
124 QDomElement elem = doc.createElement( u"scalar-settings"_s );
125 elem.setAttribute( u"min-val"_s, mClassificationMinimum );
126 elem.setAttribute( u"max-val"_s, mClassificationMaximum );
127 elem.setAttribute( u"opacity"_s, mOpacity );
128
129 QString methodTxt;
130 switch ( mDataResamplingMethod )
131 {
132 case NoResampling:
133 methodTxt = u"no-resampling"_s;
134 break;
135 case NeighbourAverage:
136 methodTxt = u"neighbour-average"_s;
137 break;
138 }
139 elem.setAttribute( u"interpolation-method"_s, methodTxt );
140
141 if ( mRangeExtent != Qgis::MeshRangeExtent::WholeMesh )
142 elem.setAttribute( u"range-extent"_s, qgsEnumValueToKey( mRangeExtent ) );
143 if ( mRangeLimit != Qgis::MeshRangeLimit::NotSet )
144 elem.setAttribute( u"range-limit"_s, qgsEnumValueToKey( mRangeLimit ) );
145
146 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
147 elem.appendChild( elemShader );
148
149 QDomElement elemEdge = doc.createElement( u"edge-settings"_s );
150 elemEdge.appendChild( mEdgeStrokeWidth.writeXml( doc, context ) );
151 elemEdge.setAttribute( u"stroke-width-unit"_s, static_cast< int >( mEdgeStrokeWidthUnit ) );
152 elem.appendChild( elemEdge );
153
154 return elem;
155}
156
157void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
158{
159 mClassificationMinimum = elem.attribute( u"min-val"_s ).toDouble();
160 mClassificationMaximum = elem.attribute( u"max-val"_s ).toDouble();
161 mOpacity = elem.attribute( u"opacity"_s ).toDouble();
162
163 const QString methodTxt = elem.attribute( u"interpolation-method"_s );
164 if ( u"neighbour-average"_s == methodTxt )
165 {
166 mDataResamplingMethod = DataResamplingMethod::NeighbourAverage;
167 }
168 else
169 {
170 mDataResamplingMethod = DataResamplingMethod::NoResampling;
171 }
172
173 mRangeExtent = qgsEnumKeyToValue( elem.attribute( "range-extent" ), Qgis::MeshRangeExtent::WholeMesh );
174 mRangeLimit = qgsEnumKeyToValue( elem.attribute( "range-limit" ), Qgis::MeshRangeLimit::NotSet );
175
176 const QDomElement elemShader = elem.firstChildElement( u"colorrampshader"_s );
177 mColorRampShader.readXml( elemShader, context );
178
179 const QDomElement elemEdge = elem.firstChildElement( u"edge-settings"_s );
180 const QDomElement elemEdgeStrokeWidth = elemEdge.firstChildElement( u"mesh-stroke-width"_s );
181 mEdgeStrokeWidth.readXml( elemEdgeStrokeWidth, context );
182 mEdgeStrokeWidthUnit = static_cast<Qgis::RenderUnit>(
183 elemEdge.attribute( u"stroke-width-unit"_s ).toInt() );
184}
185
190
192{
193 mEdgeStrokeWidth = strokeWidth;
194}
195
197{
198 return mEdgeStrokeWidthUnit;
199}
200
205
206void QgsMeshRendererScalarSettings::updateShader()
207{
208
209 mColorRampShader.setMinimumValue( mClassificationMinimum );
210 mColorRampShader.setMaximumValue( mClassificationMaximum );
211
212 if ( !mColorRampShader.isEmpty() )
213 mColorRampShader.classifyColorRamp( mColorRampShader.sourceColorRamp()->count(), 1, QgsRectangle(), nullptr );
214}
215
216
217// ---------------------------------------------------------------------
218
220{
221 return mLineWidth;
222}
223
225{
226 mLineWidth = lineWidth;
227}
228
230{
231 return mColor;
232}
233
234void QgsMeshRendererVectorSettings::setColor( const QColor &vectorColor )
235{
236 mColor = vectorColor;
237}
238
240{
241 return mFilterMin;
242}
243
245{
246 mFilterMin = vectorFilterMin;
247}
248
250{
251 return mFilterMax;
252}
253
255{
256 mFilterMax = vectorFilterMax;
257}
258
260{
261 return mOnUserDefinedGrid;
262}
263
265{
266 mOnUserDefinedGrid = enabled;
267}
268
270{
271 return mUserGridCellWidth;
272}
273
275{
276 mUserGridCellWidth = width;
277}
278
280{
281 return mUserGridCellHeight;
282}
283
285{
286 mUserGridCellHeight = height;
287}
288
293
298
300{
301 return mMinShaftLength;
302}
303
308
310{
311 return mMaxShaftLength;
312}
313
318
320{
321 return mScaleFactor;
322}
323
328
330{
331 return mFixedShaftLength;
332}
333
338
340{
341 return mArrowHeadWidthRatio;
342}
343
345{
346 mArrowHeadWidthRatio = vectorHeadWidthRatio;
347}
348
350{
351 return mArrowHeadLengthRatio;
352}
353
355{
356 mArrowHeadLengthRatio = vectorHeadLengthRatio;
357}
358
359QDomElement QgsMeshRendererVectorArrowSettings::writeXml( QDomDocument &doc ) const
360{
361 QDomElement elem = doc.createElement( u"vector-arrow-settings"_s );
362 elem.setAttribute( u"arrow-head-width-ratio"_s, mArrowHeadWidthRatio );
363 elem.setAttribute( u"arrow-head-length-ratio"_s, mArrowHeadLengthRatio );
364
365 QDomElement elemShaft = doc.createElement( u"shaft-length"_s );
366 QString methodTxt;
367 switch ( mShaftLengthMethod )
368 {
369 case MinMax:
370 methodTxt = u"minmax"_s;
371 elemShaft.setAttribute( u"min"_s, mMinShaftLength );
372 elemShaft.setAttribute( u"max"_s, mMaxShaftLength );
373 break;
374 case Scaled:
375 methodTxt = u"scaled"_s;
376 elemShaft.setAttribute( u"scale-factor"_s, mScaleFactor );
377 break;
378 case Fixed:
379 methodTxt = u"fixed"_s ;
380 elemShaft.setAttribute( u"fixed-length"_s, mFixedShaftLength );
381 break;
382 }
383 elemShaft.setAttribute( u"method"_s, methodTxt );
384 elem.appendChild( elemShaft );
385 return elem;
386}
387
388void QgsMeshRendererVectorArrowSettings::readXml( const QDomElement &elem )
389{
390 mArrowHeadWidthRatio = elem.attribute( u"arrow-head-width-ratio"_s ).toDouble();
391 mArrowHeadLengthRatio = elem.attribute( u"arrow-head-length-ratio"_s ).toDouble();
392
393 const QDomElement elemShaft = elem.firstChildElement( u"shaft-length"_s );
394 const QString methodTxt = elemShaft.attribute( u"method"_s );
395 if ( u"minmax"_s == methodTxt )
396 {
397 mShaftLengthMethod = MinMax;
398 mMinShaftLength = elemShaft.attribute( u"min"_s ).toDouble();
399 mMaxShaftLength = elemShaft.attribute( u"max"_s ).toDouble();
400 }
401 else if ( u"scaled"_s == methodTxt )
402 {
403 mShaftLengthMethod = Scaled;
404 mScaleFactor = elemShaft.attribute( u"scale-factor"_s ).toDouble();
405 }
406 else // fixed
407 {
408 mShaftLengthMethod = Fixed;
409 mFixedShaftLength = elemShaft.attribute( u"fixed-length"_s ).toDouble();
410 }
411}
412
413// ---------------------------------------------------------------------
414
419
421//****** IMPORTANT! editing this? make sure you update the move constructor too! *****
422 : mRendererNativeMeshSettings( other.mRendererNativeMeshSettings )
423 , mRendererTriangularMeshSettings( other.mRendererTriangularMeshSettings )
424 , mRendererEdgeMeshSettings( other.mRendererEdgeMeshSettings )
425 , mRendererScalarSettings( other.mRendererScalarSettings )
426 , mRendererVectorSettings( other.mRendererVectorSettings )
427 , mActiveScalarDatasetGroup( other.mActiveScalarDatasetGroup )
428 , mActiveVectorDatasetGroup( other.mActiveVectorDatasetGroup )
429 , mAveragingMethod( other.mAveragingMethod )
430 //****** IMPORTANT! editing this? make sure you update the move constructor too! *****
431{
432}
433
435 : mRendererNativeMeshSettings( std::move( other.mRendererNativeMeshSettings ) )
436 , mRendererTriangularMeshSettings( std::move( other.mRendererTriangularMeshSettings ) )
437 , mRendererEdgeMeshSettings( std::move( other.mRendererEdgeMeshSettings ) )
438 , mRendererScalarSettings( std::move( other.mRendererScalarSettings ) )
439 , mRendererVectorSettings( std::move( other.mRendererVectorSettings ) )
440 , mActiveScalarDatasetGroup( other.mActiveScalarDatasetGroup )
441 , mActiveVectorDatasetGroup( other.mActiveVectorDatasetGroup )
442 , mAveragingMethod( std::move( other.mAveragingMethod ) )
443{
444}
445
447{
448 if ( &other == this )
449 return *this;
450
451 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
452 mRendererNativeMeshSettings = other.mRendererNativeMeshSettings;
453 mRendererTriangularMeshSettings = other.mRendererTriangularMeshSettings;
454 mRendererEdgeMeshSettings = other.mRendererEdgeMeshSettings;
455 mRendererScalarSettings = other.mRendererScalarSettings;
456 mRendererVectorSettings = other.mRendererVectorSettings;
457 mActiveScalarDatasetGroup = other.mActiveScalarDatasetGroup;
458 mActiveVectorDatasetGroup = other.mActiveVectorDatasetGroup;
459 mAveragingMethod = other.mAveragingMethod;
460 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
461 return *this;
462}
463
465{
466 if ( &other == this )
467 return *this;
468
469 mRendererNativeMeshSettings = std::move( other.mRendererNativeMeshSettings );
470 mRendererTriangularMeshSettings = std::move( other.mRendererTriangularMeshSettings );
471 mRendererEdgeMeshSettings = std::move( other.mRendererEdgeMeshSettings );
472 mRendererScalarSettings = std::move( other.mRendererScalarSettings );
473 mRendererVectorSettings = std::move( other.mRendererVectorSettings );
474 mActiveScalarDatasetGroup = other.mActiveScalarDatasetGroup;
475 mActiveVectorDatasetGroup = other.mActiveVectorDatasetGroup;
476 mAveragingMethod = std::move( other.mAveragingMethod );
477 return *this;
478}
479
481
483{
484 return mAveragingMethod.get();
485}
486
488{
489 if ( method )
490 mAveragingMethod.reset( method->clone() );
491 else
492 mAveragingMethod.reset();
493}
494
495QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
496{
497 QDomElement elem = doc.createElement( u"mesh-renderer-settings"_s );
498
499 QDomElement elemActiveDatasetGroup = doc.createElement( u"active-dataset-group"_s );
500 elemActiveDatasetGroup.setAttribute( u"scalar"_s, mActiveScalarDatasetGroup );
501 elemActiveDatasetGroup.setAttribute( u"vector"_s, mActiveVectorDatasetGroup );
502 elem.appendChild( elemActiveDatasetGroup );
503
504 for ( auto groupIndex = mRendererScalarSettings.keyBegin(); groupIndex != mRendererScalarSettings.keyEnd(); groupIndex++ )
505 {
506 const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[*groupIndex];
507 QDomElement elemScalar = scalarSettings.writeXml( doc, context );
508 elemScalar.setAttribute( u"group"_s, *groupIndex );
509 elem.appendChild( elemScalar );
510 }
511
512 for ( auto groupIndex = mRendererVectorSettings.keyBegin(); groupIndex != mRendererVectorSettings.keyEnd(); groupIndex++ )
513 {
514 const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[*groupIndex];
515 QDomElement elemVector = vectorSettings.writeXml( doc, context );
516 elemVector.setAttribute( u"group"_s, *groupIndex );
517 elem.appendChild( elemVector );
518 }
519
520 QDomElement elemNativeMesh = mRendererNativeMeshSettings.writeXml( doc );
521 elemNativeMesh.setTagName( u"mesh-settings-native"_s );
522 elem.appendChild( elemNativeMesh );
523
524 QDomElement elemEdgeMesh = mRendererEdgeMeshSettings.writeXml( doc );
525 elemEdgeMesh.setTagName( u"mesh-settings-edge"_s );
526 elem.appendChild( elemEdgeMesh );
527
528 QDomElement elemTriangularMesh = mRendererTriangularMeshSettings.writeXml( doc );
529 elemTriangularMesh.setTagName( u"mesh-settings-triangular"_s );
530 elem.appendChild( elemTriangularMesh );
531
532 if ( mAveragingMethod )
533 {
534 QDomElement elemAveraging = doc.createElement( u"averaging-3d"_s );
535 elemAveraging.setAttribute( u"method"_s, QString::number( mAveragingMethod->method() ) ) ;
536 const QDomElement elemAveragingParams = mAveragingMethod->writeXml( doc );
537 elemAveraging.appendChild( elemAveragingParams );
538 elem.appendChild( elemAveraging );
539 }
540
541 return elem;
542}
543
544void QgsMeshRendererSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
545{
546 mRendererScalarSettings.clear();
547 mRendererVectorSettings.clear();
548 mAveragingMethod.reset();
549
550 const QDomElement elemActiveDataset = elem.firstChildElement( u"active-dataset-group"_s );
551 if ( elemActiveDataset.hasAttribute( u"scalar"_s ) )
552 mActiveScalarDatasetGroup = elemActiveDataset.attribute( u"scalar"_s ).toInt();
553
554 if ( elemActiveDataset.hasAttribute( u"vector"_s ) )
555 mActiveVectorDatasetGroup = elemActiveDataset.attribute( u"vector"_s ).toInt();
556
557 QDomElement elemScalar = elem.firstChildElement( u"scalar-settings"_s );
558 while ( !elemScalar.isNull() )
559 {
560 const int groupIndex = elemScalar.attribute( u"group"_s ).toInt();
562 scalarSettings.readXml( elemScalar, context );
563 mRendererScalarSettings.insert( groupIndex, scalarSettings );
564
565 elemScalar = elemScalar.nextSiblingElement( u"scalar-settings"_s );
566 }
567
568 QDomElement elemVector = elem.firstChildElement( u"vector-settings"_s );
569 while ( !elemVector.isNull() )
570 {
571 const int groupIndex = elemVector.attribute( u"group"_s ).toInt();
573 vectorSettings.readXml( elemVector, context );
574 mRendererVectorSettings.insert( groupIndex, vectorSettings );
575
576 elemVector = elemVector.nextSiblingElement( u"vector-settings"_s );
577 }
578
579 const QDomElement elemNativeMesh = elem.firstChildElement( u"mesh-settings-native"_s );
580 mRendererNativeMeshSettings.readXml( elemNativeMesh );
581
582 const QDomElement elemEdgeMesh = elem.firstChildElement( u"mesh-settings-edge"_s );
583 mRendererEdgeMeshSettings.readXml( elemEdgeMesh );
584
585 const QDomElement elemTriangularMesh = elem.firstChildElement( u"mesh-settings-triangular"_s );
586 mRendererTriangularMeshSettings.readXml( elemTriangularMesh );
587
588 const QDomElement elemAveraging = elem.firstChildElement( u"averaging-3d"_s );
589 if ( !elemAveraging.isNull() )
590 {
591 mAveragingMethod.reset( QgsMesh3DAveragingMethod::createFromXml( elemAveraging ) );
592 }
593}
594
596{
597 return mActiveScalarDatasetGroup;
598}
599
604
606{
607 return mActiveVectorDatasetGroup;
608}
609
614
619
624
626{
627 return mSeedingDensity;
628}
629
634
635QDomElement QgsMeshRendererVectorStreamlineSettings::writeXml( QDomDocument &doc ) const
636{
637 QDomElement elem = doc.createElement( u"vector-streamline-settings"_s );
638
639 elem.setAttribute( u"seeding-method"_s, mSeedingMethod );
640 elem.setAttribute( u"seeding-density"_s, mSeedingDensity );
641
642 return elem;
643}
644
646{
647 mSeedingMethod =
649 elem.attribute( u"seeding-method"_s ).toInt() );
650 mSeedingDensity = elem.attribute( u"seeding-density"_s ).toDouble();
651}
652
657
659{
660 mDisplayingMethod = displayingMethod;
661}
662
667
672
677
682
683QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
684{
685 QDomElement elem = doc.createElement( u"vector-settings"_s );
686 elem.setAttribute( u"symbology"_s, mDisplayingMethod );
687
688 elem.setAttribute( u"line-width"_s, mLineWidth );
689 elem.setAttribute( u"coloring-method"_s, coloringMethod() );
690 elem.setAttribute( u"color"_s, QgsColorUtils::colorToString( mColor ) );
691 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
692 elem.appendChild( elemShader );
693 elem.setAttribute( u"filter-min"_s, mFilterMin );
694 elem.setAttribute( u"filter-max"_s, mFilterMax );
695
696 elem.setAttribute( u"user-grid-enabled"_s, mOnUserDefinedGrid ? u"1"_s : u"0"_s );
697 elem.setAttribute( u"user-grid-width"_s, mUserGridCellWidth );
698 elem.setAttribute( u"user-grid-height"_s, mUserGridCellHeight );
699
700 elem.appendChild( mArrowsSettings.writeXml( doc ) );
701 elem.appendChild( mStreamLinesSettings.writeXml( doc ) );
702 elem.appendChild( mTracesSettings.writeXml( doc ) );
703 elem.appendChild( mWindBarbSettings.writeXml( doc ) );
704
705 return elem;
706}
707
708void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
709{
710 mDisplayingMethod = static_cast<QgsMeshRendererVectorSettings::Symbology>(
711 elem.attribute( u"symbology"_s ).toInt() );
712
713 mLineWidth = elem.attribute( u"line-width"_s ).toDouble();
714 mColoringMethod = static_cast<QgsInterpolatedLineColor::ColoringMethod>(
715 elem.attribute( u"coloring-method"_s ).toInt() );
716 mColor = QgsColorUtils::colorFromString( elem.attribute( u"color"_s ) );
717 mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context );
718 mFilterMin = elem.attribute( u"filter-min"_s ).toDouble();
719 mFilterMax = elem.attribute( u"filter-max"_s ).toDouble();
720
721 mOnUserDefinedGrid = elem.attribute( u"user-grid-enabled"_s ).toInt(); //bool
722 mUserGridCellWidth = elem.attribute( u"user-grid-width"_s ).toInt();
723 mUserGridCellHeight = elem.attribute( u"user-grid-height"_s ).toInt();
724
725 const QDomElement elemVector = elem.firstChildElement( u"vector-arrow-settings"_s );
726 if ( ! elemVector.isNull() )
727 mArrowsSettings.readXml( elemVector );
728
729 const QDomElement elemStreamLine = elem.firstChildElement( u"vector-streamline-settings"_s );
730 if ( ! elemStreamLine.isNull() )
731 mStreamLinesSettings.readXml( elemStreamLine );
732
733 const QDomElement elemTraces = elem.firstChildElement( u"vector-traces-settings"_s );
734 if ( ! elemTraces.isNull() )
735 mTracesSettings.readXml( elemTraces );
736
737 const QDomElement elemWindBarb = elem.firstChildElement( u"vector-windbarb-settings"_s );
738 if ( ! elemWindBarb.isNull() )
739 mWindBarbSettings.readXml( elemWindBarb );
740}
741
746
751
753{
754 return mColorRampShader;
755}
756
761
763{
764 QgsInterpolatedLineColor strokeColoring;
765 switch ( mColoringMethod )
766 {
768 strokeColoring = QgsInterpolatedLineColor( mColor );
769 break;
771 strokeColoring = QgsInterpolatedLineColor( mColorRampShader );
772 break;
773 }
774
775 return strokeColoring;
776}
777
782
787
788void QgsMeshRendererVectorTracesSettings::readXml( const QDomElement &elem )
789{
790 mMaximumTailLength = elem.attribute( u"maximum-tail-length"_s ).toInt();
791 mMaximumTailLengthUnit = static_cast<Qgis::RenderUnit>(
792 elem.attribute( u"maximum-tail-length-unit"_s ).toInt() );
793 mParticlesCount = elem.attribute( u"particles-count"_s ).toInt();
794}
795
796QDomElement QgsMeshRendererVectorTracesSettings::writeXml( QDomDocument &doc ) const
797{
798 QDomElement elem = doc.createElement( u"vector-traces-settings"_s );
799 elem.setAttribute( u"maximum-tail-length"_s, mMaximumTailLength );
800 elem.setAttribute( u"maximum-tail-length-unit"_s, static_cast< int >( mMaximumTailLengthUnit ) );
801 elem.setAttribute( u"particles-count"_s, mParticlesCount );
802
803 return elem;
804}
805
807{
808 return mMaximumTailLengthUnit;
809}
810
815
817{
818 return mMaximumTailLength;
819}
820
825
827{
828 return mParticlesCount;
829}
830
832{
833 mParticlesCount = value;
834}
835
836bool QgsMeshRendererSettings::hasSettings( int datasetGroupIndex ) const
837{
838 return mRendererScalarSettings.contains( datasetGroupIndex ) || mRendererVectorSettings.contains( datasetGroupIndex );
839}
840
845
850
852{
853 mShaftLength = elem.attribute( u"shaft-length"_s, u"10"_s ).toDouble();
854 mShaftLengthUnits = static_cast<Qgis::RenderUnit>(
855 elem.attribute( u"shaft-length-units"_s ).toInt() );
856 mMagnitudeMultiplier = elem.attribute( u"magnitude-multiplier"_s, u"1"_s ).toDouble();
857 mMagnitudeUnits = static_cast<WindSpeedUnit>(
858 elem.attribute( u"magnitude-units"_s, u"0"_s ).toInt() );
859}
860
861QDomElement QgsMeshRendererVectorWindBarbSettings::writeXml( QDomDocument &doc ) const
862{
863 QDomElement elem = doc.createElement( u"vector-windbarb-settings"_s );
864 elem.setAttribute( u"shaft-length"_s, mShaftLength );
865 elem.setAttribute( u"shaft-length-units"_s, static_cast< int >( mShaftLengthUnits ) );
866 elem.setAttribute( u"magnitude-multiplier"_s, mMagnitudeMultiplier );
867 elem.setAttribute( u"magnitude-units"_s, static_cast< int >( mMagnitudeUnits ) );
868 return elem;
869}
870
872{
873 switch ( mMagnitudeUnits )
874 {
876 return 1.0;
878 return 3600.0 / 1852.0;
880 return 1.0 / 1.852;
882 return 1.609344 / 1.852;
884 return 3600.0 / 1.852 / 5280.0 * 1.609344 ;
886 return mMagnitudeMultiplier;
887 }
888 return 1.0; // should not reach
889}
890
895
897{
898 return mShaftLength;
899}
900
905
907{
908 return mShaftLengthUnits;
909}
910
912{
913 mShaftLengthUnits = shaftLengthUnit;
914}
915
920
922{
923 mMagnitudeUnits = units;
924}
@ NotSet
User defined.
Definition qgis.h:6315
@ WholeMesh
Whole mesh is used to compute statistics.
Definition qgis.h:6327
RenderUnit
Rendering size units.
Definition qgis.h:5255
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
bool isEmpty() const
Whether the color ramp contains any items.
QgsColorRamp * sourceColorRamp() const
Returns the source color ramp.
void classifyColorRamp(int classes=0, int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
Classify color ramp shader.
virtual int count() const =0
Returns number of defined colors, or -1 if undefined.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Defines color interpolation for rendering mesh datasets.
ColoringMethod
Defines how the color is defined.
@ ColorRamp
Render with a color ramp.
@ SingleColor
Render with a single color.
Represents a width that can vary depending on values.
Abstract class for interpolating 3d stacked mesh data to 2d data.
static QgsMesh3DAveragingMethod * createFromXml(const QDomElement &elem)
Creates the instance from XML by calling readXml of derived classes.
virtual QDomElement writeXml(QDomDocument &doc) const =0
Writes configuration to a new DOM element.
virtual QgsMesh3DAveragingMethod * clone() const =0
Clone the instance.
void setLineWidthUnit(Qgis::RenderUnit lineWidthUnit)
Sets units of the width of the mesh frame.
void setEnabled(bool enabled)
Sets whether mesh structure rendering is enabled.
QColor color() const
Returns color used for rendering.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
double lineWidth() const
Returns line width used for rendering (in millimeters).
void setLineWidth(double lineWidth)
Sets line width used for rendering (in millimeters).
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
Qgis::RenderUnit lineWidthUnit() const
Returns units of the width of the mesh frame.
bool isEnabled() const
Returns whether mesh structure rendering is enabled.
void setColor(const QColor &color)
Sets color used for rendering of the mesh.
Represents a mesh renderer settings for scalar datasets.
void setClassificationMinimumMaximum(double minimum, double maximum)
Sets min/max values used for creation of the color ramp shader.
double opacity() const
Returns opacity.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads configuration from the given DOM element.
void setEdgeStrokeWidthUnit(Qgis::RenderUnit edgeStrokeWidthUnit)
Sets the stroke width unit used to render edges scalar dataset.
void setColorRampShader(const QgsColorRampShader &shader)
Sets color ramp shader function.
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
double classificationMinimum() const
Returns min value used for creation of the color ramp shader.
void setOpacity(double opacity)
Sets opacity.
DataResamplingMethod
Resampling of value from dataset.
@ NoResampling
Does not use resampling.
@ NeighbourAverage
Does a simple average of values defined for all surrounding faces/vertices.
Qgis::RenderUnit edgeStrokeWidthUnit() const
Returns the stroke width unit used to render edges scalar dataset.
DataResamplingMethod dataResamplingMethod() const
Returns the type of interpolation to use to convert face defined datasets to values on vertices.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes configuration to a new DOM element.
void setEdgeStrokeWidth(const QgsInterpolatedLineWidth &strokeWidth)
Sets the stroke width used to render edges scalar dataset.
double classificationMaximum() const
Returns max value used for creation of the color ramp shader.
QgsInterpolatedLineWidth edgeStrokeWidth() const
Returns the stroke width used to render edges scalar dataset.
void setDataResamplingMethod(const DataResamplingMethod &dataResamplingMethod)
Sets data interpolation method.
void setAveragingMethod(QgsMesh3DAveragingMethod *method)
Sets averaging method for conversion of 3d stacked mesh data to 2d data.
void setActiveVectorDatasetGroup(int activeVectorDatasetGroup)
Sets the active vector dataset group.
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
QgsMesh3DAveragingMethod * averagingMethod() const
Returns averaging method for conversion of 3d stacked mesh data to 2d data.
bool hasSettings(int datasetGroupIndex) const
Returns whether the group with index has render settings (scalar or vector).
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
QgsMeshRendererVectorSettings vectorSettings(int groupIndex) const
Returns renderer settings.
void setActiveScalarDatasetGroup(int activeScalarDatasetGroup)
Sets the active scalar dataset group.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads configuration from the given DOM element.
QgsMeshRendererSettings()
Constructs renderer with default single layer averaging method.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes configuration to a new DOM element.
QgsMeshRendererSettings & operator=(const QgsMeshRendererSettings &other)
Represents a mesh renderer settings for vector datasets displayed with arrows.
void setFixedShaftLength(double fixedShaftLength)
Sets fixed length (in millimeters).
void setMaxShaftLength(double maxShaftLength)
Sets maximum shaft length (in millimeters).
QgsMeshRendererVectorArrowSettings::ArrowScalingMethod shaftLengthMethod() const
Returns method used for drawing arrows.
void setMinShaftLength(double minShaftLength)
Sets mininimum shaft length (in millimeters).
double fixedShaftLength() const
Returns fixed arrow length (in millimeters).
void setArrowHeadWidthRatio(double arrowHeadWidthRatio)
Sets ratio of the head width of the arrow (range 0-1).
double scaleFactor() const
Returns scale factor.
double maxShaftLength() const
Returns maximum shaft length (in millimeters).
double arrowHeadWidthRatio() const
Returns ratio of the head width of the arrow (range 0-1).
void setArrowHeadLengthRatio(double arrowHeadLengthRatio)
Sets ratio of the head length of the arrow (range 0-1).
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
void setScaleFactor(double scaleFactor)
Sets scale factor.
void setShaftLengthMethod(ArrowScalingMethod shaftLengthMethod)
Sets method used for drawing arrows.
ArrowScalingMethod
Algorithm how to transform vector magnitude to length of arrow on the device in pixels.
@ Scaled
Scale vector magnitude by factor scaleFactor().
@ MinMax
Scale vector magnitude linearly to fit in range of vectorFilterMin() and vectorFilterMax().
@ Fixed
Use fixed length fixedShaftLength() regardless of vector's magnitude.
double minShaftLength() const
Returns mininimum shaft length (in millimeters).
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
double arrowHeadLengthRatio() const
Returns ratio of the head length of the arrow (range 0-1).
Represents a renderer settings for vector datasets.
void setColorRampShader(const QgsColorRampShader &colorRampShader)
Returns the color ramp shader used to render vector datasets.
void setStreamLinesSettings(const QgsMeshRendererVectorStreamlineSettings &streamLinesSettings)
Sets settings for vector rendered with streamlines.
int userGridCellWidth() const
Returns width in pixels of user grid cell.
void setArrowsSettings(const QgsMeshRendererVectorArrowSettings &arrowSettings)
Sets settings for vector rendered with arrows.
void setUserGridCellWidth(int width)
Sets width of user grid cell (in pixels).
void setColor(const QColor &color)
Sets color used for drawing arrows.
QgsMeshRendererVectorTracesSettings tracesSettings() const
Returns settings for vector rendered with traces.
QColor color() const
Returns color used for drawing arrows.
int userGridCellHeight() const
Returns height in pixels of user grid cell.
void setOnUserDefinedGrid(bool enabled)
Toggles drawing of vectors on user defined grid.
double lineWidth() const
Returns line width of the arrow (in millimeters).
Symbology
Defines the symbology of vector rendering.
void setUserGridCellHeight(int height)
Sets height of user grid cell (in pixels).
Symbology symbology() const
Returns the displaying method used to render vector datasets.
double filterMax() const
Returns filter value for vector magnitudes.
QgsColorRampShader colorRampShader() const
Sets the color ramp shader used to render vector datasets.
void setSymbology(const Symbology &symbology)
Sets the displaying method used to render vector datasets.
void setFilterMin(double filterMin)
Sets filter value for vector magnitudes.
QgsMeshRendererVectorArrowSettings arrowSettings() const
Returns settings for vector rendered with arrows.
void setFilterMax(double filterMax)
Sets filter value for vector magnitudes.
QgsInterpolatedLineColor vectorStrokeColoring() const
Returns the stroke coloring used to render vector datasets.
void setTracesSettings(const QgsMeshRendererVectorTracesSettings &tracesSettings)
Sets settings for vector rendered with traces.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes configuration to a new DOM element.
void setColoringMethod(const QgsInterpolatedLineColor::ColoringMethod &coloringMethod)
Sets the coloring method used to render vector datasets.
QgsInterpolatedLineColor::ColoringMethod coloringMethod() const
Returns the coloring method used to render vector datasets.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads configuration from the given DOM element.
QgsMeshRendererVectorWindBarbSettings windBarbSettings() const
Returns settings for vector rendered with wind barbs.
void setLineWidth(double lineWidth)
Sets line width of the arrow in pixels (in millimeters).
bool isOnUserDefinedGrid() const
Returns whether vectors are drawn on user-defined grid.
double filterMin() const
Returns filter value for vector magnitudes.
void setWindBarbSettings(const QgsMeshRendererVectorWindBarbSettings &windBarbSettings)
Sets settings for vector rendered with wind barbs.
QgsMeshRendererVectorStreamlineSettings streamLinesSettings() const
Returns settings for vector rendered with streamlines.
Represents a streamline renderer settings for vector datasets displayed by streamlines.
void setSeedingDensity(double seedingDensity)
Sets the density used for seeding start points.
SeedingStartPointsMethod seedingMethod() const
Returns the method used for seeding start points of strealines.
void setSeedingMethod(const SeedingStartPointsMethod &seedingMethod)
Sets the method used for seeding start points of strealines.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
SeedingStartPointsMethod
Method used to define start points that are used to draw streamlines.
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
double seedingDensity() const
Returns the density used for seeding start points.
Represents a trace renderer settings for vector datasets displayed by particle traces.
Qgis::RenderUnit maximumTailLengthUnit() const
Returns the maximum tail length unit.
void setMaximumTailLength(double maximumTailLength)
Sets the maximums tail length.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
void setMaximumTailLengthUnit(Qgis::RenderUnit maximumTailLengthUnit)
Sets the maximum tail length unit.
double maximumTailLength() const
Returns the maximum tail length.
int particlesCount() const
Returns particles count.
void setParticlesCount(int value)
Sets particles count.
Represents a mesh renderer settings for vector datasets displayed with wind barbs.
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
void setShaftLengthUnits(Qgis::RenderUnit shaftLengthUnit)
Sets the units for the shaft length.
WindSpeedUnit magnitudeUnits() const
Returns the units that the data are in.
void setMagnitudeUnits(WindSpeedUnit units)
Sets the units that the data are in.
void setMagnitudeMultiplier(double magnitudeMultiplier)
Sets a multiplier for the magnitude to convert it to knots.
double shaftLength() const
Returns the shaft length (in millimeters).
void setShaftLength(double shaftLength)
Sets the shaft length (in millimeters).
Qgis::RenderUnit shaftLengthUnits() const
Returns the units for the shaft length.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
WindSpeedUnit
Wind speed units. Wind barbs use knots so we use this enum for preset conversion values.
double magnitudeMultiplier() const
Returns the multiplier for the magnitude to convert it to knots, according to the units set with setM...
Sigma averages over the values between 0 (bed level) and 1 (surface).
virtual void setMaximumValue(double value)
Sets the maximum value for the raster shader.
virtual void setMinimumValue(double value)
Sets the minimum value for the raster shader.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:7110
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7091