QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
98{
99 return mClassificationMinimum;
100}
101
103{
104 return mClassificationMaximum;
105}
106
108{
109 mClassificationMinimum = minimum;
110 mClassificationMaximum = maximum;
111 updateShader();
112}
113
115{
116 return mOpacity;
117}
118
120{
121 mOpacity = opacity;
122}
123
128
130{
131 mDataResamplingMethod = dataInterpolationMethod;
132}
133
134QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
135{
136 QDomElement elem = doc.createElement( u"scalar-settings"_s );
137 elem.setAttribute( u"min-val"_s, mClassificationMinimum );
138 elem.setAttribute( u"max-val"_s, mClassificationMaximum );
139 elem.setAttribute( u"opacity"_s, mOpacity );
140
141 QString methodTxt;
142 switch ( mDataResamplingMethod )
143 {
144 case NoResampling:
145 methodTxt = u"no-resampling"_s;
146 break;
147 case NeighbourAverage:
148 methodTxt = u"neighbour-average"_s;
149 break;
150 }
151 elem.setAttribute( u"interpolation-method"_s, methodTxt );
152
153 if ( mRangeExtent != Qgis::MeshRangeExtent::WholeMesh )
154 elem.setAttribute( u"range-extent"_s, qgsEnumValueToKey( mRangeExtent ) );
155 if ( mRangeLimit != Qgis::MeshRangeLimit::NotSet )
156 elem.setAttribute( u"range-limit"_s, qgsEnumValueToKey( mRangeLimit ) );
157
158 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
159 elem.appendChild( elemShader );
160
161 QDomElement elemEdge = doc.createElement( u"edge-settings"_s );
162 elemEdge.appendChild( mEdgeStrokeWidth.writeXml( doc, context ) );
163 elemEdge.setAttribute( u"stroke-width-unit"_s, static_cast< int >( mEdgeStrokeWidthUnit ) );
164 elem.appendChild( elemEdge );
165
166 return elem;
167}
168
169void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
170{
171 mClassificationMinimum = elem.attribute( u"min-val"_s ).toDouble();
172 mClassificationMaximum = elem.attribute( u"max-val"_s ).toDouble();
173 mOpacity = elem.attribute( u"opacity"_s ).toDouble();
174
175 const QString methodTxt = elem.attribute( u"interpolation-method"_s );
176 if ( u"neighbour-average"_s == methodTxt )
177 {
178 mDataResamplingMethod = DataResamplingMethod::NeighbourAverage;
179 }
180 else
181 {
182 mDataResamplingMethod = DataResamplingMethod::NoResampling;
183 }
184
185 mRangeExtent = qgsEnumKeyToValue( elem.attribute( "range-extent" ), Qgis::MeshRangeExtent::WholeMesh );
186 mRangeLimit = qgsEnumKeyToValue( elem.attribute( "range-limit" ), Qgis::MeshRangeLimit::NotSet );
187
188 const QDomElement elemShader = elem.firstChildElement( u"colorrampshader"_s );
189 mColorRampShader.readXml( elemShader, context );
190
191 const QDomElement elemEdge = elem.firstChildElement( u"edge-settings"_s );
192 const QDomElement elemEdgeStrokeWidth = elemEdge.firstChildElement( u"mesh-stroke-width"_s );
193 mEdgeStrokeWidth.readXml( elemEdgeStrokeWidth, context );
194 mEdgeStrokeWidthUnit = static_cast<Qgis::RenderUnit>( elemEdge.attribute( u"stroke-width-unit"_s ).toInt() );
195}
196
201
203{
204 mEdgeStrokeWidth = strokeWidth;
205}
206
208{
209 return mEdgeStrokeWidthUnit;
210}
211
216
217void QgsMeshRendererScalarSettings::updateShader()
218{
219 mColorRampShader.setMinimumValue( mClassificationMinimum );
220 mColorRampShader.setMaximumValue( mClassificationMaximum );
221
222 if ( !mColorRampShader.isEmpty() )
223 mColorRampShader.classifyColorRamp( mColorRampShader.sourceColorRamp()->count(), 1, QgsRectangle(), nullptr );
224}
225
226
227// ---------------------------------------------------------------------
228
230{
231 return mLineWidth;
232}
233
235{
236 mLineWidth = lineWidth;
237}
238
240{
241 return mColor;
242}
243
244void QgsMeshRendererVectorSettings::setColor( const QColor &vectorColor )
245{
246 mColor = vectorColor;
247}
248
250{
251 return mFilterMin;
252}
253
255{
256 mFilterMin = vectorFilterMin;
257}
258
260{
261 return mFilterMax;
262}
263
265{
266 mFilterMax = vectorFilterMax;
267}
268
270{
271 return mOnUserDefinedGrid;
272}
273
275{
276 mOnUserDefinedGrid = enabled;
277}
278
280{
281 return mUserGridCellWidth;
282}
283
285{
286 mUserGridCellWidth = width;
287}
288
290{
291 return mUserGridCellHeight;
292}
293
295{
296 mUserGridCellHeight = height;
297}
298
303
308
310{
311 return mMinShaftLength;
312}
313
318
320{
321 return mMaxShaftLength;
322}
323
328
330{
331 return mScaleFactor;
332}
333
338
340{
341 return mFixedShaftLength;
342}
343
348
350{
351 return mArrowHeadWidthRatio;
352}
353
355{
356 mArrowHeadWidthRatio = vectorHeadWidthRatio;
357}
358
360{
361 return mArrowHeadLengthRatio;
362}
363
365{
366 mArrowHeadLengthRatio = vectorHeadLengthRatio;
367}
368
369QDomElement QgsMeshRendererVectorArrowSettings::writeXml( QDomDocument &doc ) const
370{
371 QDomElement elem = doc.createElement( u"vector-arrow-settings"_s );
372 elem.setAttribute( u"arrow-head-width-ratio"_s, mArrowHeadWidthRatio );
373 elem.setAttribute( u"arrow-head-length-ratio"_s, mArrowHeadLengthRatio );
374
375 QDomElement elemShaft = doc.createElement( u"shaft-length"_s );
376 QString methodTxt;
377 switch ( mShaftLengthMethod )
378 {
379 case MinMax:
380 methodTxt = u"minmax"_s;
381 elemShaft.setAttribute( u"min"_s, mMinShaftLength );
382 elemShaft.setAttribute( u"max"_s, mMaxShaftLength );
383 break;
384 case Scaled:
385 methodTxt = u"scaled"_s;
386 elemShaft.setAttribute( u"scale-factor"_s, mScaleFactor );
387 break;
388 case Fixed:
389 methodTxt = u"fixed"_s;
390 elemShaft.setAttribute( u"fixed-length"_s, mFixedShaftLength );
391 break;
392 }
393 elemShaft.setAttribute( u"method"_s, methodTxt );
394 elem.appendChild( elemShaft );
395 return elem;
396}
397
398void QgsMeshRendererVectorArrowSettings::readXml( const QDomElement &elem )
399{
400 mArrowHeadWidthRatio = elem.attribute( u"arrow-head-width-ratio"_s ).toDouble();
401 mArrowHeadLengthRatio = elem.attribute( u"arrow-head-length-ratio"_s ).toDouble();
402
403 const QDomElement elemShaft = elem.firstChildElement( u"shaft-length"_s );
404 const QString methodTxt = elemShaft.attribute( u"method"_s );
405 if ( u"minmax"_s == methodTxt )
406 {
407 mShaftLengthMethod = MinMax;
408 mMinShaftLength = elemShaft.attribute( u"min"_s ).toDouble();
409 mMaxShaftLength = elemShaft.attribute( u"max"_s ).toDouble();
410 }
411 else if ( u"scaled"_s == methodTxt )
412 {
413 mShaftLengthMethod = Scaled;
414 mScaleFactor = elemShaft.attribute( u"scale-factor"_s ).toDouble();
415 }
416 else // fixed
417 {
418 mShaftLengthMethod = Fixed;
419 mFixedShaftLength = elemShaft.attribute( u"fixed-length"_s ).toDouble();
420 }
421}
422
423// ---------------------------------------------------------------------
424
428
430 //****** IMPORTANT! editing this? make sure you update the move constructor too! *****
431 : mRendererNativeMeshSettings( other.mRendererNativeMeshSettings )
432 , mRendererTriangularMeshSettings( other.mRendererTriangularMeshSettings )
433 , mRendererEdgeMeshSettings( other.mRendererEdgeMeshSettings )
434 , mRendererScalarSettings( other.mRendererScalarSettings )
435 , mRendererVectorSettings( other.mRendererVectorSettings )
436 , mActiveScalarDatasetGroup( other.mActiveScalarDatasetGroup )
437 , mActiveVectorDatasetGroup( other.mActiveVectorDatasetGroup )
438 , mAveragingMethod( other.mAveragingMethod )
439//****** IMPORTANT! editing this? make sure you update the move constructor too! *****
440{}
441
443 : mRendererNativeMeshSettings( std::move( other.mRendererNativeMeshSettings ) )
444 , mRendererTriangularMeshSettings( std::move( other.mRendererTriangularMeshSettings ) )
445 , mRendererEdgeMeshSettings( std::move( other.mRendererEdgeMeshSettings ) )
446 , mRendererScalarSettings( std::move( other.mRendererScalarSettings ) )
447 , mRendererVectorSettings( std::move( other.mRendererVectorSettings ) )
448 , mActiveScalarDatasetGroup( other.mActiveScalarDatasetGroup )
449 , mActiveVectorDatasetGroup( other.mActiveVectorDatasetGroup )
450 , mAveragingMethod( std::move( other.mAveragingMethod ) )
451{}
452
454{
455 if ( &other == this )
456 return *this;
457
458 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
459 mRendererNativeMeshSettings = other.mRendererNativeMeshSettings;
460 mRendererTriangularMeshSettings = other.mRendererTriangularMeshSettings;
461 mRendererEdgeMeshSettings = other.mRendererEdgeMeshSettings;
462 mRendererScalarSettings = other.mRendererScalarSettings;
463 mRendererVectorSettings = other.mRendererVectorSettings;
464 mActiveScalarDatasetGroup = other.mActiveScalarDatasetGroup;
465 mActiveVectorDatasetGroup = other.mActiveVectorDatasetGroup;
466 mAveragingMethod = other.mAveragingMethod;
467 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
468 return *this;
469}
470
472{
473 if ( &other == this )
474 return *this;
475
476 mRendererNativeMeshSettings = std::move( other.mRendererNativeMeshSettings );
477 mRendererTriangularMeshSettings = std::move( other.mRendererTriangularMeshSettings );
478 mRendererEdgeMeshSettings = std::move( other.mRendererEdgeMeshSettings );
479 mRendererScalarSettings = std::move( other.mRendererScalarSettings );
480 mRendererVectorSettings = std::move( other.mRendererVectorSettings );
481 mActiveScalarDatasetGroup = other.mActiveScalarDatasetGroup;
482 mActiveVectorDatasetGroup = other.mActiveVectorDatasetGroup;
483 mAveragingMethod = std::move( other.mAveragingMethod );
484 return *this;
485}
486
488
490{
491 return mAveragingMethod.get();
492}
493
495{
496 if ( method )
497 mAveragingMethod.reset( method->clone() );
498 else
499 mAveragingMethod.reset();
500}
501
502QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
503{
504 QDomElement elem = doc.createElement( u"mesh-renderer-settings"_s );
505
506 QDomElement elemActiveDatasetGroup = doc.createElement( u"active-dataset-group"_s );
507 elemActiveDatasetGroup.setAttribute( u"scalar"_s, mActiveScalarDatasetGroup );
508 elemActiveDatasetGroup.setAttribute( u"vector"_s, mActiveVectorDatasetGroup );
509 elem.appendChild( elemActiveDatasetGroup );
510
511 for ( auto groupIndex = mRendererScalarSettings.keyBegin(); groupIndex != mRendererScalarSettings.keyEnd(); groupIndex++ )
512 {
513 const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[*groupIndex];
514 QDomElement elemScalar = scalarSettings.writeXml( doc, context );
515 elemScalar.setAttribute( u"group"_s, *groupIndex );
516 elem.appendChild( elemScalar );
517 }
518
519 for ( auto groupIndex = mRendererVectorSettings.keyBegin(); groupIndex != mRendererVectorSettings.keyEnd(); groupIndex++ )
520 {
521 const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[*groupIndex];
522 QDomElement elemVector = vectorSettings.writeXml( doc, context );
523 elemVector.setAttribute( u"group"_s, *groupIndex );
524 elem.appendChild( elemVector );
525 }
526
527 QDomElement elemNativeMesh = mRendererNativeMeshSettings.writeXml( doc );
528 elemNativeMesh.setTagName( u"mesh-settings-native"_s );
529 elem.appendChild( elemNativeMesh );
530
531 QDomElement elemEdgeMesh = mRendererEdgeMeshSettings.writeXml( doc );
532 elemEdgeMesh.setTagName( u"mesh-settings-edge"_s );
533 elem.appendChild( elemEdgeMesh );
534
535 QDomElement elemTriangularMesh = mRendererTriangularMeshSettings.writeXml( doc );
536 elemTriangularMesh.setTagName( u"mesh-settings-triangular"_s );
537 elem.appendChild( elemTriangularMesh );
538
539 if ( mAveragingMethod )
540 {
541 QDomElement elemAveraging = doc.createElement( u"averaging-3d"_s );
542 elemAveraging.setAttribute( u"method"_s, QString::number( mAveragingMethod->method() ) );
543 const QDomElement elemAveragingParams = mAveragingMethod->writeXml( doc );
544 elemAveraging.appendChild( elemAveragingParams );
545 elem.appendChild( elemAveraging );
546 }
547
548 return elem;
549}
550
551void QgsMeshRendererSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
552{
553 mRendererScalarSettings.clear();
554 mRendererVectorSettings.clear();
555 mAveragingMethod.reset();
556
557 const QDomElement elemActiveDataset = elem.firstChildElement( u"active-dataset-group"_s );
558 if ( elemActiveDataset.hasAttribute( u"scalar"_s ) )
559 mActiveScalarDatasetGroup = elemActiveDataset.attribute( u"scalar"_s ).toInt();
560
561 if ( elemActiveDataset.hasAttribute( u"vector"_s ) )
562 mActiveVectorDatasetGroup = elemActiveDataset.attribute( u"vector"_s ).toInt();
563
564 QDomElement elemScalar = elem.firstChildElement( u"scalar-settings"_s );
565 while ( !elemScalar.isNull() )
566 {
567 const int groupIndex = elemScalar.attribute( u"group"_s ).toInt();
569 scalarSettings.readXml( elemScalar, context );
570 mRendererScalarSettings.insert( groupIndex, scalarSettings );
571
572 elemScalar = elemScalar.nextSiblingElement( u"scalar-settings"_s );
573 }
574
575 QDomElement elemVector = elem.firstChildElement( u"vector-settings"_s );
576 while ( !elemVector.isNull() )
577 {
578 const int groupIndex = elemVector.attribute( u"group"_s ).toInt();
580 vectorSettings.readXml( elemVector, context );
581 mRendererVectorSettings.insert( groupIndex, vectorSettings );
582
583 elemVector = elemVector.nextSiblingElement( u"vector-settings"_s );
584 }
585
586 const QDomElement elemNativeMesh = elem.firstChildElement( u"mesh-settings-native"_s );
587 mRendererNativeMeshSettings.readXml( elemNativeMesh );
588
589 const QDomElement elemEdgeMesh = elem.firstChildElement( u"mesh-settings-edge"_s );
590 mRendererEdgeMeshSettings.readXml( elemEdgeMesh );
591
592 const QDomElement elemTriangularMesh = elem.firstChildElement( u"mesh-settings-triangular"_s );
593 mRendererTriangularMeshSettings.readXml( elemTriangularMesh );
594
595 const QDomElement elemAveraging = elem.firstChildElement( u"averaging-3d"_s );
596 if ( !elemAveraging.isNull() )
597 {
598 mAveragingMethod.reset( QgsMesh3DAveragingMethod::createFromXml( elemAveraging ) );
599 }
600}
601
603{
604 return mActiveScalarDatasetGroup;
605}
606
611
613{
614 return mActiveVectorDatasetGroup;
615}
616
621
626
631
633{
634 return mSeedingDensity;
635}
636
641
642QDomElement QgsMeshRendererVectorStreamlineSettings::writeXml( QDomDocument &doc ) const
643{
644 QDomElement elem = doc.createElement( u"vector-streamline-settings"_s );
645
646 elem.setAttribute( u"seeding-method"_s, mSeedingMethod );
647 elem.setAttribute( u"seeding-density"_s, mSeedingDensity );
648
649 return elem;
650}
651
653{
654 mSeedingMethod = static_cast<QgsMeshRendererVectorStreamlineSettings::SeedingStartPointsMethod>( elem.attribute( u"seeding-method"_s ).toInt() );
655 mSeedingDensity = elem.attribute( u"seeding-density"_s ).toDouble();
656}
657
662
664{
665 mDisplayingMethod = displayingMethod;
666}
667
672
677
682
687
688QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
689{
690 QDomElement elem = doc.createElement( u"vector-settings"_s );
691 elem.setAttribute( u"symbology"_s, mDisplayingMethod );
692
693 elem.setAttribute( u"line-width"_s, mLineWidth );
694 elem.setAttribute( u"coloring-method"_s, coloringMethod() );
695 elem.setAttribute( u"color"_s, QgsColorUtils::colorToString( mColor ) );
696 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
697 elem.appendChild( elemShader );
698 elem.setAttribute( u"filter-min"_s, mFilterMin );
699 elem.setAttribute( u"filter-max"_s, mFilterMax );
700
701 elem.setAttribute( u"user-grid-enabled"_s, mOnUserDefinedGrid ? u"1"_s : u"0"_s );
702 elem.setAttribute( u"user-grid-width"_s, mUserGridCellWidth );
703 elem.setAttribute( u"user-grid-height"_s, mUserGridCellHeight );
704
705 elem.appendChild( mArrowsSettings.writeXml( doc ) );
706 elem.appendChild( mStreamLinesSettings.writeXml( doc ) );
707 elem.appendChild( mTracesSettings.writeXml( doc ) );
708 elem.appendChild( mWindBarbSettings.writeXml( doc ) );
709
710 return elem;
711}
712
713void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
714{
715 mDisplayingMethod = static_cast<QgsMeshRendererVectorSettings::Symbology>( elem.attribute( u"symbology"_s ).toInt() );
716
717 mLineWidth = elem.attribute( u"line-width"_s ).toDouble();
718 mColoringMethod = static_cast<QgsInterpolatedLineColor::ColoringMethod>( elem.attribute( u"coloring-method"_s ).toInt() );
719 mColor = QgsColorUtils::colorFromString( elem.attribute( u"color"_s ) );
720 mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context );
721 mFilterMin = elem.attribute( u"filter-min"_s ).toDouble();
722 mFilterMax = elem.attribute( u"filter-max"_s ).toDouble();
723
724 mOnUserDefinedGrid = elem.attribute( u"user-grid-enabled"_s ).toInt(); //bool
725 mUserGridCellWidth = elem.attribute( u"user-grid-width"_s ).toInt();
726 mUserGridCellHeight = elem.attribute( u"user-grid-height"_s ).toInt();
727
728 const QDomElement elemVector = elem.firstChildElement( u"vector-arrow-settings"_s );
729 if ( !elemVector.isNull() )
730 mArrowsSettings.readXml( elemVector );
731
732 const QDomElement elemStreamLine = elem.firstChildElement( u"vector-streamline-settings"_s );
733 if ( !elemStreamLine.isNull() )
734 mStreamLinesSettings.readXml( elemStreamLine );
735
736 const QDomElement elemTraces = elem.firstChildElement( u"vector-traces-settings"_s );
737 if ( !elemTraces.isNull() )
738 mTracesSettings.readXml( elemTraces );
739
740 const QDomElement elemWindBarb = elem.firstChildElement( u"vector-windbarb-settings"_s );
741 if ( !elemWindBarb.isNull() )
742 mWindBarbSettings.readXml( elemWindBarb );
743}
744
749
754
756{
757 return mColorRampShader;
758}
759
764
766{
767 QgsInterpolatedLineColor strokeColoring;
768 switch ( mColoringMethod )
769 {
771 strokeColoring = QgsInterpolatedLineColor( mColor );
772 break;
774 strokeColoring = QgsInterpolatedLineColor( mColorRampShader );
775 break;
776 }
777
778 return strokeColoring;
779}
780
785
790
791void QgsMeshRendererVectorTracesSettings::readXml( const QDomElement &elem )
792{
793 mMaximumTailLength = elem.attribute( u"maximum-tail-length"_s ).toInt();
794 mMaximumTailLengthUnit = static_cast<Qgis::RenderUnit>( elem.attribute( u"maximum-tail-length-unit"_s ).toInt() );
795 mParticlesCount = elem.attribute( u"particles-count"_s ).toInt();
796}
797
798QDomElement QgsMeshRendererVectorTracesSettings::writeXml( QDomDocument &doc ) const
799{
800 QDomElement elem = doc.createElement( u"vector-traces-settings"_s );
801 elem.setAttribute( u"maximum-tail-length"_s, mMaximumTailLength );
802 elem.setAttribute( u"maximum-tail-length-unit"_s, static_cast< int >( mMaximumTailLengthUnit ) );
803 elem.setAttribute( u"particles-count"_s, mParticlesCount );
804
805 return elem;
806}
807
809{
810 return mMaximumTailLengthUnit;
811}
812
817
819{
820 return mMaximumTailLength;
821}
822
827
829{
830 return mParticlesCount;
831}
832
834{
835 mParticlesCount = value;
836}
837
838bool QgsMeshRendererSettings::hasSettings( int datasetGroupIndex ) const
839{
840 return mRendererScalarSettings.contains( datasetGroupIndex ) || mRendererVectorSettings.contains( datasetGroupIndex );
841}
842
847
852
854{
855 mShaftLength = elem.attribute( u"shaft-length"_s, u"10"_s ).toDouble();
856 mShaftLengthUnits = static_cast<Qgis::RenderUnit>( elem.attribute( u"shaft-length-units"_s ).toInt() );
857 mMagnitudeMultiplier = elem.attribute( u"magnitude-multiplier"_s, u"1"_s ).toDouble();
858 mMagnitudeUnits = static_cast<WindSpeedUnit>( 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:6407
@ WholeMesh
Whole mesh is used to compute statistics.
Definition qgis.h:6419
RenderUnit
Rendering size units.
Definition qgis.h:5340
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:7176
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7157