QGIS API Documentation 3.41.0-Master (02257426e5a)
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 if ( mRangeExtent != Qgis::MeshRangeExtent::WholeMesh )
137 elem.setAttribute( QStringLiteral( "range-extent" ), qgsEnumValueToKey( mRangeExtent ) );
138 if ( mRangeLimit != Qgis::MeshRangeLimit::NotSet )
139 elem.setAttribute( QStringLiteral( "range-limit" ), qgsEnumValueToKey( mRangeLimit ) );
140
141 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
142 elem.appendChild( elemShader );
143
144 QDomElement elemEdge = doc.createElement( QStringLiteral( "edge-settings" ) );
145 elemEdge.appendChild( mEdgeStrokeWidth.writeXml( doc, context ) );
146 elemEdge.setAttribute( QStringLiteral( "stroke-width-unit" ), static_cast< int >( mEdgeStrokeWidthUnit ) );
147 elem.appendChild( elemEdge );
148
149 return elem;
150}
151
152void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
153{
154 mClassificationMinimum = elem.attribute( QStringLiteral( "min-val" ) ).toDouble();
155 mClassificationMaximum = elem.attribute( QStringLiteral( "max-val" ) ).toDouble();
156 mOpacity = elem.attribute( QStringLiteral( "opacity" ) ).toDouble();
157
158 const QString methodTxt = elem.attribute( QStringLiteral( "interpolation-method" ) );
159 if ( QStringLiteral( "neighbour-average" ) == methodTxt )
160 {
161 mDataResamplingMethod = DataResamplingMethod::NeighbourAverage;
162 }
163 else
164 {
165 mDataResamplingMethod = DataResamplingMethod::NoResampling;
166 }
167
168 mRangeExtent = qgsEnumKeyToValue( elem.attribute( "range-extent" ), Qgis::MeshRangeExtent::WholeMesh );
169 mRangeLimit = qgsEnumKeyToValue( elem.attribute( "range-limit" ), Qgis::MeshRangeLimit::NotSet );
170
171 const QDomElement elemShader = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
172 mColorRampShader.readXml( elemShader, context );
173
174 const QDomElement elemEdge = elem.firstChildElement( QStringLiteral( "edge-settings" ) );
175 const QDomElement elemEdgeStrokeWidth = elemEdge.firstChildElement( QStringLiteral( "mesh-stroke-width" ) );
176 mEdgeStrokeWidth.readXml( elemEdgeStrokeWidth, context );
177 mEdgeStrokeWidthUnit = static_cast<Qgis::RenderUnit>(
178 elemEdge.attribute( QStringLiteral( "stroke-width-unit" ) ).toInt() );
179}
180
185
187{
188 mEdgeStrokeWidth = strokeWidth;
189}
190
192{
193 return mEdgeStrokeWidthUnit;
194}
195
197{
198 mEdgeStrokeWidthUnit = edgeStrokeWidthUnit;
199}
200
201void QgsMeshRendererScalarSettings::updateShader()
202{
203
204 mColorRampShader.setMinimumValue( mClassificationMinimum );
205 mColorRampShader.setMaximumValue( mClassificationMaximum );
206
207 if ( !mColorRampShader.isEmpty() )
208 mColorRampShader.classifyColorRamp( mColorRampShader.sourceColorRamp()->count(), 1, QgsRectangle(), nullptr );
209}
210
211
212// ---------------------------------------------------------------------
213
215{
216 return mLineWidth;
217}
218
220{
221 mLineWidth = lineWidth;
222}
223
225{
226 return mColor;
227}
228
229void QgsMeshRendererVectorSettings::setColor( const QColor &vectorColor )
230{
231 mColor = vectorColor;
232}
233
235{
236 return mFilterMin;
237}
238
240{
241 mFilterMin = vectorFilterMin;
242}
243
245{
246 return mFilterMax;
247}
248
250{
251 mFilterMax = vectorFilterMax;
252}
253
255{
256 return mOnUserDefinedGrid;
257}
258
260{
261 mOnUserDefinedGrid = enabled;
262}
263
265{
266 return mUserGridCellWidth;
267}
268
270{
271 mUserGridCellWidth = width;
272}
273
275{
276 return mUserGridCellHeight;
277}
278
280{
281 mUserGridCellHeight = height;
282}
283
288
293
295{
296 return mMinShaftLength;
297}
298
300{
301 mMinShaftLength = minShaftLength;
302}
303
305{
306 return mMaxShaftLength;
307}
308
310{
311 mMaxShaftLength = maxShaftLength;
312}
313
315{
316 return mScaleFactor;
317}
318
320{
321 mScaleFactor = scaleFactor;
322}
323
325{
326 return mFixedShaftLength;
327}
328
330{
331 mFixedShaftLength = fixedShaftLength;
332}
333
335{
336 return mArrowHeadWidthRatio;
337}
338
340{
341 mArrowHeadWidthRatio = vectorHeadWidthRatio;
342}
343
345{
346 return mArrowHeadLengthRatio;
347}
348
350{
351 mArrowHeadLengthRatio = vectorHeadLengthRatio;
352}
353
354QDomElement QgsMeshRendererVectorArrowSettings::writeXml( QDomDocument &doc ) const
355{
356 QDomElement elem = doc.createElement( QStringLiteral( "vector-arrow-settings" ) );
357 elem.setAttribute( QStringLiteral( "arrow-head-width-ratio" ), mArrowHeadWidthRatio );
358 elem.setAttribute( QStringLiteral( "arrow-head-length-ratio" ), mArrowHeadLengthRatio );
359
360 QDomElement elemShaft = doc.createElement( QStringLiteral( "shaft-length" ) );
361 QString methodTxt;
362 switch ( mShaftLengthMethod )
363 {
364 case MinMax:
365 methodTxt = QStringLiteral( "minmax" );
366 elemShaft.setAttribute( QStringLiteral( "min" ), mMinShaftLength );
367 elemShaft.setAttribute( QStringLiteral( "max" ), mMaxShaftLength );
368 break;
369 case Scaled:
370 methodTxt = QStringLiteral( "scaled" );
371 elemShaft.setAttribute( QStringLiteral( "scale-factor" ), mScaleFactor );
372 break;
373 case Fixed:
374 methodTxt = QStringLiteral( "fixed" ) ;
375 elemShaft.setAttribute( QStringLiteral( "fixed-length" ), mFixedShaftLength );
376 break;
377 }
378 elemShaft.setAttribute( QStringLiteral( "method" ), methodTxt );
379 elem.appendChild( elemShaft );
380 return elem;
381}
382
383void QgsMeshRendererVectorArrowSettings::readXml( const QDomElement &elem )
384{
385 mArrowHeadWidthRatio = elem.attribute( QStringLiteral( "arrow-head-width-ratio" ) ).toDouble();
386 mArrowHeadLengthRatio = elem.attribute( QStringLiteral( "arrow-head-length-ratio" ) ).toDouble();
387
388 const QDomElement elemShaft = elem.firstChildElement( QStringLiteral( "shaft-length" ) );
389 const QString methodTxt = elemShaft.attribute( QStringLiteral( "method" ) );
390 if ( QStringLiteral( "minmax" ) == methodTxt )
391 {
392 mShaftLengthMethod = MinMax;
393 mMinShaftLength = elemShaft.attribute( QStringLiteral( "min" ) ).toDouble();
394 mMaxShaftLength = elemShaft.attribute( QStringLiteral( "max" ) ).toDouble();
395 }
396 else if ( QStringLiteral( "scaled" ) == methodTxt )
397 {
398 mShaftLengthMethod = Scaled;
399 mScaleFactor = elemShaft.attribute( QStringLiteral( "scale-factor" ) ).toDouble();
400 }
401 else // fixed
402 {
403 mShaftLengthMethod = Fixed;
404 mFixedShaftLength = elemShaft.attribute( QStringLiteral( "fixed-length" ) ).toDouble();
405 }
406}
407
408// ---------------------------------------------------------------------
409
414
416
418{
419 return mAveragingMethod.get();
420}
421
423{
424 if ( method )
425 mAveragingMethod.reset( method->clone() );
426 else
427 mAveragingMethod.reset();
428}
429
430QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
431{
432 QDomElement elem = doc.createElement( QStringLiteral( "mesh-renderer-settings" ) );
433
434 QDomElement elemActiveDatasetGroup = doc.createElement( QStringLiteral( "active-dataset-group" ) );
435 elemActiveDatasetGroup.setAttribute( QStringLiteral( "scalar" ), mActiveScalarDatasetGroup );
436 elemActiveDatasetGroup.setAttribute( QStringLiteral( "vector" ), mActiveVectorDatasetGroup );
437 elem.appendChild( elemActiveDatasetGroup );
438
439 for ( auto groupIndex = mRendererScalarSettings.keyBegin(); groupIndex != mRendererScalarSettings.keyEnd(); groupIndex++ )
440 {
441 const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[*groupIndex];
442 QDomElement elemScalar = scalarSettings.writeXml( doc, context );
443 elemScalar.setAttribute( QStringLiteral( "group" ), *groupIndex );
444 elem.appendChild( elemScalar );
445 }
446
447 for ( auto groupIndex = mRendererVectorSettings.keyBegin(); groupIndex != mRendererVectorSettings.keyEnd(); groupIndex++ )
448 {
449 const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[*groupIndex];
450 QDomElement elemVector = vectorSettings.writeXml( doc, context );
451 elemVector.setAttribute( QStringLiteral( "group" ), *groupIndex );
452 elem.appendChild( elemVector );
453 }
454
455 QDomElement elemNativeMesh = mRendererNativeMeshSettings.writeXml( doc );
456 elemNativeMesh.setTagName( QStringLiteral( "mesh-settings-native" ) );
457 elem.appendChild( elemNativeMesh );
458
459 QDomElement elemEdgeMesh = mRendererEdgeMeshSettings.writeXml( doc );
460 elemEdgeMesh.setTagName( QStringLiteral( "mesh-settings-edge" ) );
461 elem.appendChild( elemEdgeMesh );
462
463 QDomElement elemTriangularMesh = mRendererTriangularMeshSettings.writeXml( doc );
464 elemTriangularMesh.setTagName( QStringLiteral( "mesh-settings-triangular" ) );
465 elem.appendChild( elemTriangularMesh );
466
467 if ( mAveragingMethod )
468 {
469 QDomElement elemAveraging = doc.createElement( QStringLiteral( "averaging-3d" ) );
470 elemAveraging.setAttribute( QStringLiteral( "method" ), QString::number( mAveragingMethod->method() ) ) ;
471 const QDomElement elemAveragingParams = mAveragingMethod->writeXml( doc );
472 elemAveraging.appendChild( elemAveragingParams );
473 elem.appendChild( elemAveraging );
474 }
475
476 return elem;
477}
478
479void QgsMeshRendererSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
480{
481 mRendererScalarSettings.clear();
482 mRendererVectorSettings.clear();
483 mAveragingMethod.reset();
484
485 const QDomElement elemActiveDataset = elem.firstChildElement( QStringLiteral( "active-dataset-group" ) );
486 if ( elemActiveDataset.hasAttribute( QStringLiteral( "scalar" ) ) )
487 mActiveScalarDatasetGroup = elemActiveDataset.attribute( QStringLiteral( "scalar" ) ).toInt();
488
489 if ( elemActiveDataset.hasAttribute( QStringLiteral( "vector" ) ) )
490 mActiveVectorDatasetGroup = elemActiveDataset.attribute( QStringLiteral( "vector" ) ).toInt();
491
492 QDomElement elemScalar = elem.firstChildElement( QStringLiteral( "scalar-settings" ) );
493 while ( !elemScalar.isNull() )
494 {
495 const int groupIndex = elemScalar.attribute( QStringLiteral( "group" ) ).toInt();
497 scalarSettings.readXml( elemScalar, context );
498 mRendererScalarSettings.insert( groupIndex, scalarSettings );
499
500 elemScalar = elemScalar.nextSiblingElement( QStringLiteral( "scalar-settings" ) );
501 }
502
503 QDomElement elemVector = elem.firstChildElement( QStringLiteral( "vector-settings" ) );
504 while ( !elemVector.isNull() )
505 {
506 const int groupIndex = elemVector.attribute( QStringLiteral( "group" ) ).toInt();
508 vectorSettings.readXml( elemVector, context );
509 mRendererVectorSettings.insert( groupIndex, vectorSettings );
510
511 elemVector = elemVector.nextSiblingElement( QStringLiteral( "vector-settings" ) );
512 }
513
514 const QDomElement elemNativeMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-native" ) );
515 mRendererNativeMeshSettings.readXml( elemNativeMesh );
516
517 const QDomElement elemEdgeMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-edge" ) );
518 mRendererEdgeMeshSettings.readXml( elemEdgeMesh );
519
520 const QDomElement elemTriangularMesh = elem.firstChildElement( QStringLiteral( "mesh-settings-triangular" ) );
521 mRendererTriangularMeshSettings.readXml( elemTriangularMesh );
522
523 const QDomElement elemAveraging = elem.firstChildElement( QStringLiteral( "averaging-3d" ) );
524 if ( !elemAveraging.isNull() )
525 {
526 mAveragingMethod.reset( QgsMesh3DAveragingMethod::createFromXml( elemAveraging ) );
527 }
528}
529
531{
532 return mActiveScalarDatasetGroup;
533}
534
536{
537 mActiveScalarDatasetGroup = activeScalarDatasetGroup;
538}
539
541{
542 return mActiveVectorDatasetGroup;
543}
544
546{
547 mActiveVectorDatasetGroup = activeVectorDatasetGroup;
548}
549
554
559
561{
562 return mSeedingDensity;
563}
564
566{
567 mSeedingDensity = seedingDensity;
568}
569
570QDomElement QgsMeshRendererVectorStreamlineSettings::writeXml( QDomDocument &doc ) const
571{
572 QDomElement elem = doc.createElement( QStringLiteral( "vector-streamline-settings" ) );
573
574 elem.setAttribute( QStringLiteral( "seeding-method" ), mSeedingMethod );
575 elem.setAttribute( QStringLiteral( "seeding-density" ), mSeedingDensity );
576
577 return elem;
578}
579
581{
582 mSeedingMethod =
584 elem.attribute( QStringLiteral( "seeding-method" ) ).toInt() );
585 mSeedingDensity = elem.attribute( QStringLiteral( "seeding-density" ) ).toDouble();
586}
587
592
594{
595 mDisplayingMethod = displayingMethod;
596}
597
602
607
612
617
618QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
619{
620 QDomElement elem = doc.createElement( QStringLiteral( "vector-settings" ) );
621 elem.setAttribute( QStringLiteral( "symbology" ), mDisplayingMethod );
622
623 elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth );
624 elem.setAttribute( QStringLiteral( "coloring-method" ), coloringMethod() );
625 elem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) );
626 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
627 elem.appendChild( elemShader );
628 elem.setAttribute( QStringLiteral( "filter-min" ), mFilterMin );
629 elem.setAttribute( QStringLiteral( "filter-max" ), mFilterMax );
630
631 elem.setAttribute( QStringLiteral( "user-grid-enabled" ), mOnUserDefinedGrid ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
632 elem.setAttribute( QStringLiteral( "user-grid-width" ), mUserGridCellWidth );
633 elem.setAttribute( QStringLiteral( "user-grid-height" ), mUserGridCellHeight );
634
635 elem.appendChild( mArrowsSettings.writeXml( doc ) );
636 elem.appendChild( mStreamLinesSettings.writeXml( doc ) );
637 elem.appendChild( mTracesSettings.writeXml( doc ) );
638 elem.appendChild( mWindBarbSettings.writeXml( doc ) );
639
640 return elem;
641}
642
643void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
644{
645 mDisplayingMethod = static_cast<QgsMeshRendererVectorSettings::Symbology>(
646 elem.attribute( QStringLiteral( "symbology" ) ).toInt() );
647
648 mLineWidth = elem.attribute( QStringLiteral( "line-width" ) ).toDouble();
649 mColoringMethod = static_cast<QgsInterpolatedLineColor::ColoringMethod>(
650 elem.attribute( QStringLiteral( "coloring-method" ) ).toInt() );
651 mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) );
652 mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context );
653 mFilterMin = elem.attribute( QStringLiteral( "filter-min" ) ).toDouble();
654 mFilterMax = elem.attribute( QStringLiteral( "filter-max" ) ).toDouble();
655
656 mOnUserDefinedGrid = elem.attribute( QStringLiteral( "user-grid-enabled" ) ).toInt(); //bool
657 mUserGridCellWidth = elem.attribute( QStringLiteral( "user-grid-width" ) ).toInt();
658 mUserGridCellHeight = elem.attribute( QStringLiteral( "user-grid-height" ) ).toInt();
659
660 const QDomElement elemVector = elem.firstChildElement( QStringLiteral( "vector-arrow-settings" ) );
661 if ( ! elemVector.isNull() )
662 mArrowsSettings.readXml( elemVector );
663
664 const QDomElement elemStreamLine = elem.firstChildElement( QStringLiteral( "vector-streamline-settings" ) );
665 if ( ! elemStreamLine.isNull() )
666 mStreamLinesSettings.readXml( elemStreamLine );
667
668 const QDomElement elemTraces = elem.firstChildElement( QStringLiteral( "vector-traces-settings" ) );
669 if ( ! elemTraces.isNull() )
670 mTracesSettings.readXml( elemTraces );
671
672 const QDomElement elemWindBarb = elem.firstChildElement( QStringLiteral( "vector-windbarb-settings" ) );
673 if ( ! elemWindBarb.isNull() )
674 mWindBarbSettings.readXml( elemWindBarb );
675}
676
681
686
688{
689 return mColorRampShader;
690}
691
693{
694 mColorRampShader = colorRampShader;
695}
696
698{
699 QgsInterpolatedLineColor strokeColoring;
700 switch ( mColoringMethod )
701 {
703 strokeColoring = QgsInterpolatedLineColor( mColor );
704 break;
706 strokeColoring = QgsInterpolatedLineColor( mColorRampShader );
707 break;
708 }
709
710 return strokeColoring;
711}
712
717
722
723void QgsMeshRendererVectorTracesSettings::readXml( const QDomElement &elem )
724{
725 mMaximumTailLength = elem.attribute( QStringLiteral( "maximum-tail-length" ) ).toInt();
726 mMaximumTailLengthUnit = static_cast<Qgis::RenderUnit>(
727 elem.attribute( QStringLiteral( "maximum-tail-length-unit" ) ).toInt() );
728 mParticlesCount = elem.attribute( QStringLiteral( "particles-count" ) ).toInt();
729}
730
731QDomElement QgsMeshRendererVectorTracesSettings::writeXml( QDomDocument &doc ) const
732{
733 QDomElement elem = doc.createElement( QStringLiteral( "vector-traces-settings" ) );
734 elem.setAttribute( QStringLiteral( "maximum-tail-length" ), mMaximumTailLength );
735 elem.setAttribute( QStringLiteral( "maximum-tail-length-unit" ), static_cast< int >( mMaximumTailLengthUnit ) );
736 elem.setAttribute( QStringLiteral( "particles-count" ), mParticlesCount );
737
738 return elem;
739}
740
742{
743 return mMaximumTailLengthUnit;
744}
745
747{
748 mMaximumTailLengthUnit = maximumTailLengthUnit;
749}
750
752{
753 return mMaximumTailLength;
754}
755
757{
758 mMaximumTailLength = maximumTailLength;
759}
760
762{
763 return mParticlesCount;
764}
765
767{
768 mParticlesCount = value;
769}
770
771bool QgsMeshRendererSettings::hasSettings( int datasetGroupIndex ) const
772{
773 return mRendererScalarSettings.contains( datasetGroupIndex ) || mRendererVectorSettings.contains( datasetGroupIndex );
774}
775
780
785
787{
788 mShaftLength = elem.attribute( QStringLiteral( "shaft-length" ), QStringLiteral( "10" ) ).toDouble();
789 mShaftLengthUnits = static_cast<Qgis::RenderUnit>(
790 elem.attribute( QStringLiteral( "shaft-length-units" ) ).toInt() );
791 mMagnitudeMultiplier = elem.attribute( QStringLiteral( "magnitude-multiplier" ), QStringLiteral( "1" ) ).toDouble();
792 mMagnitudeUnits = static_cast<WindSpeedUnit>(
793 elem.attribute( QStringLiteral( "magnitude-units" ), QStringLiteral( "0" ) ).toInt() );
794}
795
796QDomElement QgsMeshRendererVectorWindBarbSettings::writeXml( QDomDocument &doc ) const
797{
798 QDomElement elem = doc.createElement( QStringLiteral( "vector-windbarb-settings" ) );
799 elem.setAttribute( QStringLiteral( "shaft-length" ), mShaftLength );
800 elem.setAttribute( QStringLiteral( "shaft-length-units" ), static_cast< int >( mShaftLengthUnits ) );
801 elem.setAttribute( QStringLiteral( "magnitude-multiplier" ), mMagnitudeMultiplier );
802 elem.setAttribute( QStringLiteral( "magnitude-units" ), static_cast< int >( mMagnitudeUnits ) );
803 return elem;
804}
805
807{
808 switch ( mMagnitudeUnits )
809 {
811 return 1.0;
813 return 3600.0 / 1852.0;
815 return 1.0 / 1.852;
817 return 1.609344 / 1.852;
819 return 3600.0 / 1.852 / 5280.0 * 1.609344 ;
821 return mMagnitudeMultiplier;
822 }
823 return 1.0; // should not reach
824}
825
827{
828 mMagnitudeMultiplier = magnitudeMultiplier;
829}
830
832{
833 return mShaftLength;
834}
835
837{
838 mShaftLength = shaftLength;
839}
840
842{
843 return mShaftLengthUnits;
844}
845
847{
848 mShaftLengthUnits = shaftLengthUnit;
849}
850
855
857{
858 mMagnitudeUnits = units;
859}
@ NotSet
User defined.
@ WholeMesh
Whole mesh 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.
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.
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.
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:6301
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6282