19#include "moc_qgsprojectgpssettings.cpp"
29 mDestinationLayer.resolveWeakly( project );
33 if ( mDestinationLayer )
43 mAutoAddTrackVertices =
false;
44 mAutoCommitFeatures =
false;
45 mDestinationFollowsActiveLayer =
true;
47 mDestinationLayer.setLayer(
nullptr );
48 mDestinationTimestampFields.clear();
59 mAutoAddTrackVertices = element.attribute( QStringLiteral(
"autoAddTrackVertices" ),
"0" ).toInt();
60 mAutoCommitFeatures = element.attribute( QStringLiteral(
"autoCommitFeatures" ),
"0" ).toInt();
61 mDestinationFollowsActiveLayer = element.attribute( QStringLiteral(
"destinationFollowsActiveLayer" ),
"1" ).toInt();
63 const QString layerId = element.attribute( QStringLiteral(
"destinationLayer" ) );
64 const QString layerName = element.attribute( QStringLiteral(
"destinationLayerName" ) );
65 const QString layerSource = element.attribute( QStringLiteral(
"destinationLayerSource" ) );
66 const QString layerProvider = element.attribute( QStringLiteral(
"destinationLayerProvider" ) );
68 mDestinationLayer =
QgsVectorLayerRef( layerId, layerName, layerSource, layerProvider );
70 mDestinationTimestampFields.clear();
72 const QDomElement timeStampElement = element.firstChildElement( QStringLiteral(
"timeStampFields" ) );
73 QDomElement layerElement = timeStampElement.firstChildElement();
74 while ( !layerElement.isNull() )
76 const QString layerId = layerElement.attribute( QStringLiteral(
"destinationLayer" ) );
77 const QString field = layerElement.attribute( QStringLiteral(
"field" ) );
78 mDestinationTimestampFields[ layerId ] = field;
79 layerElement = layerElement.nextSiblingElement();
93 QDomElement element = doc.createElement( QStringLiteral(
"ProjectGpsSettings" ) );
95 element.setAttribute( QStringLiteral(
"autoAddTrackVertices" ), mAutoAddTrackVertices ? 1 : 0 );
96 element.setAttribute( QStringLiteral(
"autoCommitFeatures" ), mAutoCommitFeatures ? 1 : 0 );
97 element.setAttribute( QStringLiteral(
"destinationFollowsActiveLayer" ), mDestinationFollowsActiveLayer ? 1 : 0 );
99 if ( mDestinationLayer )
101 element.setAttribute( QStringLiteral(
"destinationLayer" ), mDestinationLayer.layerId );
102 element.setAttribute( QStringLiteral(
"destinationLayerName" ), mDestinationLayer.name );
103 element.setAttribute( QStringLiteral(
"destinationLayerSource" ), mDestinationLayer.source );
104 element.setAttribute( QStringLiteral(
"destinationLayerProvider" ), mDestinationLayer.provider );
108 element.setAttribute( QStringLiteral(
"destinationLayer" ), QString() );
112 QDomElement timeStampElement = doc.createElement( QStringLiteral(
"timeStampFields" ) );
113 for (
auto it = mDestinationTimestampFields.constBegin(); it != mDestinationTimestampFields.constEnd(); ++it )
115 const QString layerId = it.key();
116 if (
QgsProject *project = qobject_cast< QgsProject * >( parent() ) )
119 if ( !project->mapLayer( layerId ) )
123 QDomElement layerElement = doc.createElement( QStringLiteral(
"field" ) );
124 layerElement.setAttribute( QStringLiteral(
"destinationLayer" ), layerId );
125 layerElement.setAttribute( QStringLiteral(
"field" ), it.value() );
126 timeStampElement.appendChild( layerElement );
128 element.appendChild( timeStampElement );
136 return mAutoAddTrackVertices;
141 return mAutoCommitFeatures;
146 return mDestinationFollowsActiveLayer;
151 return mDestinationLayer.get();
156 return mDestinationTimestampFields;
163 return mDestinationTimestampFields.value( vl->id() );
170 if ( enabled == mAutoAddTrackVertices )
173 mAutoAddTrackVertices = enabled;
179 if ( enabled == mAutoCommitFeatures )
182 mAutoCommitFeatures = enabled;
188 if ( follow == mDestinationFollowsActiveLayer )
191 mDestinationFollowsActiveLayer = follow;
197 if ( layer == mDestinationLayer.get() )
202 mDestinationLayer.setLayer( layer );
220 if ( mDestinationTimestampFields.value( layer->
id() ) != field )
222 mDestinationTimestampFields.insert( layer->
id(), field );
void setAutomaticallyCommitFeatures(bool enabled)
Sets whether features created from GPS locations should be immediately committed to their target laye...
bool automaticallyCommitFeatures
void destinationFollowsActiveLayerChanged(bool follows)
Emitted whenever the destinationFollowsActiveLayer() setting is changed.
bool automaticallyAddTrackVertices
void destinationLayerChanged(QgsVectorLayer *layer)
Emitted whenever the destination layer for features digitized from GPS is changed.
void setDestinationFollowsActiveLayer(bool follow)
Sets whether the destination layer for storing features digitized from GPS should follow the current ...
QMap< QString, QString > destinationTimeStampFields() const
Returns the map of destination layer ID to target time stamp field name.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the settings's state from a DOM element.
QgsProjectGpsSettings(QObject *parent=nullptr)
Constructor for QgsProjectGpsSettings with the specified parent object.
void reset()
Resets the settings to a default state.
QgsVectorLayer * destinationLayer
void setDestinationLayer(QgsVectorLayer *layer)
Sets the destination layer to be used for storing features digitized from GPS.
void setAutomaticallyAddTrackVertices(bool enabled)
Sets whether track vertices should be automatically created whenever new locations are received from ...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Returns a DOM element representing the settings.
void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID (if it has not been resolved already).
void setDestinationTimeStampField(QgsVectorLayer *layer, const QString &field)
Sets the destination field name for automatically storing timestamps in the specified destination lay...
bool destinationFollowsActiveLayer() const
Returns true if the destination layer for storing features digitized from GPS should follow the curre...
void destinationTimeStampFieldChanged(const QString &field)
Emitted whenever the destination field for automatic time stamps is changed.
~QgsProjectGpsSettings() override
void automaticallyCommitFeaturesChanged(bool enabled)
Emitted whenever the automaticallyCommitFeatures() setting is changed.
void automaticallyAddTrackVerticesChanged(bool enabled)
Emitted whenever the automaticallyAddTrackVertices() setting is changed.
QString destinationTimeStampField() const
Returns the destination time stamp field name for the current destinationLayer(), or an empty string ...
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.
Represents a vector layer which manages a vector based dataset.
_LayerRef< QgsVectorLayer > QgsVectorLayerRef