QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
25{
26 return mEnabled;
27}
28
30{
31 mEnabled = on;
32}
33
35{
36 return mLineWidth;
37}
38
40{
41 mLineWidth = lineWidth;
42}
43
45{
46 return mColor;
47}
48
50{
51 mColor = color;
52}
53
55{
56 return mLineWidthUnit;
57}
58
63
64QDomElement QgsMeshRendererMeshSettings::writeXml( QDomDocument &doc ) const
65{
66 QDomElement elem = doc.createElement( QStringLiteral( "mesh-settings" ) );
67 elem.setAttribute( QStringLiteral( "enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
68 elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth );
69 elem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) );
70 elem.setAttribute( QStringLiteral( "line-width-unit" ), QgsUnitTypes::encodeUnit( mLineWidthUnit ) );
71 return elem;
72}
73
74void QgsMeshRendererMeshSettings::readXml( const QDomElement &elem )
75{
76 mEnabled = elem.attribute( QStringLiteral( "enabled" ) ).toInt();
77 mLineWidth = elem.attribute( QStringLiteral( "line-width" ) ).toDouble();
78 mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) );
79 mLineWidthUnit = QgsUnitTypes::decodeRenderUnit( elem.attribute( QStringLiteral( "line-width-unit" ) ) );
80}
81// ---------------------------------------------------------------------
82
84{
85 return mColorRampShader;
86}
87
89{
90 mColorRampShader = shader;
91}
92
93double QgsMeshRendererScalarSettings::classificationMinimum() const { return mClassificationMinimum; }
94
95double QgsMeshRendererScalarSettings::classificationMaximum() const { return mClassificationMaximum; }
96
98{
99 mClassificationMinimum = minimum;
100 mClassificationMaximum = maximum;
101 updateShader();
102}
103
104double QgsMeshRendererScalarSettings::opacity() const { return mOpacity; }
105
107
112
114{
115 mDataResamplingMethod = dataInterpolationMethod;
116}
117
118QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
119{
120 QDomElement elem = doc.createElement( QStringLiteral( "scalar-settings" ) );
121 elem.setAttribute( QStringLiteral( "min-val" ), mClassificationMinimum );
122 elem.setAttribute( QStringLiteral( "max-val" ), mClassificationMaximum );
123 elem.setAttribute( QStringLiteral( "opacity" ), mOpacity );
124
125 QString methodTxt;
126 switch ( mDataResamplingMethod )
127 {
128 case NoResampling:
129 methodTxt = QStringLiteral( "no-resampling" );
130 break;
131 case NeighbourAverage:
132 methodTxt = QStringLiteral( "neighbour-average" );
133 break;
134 }
135 elem.setAttribute( QStringLiteral( "interpolation-method" ), methodTxt );
136
137 if ( mRangeExtent != Qgis::MeshRangeExtent::WholeMesh )
138 elem.setAttribute( QStringLiteral( "range-extent" ), qgsEnumValueToKey( mRangeExtent ) );
139 if ( mRangeLimit != Qgis::MeshRangeLimit::NotSet )
140 elem.setAttribute( QStringLiteral( "range-limit" ), qgsEnumValueToKey( mRangeLimit ) );
141
142 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
143 elem.appendChild( elemShader );
144
145 QDomElement elemEdge = doc.createElement( QStringLiteral( "edge-settings" ) );
146 elemEdge.appendChild( mEdgeStrokeWidth.writeXml( doc, context ) );
147 elemEdge.setAttribute( QStringLiteral( "stroke-width-unit" ), static_cast< int >( mEdgeStrokeWidthUnit ) );
148 elem.appendChild( elemEdge );
149
150 return elem;
151}
152
153void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
154{
155 mClassificationMinimum = elem.attribute( QStringLiteral( "min-val" ) ).toDouble();
156 mClassificationMaximum = elem.attribute( QStringLiteral( "max-val" ) ).toDouble();
157 mOpacity = elem.attribute( QStringLiteral( "opacity" ) ).toDouble();
158
159 const QString methodTxt = elem.attribute( QStringLiteral( "interpolation-method" ) );
160 if ( QStringLiteral( "neighbour-average" ) == methodTxt )
161 {
162 mDataResamplingMethod = DataResamplingMethod::NeighbourAverage;
163 }
164 else
165 {
166 mDataResamplingMethod = DataResamplingMethod::NoResampling;
167 }
168
169 mRangeExtent = qgsEnumKeyToValue( elem.attribute( "range-extent" ), Qgis::MeshRangeExtent::WholeMesh );
170 mRangeLimit = qgsEnumKeyToValue( elem.attribute( "range-limit" ), Qgis::MeshRangeLimit::NotSet );
171
172 const QDomElement elemShader = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
173 mColorRampShader.readXml( elemShader, context );
174
175 const QDomElement elemEdge = elem.firstChildElement( QStringLiteral( "edge-settings" ) );
176 const QDomElement elemEdgeStrokeWidth = elemEdge.firstChildElement( QStringLiteral( "mesh-stroke-width" ) );
177 mEdgeStrokeWidth.readXml( elemEdgeStrokeWidth, context );
178 mEdgeStrokeWidthUnit = static_cast<Qgis::RenderUnit>(
179 elemEdge.attribute( QStringLiteral( "stroke-width-unit" ) ).toInt() );
180}
181
186
188{
189 mEdgeStrokeWidth = strokeWidth;
190}
191
193{
194 return mEdgeStrokeWidthUnit;
195}
196
201
202void QgsMeshRendererScalarSettings::updateShader()
203{
204
205 mColorRampShader.setMinimumValue( mClassificationMinimum );
206 mColorRampShader.setMaximumValue( mClassificationMaximum );
207
208 if ( !mColorRampShader.isEmpty() )
209 mColorRampShader.classifyColorRamp( mColorRampShader.sourceColorRamp()->count(), 1, QgsRectangle(), nullptr );
210}
211
212
213// ---------------------------------------------------------------------
214
216{
217 return mLineWidth;
218}
219
221{
222 mLineWidth = lineWidth;
223}
224
226{
227 return mColor;
228}
229
230void QgsMeshRendererVectorSettings::setColor( const QColor &vectorColor )
231{
232 mColor = vectorColor;
233}
234
236{
237 return mFilterMin;
238}
239
241{
242 mFilterMin = vectorFilterMin;
243}
244
246{
247 return mFilterMax;
248}
249
251{
252 mFilterMax = vectorFilterMax;
253}
254
256{
257 return mOnUserDefinedGrid;
258}
259
261{
262 mOnUserDefinedGrid = enabled;
263}
264
266{
267 return mUserGridCellWidth;
268}
269
271{
272 mUserGridCellWidth = width;
273}
274
276{
277 return mUserGridCellHeight;
278}
279
281{
282 mUserGridCellHeight = height;
283}
284
289
294
296{
297 return mMinShaftLength;
298}
299
304
306{
307 return mMaxShaftLength;
308}
309
314
316{
317 return mScaleFactor;
318}
319
324
326{
327 return mFixedShaftLength;
328}
329
334
336{
337 return mArrowHeadWidthRatio;
338}
339
341{
342 mArrowHeadWidthRatio = vectorHeadWidthRatio;
343}
344
346{
347 return mArrowHeadLengthRatio;
348}
349
351{
352 mArrowHeadLengthRatio = vectorHeadLengthRatio;
353}
354
355QDomElement QgsMeshRendererVectorArrowSettings::writeXml( QDomDocument &doc ) const
356{
357 QDomElement elem = doc.createElement( QStringLiteral( "vector-arrow-settings" ) );
358 elem.setAttribute( QStringLiteral( "arrow-head-width-ratio" ), mArrowHeadWidthRatio );
359 elem.setAttribute( QStringLiteral( "arrow-head-length-ratio" ), mArrowHeadLengthRatio );
360
361 QDomElement elemShaft = doc.createElement( QStringLiteral( "shaft-length" ) );
362 QString methodTxt;
363 switch ( mShaftLengthMethod )
364 {
365 case MinMax:
366 methodTxt = QStringLiteral( "minmax" );
367 elemShaft.setAttribute( QStringLiteral( "min" ), mMinShaftLength );
368 elemShaft.setAttribute( QStringLiteral( "max" ), mMaxShaftLength );
369 break;
370 case Scaled:
371 methodTxt = QStringLiteral( "scaled" );
372 elemShaft.setAttribute( QStringLiteral( "scale-factor" ), mScaleFactor );
373 break;
374 case Fixed:
375 methodTxt = QStringLiteral( "fixed" ) ;
376 elemShaft.setAttribute( QStringLiteral( "fixed-length" ), mFixedShaftLength );
377 break;
378 }
379 elemShaft.setAttribute( QStringLiteral( "method" ), methodTxt );
380 elem.appendChild( elemShaft );
381 return elem;
382}
383
384void QgsMeshRendererVectorArrowSettings::readXml( const QDomElement &elem )
385{
386 mArrowHeadWidthRatio = elem.attribute( QStringLiteral( "arrow-head-width-ratio" ) ).toDouble();
387 mArrowHeadLengthRatio = elem.attribute( QStringLiteral( "arrow-head-length-ratio" ) ).toDouble();
388
389 const QDomElement elemShaft = elem.firstChildElement( QStringLiteral( "shaft-length" ) );
390 const QString methodTxt = elemShaft.attribute( QStringLiteral( "method" ) );
391 if ( QStringLiteral( "minmax" ) == methodTxt )
392 {
393 mShaftLengthMethod = MinMax;
394 mMinShaftLength = elemShaft.attribute( QStringLiteral( "min" ) ).toDouble();
395 mMaxShaftLength = elemShaft.attribute( QStringLiteral( "max" ) ).toDouble();
396 }
397 else if ( QStringLiteral( "scaled" ) == methodTxt )
398 {
399 mShaftLengthMethod = Scaled;
400 mScaleFactor = elemShaft.attribute( QStringLiteral( "scale-factor" ) ).toDouble();
401 }
402 else // fixed
403 {
404 mShaftLengthMethod = Fixed;
405 mFixedShaftLength = elemShaft.attribute( QStringLiteral( "fixed-length" ) ).toDouble();
406 }
407}
408
409// ---------------------------------------------------------------------
410
415
417//****** IMPORTANT! editing this? make sure you update the move constructor too! *****
418 : mRendererNativeMeshSettings( other.mRendererNativeMeshSettings )
419 , mRendererTriangularMeshSettings( other.mRendererTriangularMeshSettings )
420 , mRendererEdgeMeshSettings( other.mRendererEdgeMeshSettings )
421 , mRendererScalarSettings( other.mRendererScalarSettings )
422 , mRendererVectorSettings( other.mRendererVectorSettings )
423 , mActiveScalarDatasetGroup( other.mActiveScalarDatasetGroup )
424 , mActiveVectorDatasetGroup( other.mActiveVectorDatasetGroup )
425 , mAveragingMethod( other.mAveragingMethod )
426 //****** IMPORTANT! editing this? make sure you update the move constructor too! *****
427{
428}
429
431 : mRendererNativeMeshSettings( std::move( other.mRendererNativeMeshSettings ) )
432 , mRendererTriangularMeshSettings( std::move( other.mRendererTriangularMeshSettings ) )
433 , mRendererEdgeMeshSettings( std::move( other.mRendererEdgeMeshSettings ) )
434 , mRendererScalarSettings( std::move( other.mRendererScalarSettings ) )
435 , mRendererVectorSettings( std::move( other.mRendererVectorSettings ) )
436 , mActiveScalarDatasetGroup( other.mActiveScalarDatasetGroup )
437 , mActiveVectorDatasetGroup( other.mActiveVectorDatasetGroup )
438 , mAveragingMethod( std::move( other.mAveragingMethod ) )
439{
440}
441
443{
444 if ( &other == this )
445 return *this;
446
447 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
448 mRendererNativeMeshSettings = other.mRendererNativeMeshSettings;
449 mRendererTriangularMeshSettings = other.mRendererTriangularMeshSettings;
450 mRendererEdgeMeshSettings = other.mRendererEdgeMeshSettings;
451 mRendererScalarSettings = other.mRendererScalarSettings;
452 mRendererVectorSettings = other.mRendererVectorSettings;
453 mActiveScalarDatasetGroup = other.mActiveScalarDatasetGroup;
454 mActiveVectorDatasetGroup = other.mActiveVectorDatasetGroup;
455 mAveragingMethod = other.mAveragingMethod;
456 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
457 return *this;
458}
459
461{
462 if ( &other == this )
463 return *this;
464
465 mRendererNativeMeshSettings = std::move( other.mRendererNativeMeshSettings );
466 mRendererTriangularMeshSettings = std::move( other.mRendererTriangularMeshSettings );
467 mRendererEdgeMeshSettings = std::move( other.mRendererEdgeMeshSettings );
468 mRendererScalarSettings = std::move( other.mRendererScalarSettings );
469 mRendererVectorSettings = std::move( other.mRendererVectorSettings );
470 mActiveScalarDatasetGroup = other.mActiveScalarDatasetGroup;
471 mActiveVectorDatasetGroup = other.mActiveVectorDatasetGroup;
472 mAveragingMethod = std::move( other.mAveragingMethod );
473 return *this;
474}
475
477
479{
480 return mAveragingMethod.get();
481}
482
484{
485 if ( method )
486 mAveragingMethod.reset( method->clone() );
487 else
488 mAveragingMethod.reset();
489}
490
491QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
492{
493 QDomElement elem = doc.createElement( QStringLiteral( "mesh-renderer-settings" ) );
494
495 QDomElement elemActiveDatasetGroup = doc.createElement( QStringLiteral( "active-dataset-group" ) );
496 elemActiveDatasetGroup.setAttribute( QStringLiteral( "scalar" ), mActiveScalarDatasetGroup );
497 elemActiveDatasetGroup.setAttribute( QStringLiteral( "vector" ), mActiveVectorDatasetGroup );
498 elem.appendChild( elemActiveDatasetGroup );
499
500 for ( auto groupIndex = mRendererScalarSettings.keyBegin(); groupIndex != mRendererScalarSettings.keyEnd(); groupIndex++ )
501 {
502 const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[*groupIndex];
503 QDomElement elemScalar = scalarSettings.writeXml( doc, context );
504 elemScalar.setAttribute( QStringLiteral( "group" ), *groupIndex );
505 elem.appendChild( elemScalar );
506 }
507
508 for ( auto groupIndex = mRendererVectorSettings.keyBegin(); groupIndex != mRendererVectorSettings.keyEnd(); groupIndex++ )
509 {
510 const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[*groupIndex];
511 QDomElement elemVector = vectorSettings.writeXml( doc, context );
512 elemVector.setAttribute( QStringLiteral( "group" ), *groupIndex );
513 elem.appendChild( elemVector );
514 }
515
516 QDomElement elemNativeMesh = mRendererNativeMeshSettings.writeXml( doc );
517 elemNativeMesh.setTagName( QStringLiteral( "mesh-settings-native" ) );
518 elem.appendChild( elemNativeMesh );
519
520 QDomElement elemEdgeMesh = mRendererEdgeMeshSettings.writeXml( doc );
521 elemEdgeMesh.setTagName( QStringLiteral( "mesh-settings-edge" ) );
522 elem.appendChild( elemEdgeMesh );
523
524 QDomElement elemTriangularMesh = mRendererTriangularMeshSettings.writeXml( doc );
525 elemTriangularMesh.setTagName( QStringLiteral( "mesh-settings-triangular" ) );
526 elem.appendChild( elemTriangularMesh );
527
528 if ( mAveragingMethod )
529 {
530 QDomElement elemAveraging = doc.createElement( QStringLiteral( "averaging-3d" ) );
531 elemAveraging.setAttribute( QStringLiteral( "method" ), QString::number( mAveragingMethod->method() ) ) ;
532 const QDomElement elemAveragingParams = mAveragingMethod->writeXml( doc );
533 elemAveraging.appendChild( elemAveragingParams );
534 elem.appendChild( elemAveraging );
535 }
536
537 return elem;
538}
539
540void QgsMeshRendererSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
541{
542 mRendererScalarSettings.clear();
543 mRendererVectorSettings.clear();
544 mAveragingMethod.reset();
545
546 const QDomElement elemActiveDataset = elem.firstChildElement( QStringLiteral( "active-dataset-group" ) );
547 if ( elemActiveDataset.hasAttribute( QStringLiteral( "scalar" ) ) )
548 mActiveScalarDatasetGroup = elemActiveDataset.attribute( QStringLiteral( "scalar" ) ).toInt();
549
550 if ( elemActiveDataset.hasAttribute( QStringLiteral( "vector" ) ) )
551 mActiveVectorDatasetGroup = elemActiveDataset.attribute( QStringLiteral( "vector" ) ).toInt();
552
553 QDomElement elemScalar = elem.firstChildElement( QStringLiteral( "scalar-settings" ) );
554 while ( !elemScalar.isNull() )
555 {
556 const int groupIndex = elemScalar.attribute( QStringLiteral( "group" ) ).toInt();
558 scalarSettings.readXml( elemScalar, context );
559 mRendererScalarSettings.insert( groupIndex, scalarSettings );
560
561 elemScalar = elemScalar.nextSiblingElement( QStringLiteral( "scalar-settings" ) );
562 }
563
564 QDomElement elemVector = elem.firstChildElement( QStringLiteral( "vector-settings" ) );
565 while ( !elemVector.isNull() )
566 {
567 const int groupIndex = elemVector.attribute( QStringLiteral( "group" ) ).toInt();
569 vectorSettings.readXml( elemVector, context );
570 mRendererVectorSettings.insert( groupIndex, vectorSettings );
571
572 elemVector = elemVector.nextSiblingElement( QStringLiteral( "vector-settings" ) );
573 }
574
575 const QDomElement elemNativeMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-native" ) );
576 mRendererNativeMeshSettings.readXml( elemNativeMesh );
577
578 const QDomElement elemEdgeMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-edge" ) );
579 mRendererEdgeMeshSettings.readXml( elemEdgeMesh );
580
581 const QDomElement elemTriangularMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-triangular" ) );
582 mRendererTriangularMeshSettings.readXml( elemTriangularMesh );
583
584 const QDomElement elemAveraging = elem.firstChildElement( QStringLiteral( "averaging-3d" ) );
585 if ( !elemAveraging.isNull() )
586 {
587 mAveragingMethod.reset( QgsMesh3DAveragingMethod::createFromXml( elemAveraging ) );
588 }
589}
590
592{
593 return mActiveScalarDatasetGroup;
594}
595
600
602{
603 return mActiveVectorDatasetGroup;
604}
605
610
615
620
622{
623 return mSeedingDensity;
624}
625
630
631QDomElement QgsMeshRendererVectorStreamlineSettings::writeXml( QDomDocument &doc ) const
632{
633 QDomElement elem = doc.createElement( QStringLiteral( "vector-streamline-settings" ) );
634
635 elem.setAttribute( QStringLiteral( "seeding-method" ), mSeedingMethod );
636 elem.setAttribute( QStringLiteral( "seeding-density" ), mSeedingDensity );
637
638 return elem;
639}
640
642{
643 mSeedingMethod =
645 elem.attribute( QStringLiteral( "seeding-method" ) ).toInt() );
646 mSeedingDensity = elem.attribute( QStringLiteral( "seeding-density" ) ).toDouble();
647}
648
653
655{
656 mDisplayingMethod = displayingMethod;
657}
658
663
668
673
678
679QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
680{
681 QDomElement elem = doc.createElement( QStringLiteral( "vector-settings" ) );
682 elem.setAttribute( QStringLiteral( "symbology" ), mDisplayingMethod );
683
684 elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth );
685 elem.setAttribute( QStringLiteral( "coloring-method" ), coloringMethod() );
686 elem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) );
687 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
688 elem.appendChild( elemShader );
689 elem.setAttribute( QStringLiteral( "filter-min" ), mFilterMin );
690 elem.setAttribute( QStringLiteral( "filter-max" ), mFilterMax );
691
692 elem.setAttribute( QStringLiteral( "user-grid-enabled" ), mOnUserDefinedGrid ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
693 elem.setAttribute( QStringLiteral( "user-grid-width" ), mUserGridCellWidth );
694 elem.setAttribute( QStringLiteral( "user-grid-height" ), mUserGridCellHeight );
695
696 elem.appendChild( mArrowsSettings.writeXml( doc ) );
697 elem.appendChild( mStreamLinesSettings.writeXml( doc ) );
698 elem.appendChild( mTracesSettings.writeXml( doc ) );
699 elem.appendChild( mWindBarbSettings.writeXml( doc ) );
700
701 return elem;
702}
703
704void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
705{
706 mDisplayingMethod = static_cast<QgsMeshRendererVectorSettings::Symbology>(
707 elem.attribute( QStringLiteral( "symbology" ) ).toInt() );
708
709 mLineWidth = elem.attribute( QStringLiteral( "line-width" ) ).toDouble();
710 mColoringMethod = static_cast<QgsInterpolatedLineColor::ColoringMethod>(
711 elem.attribute( QStringLiteral( "coloring-method" ) ).toInt() );
712 mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) );
713 mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context );
714 mFilterMin = elem.attribute( QStringLiteral( "filter-min" ) ).toDouble();
715 mFilterMax = elem.attribute( QStringLiteral( "filter-max" ) ).toDouble();
716
717 mOnUserDefinedGrid = elem.attribute( QStringLiteral( "user-grid-enabled" ) ).toInt(); //bool
718 mUserGridCellWidth = elem.attribute( QStringLiteral( "user-grid-width" ) ).toInt();
719 mUserGridCellHeight = elem.attribute( QStringLiteral( "user-grid-height" ) ).toInt();
720
721 const QDomElement elemVector = elem.firstChildElement( QStringLiteral( "vector-arrow-settings" ) );
722 if ( ! elemVector.isNull() )
723 mArrowsSettings.readXml( elemVector );
724
725 const QDomElement elemStreamLine = elem.firstChildElement( QStringLiteral( "vector-streamline-settings" ) );
726 if ( ! elemStreamLine.isNull() )
727 mStreamLinesSettings.readXml( elemStreamLine );
728
729 const QDomElement elemTraces = elem.firstChildElement( QStringLiteral( "vector-traces-settings" ) );
730 if ( ! elemTraces.isNull() )
731 mTracesSettings.readXml( elemTraces );
732
733 const QDomElement elemWindBarb = elem.firstChildElement( QStringLiteral( "vector-windbarb-settings" ) );
734 if ( ! elemWindBarb.isNull() )
735 mWindBarbSettings.readXml( elemWindBarb );
736}
737
742
747
749{
750 return mColorRampShader;
751}
752
757
759{
760 QgsInterpolatedLineColor strokeColoring;
761 switch ( mColoringMethod )
762 {
764 strokeColoring = QgsInterpolatedLineColor( mColor );
765 break;
767 strokeColoring = QgsInterpolatedLineColor( mColorRampShader );
768 break;
769 }
770
771 return strokeColoring;
772}
773
778
783
784void QgsMeshRendererVectorTracesSettings::readXml( const QDomElement &elem )
785{
786 mMaximumTailLength = elem.attribute( QStringLiteral( "maximum-tail-length" ) ).toInt();
787 mMaximumTailLengthUnit = static_cast<Qgis::RenderUnit>(
788 elem.attribute( QStringLiteral( "maximum-tail-length-unit" ) ).toInt() );
789 mParticlesCount = elem.attribute( QStringLiteral( "particles-count" ) ).toInt();
790}
791
792QDomElement QgsMeshRendererVectorTracesSettings::writeXml( QDomDocument &doc ) const
793{
794 QDomElement elem = doc.createElement( QStringLiteral( "vector-traces-settings" ) );
795 elem.setAttribute( QStringLiteral( "maximum-tail-length" ), mMaximumTailLength );
796 elem.setAttribute( QStringLiteral( "maximum-tail-length-unit" ), static_cast< int >( mMaximumTailLengthUnit ) );
797 elem.setAttribute( QStringLiteral( "particles-count" ), mParticlesCount );
798
799 return elem;
800}
801
803{
804 return mMaximumTailLengthUnit;
805}
806
811
813{
814 return mMaximumTailLength;
815}
816
821
823{
824 return mParticlesCount;
825}
826
828{
829 mParticlesCount = value;
830}
831
832bool QgsMeshRendererSettings::hasSettings( int datasetGroupIndex ) const
833{
834 return mRendererScalarSettings.contains( datasetGroupIndex ) || mRendererVectorSettings.contains( datasetGroupIndex );
835}
836
841
846
848{
849 mShaftLength = elem.attribute( QStringLiteral( "shaft-length" ), QStringLiteral( "10" ) ).toDouble();
850 mShaftLengthUnits = static_cast<Qgis::RenderUnit>(
851 elem.attribute( QStringLiteral( "shaft-length-units" ) ).toInt() );
852 mMagnitudeMultiplier = elem.attribute( QStringLiteral( "magnitude-multiplier" ), QStringLiteral( "1" ) ).toDouble();
853 mMagnitudeUnits = static_cast<WindSpeedUnit>(
854 elem.attribute( QStringLiteral( "magnitude-units" ), QStringLiteral( "0" ) ).toInt() );
855}
856
857QDomElement QgsMeshRendererVectorWindBarbSettings::writeXml( QDomDocument &doc ) const
858{
859 QDomElement elem = doc.createElement( QStringLiteral( "vector-windbarb-settings" ) );
860 elem.setAttribute( QStringLiteral( "shaft-length" ), mShaftLength );
861 elem.setAttribute( QStringLiteral( "shaft-length-units" ), static_cast< int >( mShaftLengthUnits ) );
862 elem.setAttribute( QStringLiteral( "magnitude-multiplier" ), mMagnitudeMultiplier );
863 elem.setAttribute( QStringLiteral( "magnitude-units" ), static_cast< int >( mMagnitudeUnits ) );
864 return elem;
865}
866
868{
869 switch ( mMagnitudeUnits )
870 {
872 return 1.0;
874 return 3600.0 / 1852.0;
876 return 1.0 / 1.852;
878 return 1.609344 / 1.852;
880 return 3600.0 / 1.852 / 5280.0 * 1.609344 ;
882 return mMagnitudeMultiplier;
883 }
884 return 1.0; // should not reach
885}
886
891
893{
894 return mShaftLength;
895}
896
901
903{
904 return mShaftLengthUnits;
905}
906
908{
909 mShaftLengthUnits = shaftLengthUnit;
910}
911
916
918{
919 mMagnitudeUnits = units;
920}
@ NotSet
User defined.
Definition qgis.h:6049
@ WholeMesh
Whole mesh is used to compute statistics.
Definition qgis.h:6061
RenderUnit
Rendering size units.
Definition qgis.h:5183
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:6817
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6798