QGIS API Documentation 4.3.0-Master (2b7e6c9893e)
Loading...
Searching...
No Matches
qgsvectorfieldsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorfieldsettings.cpp
3 ---------------------
4 begin : September 2026
5 copyright : (C) 2026 by Stefanos Natsis
6 email : uclaros at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgscolorutils.h"
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
25{
26 return mLineWidth;
27}
28
30{
31 mLineWidth = lineWidth;
32}
33
35{
36 return mColor;
37}
38
39void QgsVectorFieldSettings::setColor( const QColor &vectorColor )
40{
41 mColor = vectorColor;
42}
43
45{
46 return mFilterMin;
47}
48
49void QgsVectorFieldSettings::setFilterMin( double vectorFilterMin )
50{
51 mFilterMin = vectorFilterMin;
52}
53
55{
56 return mFilterMax;
57}
58
59void QgsVectorFieldSettings::setFilterMax( double vectorFilterMax )
60{
61 mFilterMax = vectorFilterMax;
62}
63
65{
66 return mOnUserDefinedGrid;
67}
68
70{
71 mOnUserDefinedGrid = enabled;
72}
73
75{
76 return mUserGridCellWidth;
77}
78
80{
81 mUserGridCellWidth = width;
82}
83
85{
86 return mUserGridCellHeight;
87}
88
90{
91 mUserGridCellHeight = height;
92}
93
95{
96 return mDisplayingMethod;
97}
98
100{
101 mDisplayingMethod = displayingMethod;
102}
103
105{
106 return mArrowsSettings;
107}
108
113
115{
116 return mStreamLinesSettings;
117}
118
123
124QDomElement QgsVectorFieldSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
125{
126 QDomElement elem = doc.createElement( u"vector-settings"_s );
127 elem.setAttribute( u"symbology"_s, static_cast< int >( mDisplayingMethod ) );
128
129 elem.setAttribute( u"line-width"_s, mLineWidth );
130 elem.setAttribute( u"coloring-method"_s, coloringMethod() );
131 elem.setAttribute( u"color"_s, QgsColorUtils::colorToString( mColor ) );
132 const QDomElement elemShader = mColorRampShader.writeXml( doc, context );
133 elem.appendChild( elemShader );
134 elem.setAttribute( u"filter-min"_s, mFilterMin );
135 elem.setAttribute( u"filter-max"_s, mFilterMax );
136
137 elem.setAttribute( u"user-grid-enabled"_s, mOnUserDefinedGrid ? u"1"_s : u"0"_s );
138 elem.setAttribute( u"user-grid-width"_s, mUserGridCellWidth );
139 elem.setAttribute( u"user-grid-height"_s, mUserGridCellHeight );
140
141 elem.appendChild( mArrowsSettings.writeXml( doc ) );
142 elem.appendChild( mStreamLinesSettings.writeXml( doc ) );
143 elem.appendChild( mTracesSettings.writeXml( doc ) );
144 elem.appendChild( mWindBarbSettings.writeXml( doc ) );
145
146 return elem;
147}
148
149void QgsVectorFieldSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
150{
151 mDisplayingMethod = static_cast<Qgis::VectorFieldSymbology>( elem.attribute( u"symbology"_s ).toInt() );
152
153 mLineWidth = elem.attribute( u"line-width"_s ).toDouble();
154 mColoringMethod = static_cast<QgsInterpolatedLineColor::ColoringMethod>( elem.attribute( u"coloring-method"_s ).toInt() );
155 mColor = QgsColorUtils::colorFromString( elem.attribute( u"color"_s ) );
156 mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context );
157 mFilterMin = elem.attribute( u"filter-min"_s ).toDouble();
158 mFilterMax = elem.attribute( u"filter-max"_s ).toDouble();
159
160 mOnUserDefinedGrid = elem.attribute( u"user-grid-enabled"_s ).toInt(); //bool
161 mUserGridCellWidth = elem.attribute( u"user-grid-width"_s ).toInt();
162 mUserGridCellHeight = elem.attribute( u"user-grid-height"_s ).toInt();
163
164 const QDomElement elemVector = elem.firstChildElement( u"vector-arrow-settings"_s );
165 if ( !elemVector.isNull() )
166 mArrowsSettings.readXml( elemVector );
167
168 const QDomElement elemStreamLine = elem.firstChildElement( u"vector-streamline-settings"_s );
169 if ( !elemStreamLine.isNull() )
170 mStreamLinesSettings.readXml( elemStreamLine );
171
172 const QDomElement elemTraces = elem.firstChildElement( u"vector-traces-settings"_s );
173 if ( !elemTraces.isNull() )
174 mTracesSettings.readXml( elemTraces );
175
176 const QDomElement elemWindBarb = elem.firstChildElement( u"vector-windbarb-settings"_s );
177 if ( !elemWindBarb.isNull() )
178 mWindBarbSettings.readXml( elemWindBarb );
179}
180
185
190
192{
193 return mColorRampShader;
194}
195
200
202{
203 QgsInterpolatedLineColor strokeColoring;
204 switch ( mColoringMethod )
205 {
207 strokeColoring = QgsInterpolatedLineColor( mColor );
208 break;
210 strokeColoring = QgsInterpolatedLineColor( mColorRampShader );
211 break;
212 }
213
214 return strokeColoring;
215}
216
218{
219 return mTracesSettings;
220}
221
226
228{
229 return mWindBarbSettings;
230}
231
VectorFieldSymbology
Defines the symbology of vector field rendering.
Definition qgis.h:7134
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
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.
A container for the context for various read/write operations on objects.
Represents a mesh renderer settings for vector datasets displayed with arrows.
void setArrowsSettings(const QgsVectorFieldArrowSettings &arrowSettings)
Sets settings for vector rendered with arrows.
double filterMin() const
Returns filter value for vector magnitudes.
QgsVectorFieldArrowSettings arrowSettings() const
Returns settings for vector rendered with arrows.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes configuration to a new DOM element.
int userGridCellWidth() const
Returns width in pixels of user grid cell.
void setColor(const QColor &color)
Sets color used for drawing arrows.
void setStreamLinesSettings(const QgsVectorFieldStreamlineSettings &streamLinesSettings)
Sets settings for vector rendered with streamlines.
double lineWidth() const
Returns line width of the arrow (in millimeters).
QgsVectorFieldWindBarbSettings windBarbSettings() const
Returns settings for vector rendered with wind barbs.
QgsColorRampShader colorRampShader() const
Sets the color ramp shader used to render vector datasets.
void setFilterMin(double filterMin)
Sets filter value for vector magnitudes.
Qgis::VectorFieldSymbology symbology() const
Returns the displaying method used to render vector datasets.
void setTracesSettings(const QgsVectorFieldTracesSettings &tracesSettings)
Sets settings for vector rendered with traces.
QgsVectorFieldTracesSettings tracesSettings() const
Returns settings for vector rendered with traces.
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.
void setColoringMethod(const QgsInterpolatedLineColor::ColoringMethod &coloringMethod)
Sets the coloring method used to render vector datasets.
QgsVectorFieldStreamlineSettings streamLinesSettings() const
Returns settings for vector rendered with streamlines.
void setOnUserDefinedGrid(bool enabled)
Toggles drawing of vectors on user defined grid.
int userGridCellHeight() const
Returns height in pixels of user grid cell.
double filterMax() const
Returns filter value for vector magnitudes.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads configuration from the given DOM element.
void setFilterMax(double filterMax)
Sets filter value for vector magnitudes.
QgsInterpolatedLineColor::ColoringMethod coloringMethod() const
Returns the coloring method used to render vector datasets.
QgsInterpolatedLineColor vectorStrokeColoring() const
Returns the stroke coloring used to render vector datasets.
void setUserGridCellWidth(int width)
Sets width of user grid cell (in pixels).
void setUserGridCellHeight(int height)
Sets height of user grid cell (in pixels).
void setSymbology(const Qgis::VectorFieldSymbology &symbology)
Sets the displaying method used to render vector datasets.
void setColorRampShader(const QgsColorRampShader &colorRampShader)
Returns the color ramp shader used to render vector datasets.
void setWindBarbSettings(const QgsVectorFieldWindBarbSettings &windBarbSettings)
Sets settings for vector rendered with wind barbs.
QColor color() const
Returns color used for drawing arrows.
Represents a streamline renderer settings for vector datasets displayed by streamlines.
Represents a trace renderer settings for vector datasets displayed by particle traces.
Represents a mesh renderer settings for vector datasets displayed with wind barbs.