Skip to content

Commit

Permalink
Add signal for when project preset full extent is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 23, 2020
1 parent 483cb8d commit 13e8d45
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 8 deletions.
Expand Up @@ -77,8 +77,8 @@ Constructor for QgsReferencedRectangle.

operator QVariant() const;

bool operator==( const QgsReferencedRectangle &other );
bool operator!=( const QgsReferencedRectangle &other );
bool operator==( const QgsReferencedRectangle &other ) const;
bool operator!=( const QgsReferencedRectangle &other ) const;

SIP_PYOBJECT __repr__();
%MethodCode
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsprojectviewsettings.sip.in
Expand Up @@ -180,6 +180,13 @@ Emitted when the list of custom project map scales changes.
.. seealso:: :py:func:`mapScales`

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

void presetFullExtentChanged();
%Docstring
Emitted whenever the :py:func:`~QgsProjectViewSettings.presetFullExtent` is changed.

.. versionadded:: 3.18
%End

};
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsreferencedgeometry.cpp
Expand Up @@ -26,12 +26,12 @@ QgsReferencedRectangle::QgsReferencedRectangle( const QgsRectangle &rect, const
, QgsReferencedGeometryBase( crs )
{}

bool QgsReferencedRectangle::operator==( const QgsReferencedRectangle &other )
bool QgsReferencedRectangle::operator==( const QgsReferencedRectangle &other ) const
{
return QgsRectangle::operator==( other ) && crs() == other.crs();
}

bool QgsReferencedRectangle::operator!=( const QgsReferencedRectangle &other )
bool QgsReferencedRectangle::operator!=( const QgsReferencedRectangle &other ) const
{
return !( *this == other );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsreferencedgeometry.h
Expand Up @@ -91,8 +91,8 @@ class CORE_EXPORT QgsReferencedRectangle : public QgsRectangle, public QgsRefere
return QVariant::fromValue( *this );
}

bool operator==( const QgsReferencedRectangle &other );
bool operator!=( const QgsReferencedRectangle &other );
bool operator==( const QgsReferencedRectangle &other ) const;
bool operator!=( const QgsReferencedRectangle &other ) const;

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
Expand Down
13 changes: 11 additions & 2 deletions src/core/qgsprojectviewsettings.cpp
Expand Up @@ -29,7 +29,12 @@ QgsProjectViewSettings::QgsProjectViewSettings( QgsProject *project )
void QgsProjectViewSettings::reset()
{
mDefaultViewExtent = QgsReferencedRectangle();

const bool fullExtentChanged = !mPresetFullExtent.isNull();
mPresetFullExtent = QgsReferencedRectangle();
if ( fullExtentChanged )
emit presetFullExtentChanged();

if ( mUseProjectScales || !mMapScales.empty() )
{
mUseProjectScales = false;
Expand All @@ -55,7 +60,11 @@ QgsReferencedRectangle QgsProjectViewSettings::presetFullExtent() const

void QgsProjectViewSettings::setPresetFullExtent( const QgsReferencedRectangle &extent )
{
if ( extent == mPresetFullExtent )
return;

mPresetFullExtent = extent;
emit presetFullExtentChanged();
}

QgsReferencedRectangle QgsProjectViewSettings::fullExtent() const
Expand Down Expand Up @@ -208,11 +217,11 @@ bool QgsProjectViewSettings::readXml( const QDomElement &element, const QgsReadW
double yMax = presetViewElement.attribute( QStringLiteral( "ymax" ) ).toDouble();
QgsCoordinateReferenceSystem crs;
crs.readXml( presetViewElement );
mPresetFullExtent = QgsReferencedRectangle( QgsRectangle( xMin, yMin, xMax, yMax ), crs );
setPresetFullExtent( QgsReferencedRectangle( QgsRectangle( xMin, yMin, xMax, yMax ), crs ) );
}
else
{
mPresetFullExtent = QgsReferencedRectangle();
setPresetFullExtent( QgsReferencedRectangle() );
}

return true;
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsprojectviewsettings.h
Expand Up @@ -184,6 +184,13 @@ class CORE_EXPORT QgsProjectViewSettings : public QObject
*/
void mapScalesChanged();

/**
* Emitted whenever the presetFullExtent() is changed.
*
* \since QGIS 3.18
*/
void presetFullExtentChanged();

private:

QgsProject *mProject = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmapoverviewcanvas.cpp
Expand Up @@ -48,6 +48,8 @@ QgsMapOverviewCanvas::QgsMapOverviewCanvas( QWidget *parent, QgsMapCanvas *mapCa
connect( mMapCanvas, &QgsMapCanvas::extentsChanged, this, &QgsMapOverviewCanvas::drawExtentRect );
connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsMapOverviewCanvas::destinationCrsChanged );
connect( mMapCanvas, &QgsMapCanvas::transformContextChanged, this, &QgsMapOverviewCanvas::transformContextChanged );

connect( QgsProject::instance()->viewSettings(), &QgsProjectViewSettings::presetFullExtentChanged, this, &QgsMapOverviewCanvas::updateFullExtent );
}

void QgsMapOverviewCanvas::resizeEvent( QResizeEvent *e )
Expand Down
19 changes: 19 additions & 0 deletions tests/src/python/test_qgsprojectviewsettings.py
Expand Up @@ -141,6 +141,25 @@ def testPresetFullExtent(self):
p.reset()
self.assertTrue(p.presetFullExtent().isNull())

def testPresetFullExtentChangedSignal(self):
p = QgsProjectViewSettings()
spy = QSignalSpy(p.presetFullExtentChanged)

p.setPresetFullExtent(QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4), QgsCoordinateReferenceSystem("EPSG:3857")))
self.assertEqual(len(spy), 1)

p.setPresetFullExtent(QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4), QgsCoordinateReferenceSystem("EPSG:3857")))
self.assertEqual(len(spy), 1)

p.setPresetFullExtent(QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4), QgsCoordinateReferenceSystem("EPSG:4326")))
self.assertEqual(len(spy), 2)

p.reset()
self.assertEqual(len(spy), 3)

p.reset()
self.assertEqual(len(spy), 3)

def testFullExtent(self):
p = QgsProject()
p.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
Expand Down

0 comments on commit 13e8d45

Please sign in to comment.