31 if ( mDestinationLayer )
41 mAutoAddTrackVertices =
false;
42 mAutoCommitFeatures =
false;
43 mDestinationFollowsActiveLayer =
true;
45 mDestinationLayer.
setLayer(
nullptr );
46 mDestinationTimestampFields.clear();
57 mAutoAddTrackVertices = element.attribute( QStringLiteral(
"autoAddTrackVertices" ),
"0" ).toInt();
58 mAutoCommitFeatures = element.attribute( QStringLiteral(
"autoCommitFeatures" ),
"0" ).toInt();
59 mDestinationFollowsActiveLayer = element.attribute( QStringLiteral(
"destinationFollowsActiveLayer" ),
"1" ).toInt();
61 const QString layerId = element.attribute( QStringLiteral(
"destinationLayer" ) );
62 const QString layerName = element.attribute( QStringLiteral(
"destinationLayerName" ) );
63 const QString layerSource = element.attribute( QStringLiteral(
"destinationLayerSource" ) );
64 const QString layerProvider = element.attribute( QStringLiteral(
"destinationLayerProvider" ) );
66 mDestinationLayer =
QgsVectorLayerRef( layerId, layerName, layerSource, layerProvider );
68 mDestinationTimestampFields.clear();
70 const QDomElement timeStampElement = element.firstChildElement( QStringLiteral(
"timeStampFields" ) );
71 QDomElement layerElement = timeStampElement.firstChildElement();
72 while ( !layerElement.isNull() )
74 const QString layerId = layerElement.attribute( QStringLiteral(
"destinationLayer" ) );
75 const QString
field = layerElement.attribute( QStringLiteral(
"field" ) );
76 mDestinationTimestampFields[ layerId ] =
field;
77 layerElement = layerElement.nextSiblingElement();
91 QDomElement element = doc.createElement( QStringLiteral(
"ProjectGpsSettings" ) );
93 element.setAttribute( QStringLiteral(
"autoAddTrackVertices" ), mAutoAddTrackVertices ? 1 : 0 );
94 element.setAttribute( QStringLiteral(
"autoCommitFeatures" ), mAutoCommitFeatures ? 1 : 0 );
95 element.setAttribute( QStringLiteral(
"destinationFollowsActiveLayer" ), mDestinationFollowsActiveLayer ? 1 : 0 );
97 if ( mDestinationLayer )
99 element.setAttribute( QStringLiteral(
"destinationLayer" ), mDestinationLayer.
layerId );
100 element.setAttribute( QStringLiteral(
"destinationLayerName" ), mDestinationLayer.
name );
101 element.setAttribute( QStringLiteral(
"destinationLayerSource" ), mDestinationLayer.
source );
102 element.setAttribute( QStringLiteral(
"destinationLayerProvider" ), mDestinationLayer.
provider );
106 element.setAttribute( QStringLiteral(
"destinationLayer" ), QString() );
110 QDomElement timeStampElement = doc.createElement( QStringLiteral(
"timeStampFields" ) );
111 for (
auto it = mDestinationTimestampFields.constBegin(); it != mDestinationTimestampFields.constEnd(); ++it )
113 const QString layerId = it.key();
114 if (
QgsProject *project = qobject_cast< QgsProject * >( parent() ) )
117 if ( !project->mapLayer( layerId ) )
121 QDomElement layerElement = doc.createElement( QStringLiteral(
"field" ) );
122 layerElement.setAttribute( QStringLiteral(
"destinationLayer" ), layerId );
123 layerElement.setAttribute( QStringLiteral(
"field" ), it.value() );
124 timeStampElement.appendChild( layerElement );
126 element.appendChild( timeStampElement );
134 return mAutoAddTrackVertices;
139 return mAutoCommitFeatures;
144 return mDestinationFollowsActiveLayer;
149 return mDestinationLayer.
get();
154 return mDestinationTimestampFields;
161 return mDestinationTimestampFields.value( vl->id() );
168 if ( enabled == mAutoAddTrackVertices )
171 mAutoAddTrackVertices = enabled;
177 if ( enabled == mAutoCommitFeatures )
180 mAutoCommitFeatures = enabled;
186 if ( follow == mDestinationFollowsActiveLayer )
189 mDestinationFollowsActiveLayer = follow;
195 if ( layer == mDestinationLayer.
get() )
200 mDestinationLayer.
setLayer( layer );
218 if ( mDestinationTimestampFields.value( layer->
id() ) !=
field )
220 mDestinationTimestampFields.insert( layer->
id(),
field );
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
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,...
The class is used as a container of context for various read/write operations on other objects.
Represents a vector layer which manages a vector based data sets.
_LayerRef< QgsVectorLayer > QgsVectorLayerRef
TYPE * resolveWeakly(const QgsProject *project, MatchType matchType=MatchType::All)
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
QString source
Weak reference to layer public source.
QString name
Weak reference to layer name.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
QString provider
Weak reference to layer provider.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.