Skip to content

Commit

Permalink
Create new QgsProjectGpsSettings class
Browse files Browse the repository at this point in the history
Destinated for a storage location for GPS settings which are
project specific
  • Loading branch information
nyalldawson committed Nov 6, 2022
1 parent a75d250 commit 816eb16
Show file tree
Hide file tree
Showing 10 changed files with 568 additions and 27 deletions.
11 changes: 10 additions & 1 deletion python/core/auto_generated/project/qgsproject.sip.in
Expand Up @@ -821,12 +821,21 @@ Returns the project's elevation properties, which contains the project's elevati

QgsProjectDisplaySettings *displaySettings();
%Docstring
Returns the project's display settings, which settings and properties relating
Returns the project's display settings, which contains settings and properties relating
to how a QgsProject should display values such as map coordinates and bearings.

.. versionadded:: 3.12
%End


QgsProjectGpsSettings *gpsSettings();
%Docstring
Returns the project's GPS settings, which contains settings and properties relating
to how a QgsProject should interact with a GPS device.

.. versionadded:: 3.30
%End

QgsLayerTree *layerTreeRoot() const;
%Docstring
Returns pointer to the root (invisible) node of the project's layer tree
Expand Down
128 changes: 128 additions & 0 deletions python/core/auto_generated/project/qgsprojectgpssettings.sip.in
@@ -0,0 +1,128 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/project/qgsprojectgpssettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsProjectGpsSettings : QObject
{
%Docstring(signature="appended")
Contains settings and properties relating to how a :py:class:`QgsProject` should interact
with a GPS device.

.. versionadded:: 3.30
%End

%TypeHeaderCode
#include "qgsprojectgpssettings.h"
%End
public:



QgsProjectGpsSettings( QObject *parent = 0 );
%Docstring
Constructor for QgsProjectGpsSettings with the specified ``parent`` object.
%End

~QgsProjectGpsSettings();

void reset();
%Docstring
Resets the settings to a default state.
%End

bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
%Docstring
Reads the settings's state from a DOM element.

.. seealso:: :py:func:`writeXml`
%End

QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
%Docstring
Returns a DOM element representing the settings.

.. seealso:: :py:func:`readXml`
%End

bool automaticallyAddTrackPoints() const;
%Docstring
Returns ``True`` if track points should be automatically created whenever
new locations are received from the GPS device.

.. seealso:: :py:func:`setAutomaticallyAddTrackPoints`

.. seealso:: :py:func:`automaticallyAddTrackPointsChanged`
%End

bool automaticallyCommitFeatures() const;
%Docstring
Returns ``True`` if features created from GPS locations should be
immediately commited to their target layers (skipping the usual
layer edit buffer).

.. seealso:: :py:func:`setAutomaticallyCommitFeatures`

.. seealso:: :py:func:`automaticallyCommitFeaturesChanged`
%End

public slots:

void setAutomaticallyAddTrackPoints( bool enabled );
%Docstring
Sets whether track points should be automatically created whenever
new locations are received from the GPS device.

.. seealso:: :py:func:`automaticallyAddTrackPoints`

.. seealso:: :py:func:`automaticallyAddTrackPointsChanged`
%End

void setAutomaticallyCommitFeatures( bool enabled );
%Docstring
Sets whether features created from GPS locations should be
immediately commited to their target layers (skipping the usual
layer edit buffer).

.. seealso:: :py:func:`automaticallyCommitFeatures`

.. seealso:: :py:func:`automaticallyCommitFeaturesChanged`
%End

signals:

void automaticallyAddTrackPointsChanged( bool enabled );
%Docstring
Emitted whenever the :py:func:`~QgsProjectGpsSettings.automaticallyAddTrackPoints` setting
is changed.

.. seealso:: :py:func:`automaticallyAddTrackPoints`

.. seealso:: :py:func:`setAutomaticallyAddTrackPoints`
%End

void automaticallyCommitFeaturesChanged( bool enabled );
%Docstring
Emitted whenever the :py:func:`~QgsProjectGpsSettings.automaticallyCommitFeatures` setting
is changed.

.. seealso:: :py:func:`automaticallyCommitFeatures`

.. seealso:: :py:func:`setAutomaticallyCommitFeatures`
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/project/qgsprojectgpssettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -554,6 +554,7 @@
%Include auto_generated/project/qgsprojectdisplaysettings.sip
%Include auto_generated/project/qgsprojectelevationproperties.sip
%Include auto_generated/project/qgsprojectfiletransform.sip
%Include auto_generated/project/qgsprojectgpssettings.sip
%Include auto_generated/project/qgsprojectproperty.sip
%Include auto_generated/project/qgsprojectservervalidator.sip
%Include auto_generated/project/qgsprojectstorage.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -660,6 +660,7 @@ set(QGIS_CORE_SRCS
project/qgsprojectelevationproperties.cpp
project/qgsprojectfiletransform.cpp
project/qgsprojectdisplaysettings.cpp
project/qgsprojectgpssettings.cpp
project/qgsprojectproperty.cpp
project/qgsprojectservervalidator.cpp
project/qgsprojectstorage.cpp
Expand Down Expand Up @@ -1666,6 +1667,7 @@ set(QGIS_CORE_HDRS
project/qgsprojectdisplaysettings.h
project/qgsprojectelevationproperties.h
project/qgsprojectfiletransform.h
project/qgsprojectgpssettings.h
project/qgsprojectproperty.h
project/qgsprojectservervalidator.h
project/qgsprojectstorage.h
Expand Down
90 changes: 66 additions & 24 deletions src/core/project/qgsproject.cpp
Expand Up @@ -35,10 +35,8 @@
#include "qgsprojectversion.h"
#include "qgsrasterlayer.h"
#include "qgsreadwritecontext.h"
#include "qgsrectangle.h"
#include "qgsrelationmanager.h"
#include "qgsannotationmanager.h"
#include "qgsvectorlayerjoininfo.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsmapthemecollection.h"
#include "qgslayerdefinition.h"
Expand All @@ -47,7 +45,6 @@
#include "qgstransactiongroup.h"
#include "qgsvectordataprovider.h"
#include "qgsprojectbadlayerhandler.h"
#include "qgsmaplayerlistutils_p.h"
#include "qgsmeshlayer.h"
#include "qgslayoutmanager.h"
#include "qgsbookmarkmanager.h"
Expand All @@ -70,6 +67,7 @@
#include "qgsmapviewsmanager.h"
#include "qgsprojectelevationproperties.h"
#include "qgscombinedstylemodel.h"
#include "qgsprojectgpssettings.h"

#include <algorithm>
#include <QApplication>
Expand Down Expand Up @@ -381,6 +379,7 @@ QgsProject::QgsProject( QObject *parent, Qgis::ProjectCapabilities capabilities
, mTimeSettings( new QgsProjectTimeSettings( this ) )
, mElevationProperties( new QgsProjectElevationProperties( this ) )
, mDisplaySettings( new QgsProjectDisplaySettings( this ) )
, mGpsSettings( new QgsProjectGpsSettings( this ) )
, mRootGroup( new QgsLayerTree )
, mLabelingEngineSettings( new QgsLabelingEngineSettings )
, mArchive( new QgsArchive() )
Expand Down Expand Up @@ -974,6 +973,7 @@ void QgsProject::clear()
mTimeSettings->reset();
mElevationProperties->reset();
mDisplaySettings->reset();
mGpsSettings->reset();
mSnappingConfig.reset();
mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
emit avoidIntersectionsModeChanged();
Expand Down Expand Up @@ -2009,9 +2009,18 @@ bool QgsProject::readProjectFile( const QString &filename, Qgis::ProjectReadFlag
mElevationProperties->resolveReferences( this );

profile.switchTask( tr( "Loading display settings" ) );
const QDomElement displaySettingsElement = doc->documentElement().firstChildElement( QStringLiteral( "ProjectDisplaySettings" ) );
if ( !displaySettingsElement.isNull() )
mDisplaySettings->readXml( displaySettingsElement, context );
{
const QDomElement displaySettingsElement = doc->documentElement().firstChildElement( QStringLiteral( "ProjectDisplaySettings" ) );
if ( !displaySettingsElement.isNull() )
mDisplaySettings->readXml( displaySettingsElement, context );
}

profile.switchTask( tr( "Loading GPS settings" ) );
{
const QDomElement gpsSettingsElement = doc->documentElement().firstChildElement( QStringLiteral( "ProjectGpsSettings" ) );
if ( !gpsSettingsElement.isNull() )
mGpsSettings->readXml( gpsSettingsElement, context );
}

profile.switchTask( tr( "Updating variables" ) );
emit customVariablesChanged();
Expand Down Expand Up @@ -2745,32 +2754,55 @@ bool QgsProject::writeProjectFile( const QString &filename )
mMetadata.writeMetadataXml( metadataElem, *doc );
qgisNode.appendChild( metadataElem );

const QDomElement annotationsElem = mAnnotationManager->writeXml( *doc, context );
qgisNode.appendChild( annotationsElem );
{
const QDomElement annotationsElem = mAnnotationManager->writeXml( *doc, context );
qgisNode.appendChild( annotationsElem );
}

{
const QDomElement layoutElem = mLayoutManager->writeXml( *doc );
qgisNode.appendChild( layoutElem );
}

const QDomElement layoutElem = mLayoutManager->writeXml( *doc );
qgisNode.appendChild( layoutElem );
{
const QDomElement views3DElem = m3DViewsManager->writeXml( *doc );
qgisNode.appendChild( views3DElem );
}

const QDomElement views3DElem = m3DViewsManager->writeXml( *doc );
qgisNode.appendChild( views3DElem );
{
const QDomElement bookmarkElem = mBookmarkManager->writeXml( *doc );
qgisNode.appendChild( bookmarkElem );
}

const QDomElement bookmarkElem = mBookmarkManager->writeXml( *doc );
qgisNode.appendChild( bookmarkElem );
{
const QDomElement viewSettingsElem = mViewSettings->writeXml( *doc, context );
qgisNode.appendChild( viewSettingsElem );
}

const QDomElement viewSettingsElem = mViewSettings->writeXml( *doc, context );
qgisNode.appendChild( viewSettingsElem );
{
const QDomElement styleSettingsElem = mStyleSettings->writeXml( *doc, context );
qgisNode.appendChild( styleSettingsElem );
}

const QDomElement styleSettingsElem = mStyleSettings->writeXml( *doc, context );
qgisNode.appendChild( styleSettingsElem );
{
const QDomElement timeSettingsElement = mTimeSettings->writeXml( *doc, context );
qgisNode.appendChild( timeSettingsElement );
}

const QDomElement timeSettingsElement = mTimeSettings->writeXml( *doc, context );
qgisNode.appendChild( timeSettingsElement );
{
const QDomElement elevationPropertiesElement = mElevationProperties->writeXml( *doc, context );
qgisNode.appendChild( elevationPropertiesElement );
}

const QDomElement elevationPropertiesElement = mElevationProperties->writeXml( *doc, context );
qgisNode.appendChild( elevationPropertiesElement );
{
const QDomElement displaySettingsElem = mDisplaySettings->writeXml( *doc, context );
qgisNode.appendChild( displaySettingsElem );
}

const QDomElement displaySettingsElem = mDisplaySettings->writeXml( *doc, context );
qgisNode.appendChild( displaySettingsElem );
{
const QDomElement gpsSettingsElem = mGpsSettings->writeXml( *doc, context );
qgisNode.appendChild( gpsSettingsElem );
}

// now wrap it up and ship it to the project file
doc->normalize(); // XXX I'm not entirely sure what this does
Expand Down Expand Up @@ -3518,6 +3550,16 @@ QgsProjectDisplaySettings *QgsProject::displaySettings()
return mDisplaySettings;
}

const QgsProjectGpsSettings *QgsProject::gpsSettings() const
{
return mGpsSettings;
}

QgsProjectGpsSettings *QgsProject::gpsSettings()
{
return mGpsSettings;
}

QgsLayerTree *QgsProject::layerTreeRoot() const
{
return mRootGroup;
Expand Down
22 changes: 20 additions & 2 deletions src/core/project/qgsproject.h
Expand Up @@ -86,6 +86,7 @@ class QgsAttributeEditorContainer;
class QgsPropertyCollection;
class QgsMapViewsManager;
class QgsProjectElevationProperties;
class QgsProjectGpsSettings;

/**
* \ingroup core
Expand Down Expand Up @@ -862,20 +863,35 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
QgsProjectElevationProperties *elevationProperties();

/**
* Returns the project's display settings, which settings and properties relating
* Returns the project's display settings, which contains settings and properties relating
* to how a QgsProject should display values such as map coordinates and bearings.
* \note not available in Python bindings
* \since QGIS 3.12
*/
const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;

/**
* Returns the project's display settings, which settings and properties relating
* Returns the project's display settings, which contains settings and properties relating
* to how a QgsProject should display values such as map coordinates and bearings.
* \since QGIS 3.12
*/
QgsProjectDisplaySettings *displaySettings();

/**
* Returns the project's GPS settings, which contains settings and properties relating
* to how a QgsProject should interact with a GPS device.
* \note not available in Python bindings
* \since QGIS 3.30
*/
const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;

/**
* Returns the project's GPS settings, which contains settings and properties relating
* to how a QgsProject should interact with a GPS device.
* \since QGIS 3.30
*/
QgsProjectGpsSettings *gpsSettings();

/**
* Returns pointer to the root (invisible) node of the project's layer tree
* \since QGIS 2.4
Expand Down Expand Up @@ -2248,6 +2264,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera

QgsProjectDisplaySettings *mDisplaySettings = nullptr;

QgsProjectGpsSettings *mGpsSettings = nullptr;

QgsLayerTree *mRootGroup = nullptr;

QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
Expand Down

0 comments on commit 816eb16

Please sign in to comment.