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 mLayerTree->writeXml( profileElem, context );
60 if ( mSubsectionsSymbol )
62 QDomElement subsectionsElement = document.createElement( QStringLiteral(
"subsections" ) );
64 subsectionsElement.appendChild( symbolElement );
65 profileElem.appendChild( subsectionsElement );
73 if ( element.nodeName() != QLatin1String(
"ElevationProfile" ) )
78 setName( element.attribute( QStringLiteral(
"name" ) ) );
80 const QDomNodeList crsNodeList = element.elementsByTagName( QStringLiteral(
"crs" ) );
82 if ( !crsNodeList.isEmpty() )
84 const QDomElement crsElem = crsNodeList.at( 0 ).toElement();
85 crs.readXml( crsElem );
91 const QDomNodeList curveNodeList = element.elementsByTagName( QStringLiteral(
"curve" ) );
92 if ( !curveNodeList.isEmpty() )
94 const QDomElement curveElem = curveNodeList.at( 0 ).toElement();
100 mProfileCurve.reset( curveGeom->clone() );
104 mProfileCurve.reset();
109 mTolerance = element.attribute( QStringLiteral(
"tolerance" ) ).toDouble();
110 mLockAxisScales = element.attribute( QStringLiteral(
"lockAxisScales" ), QStringLiteral(
"0" ) ).toInt();
113 const QDomElement layerTreeElem = element.firstChildElement( QStringLiteral(
"layer-tree-group" ) );
115 setupLayerTreeConnections();
118 const QDomElement subsectionsElement = element.firstChildElement( QStringLiteral(
"subsections" ) );
119 const QDomElement symbolsElement = subsectionsElement.firstChildElement( QStringLiteral(
"symbol" ) );
120 if ( !symbolsElement.isNull() )
123 if ( subSectionsSymbol )
134 mLayerTree->resolveReferences( project );
144 return mLayerTree.get();
163 if ( curve == mProfileCurve.get() )
165 mProfileCurve.reset( curve );
171 return mProfileCurve.get();
190 return mLockAxisScales;
195 return mDistanceUnit;
200 if ( lock == mLockAxisScales )
203 mLockAxisScales = lock;
209 if ( mDistanceUnit == unit )
212 mDistanceUnit = unit;
216void QgsElevationProfile::dirtyProject()
219 mProject->setDirty();
222void QgsElevationProfile::setupLayerTreeConnections()
231 return mSubsectionsSymbol.get();
236 if ( symbol == mSubsectionsSymbol.get() )
239 mSubsectionsSymbol.reset( symbol );
DistanceUnit
Units of distance.
Represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
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.
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)