QGIS API Documentation 4.3.0-Master (2b7e6c9893e)
Loading...
Searching...
No Matches
qgsvectorfieldarrowsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorfieldarrowsettings.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 <QString>
19
20using namespace Qt::StringLiterals;
21
26
31
33{
34 return mMinShaftLength;
35}
36
41
43{
44 return mMaxShaftLength;
45}
46
51
53{
54 return mScaleFactor;
55}
56
61
63{
64 return mFixedShaftLength;
65}
66
71
73{
74 return mArrowHeadWidthRatio;
75}
76
77void QgsVectorFieldArrowSettings::setArrowHeadWidthRatio( double vectorHeadWidthRatio )
78{
79 mArrowHeadWidthRatio = vectorHeadWidthRatio;
80}
81
83{
84 return mArrowHeadLengthRatio;
85}
86
87void QgsVectorFieldArrowSettings::setArrowHeadLengthRatio( double vectorHeadLengthRatio )
88{
89 mArrowHeadLengthRatio = vectorHeadLengthRatio;
90}
91
92QDomElement QgsVectorFieldArrowSettings::writeXml( QDomDocument &doc ) const
93{
94 QDomElement elem = doc.createElement( u"vector-arrow-settings"_s );
95 elem.setAttribute( u"arrow-head-width-ratio"_s, mArrowHeadWidthRatio );
96 elem.setAttribute( u"arrow-head-length-ratio"_s, mArrowHeadLengthRatio );
97
98 QDomElement elemShaft = doc.createElement( u"shaft-length"_s );
99 QString methodTxt;
100 switch ( mShaftLengthMethod )
101 {
103 methodTxt = u"minmax"_s;
104 elemShaft.setAttribute( u"min"_s, mMinShaftLength );
105 elemShaft.setAttribute( u"max"_s, mMaxShaftLength );
106 break;
108 methodTxt = u"scaled"_s;
109 elemShaft.setAttribute( u"scale-factor"_s, mScaleFactor );
110 break;
112 methodTxt = u"fixed"_s;
113 elemShaft.setAttribute( u"fixed-length"_s, mFixedShaftLength );
114 break;
115 }
116 elemShaft.setAttribute( u"method"_s, methodTxt );
117 elem.appendChild( elemShaft );
118 return elem;
119}
120
121void QgsVectorFieldArrowSettings::readXml( const QDomElement &elem )
122{
123 mArrowHeadWidthRatio = elem.attribute( u"arrow-head-width-ratio"_s ).toDouble();
124 mArrowHeadLengthRatio = elem.attribute( u"arrow-head-length-ratio"_s ).toDouble();
125
126 const QDomElement elemShaft = elem.firstChildElement( u"shaft-length"_s );
127 const QString methodTxt = elemShaft.attribute( u"method"_s );
128 if ( u"minmax"_s == methodTxt )
129 {
131 mMinShaftLength = elemShaft.attribute( u"min"_s ).toDouble();
132 mMaxShaftLength = elemShaft.attribute( u"max"_s ).toDouble();
133 }
134 else if ( u"scaled"_s == methodTxt )
135 {
137 mScaleFactor = elemShaft.attribute( u"scale-factor"_s ).toDouble();
138 }
139 else // fixed
140 {
142 mFixedShaftLength = elemShaft.attribute( u"fixed-length"_s ).toDouble();
143 }
144}
VectorFieldArrowScalingMethod
Algorithm to transform vector magnitude to length of arrow on the device in pixels.
Definition qgis.h:7119
@ Fixed
Use fixed length fixedShaftLength() regardless of vector's magnitude.
Definition qgis.h:7122
@ Scaled
Scale vector magnitude by factor scaleFactor().
Definition qgis.h:7121
@ MinMax
Scale vector magnitude linearly to fit in range of vectorFilterMin() and vectorFilterMax().
Definition qgis.h:7120
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
void setFixedShaftLength(double fixedShaftLength)
Sets fixed length (in millimeters).
double minShaftLength() const
Returns mininimum shaft length (in millimeters).
Qgis::VectorFieldArrowScalingMethod shaftLengthMethod() const
Returns method used for drawing arrows.
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
void setMinShaftLength(double minShaftLength)
Sets mininimum shaft length (in millimeters).
double arrowHeadLengthRatio() const
Returns ratio of the head length of the arrow (range 0-1).
void setShaftLengthMethod(Qgis::VectorFieldArrowScalingMethod shaftLengthMethod)
Sets method used for drawing arrows.
void setScaleFactor(double scaleFactor)
Sets scale factor.
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).
void setMaxShaftLength(double maxShaftLength)
Sets maximum shaft length (in millimeters).
double arrowHeadWidthRatio() const
Returns ratio of the head width of the arrow (range 0-1).
double maxShaftLength() const
Returns maximum shaft length (in millimeters).
double scaleFactor() const
Returns scale factor.
void setArrowHeadLengthRatio(double arrowHeadLengthRatio)
Sets ratio of the head length of the arrow (range 0-1).