QGIS API Documentation 3.41.0-Master (af5edcb665c)
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#include "qgscolorutils.h"
20#include "qgsunittypes.h"
21#include "qgscolorramp.h"
22
24{
25 return mEnabled;
26}
27
29{
30 mEnabled = on;
31}
32
34{
35 return mLineWidth;
36}
37
39{
40 mLineWidth = lineWidth;
41}
42
44{
45 return mColor;
46}
47
48void QgsMeshRendererMeshSettings::setColor( const QColor &color )
49{
50 mColor = color;
51}
52
54{
55 return mLineWidthUnit;
56}
57
59{
60 mLineWidthUnit = lineWidthUnit;
61}
62
63QDomElement QgsMeshRendererMeshSettings::writeXml( QDomDocument &doc ) const
64{
65 QDomElement elem = doc.createElement( QStringLiteral( "mesh-settings" ) );
66 elem.setAttribute( QStringLiteral( "enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
67 elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth );
68 elem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) );
69 elem.setAttribute( QStringLiteral( "line-width-unit" ), QgsUnitTypes::encodeUnit( mLineWidthUnit ) );
70 return elem;
71}
72
73void QgsMeshRendererMeshSettings::readXml( const QDomElement &elem )
74{
75 mEnabled = elem.attribute( QStringLiteral( "enabled" ) ).toInt();
76 mLineWidth = elem.attribute( QStringLiteral( "line-width" ) ).toDouble();
77 mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) );
78 mLineWidthUnit = QgsUnitTypes::decodeRenderUnit( elem.attribute( QStringLiteral( "line-width-unit" ) ) );
79}
80// ---------------------------------------------------------------------
81
83{
84 return mColorRampShader;
85}
86
88{
89 mColorRampShader = shader;
90}
91
92double QgsMeshRendererScalarSettings::classificationMinimum() const { return mClassificationMinimum; }
93
94double QgsMeshRendererScalarSettings::classificationMaximum() const { return mClassificationMaximum; }
95
97{
98 mClassificationMinimum = minimum;
99 mClassificationMaximum = maximum;
100 updateShader();
101}
102
103double QgsMeshRendererScalarSettings::opacity() const { return mOpacity; }
104
105void QgsMeshRendererScalarSettings::setOpacity( double opacity ) { mOpacity = opacity; }
106
111
113{
114 mDataResamplingMethod = dataInterpolationMethod;
115}
116
117QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
118{
119 QDomElement elem = doc.createElement( QStringLiteral( "scalar-settings" ) );
120 elem.setAttribute( QStringLiteral( "min-val" ), mClassificationMinimum );
121 elem.setAttribute( QStringLiteral( "max-val" ), mClassificationMaximum );
122 elem.setAttribute( QStringLiteral( "opacity" ), mOpacity );
123
124 QString methodTxt;
125 switch ( mDataResamplingMethod )
126 {
127 case NoResampling:
128 methodTxt = QStringLiteral( "no-resampling" );
129 break;
130 case NeighbourAverage:
131 methodTxt = QStringLiteral( "neighbour-average" );
132 break;
133 }
134 elem.setAttribute( QStringLiteral( "interpolation-method" ), methodTxt );
135
136 elem.setAttribute( QStringLiteral( "range-extent" ), QgsMeshRendererScalarSettings::extentString( mRangeExtent ) );
137 elem.setAttribute( QStringLiteral( "range-limit" ), QgsMeshRendererScalarSettings::limitsString( mRangeLimit ) );
138
139 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
140 elem.appendChild( elemShader );
141
142 QDomElement elemEdge = doc.createElement( QStringLiteral( "edge-settings" ) );
143 elemEdge.appendChild( mEdgeStrokeWidth.writeXml( doc, context ) );
144 elemEdge.setAttribute( QStringLiteral( "stroke-width-unit" ), static_cast< int >( mEdgeStrokeWidthUnit ) );
145 elem.appendChild( elemEdge );
146
147 return elem;
148}
149
150void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
151{
152 mClassificationMinimum = elem.attribute( QStringLiteral( "min-val" ) ).toDouble();
153 mClassificationMaximum = elem.attribute( QStringLiteral( "max-val" ) ).toDouble();
154 mOpacity = elem.attribute( QStringLiteral( "opacity" ) ).toDouble();
155
156 const QString methodTxt = elem.attribute( QStringLiteral( "interpolation-method" ) );
157 if ( QStringLiteral( "neighbour-average" ) == methodTxt )
158 {
159 mDataResamplingMethod = DataResamplingMethod::NeighbourAverage;
160 }
161 else
162 {
163 mDataResamplingMethod = DataResamplingMethod::NoResampling;
164 }
165
166 mRangeExtent = QgsMeshRendererScalarSettings::extentFromString( elem.attribute( "range-extent" ) );
167 mRangeLimit = QgsMeshRendererScalarSettings::limitsFromString( elem.attribute( "range-limit" ) );
168
169 const QDomElement elemShader = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
170 mColorRampShader.readXml( elemShader, context );
171
172 const QDomElement elemEdge = elem.firstChildElement( QStringLiteral( "edge-settings" ) );
173 const QDomElement elemEdgeStrokeWidth = elemEdge.firstChildElement( QStringLiteral( "mesh-stroke-width" ) );
174 mEdgeStrokeWidth.readXml( elemEdgeStrokeWidth, context );
175 mEdgeStrokeWidthUnit = static_cast<Qgis::RenderUnit>(
176 elemEdge.attribute( QStringLiteral( "stroke-width-unit" ) ).toInt() );
177}
178
183
185{
186 mEdgeStrokeWidth = strokeWidth;
187}
188
190{
191 return mEdgeStrokeWidthUnit;
192}
193
195{
196 mEdgeStrokeWidthUnit = edgeStrokeWidthUnit;
197}
198
199void QgsMeshRendererScalarSettings::updateShader()
200{
201
202 mColorRampShader.setMinimumValue( mClassificationMinimum );
203 mColorRampShader.setMaximumValue( mClassificationMaximum );
204
205 if ( !mColorRampShader.isEmpty() )
206 mColorRampShader.classifyColorRamp( mColorRampShader.sourceColorRamp()->count(), 1, QgsRectangle(), nullptr );
207}
208
209QString QgsMeshRendererScalarSettings::extentString( Qgis::MeshRangeExtent extent )
210{
211 switch ( extent )
212 {
214 return QStringLiteral( "WholeMesh" );
216 return QStringLiteral( "CurrentCanvas" );
218 return QStringLiteral( "UpdatedCanvas" );
219 }
220 return QStringLiteral( "WholeMesh" );
221}
222
223Qgis::MeshRangeExtent QgsMeshRendererScalarSettings::extentFromString( const QString &extent )
224{
225 if ( extent == QLatin1String( "WholeMesh" ) )
226 {
228 }
229 else if ( extent == QLatin1String( "CurrentCanvas" ) )
230 {
232 }
233 else if ( extent == QLatin1String( "UpdatedCanvas" ) )
234 {
236 }
237
239}
240
241QString QgsMeshRendererScalarSettings::limitsString( Qgis::MeshRangeLimit limits )
242{
243 switch ( limits )
244 {
246 return QStringLiteral( "MinMax" );
247 default:
248 break;
249 }
250 return QStringLiteral( "None" );
251}
252
253Qgis::MeshRangeLimit QgsMeshRendererScalarSettings::limitsFromString( const QString &limits )
254{
255 if ( limits == QLatin1String( "MinMax" ) )
256 {
258 }
260}
261
262// ---------------------------------------------------------------------
263
265{
266 return mLineWidth;
267}
268
270{
271 mLineWidth = lineWidth;
272}
273
275{
276 return mColor;
277}
278
279void QgsMeshRendererVectorSettings::setColor( const QColor &vectorColor )
280{
281 mColor = vectorColor;
282}
283
285{
286 return mFilterMin;
287}
288
290{
291 mFilterMin = vectorFilterMin;
292}
293
295{
296 return mFilterMax;
297}
298
300{
301 mFilterMax = vectorFilterMax;
302}
303
305{
306 return mOnUserDefinedGrid;
307}
308
310{
311 mOnUserDefinedGrid = enabled;
312}
313
315{
316 return mUserGridCellWidth;
317}
318
320{
321 mUserGridCellWidth = width;
322}
323
325{
326 return mUserGridCellHeight;
327}
328
330{
331 mUserGridCellHeight = height;
332}
333
338
343
345{
346 return mMinShaftLength;
347}
348
350{
351 mMinShaftLength = minShaftLength;
352}
353
355{
356 return mMaxShaftLength;
357}
358
360{
361 mMaxShaftLength = maxShaftLength;
362}
363
365{
366 return mScaleFactor;
367}
368
370{
371 mScaleFactor = scaleFactor;
372}
373
375{
376 return mFixedShaftLength;
377}
378
380{
381 mFixedShaftLength = fixedShaftLength;
382}
383
385{
386 return mArrowHeadWidthRatio;
387}
388
390{
391 mArrowHeadWidthRatio = vectorHeadWidthRatio;
392}
393
395{
396 return mArrowHeadLengthRatio;
397}
398
400{
401 mArrowHeadLengthRatio = vectorHeadLengthRatio;
402}
403
404QDomElement QgsMeshRendererVectorArrowSettings::writeXml( QDomDocument &doc ) const
405{
406 QDomElement elem = doc.createElement( QStringLiteral( "vector-arrow-settings" ) );
407 elem.setAttribute( QStringLiteral( "arrow-head-width-ratio" ), mArrowHeadWidthRatio );
408 elem.setAttribute( QStringLiteral( "arrow-head-length-ratio" ), mArrowHeadLengthRatio );
409
410 QDomElement elemShaft = doc.createElement( QStringLiteral( "shaft-length" ) );
411 QString methodTxt;
412 switch ( mShaftLengthMethod )
413 {
414 case MinMax:
415 methodTxt = QStringLiteral( "minmax" );
416 elemShaft.setAttribute( QStringLiteral( "min" ), mMinShaftLength );
417 elemShaft.setAttribute( QStringLiteral( "max" ), mMaxShaftLength );
418 break;
419 case Scaled:
420 methodTxt = QStringLiteral( "scaled" );
421 elemShaft.setAttribute( QStringLiteral( "scale-factor" ), mScaleFactor );
422 break;
423 case Fixed:
424 methodTxt = QStringLiteral( "fixed" ) ;
425 elemShaft.setAttribute( QStringLiteral( "fixed-length" ), mFixedShaftLength );
426 break;
427 }
428 elemShaft.setAttribute( QStringLiteral( "method" ), methodTxt );
429 elem.appendChild( elemShaft );
430 return elem;
431}
432
433void QgsMeshRendererVectorArrowSettings::readXml( const QDomElement &elem )
434{
435 mArrowHeadWidthRatio = elem.attribute( QStringLiteral( "arrow-head-width-ratio" ) ).toDouble();
436 mArrowHeadLengthRatio = elem.attribute( QStringLiteral( "arrow-head-length-ratio" ) ).toDouble();
437
438 const QDomElement elemShaft = elem.firstChildElement( QStringLiteral( "shaft-length" ) );
439 const QString methodTxt = elemShaft.attribute( QStringLiteral( "method" ) );
440 if ( QStringLiteral( "minmax" ) == methodTxt )
441 {
442 mShaftLengthMethod = MinMax;
443 mMinShaftLength = elemShaft.attribute( QStringLiteral( "min" ) ).toDouble();
444 mMaxShaftLength = elemShaft.attribute( QStringLiteral( "max" ) ).toDouble();
445 }
446 else if ( QStringLiteral( "scaled" ) == methodTxt )
447 {
448 mShaftLengthMethod = Scaled;
449 mScaleFactor = elemShaft.attribute( QStringLiteral( "scale-factor" ) ).toDouble();
450 }
451 else // fixed
452 {
453 mShaftLengthMethod = Fixed;
454 mFixedShaftLength = elemShaft.attribute( QStringLiteral( "fixed-length" ) ).toDouble();
455 }
456}
457
458// ---------------------------------------------------------------------
459
464
466
468{
469 return mAveragingMethod.get();
470}
471
473{
474 if ( method )
475 mAveragingMethod.reset( method->clone() );
476 else
477 mAveragingMethod.reset();
478}
479
480QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
481{
482 QDomElement elem = doc.createElement( QStringLiteral( "mesh-renderer-settings" ) );
483
484 QDomElement elemActiveDatasetGroup = doc.createElement( QStringLiteral( "active-dataset-group" ) );
485 elemActiveDatasetGroup.setAttribute( QStringLiteral( "scalar" ), mActiveScalarDatasetGroup );
486 elemActiveDatasetGroup.setAttribute( QStringLiteral( "vector" ), mActiveVectorDatasetGroup );
487 elem.appendChild( elemActiveDatasetGroup );
488
489 for ( auto groupIndex = mRendererScalarSettings.keyBegin(); groupIndex != mRendererScalarSettings.keyEnd(); groupIndex++ )
490 {
491 const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[*groupIndex];
492 QDomElement elemScalar = scalarSettings.writeXml( doc, context );
493 elemScalar.setAttribute( QStringLiteral( "group" ), *groupIndex );
494 elem.appendChild( elemScalar );
495 }
496
497 for ( auto groupIndex = mRendererVectorSettings.keyBegin(); groupIndex != mRendererVectorSettings.keyEnd(); groupIndex++ )
498 {
499 const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[*groupIndex];
500 QDomElement elemVector = vectorSettings.writeXml( doc, context );
501 elemVector.setAttribute( QStringLiteral( "group" ), *groupIndex );
502 elem.appendChild( elemVector );
503 }
504
505 QDomElement elemNativeMesh = mRendererNativeMeshSettings.writeXml( doc );
506 elemNativeMesh.setTagName( QStringLiteral( "mesh-settings-native" ) );
507 elem.appendChild( elemNativeMesh );
508
509 QDomElement elemEdgeMesh = mRendererEdgeMeshSettings.writeXml( doc );
510 elemEdgeMesh.setTagName( QStringLiteral( "mesh-settings-edge" ) );
511 elem.appendChild( elemEdgeMesh );
512
513 QDomElement elemTriangularMesh = mRendererTriangularMeshSettings.writeXml( doc );
514 elemTriangularMesh.setTagName( QStringLiteral( "mesh-settings-triangular" ) );
515 elem.appendChild( elemTriangularMesh );
516
517 if ( mAveragingMethod )
518 {
519 QDomElement elemAveraging = doc.createElement( QStringLiteral( "averaging-3d" ) );
520 elemAveraging.setAttribute( QStringLiteral( "method" ), QString::number( mAveragingMethod->method() ) ) ;
521 const QDomElement elemAveragingParams = mAveragingMethod->writeXml( doc );
522 elemAveraging.appendChild( elemAveragingParams );
523 elem.appendChild( elemAveraging );
524 }
525
526 return elem;
527}
528
529void QgsMeshRendererSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
530{
531 mRendererScalarSettings.clear();
532 mRendererVectorSettings.clear();
533 mAveragingMethod.reset();
534
535 const QDomElement elemActiveDataset = elem.firstChildElement( QStringLiteral( "active-dataset-group" ) );
536 if ( elemActiveDataset.hasAttribute( QStringLiteral( "scalar" ) ) )
537 mActiveScalarDatasetGroup = elemActiveDataset.attribute( QStringLiteral( "scalar" ) ).toInt();
538
539 if ( elemActiveDataset.hasAttribute( QStringLiteral( "vector" ) ) )
540 mActiveVectorDatasetGroup = elemActiveDataset.attribute( QStringLiteral( "vector" ) ).toInt();
541
542 QDomElement elemScalar = elem.firstChildElement( QStringLiteral( "scalar-settings" ) );
543 while ( !elemScalar.isNull() )
544 {
545 const int groupIndex = elemScalar.attribute( QStringLiteral( "group" ) ).toInt();
547 scalarSettings.readXml( elemScalar, context );
548 mRendererScalarSettings.insert( groupIndex, scalarSettings );
549
550 elemScalar = elemScalar.nextSiblingElement( QStringLiteral( "scalar-settings" ) );
551 }
552
553 QDomElement elemVector = elem.firstChildElement( QStringLiteral( "vector-settings" ) );
554 while ( !elemVector.isNull() )
555 {
556 const int groupIndex = elemVector.attribute( QStringLiteral( "group" ) ).toInt();
558 vectorSettings.readXml( elemVector, context );
559 mRendererVectorSettings.insert( groupIndex, vectorSettings );
560
561 elemVector = elemVector.nextSiblingElement( QStringLiteral( "vector-settings" ) );
562 }
563
564 const QDomElement elemNativeMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-native" ) );
565 mRendererNativeMeshSettings.readXml( elemNativeMesh );
566
567 const QDomElement elemEdgeMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-edge" ) );
568 mRendererEdgeMeshSettings.readXml( elemEdgeMesh );
569
570 const QDomElement elemTriangularMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-triangular" ) );
571 mRendererTriangularMeshSettings.readXml( elemTriangularMesh );
572
573 const QDomElement elemAveraging = elem.firstChildElement( QStringLiteral( "averaging-3d" ) );
574 if ( !elemAveraging.isNull() )
575 {
576 mAveragingMethod.reset( QgsMesh3DAveragingMethod::createFromXml( elemAveraging ) );
577 }
578}
579
581{
582 return mActiveScalarDatasetGroup;
583}
584
586{
587 mActiveScalarDatasetGroup = activeScalarDatasetGroup;
588}
589
591{
592 return mActiveVectorDatasetGroup;
593}
594
596{
597 mActiveVectorDatasetGroup = activeVectorDatasetGroup;
598}
599
604
609
611{
612 return mSeedingDensity;
613}
614
616{
617 mSeedingDensity = seedingDensity;
618}
619
620QDomElement QgsMeshRendererVectorStreamlineSettings::writeXml( QDomDocument &doc ) const
621{
622 QDomElement elem = doc.createElement( QStringLiteral( "vector-streamline-settings" ) );
623
624 elem.setAttribute( QStringLiteral( "seeding-method" ), mSeedingMethod );
625 elem.setAttribute( QStringLiteral( "seeding-density" ), mSeedingDensity );
626
627 return elem;
628}
629
631{
632 mSeedingMethod =
634 elem.attribute( QStringLiteral( "seeding-method" ) ).toInt() );
635 mSeedingDensity = elem.attribute( QStringLiteral( "seeding-density" ) ).toDouble();
636}
637
642
644{
645 mDisplayingMethod = displayingMethod;
646}
647
652
657
662
667
668QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
669{
670 QDomElement elem = doc.createElement( QStringLiteral( "vector-settings" ) );
671 elem.setAttribute( QStringLiteral( "symbology" ), mDisplayingMethod );
672
673 elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth );
674 elem.setAttribute( QStringLiteral( "coloring-method" ), coloringMethod() );
675 elem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) );
676 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
677 elem.appendChild( elemShader );
678 elem.setAttribute( QStringLiteral( "filter-min" ), mFilterMin );
679 elem.setAttribute( QStringLiteral( "filter-max" ), mFilterMax );
680
681 elem.setAttribute( QStringLiteral( "user-grid-enabled" ), mOnUserDefinedGrid ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
682 elem.setAttribute( QStringLiteral( "user-grid-width" ), mUserGridCellWidth );
683 elem.setAttribute( QStringLiteral( "user-grid-height" ), mUserGridCellHeight );
684
685 elem.appendChild( mArrowsSettings.writeXml( doc ) );
686 elem.appendChild( mStreamLinesSettings.writeXml( doc ) );
687 elem.appendChild( mTracesSettings.writeXml( doc ) );
688 elem.appendChild( mWindBarbSettings.writeXml( doc ) );
689
690 return elem;
691}
692
693void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
694{
695 mDisplayingMethod = static_cast<QgsMeshRendererVectorSettings::Symbology>(
696 elem.attribute( QStringLiteral( "symbology" ) ).toInt() );
697
698 mLineWidth = elem.attribute( QStringLiteral( "line-width" ) ).toDouble();
699 mColoringMethod = static_cast<QgsInterpolatedLineColor::ColoringMethod>(
700 elem.attribute( QStringLiteral( "coloring-method" ) ).toInt() );
701 mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) );
702 mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context );
703 mFilterMin = elem.attribute( QStringLiteral( "filter-min" ) ).toDouble();
704 mFilterMax = elem.attribute( QStringLiteral( "filter-max" ) ).toDouble();
705
706 mOnUserDefinedGrid = elem.attribute( QStringLiteral( "user-grid-enabled" ) ).toInt(); //bool
707 mUserGridCellWidth = elem.attribute( QStringLiteral( "user-grid-width" ) ).toInt();
708 mUserGridCellHeight = elem.attribute( QStringLiteral( "user-grid-height" ) ).toInt();
709
710 const QDomElement elemVector = elem.firstChildElement( QStringLiteral( "vector-arrow-settings" ) );
711 if ( ! elemVector.isNull() )
712 mArrowsSettings.readXml( elemVector );
713
714 const QDomElement elemStreamLine = elem.firstChildElement( QStringLiteral( "vector-streamline-settings" ) );
715 if ( ! elemStreamLine.isNull() )
716 mStreamLinesSettings.readXml( elemStreamLine );
717
718 const QDomElement elemTraces = elem.firstChildElement( QStringLiteral( "vector-traces-settings" ) );
719 if ( ! elemTraces.isNull() )
720 mTracesSettings.readXml( elemTraces );
721
722 const QDomElement elemWindBarb = elem.firstChildElement( QStringLiteral( "vector-windbarb-settings" ) );
723 if ( ! elemWindBarb.isNull() )
724 mWindBarbSettings.readXml( elemWindBarb );
725}
726
731
736
738{
739 return mColorRampShader;
740}
741
743{
744 mColorRampShader = colorRampShader;
745}
746
748{
749 QgsInterpolatedLineColor strokeColoring;
750 switch ( mColoringMethod )
751 {
753 strokeColoring = QgsInterpolatedLineColor( mColor );
754 break;
756 strokeColoring = QgsInterpolatedLineColor( mColorRampShader );
757 break;
758 }
759
760 return strokeColoring;
761}
762
767
772
773void QgsMeshRendererVectorTracesSettings::readXml( const QDomElement &elem )
774{
775 mMaximumTailLength = elem.attribute( QStringLiteral( "maximum-tail-length" ) ).toInt();
776 mMaximumTailLengthUnit = static_cast<Qgis::RenderUnit>(
777 elem.attribute( QStringLiteral( "maximum-tail-length-unit" ) ).toInt() );
778 mParticlesCount = elem.attribute( QStringLiteral( "particles-count" ) ).toInt();
779}
780
781QDomElement QgsMeshRendererVectorTracesSettings::writeXml( QDomDocument &doc ) const
782{
783 QDomElement elem = doc.createElement( QStringLiteral( "vector-traces-settings" ) );
784 elem.setAttribute( QStringLiteral( "maximum-tail-length" ), mMaximumTailLength );
785 elem.setAttribute( QStringLiteral( "maximum-tail-length-unit" ), static_cast< int >( mMaximumTailLengthUnit ) );
786 elem.setAttribute( QStringLiteral( "particles-count" ), mParticlesCount );
787
788 return elem;
789}
790
792{
793 return mMaximumTailLengthUnit;
794}
795
797{
798 mMaximumTailLengthUnit = maximumTailLengthUnit;
799}
800
802{
803 return mMaximumTailLength;
804}
805
807{
808 mMaximumTailLength = maximumTailLength;
809}
810
812{
813 return mParticlesCount;
814}
815
817{
818 mParticlesCount = value;
819}
820
821bool QgsMeshRendererSettings::hasSettings( int datasetGroupIndex ) const
822{
823 return mRendererScalarSettings.contains( datasetGroupIndex ) || mRendererVectorSettings.contains( datasetGroupIndex );
824}
825
830
835
837{
838 mShaftLength = elem.attribute( QStringLiteral( "shaft-length" ), QStringLiteral( "10" ) ).toDouble();
839 mShaftLengthUnits = static_cast<Qgis::RenderUnit>(
840 elem.attribute( QStringLiteral( "shaft-length-units" ) ).toInt() );
841 mMagnitudeMultiplier = elem.attribute( QStringLiteral( "magnitude-multiplier" ), QStringLiteral( "1" ) ).toDouble();
842 mMagnitudeUnits = static_cast<WindSpeedUnit>(
843 elem.attribute( QStringLiteral( "magnitude-units" ), QStringLiteral( "0" ) ).toInt() );
844}
845
846QDomElement QgsMeshRendererVectorWindBarbSettings::writeXml( QDomDocument &doc ) const
847{
848 QDomElement elem = doc.createElement( QStringLiteral( "vector-windbarb-settings" ) );
849 elem.setAttribute( QStringLiteral( "shaft-length" ), mShaftLength );
850 elem.setAttribute( QStringLiteral( "shaft-length-units" ), static_cast< int >( mShaftLengthUnits ) );
851 elem.setAttribute( QStringLiteral( "magnitude-multiplier" ), mMagnitudeMultiplier );
852 elem.setAttribute( QStringLiteral( "magnitude-units" ), static_cast< int >( mMagnitudeUnits ) );
853 return elem;
854}
855
857{
858 switch ( mMagnitudeUnits )
859 {
861 return 1.0;
863 return 3600.0 / 1852.0;
865 return 1.0 / 1.852;
867 return 1.609344 / 1.852;
869 return 3600.0 / 1.852 / 5280.0 * 1.609344 ;
871 return mMagnitudeMultiplier;
872 }
873 return 1.0; // should not reach
874}
875
877{
878 mMagnitudeMultiplier = magnitudeMultiplier;
879}
880
882{
883 return mShaftLength;
884}
885
887{
888 mShaftLength = shaftLength;
889}
890
892{
893 return mShaftLengthUnits;
894}
895
897{
898 mShaftLengthUnits = shaftLengthUnit;
899}
900
905
907{
908 mMagnitudeUnits = units;
909}
MeshRangeLimit
Describes the limits used to compute mesh ranges (min/max values).
Definition qgis.h:5705
@ MinimumMaximum
Real min-max values.
@ NotSet
User defined.
MeshRangeExtent
Describes the extent used to compute mesh ranges (min/max values).
Definition qgis.h:5717
@ UpdatedCanvas
Constantly updated extent of the canvas is used to compute statistics.
@ WholeMesh
Whole mesh is used to compute statistics.
@ FixedCanvas
Current extent of the canvas (at the time of computation) is used to compute statistics.
RenderUnit
Rendering size units.
Definition qgis.h:4910
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.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes configuration to a new DOM element.
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.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads configuration from the given DOM element.
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.
Class defining color to render mesh datasets.
ColoringMethod
Defines how the color is defined.
@ ColorRamp
Render with a color ramp.
@ SingleColor
Render with a single color.
Represents a width than can vary depending on values.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from the given DOM element.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a new DOM element.
Abstract class to interpolate 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 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.
Qgis::MeshRangeExtent extent() const
Returns the mesh extent for minimum maximum calculation.
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.
Qgis::MeshRangeLimit limits() const
Returns the range limits type for minimum maximum calculation.
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.
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.
The class is used as a container of context for various read/write operations on other 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.