20#include "moc_qgsprojectgpssettings.cpp"
22using namespace Qt::StringLiterals;
32 mDestinationLayer.resolveWeakly( project );
36 if ( mDestinationLayer )
46 mAutoAddTrackVertices =
false;
47 mAutoCommitFeatures =
false;
48 mDestinationFollowsActiveLayer =
true;
50 mDestinationLayer.setLayer(
nullptr );
51 mDestinationTimestampFields.clear();
62 mAutoAddTrackVertices = element.attribute( u
"autoAddTrackVertices"_s,
"0" ).toInt();
63 mAutoCommitFeatures = element.attribute( u
"autoCommitFeatures"_s,
"0" ).toInt();
64 mDestinationFollowsActiveLayer = element.attribute( u
"destinationFollowsActiveLayer"_s,
"1" ).toInt();
66 const QString layerId = element.attribute( u
"destinationLayer"_s );
67 const QString layerName = element.attribute( u
"destinationLayerName"_s );
68 const QString layerSource = element.attribute( u
"destinationLayerSource"_s );
69 const QString layerProvider = element.attribute( u
"destinationLayerProvider"_s );
71 mDestinationLayer =
QgsVectorLayerRef( layerId, layerName, layerSource, layerProvider );
73 mDestinationTimestampFields.clear();
75 const QDomElement timeStampElement = element.firstChildElement( u
"timeStampFields"_s );
76 QDomElement layerElement = timeStampElement.firstChildElement();
77 while ( !layerElement.isNull() )
79 const QString layerId = layerElement.attribute( u
"destinationLayer"_s );
80 const QString field = layerElement.attribute( u
"field"_s );
81 mDestinationTimestampFields[ layerId ] = field;
82 layerElement = layerElement.nextSiblingElement();
96 QDomElement element = doc.createElement( u
"ProjectGpsSettings"_s );
98 element.setAttribute( u
"autoAddTrackVertices"_s, mAutoAddTrackVertices ? 1 : 0 );
99 element.setAttribute( u
"autoCommitFeatures"_s, mAutoCommitFeatures ? 1 : 0 );
100 element.setAttribute( u
"destinationFollowsActiveLayer"_s, mDestinationFollowsActiveLayer ? 1 : 0 );
102 if ( mDestinationLayer )
104 element.setAttribute( u
"destinationLayer"_s, mDestinationLayer.layerId );
105 element.setAttribute( u
"destinationLayerName"_s, mDestinationLayer.name );
106 element.setAttribute( u
"destinationLayerSource"_s, mDestinationLayer.source );
107 element.setAttribute( u
"destinationLayerProvider"_s, mDestinationLayer.provider );
111 element.setAttribute( u
"destinationLayer"_s, QString() );
115 QDomElement timeStampElement = doc.createElement( u
"timeStampFields"_s );
116 for (
auto it = mDestinationTimestampFields.constBegin(); it != mDestinationTimestampFields.constEnd(); ++it )
118 const QString layerId = it.key();
119 if (
QgsProject *project = qobject_cast< QgsProject * >( parent() ) )
122 if ( !project->mapLayer( layerId ) )
126 QDomElement layerElement = doc.createElement( u
"field"_s );
127 layerElement.setAttribute( u
"destinationLayer"_s, layerId );
128 layerElement.setAttribute( u
"field"_s, it.value() );
129 timeStampElement.appendChild( layerElement );
131 element.appendChild( timeStampElement );
139 return mAutoAddTrackVertices;
144 return mAutoCommitFeatures;
149 return mDestinationFollowsActiveLayer;
154 return mDestinationLayer.get();
159 return mDestinationTimestampFields;
166 return mDestinationTimestampFields.value( vl->id() );
173 if ( enabled == mAutoAddTrackVertices )
176 mAutoAddTrackVertices = enabled;
182 if ( enabled == mAutoCommitFeatures )
185 mAutoCommitFeatures = enabled;
191 if ( follow == mDestinationFollowsActiveLayer )
194 mDestinationFollowsActiveLayer = follow;
200 if ( layer == mDestinationLayer.get() )
205 mDestinationLayer.setLayer( layer );
223 if ( mDestinationTimestampFields.value( layer->
id() ) != field )
225 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