25#include "moc_qgselevationprofile.cpp"
27using namespace Qt::StringLiterals;
33 setupLayerTreeConnections();
40 QDomElement profileElem = document.createElement( u
"ElevationProfile"_s );
41 profileElem.setAttribute( u
"name"_s, mName );
43 profileElem.setAttribute( u
"distanceUnit"_s,
qgsEnumValueToKey( mDistanceUnit ) );
45 profileElem.setAttribute( u
"tolerance"_s, mTolerance );
46 if ( mLockAxisScales )
47 profileElem.setAttribute( u
"lockAxisScales"_s, u
"1"_s );
51 QDomElement crsElem = document.createElement( u
"crs"_s );
52 mCrs.writeXml( crsElem, document );
53 profileElem.appendChild( crsElem );
57 QDomElement curveElem = document.createElement( u
"curve"_s );
58 curveElem.appendChild( document.createTextNode( mProfileCurve->asWkt( ) ) );
59 profileElem.appendChild( curveElem );
62 if ( !mUseProjectLayerTree )
64 mLayerTree->writeXml( profileElem, context );
68 profileElem.setAttribute( u
"useProjectLayerTree"_s, u
"1"_s );
71 if ( mSubsectionsSymbol )
73 QDomElement subsectionsElement = document.createElement( u
"subsections"_s );
75 subsectionsElement.appendChild( symbolElement );
76 profileElem.appendChild( subsectionsElement );
84 if ( element.nodeName() !=
"ElevationProfile"_L1 )
89 setName( element.attribute( u
"name"_s ) );
91 const QDomNodeList crsNodeList = element.elementsByTagName( u
"crs"_s );
93 if ( !crsNodeList.isEmpty() )
95 const QDomElement crsElem = crsNodeList.at( 0 ).toElement();
96 crs.readXml( crsElem );
102 const QDomNodeList curveNodeList = element.elementsByTagName( u
"curve"_s );
103 if ( !curveNodeList.isEmpty() )
105 const QDomElement curveElem = curveNodeList.at( 0 ).toElement();
111 mProfileCurve.reset( curveGeom->clone() );
115 mProfileCurve.reset();
120 mTolerance = element.attribute( u
"tolerance"_s ).toDouble();
121 mLockAxisScales = element.attribute( u
"lockAxisScales"_s, u
"0"_s ).toInt();
124 if ( !mUseProjectLayerTree )
126 const QDomElement layerTreeElem = element.firstChildElement( u
"layer-tree-group"_s );
128 setupLayerTreeConnections();
131 const QDomElement subsectionsElement = element.firstChildElement( u
"subsections"_s );
132 const QDomElement symbolsElement = subsectionsElement.firstChildElement( u
"symbol"_s );
133 if ( !symbolsElement.isNull() )
136 if ( subSectionsSymbol )
147 mLayerTree->resolveReferences( project );
157 return !mUseProjectLayerTree ? mLayerTree.get() :
nullptr;
176 if ( curve == mProfileCurve.get() )
178 mProfileCurve.reset( curve );
184 return mProfileCurve.get();
203 return mLockAxisScales;
208 return mDistanceUnit;
213 if ( lock == mLockAxisScales )
216 mLockAxisScales = lock;
222 if ( mDistanceUnit == unit )
225 mDistanceUnit = unit;
231 if ( mUseProjectLayerTree == useProjectTree )
234 mUseProjectLayerTree = useProjectTree;
239void QgsElevationProfile::dirtyProject()
242 mProject->setDirty();
245void QgsElevationProfile::setupLayerTreeConnections()
254 return mSubsectionsSymbol.get();
259 if ( symbol == mSubsectionsSymbol.get() )
262 mSubsectionsSymbol.reset( symbol );
DistanceUnit
Units of distance.
Represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
void useProjectLayerTreeChanged(bool useProjectTree)
Emitted when the use project layer tree property is changed.
void setName(const QString &name)
Sets the profile's unique name.
QgsCoordinateReferenceSystem crs() const
Returns the crs associated with the profile's map coordinates.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Returns the profiles's state encapsulated in a DOM element.
double tolerance() const
Returns the tolerance of the profile (in crs() units).
void setLockAxisScales(bool lock)
Sets whether the distance and elevation scales are locked to each other.
QgsElevationProfile(QgsProject *project)
Constructor for QgsElevationProfile.
QgsLineSymbol * subsectionsSymbol()
Returns the symbol used to draw the subsections.
void setSubsectionsSymbol(QgsLineSymbol *symbol)
Sets the symbol used to draw the subsections.
void nameChanged(const QString &newName)
Emitted when the profile is renamed.
void setDistanceUnit(Qgis::DistanceUnit unit)
Sets the distance unit used by the profile.
QgsCurve * profileCurve() const
Returns the profile curve.
void resolveReferences(const QgsProject *project)
After reading settings from XML, resolves references to any layers in a project that have been read a...
void setTolerance(double tolerance)
Sets the profile tolerance (in crs() units).
QIcon icon() const
Returns the icon to use for the elevation profile.
bool lockAxisScales() const
Returns true if the distance and elevation scales are locked to each other.
QString name() const
Returns the profile's unique name.
void setUseProjectLayerTree(bool useProjectTree)
Sets whether the profile should always use the project's layer tree.
Qgis::DistanceUnit distanceUnit() const
Returns the distance unit used by the profile.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the crs associated with the profile's map coordinates.
QgsLayerTree * layerTree()
Returns the layer tree used by the profile.
void setProfileCurve(QgsCurve *curve)
Sets the profile curve.
bool readXml(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the profiles's state from a DOM element.
~QgsElevationProfile() override
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
void visibilityChanged(QgsLayerTreeNode *node)
Emitted when check state of a node within the tree has been changed.
Namespace with helper functions for layer tree operations.
static std::unique_ptr< QgsLayerTree > readXml(const QDomElement &element, const QgsReadWriteContext &context)
Load the layer tree from an XML element.
void layerOrderChanged()
Emitted when the layer order has changed.
A line symbol type, for rendering LineString and MultiLineString geometries.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
A container for the context for various read/write operations on objects.
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
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.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)