Skip to content

Commit

Permalink
Rename methods for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 6, 2022
1 parent 4b7668a commit 89c1952
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 63 deletions.
25 changes: 12 additions & 13 deletions python/core/auto_generated/project/qgsprojectgpssettings.sip.in
Expand Up @@ -24,7 +24,6 @@ with a GPS device.
public:



QgsProjectGpsSettings( QObject *parent = 0 );
%Docstring
Constructor for QgsProjectGpsSettings with the specified ``parent`` object.
Expand All @@ -51,14 +50,14 @@ Returns a DOM element representing the settings.
.. seealso:: :py:func:`readXml`
%End

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

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

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

bool automaticallyCommitFeatures() const;
Expand All @@ -74,14 +73,14 @@ layer edit buffer).

public slots:

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

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

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

void setAutomaticallyCommitFeatures( bool enabled );
Expand All @@ -97,14 +96,14 @@ layer edit buffer).

signals:

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

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

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

void automaticallyCommitFeaturesChanged( bool enabled );
Expand Down
2 changes: 1 addition & 1 deletion src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -499,7 +499,7 @@ void QgsAppGpsDigitizing::gpsStateChanged( const QgsGpsInformation &info )
mLastNmeaPosition = newNmeaPosition;
mLastElevation = newAlt;

if ( QgsProject::instance()->gpsSettings()->automaticallyAddTrackPoints() )
if ( QgsProject::instance()->gpsSettings()->automaticallyAddTrackVertices() )
{
addVertex();
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/gps/qgsappgpssettingsmenu.cpp
Expand Up @@ -180,13 +180,13 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )

addSeparator();

mAutoAddTrackPointAction = new QAction( tr( "Automatically Add Track Points" ), this );
mAutoAddTrackPointAction->setCheckable( true );
mAutoAddTrackPointAction->setChecked( QgsProject::instance()->gpsSettings()->automaticallyAddTrackPoints() );
connect( mAutoAddTrackPointAction, &QAction::toggled, QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::setAutomaticallyAddTrackPoints );
connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyAddTrackPointsChanged, mAutoAddTrackPointAction, &QAction::setChecked );
mAutoAddTrackVerticesAction = new QAction( tr( "Automatically Add Track Vertices" ), this );
mAutoAddTrackVerticesAction->setCheckable( true );
mAutoAddTrackVerticesAction->setChecked( QgsProject::instance()->gpsSettings()->automaticallyAddTrackVertices() );
connect( mAutoAddTrackVerticesAction, &QAction::toggled, QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::setAutomaticallyAddTrackVertices );
connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyAddTrackVerticesChanged, mAutoAddTrackVerticesAction, &QAction::setChecked );

addAction( mAutoAddTrackPointAction );
addAction( mAutoAddTrackVerticesAction );

mAutoSaveAddedFeatureAction = new QAction( tr( "Automatically Save Added Feature" ), this );
mAutoSaveAddedFeatureAction->setCheckable( true );
Expand Down
2 changes: 1 addition & 1 deletion src/app/gps/qgsappgpssettingsmenu.h
Expand Up @@ -80,7 +80,7 @@ class APP_EXPORT QgsAppGpsSettingsMenu : public QMenu
QAction *mShowLocationMarkerAction = nullptr;
QAction *mShowBearingLineAction = nullptr;
QAction *mRotateMapAction = nullptr;
QAction *mAutoAddTrackPointAction = nullptr;
QAction *mAutoAddTrackVerticesAction = nullptr;
QAction *mAutoSaveAddedFeatureAction = nullptr;
QAction *mActionNmeaLog = nullptr;

Expand Down
4 changes: 2 additions & 2 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -160,8 +160,8 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
connect( QgisApp::instance(), &QgisApp::activeLayerChanged,
this, &QgsGpsToolBar::updateCloseFeatureButton );

connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyAddTrackPointsChanged, this, [ = ]( bool enabled ) { setAddVertexButtonEnabled( !enabled ); } );
setAddVertexButtonEnabled( !QgsProject::instance()->gpsSettings()->automaticallyAddTrackPoints() );
connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyAddTrackVerticesChanged, this, [ = ]( bool enabled ) { setAddVertexButtonEnabled( !enabled ); } );
setAddVertexButtonEnabled( !QgsProject::instance()->gpsSettings()->automaticallyAddTrackVertices() );
}

void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled )
Expand Down
22 changes: 11 additions & 11 deletions src/core/project/qgsprojectgpssettings.cpp
Expand Up @@ -26,19 +26,19 @@ QgsProjectGpsSettings::~QgsProjectGpsSettings() = default;

