23#include "moc_qgselevationprofile.cpp"
29 setupLayerTreeConnections();
36 QDomElement profileElem = document.createElement( QStringLiteral(
"ElevationProfile" ) );
37 profileElem.setAttribute( QStringLiteral(
"name" ), mName );
39 profileElem.setAttribute( QStringLiteral(
"distanceUnit" ),
qgsEnumValueToKey( mDistanceUnit ) );
41 profileElem.setAttribute( QStringLiteral(
"tolerance" ), mTolerance );
42 if ( mLockAxisScales )
43 profileElem.setAttribute( QStringLiteral(
"lockAxisScales" ), QStringLiteral(
"1" ) );
47 QDomElement crsElem = document.createElement( QStringLiteral(
"crs" ) );
48 mCrs.writeXml( crsElem, document );
49 profileElem.appendChild( crsElem );
53 QDomElement curveElem = document.createElement( QStringLiteral(
"curve" ) );
54 curveElem.appendChild( document.createTextNode( mProfileCurve->asWkt( ) ) );
55 profileElem.appendChild( curveElem );
58 if ( !mUseProjectLayerTree )
60 mLayerTree->writeXml( profileElem, context );
64 profileElem.setAttribute( QStringLiteral(
"useProjectLayerTree" ), QStringLiteral(
"1" ) );
67 if ( mSubsectionsSymbol )
69 QDomElement subsectionsElement = document.createElement( QStringLiteral(
"subsections" ) );
71 subsectionsElement.appendChild( symbolElement );
72 profileElem.appendChild( subsectionsElement );
80 if ( element.nodeName() != QLatin1String(
"ElevationProfile" ) )
85 setName( element.attribute( QStringLiteral(
"name" ) ) );
87 const QDomNodeList crsNodeList = element.elementsByTagName( QStringLiteral(
"crs" ) );
89 if ( !crsNodeList.isEmpty() )
91 const QDomElement crsElem = crsNodeList.at( 0 ).toElement();
92 crs.readXml( crsElem );
98 const QDomNodeList curveNodeList = element.elementsByTagName( QStringLiteral(
"curve" ) );
99 if ( !curveNodeList.isEmpty() )
101 const QDomElement curveElem = curveNodeList.at( 0 ).toElement();
107 mProfileCurve.reset( curveGeom->clone() );
111 mProfileCurve.reset();
116 mTolerance = element.attribute( QStringLiteral(
"tolerance" ) ).toDouble();
117 mLockAxisScales = element.attribute( QStringLiteral(
"lockAxisScales" ), QStringLiteral(
"0" ) ).toInt();
119 setUseProjectLayerTree( element.attribute( QStringLiteral(
"useProjectLayerTree" ), QStringLiteral(
"0" ) ).toInt() );
120 if ( !mUseProjectLayerTree )
122 const QDomElement layerTreeElem = element.firstChildElement( QStringLiteral(
"layer-tree-group" ) );
124 setupLayerTreeConnections();
127 const QDomElement subsectionsElement = element.firstChildElement( QStringLiteral(
"subsections" ) );
128 const QDomElement symbolsElement = subsectionsElement.firstChildElement( QStringLiteral(
"symbol" ) );
129 if ( !symbolsElement.isNull() )
132 if ( subSectionsSymbol )
143 mLayerTree->resolveReferences( project );
153 return !mUseProjectLayerTree ? mLayerTree.get() :
nullptr;
172 if ( curve == mProfileCurve.get() )
174 mProfileCurve.reset( curve );
180 return mProfileCurve.get();
199 return mLockAxisScales;
204 return mDistanceUnit;
209 if ( lock == mLockAxisScales )
212 mLockAxisScales = lock;
218 if ( mDistanceUnit == unit )
221 mDistanceUnit = unit;
227 if ( mUseProjectLayerTree == useProjectTree )
230 mUseProjectLayerTree = useProjectTree;
235void QgsElevationProfile::dirtyProject()
238 mProject->setDirty();
241void QgsElevationProfile::setupLayerTreeConnections()
250 return mSubsectionsSymbol.get();
255 if ( symbol == mSubsectionsSymbol.get() )
258 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)