void QgsProjectGpsSettings::reset()
{
mAutoAddTrackPoints = false;
mAutoAddTrackVertices = false;
mAutoCommitFeatures = false;

emit automaticallyAddTrackPointsChanged( false );
emit automaticallyAddTrackVerticesChanged( false );
emit automaticallyCommitFeaturesChanged( false );
}

bool QgsProjectGpsSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
{
mAutoAddTrackPoints = element.attribute( QStringLiteral( "autoAddTrackPoints" ), "0" ).toInt();
mAutoAddTrackVertices = element.attribute( QStringLiteral( "autoAddTrackVertices" ), "0" ).toInt();
mAutoCommitFeatures = element.attribute( QStringLiteral( "autoCommitFeatures" ), "0" ).toInt();

emit automaticallyAddTrackPointsChanged( mAutoAddTrackPoints );
emit automaticallyAddTrackVerticesChanged( mAutoAddTrackVertices );
emit automaticallyCommitFeaturesChanged( mAutoCommitFeatures );
return true;
}
Expand All @@ -47,29 +47,29 @@ QDomElement QgsProjectGpsSettings::writeXml( QDomDocument &doc, const QgsReadWri
{
QDomElement element = doc.createElement( QStringLiteral( "ProjectGpsSettings" ) );

element.setAttribute( QStringLiteral( "autoAddTrackPoints" ), mAutoAddTrackPoints ? 1 : 0 );
element.setAttribute( QStringLiteral( "autoAddTrackVertices" ), mAutoAddTrackVertices ? 1 : 0 );
element.setAttribute( QStringLiteral( "autoCommitFeatures" ), mAutoCommitFeatures ? 1 : 0 );

return element;
}

bool QgsProjectGpsSettings::automaticallyAddTrackPoints() const
bool QgsProjectGpsSettings::automaticallyAddTrackVertices() const
{
return mAutoAddTrackPoints;
return mAutoAddTrackVertices;
}

bool QgsProjectGpsSettings::automaticallyCommitFeatures() const
{
return mAutoCommitFeatures;
}

void QgsProjectGpsSettings::setAutomaticallyAddTrackPoints( bool enabled )
void QgsProjectGpsSettings::setAutomaticallyAddTrackVertices( bool enabled )
{
if ( enabled == mAutoAddTrackPoints )
if ( enabled == mAutoAddTrackVertices )
return;

mAutoAddTrackPoints = enabled;
emit automaticallyAddTrackPointsChanged( enabled );
mAutoAddTrackVertices = enabled;
emit automaticallyAddTrackVerticesChanged( enabled );
}

void QgsProjectGpsSettings::setAutomaticallyCommitFeatures( bool enabled )
Expand Down
31 changes: 15 additions & 16 deletions src/core/project/qgsprojectgpssettings.h
Expand Up @@ -38,8 +38,8 @@ class CORE_EXPORT QgsProjectGpsSettings : public QObject

public:

Q_PROPERTY( bool automaticallyAddTrackPoints READ automaticallyAddTrackPoints WRITE setAutomaticallyAddTrackPoints NOTIFY automaticallyAddTrackPointsChanged )

Q_PROPERTY( bool automaticallyAddTrackVertices READ automaticallyAddTrackVertices WRITE setAutomaticallyAddTrackVertices NOTIFY automaticallyAddTrackVerticesChanged )
Q_PROPERTY( bool automaticallyCommitFeatures READ automaticallyCommitFeatures WRITE setAutomaticallyCommitFeatures NOTIFY automaticallyCommitFeaturesChanged )

/**
* Constructor for QgsProjectGpsSettings with the specified \a parent object.
Expand All @@ -66,13 +66,13 @@ class CORE_EXPORT QgsProjectGpsSettings : public QObject
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;

/**
* Returns TRUE if track points should be automatically created whenever
* Returns TRUE if track vertices should be automatically created whenever
* new locations are received from the GPS device.
*
* \see setAutomaticallyAddTrackPoints()
* \see automaticallyAddTrackPointsChanged()
* \see setAutomaticallyAddTrackVertices()
* \see automaticallyAddTrackVerticesChanged()
*/
bool automaticallyAddTrackPoints() const;
bool automaticallyAddTrackVertices() const;

/**
* Returns TRUE if features created from GPS locations should be
Expand All @@ -87,13 +87,13 @@ class CORE_EXPORT QgsProjectGpsSettings : public QObject
public slots:

/**
* Sets whether track points should be automatically created whenever
* Sets whether track vertices should be automatically created whenever
* new locations are received from the GPS device.
*
* \see automaticallyAddTrackPoints()
* \see automaticallyAddTrackPointsChanged()
* \see automaticallyAddTrackVertices()
* \see automaticallyAddTrackVerticesChanged()
*/
void setAutomaticallyAddTrackPoints( bool enabled );
void setAutomaticallyAddTrackVertices( bool enabled );

/**
* Sets whether features created from GPS locations should be
Expand All @@ -108,13 +108,13 @@ class CORE_EXPORT QgsProjectGpsSettings : public QObject
signals:

/**
* Emitted whenever the automaticallyAddTrackPoints() setting
* Emitted whenever the automaticallyAddTrackVertices() setting
* is changed.
*
* \see automaticallyAddTrackPoints()
* \see setAutomaticallyAddTrackPoints()
* \see automaticallyAddTrackVertices()
* \see setAutomaticallyAddTrackVertices()
*/
void automaticallyAddTrackPointsChanged( bool enabled );
void automaticallyAddTrackVerticesChanged( bool enabled );

/**
* Emitted whenever the automaticallyCommitFeatures() setting
Expand All @@ -127,10 +127,9 @@ class CORE_EXPORT QgsProjectGpsSettings : public QObject

private:

bool mAutoAddTrackPoints = false;
bool mAutoAddTrackVertices = false;
bool mAutoCommitFeatures = false;


};

#endif // QGSPROJECTGPSSETTINGS_H
26 changes: 13 additions & 13 deletions tests/src/python/test_qgsprojectgpssettings.py
Expand Up @@ -48,20 +48,20 @@ def setUpClass(cls):
def testSettings(self):
p = QgsProjectGpsSettings()
self.assertFalse(p.automaticallyCommitFeatures())
self.assertFalse(p.automaticallyAddTrackPoints())
self.assertFalse(p.automaticallyAddTrackVertices())

spy_add_track = QSignalSpy(p.automaticallyAddTrackPointsChanged)
spy_add_track = QSignalSpy(p.automaticallyAddTrackVerticesChanged)
spy_auto_commit = QSignalSpy(p.automaticallyCommitFeaturesChanged)

p.setAutomaticallyAddTrackPoints(True)
p.setAutomaticallyAddTrackVertices(True)
self.assertEqual(len(spy_add_track), 1)
self.assertTrue(spy_add_track[-1][0])

p.setAutomaticallyAddTrackPoints(True)
p.setAutomaticallyAddTrackVertices(True)
self.assertEqual(len(spy_add_track), 1)

self.assertTrue(p.automaticallyAddTrackPoints())
p.setAutomaticallyAddTrackPoints(False)
self.assertTrue(p.automaticallyAddTrackVertices())
p.setAutomaticallyAddTrackVertices(False)
self.assertEqual(len(spy_add_track), 2)
self.assertFalse(spy_add_track[-1][0])

Expand All @@ -83,15 +83,15 @@ def testReset(self):
"""
p = QgsProjectGpsSettings()
self.assertFalse(p.automaticallyCommitFeatures())
self.assertFalse(p.automaticallyAddTrackPoints())
self.assertFalse(p.automaticallyAddTrackVertices())

p.setAutomaticallyCommitFeatures(True)
p.setAutomaticallyAddTrackPoints(True)
spy_add_track = QSignalSpy(p.automaticallyAddTrackPointsChanged)
p.setAutomaticallyAddTrackVertices(True)
spy_add_track = QSignalSpy(p.automaticallyAddTrackVerticesChanged)
spy_auto_commit = QSignalSpy(p.automaticallyCommitFeaturesChanged)

p.reset()
self.assertFalse(p.automaticallyAddTrackPoints())
self.assertFalse(p.automaticallyAddTrackVertices())
self.assertFalse(p.automaticallyCommitFeatures())

self.assertEqual(len(spy_add_track), 1)
Expand All @@ -103,19 +103,19 @@ def testReadWrite(self):
p = QgsProjectGpsSettings()

p.setAutomaticallyCommitFeatures(True)
p.setAutomaticallyAddTrackPoints(True)
p.setAutomaticallyAddTrackVertices(True)

doc = QDomDocument("testdoc")
elem = p.writeXml(doc, QgsReadWriteContext())

p2 = QgsProjectGpsSettings()
spy = QSignalSpy(p2.automaticallyAddTrackPointsChanged)
spy = QSignalSpy(p2.automaticallyAddTrackVerticesChanged)
spy2 = QSignalSpy(p2.automaticallyCommitFeaturesChanged)
self.assertTrue(p2.readXml(elem, QgsReadWriteContext()))
self.assertEqual(len(spy), 1)
self.assertEqual(len(spy2), 1)
self.assertTrue(p.automaticallyCommitFeatures())
self.assertTrue(p.automaticallyAddTrackPoints())
self.assertTrue(p.automaticallyAddTrackVertices())


if __name__ == '__main__':
Expand Down

0 comments on commit 89c1952

Please sign in to comment.