Skip to content

Commit

Permalink
added tests for changed signal in temporal properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Mar 10, 2020
1 parent 2aaac59 commit 9845ffa
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 19 deletions.
Expand Up @@ -27,7 +27,7 @@ how an individual QgsMapLayer behaves in a temporal context, e.g. while animatin
%End
public:

QgsMapLayerTemporalProperties( bool enabled = false );
QgsMapLayerTemporalProperties( QObject *parent, bool enabled = false );
%Docstring
Constructor for QgsMapLayerTemporalProperties.

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgstemporalproperty.sip.in
Expand Up @@ -25,7 +25,7 @@ Base class for temporal property.
%End
public:

QgsTemporalProperty( bool enabled = false );
QgsTemporalProperty( QObject *parent = 0, bool enabled = false );
%Docstring
Constructor for QgsTemporalProperty.

Expand Down
Expand Up @@ -23,7 +23,7 @@ Implementation of map layer temporal properties for raster layers.
%End
public:

QgsRasterLayerTemporalProperties( bool enabled = false );
QgsRasterLayerTemporalProperties( QObject *parent = 0, bool enabled = false );
%Docstring
Constructor for QgsRasterLayerTemporalProperties.

Expand Down
3 changes: 1 addition & 2 deletions src/app/qgslayertreeviewtemporalindicator.cpp
Expand Up @@ -32,9 +32,8 @@ void QgsLayerTreeViewTemporalIndicatorProvider::connectSignals( QgsMapLayer *lay
{
if ( !( qobject_cast<QgsVectorLayer *>( layer ) || qobject_cast<QgsRasterLayer *>( layer ) ) )
return;
QgsMapLayer *mapLayer = layer;
connect( mapLayer->temporalProperties(), &QgsMapLayerTemporalProperties::changed, this, [ this, mapLayer ]( ) { this->onLayerChanged( mapLayer ); } );

connect( layer->temporalProperties(), &QgsMapLayerTemporalProperties::changed, this, [ this, layer ]( ) { this->onLayerChanged( layer ); } );
}

void QgsLayerTreeViewTemporalIndicatorProvider::onIndicatorClicked( const QModelIndex &index )
Expand Down
11 changes: 7 additions & 4 deletions src/core/qgsmaplayertemporalproperties.cpp
Expand Up @@ -17,8 +17,8 @@

#include "qgsmaplayertemporalproperties.h"

QgsMapLayerTemporalProperties::QgsMapLayerTemporalProperties( bool enabled )
: QgsTemporalProperty( enabled )
QgsMapLayerTemporalProperties::QgsMapLayerTemporalProperties( QObject *parent, bool enabled )
: QgsTemporalProperty( parent, enabled )
{
}

Expand All @@ -28,8 +28,11 @@ QgsMapLayerTemporalProperties::~QgsMapLayerTemporalProperties()

void QgsMapLayerTemporalProperties::setTemporalSource( QgsMapLayerTemporalProperties::TemporalSource source )
{
mSource = source;
emit changed();
if ( mSource != source )
{
mSource = source;
emit changed();
}
}

QgsMapLayerTemporalProperties::TemporalSource QgsMapLayerTemporalProperties::temporalSource() const
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaplayertemporalproperties.h
Expand Up @@ -38,6 +38,7 @@
*/
class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
{
Q_OBJECT

public:

Expand All @@ -46,7 +47,7 @@ class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
*
* The \a enabled argument specifies whether the temporal properties are initially enabled or not (see isActive()).
*/
QgsMapLayerTemporalProperties( bool enabled = false );
QgsMapLayerTemporalProperties( QObject *parent, bool enabled = false );

~QgsMapLayerTemporalProperties() override;

Expand Down
5 changes: 3 additions & 2 deletions src/core/qgstemporalproperty.cpp
Expand Up @@ -18,8 +18,9 @@

#include "qgstemporalproperty.h"

QgsTemporalProperty::QgsTemporalProperty( bool enabled )
: mActive( enabled )
QgsTemporalProperty::QgsTemporalProperty( QObject *parent, bool enabled )
: QObject( parent )
, mActive( enabled )
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgstemporalproperty.h
Expand Up @@ -43,7 +43,7 @@ class CORE_EXPORT QgsTemporalProperty : public QObject
*
* The \a active argument specifies whether the property is initially active (see isActive()).
*/
QgsTemporalProperty( bool enabled = false );
QgsTemporalProperty( QObject *parent = nullptr, bool enabled = false );

/**
* Sets whether the temporal property is \a active.
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -577,7 +577,7 @@ void QgsRasterLayer::init()
mLastViewPort.mWidth = 0;
mLastViewPort.mHeight = 0;

mTemporalProperties = qgis::make_unique<QgsRasterLayerTemporalProperties>();
mTemporalProperties = new QgsRasterLayerTemporalProperties( this );
}

void QgsRasterLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options )
Expand Down Expand Up @@ -955,7 +955,7 @@ bool QgsRasterLayer::ignoreExtents() const

QgsRasterLayerTemporalProperties *QgsRasterLayer::temporalProperties()
{
return mTemporalProperties.get();
return mTemporalProperties;
}

void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, QgsRasterMinMaxOrigin::Limits limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag )
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterlayer.h
Expand Up @@ -520,7 +520,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
QgsRasterDataProvider *mDataProvider = nullptr;

//! Pointer to temporal properties
std::unique_ptr< QgsRasterLayerTemporalProperties > mTemporalProperties;
QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;

//! [ data provider interface ] Timestamp, the last modified time of the data source when the layer was created
QDateTime mLastModified;
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterlayertemporalproperties.cpp
Expand Up @@ -17,8 +17,8 @@

#include "qgsrasterlayertemporalproperties.h"

QgsRasterLayerTemporalProperties::QgsRasterLayerTemporalProperties( bool enabled )
: QgsMapLayerTemporalProperties( enabled )
QgsRasterLayerTemporalProperties::QgsRasterLayerTemporalProperties( QObject *parent, bool enabled )
: QgsMapLayerTemporalProperties( parent, enabled )
{
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/raster/qgsrasterlayertemporalproperties.h
Expand Up @@ -33,14 +33,16 @@
*/
class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalProperties
{
Q_OBJECT

public:

/**
* Constructor for QgsRasterLayerTemporalProperties.
*
* The \a enabled argument specifies whether the temporal properties are initially enabled or not (see isActive()).
*/
QgsRasterLayerTemporalProperties( bool enabled = false );
QgsRasterLayerTemporalProperties( QObject *parent = nullptr, bool enabled = false );

virtual ~QgsRasterLayerTemporalProperties() = default;

Expand Down
15 changes: 15 additions & 0 deletions tests/src/core/testqgsrasterlayertemporalproperties.cpp
Expand Up @@ -39,6 +39,7 @@ class TestQgsRasterLayerTemporalProperties : public QObject
void cleanup(); // will be called after every testfunction.

void checkSettingTemporalRange();
void testChangedSignal();

private:
QgsRasterLayerTemporalProperties *temporalProperties = nullptr;
Expand Down Expand Up @@ -82,5 +83,19 @@ void TestQgsRasterLayerTemporalProperties::checkSettingTemporalRange()
QCOMPARE( temporalProperties->fixedTemporalRange(), dateTimeRange );
}

void TestQgsRasterLayerTemporalProperties::testChangedSignal()
{
QCOMPARE( temporalProperties->temporalSource(), QgsMapLayerTemporalProperties::TemporalSource::Layer );
QSignalSpy spy( temporalProperties, SIGNAL( changed() ) );

temporalProperties->setTemporalSource( QgsMapLayerTemporalProperties::TemporalSource::Layer );
QCOMPARE( spy.count(), 0 );
temporalProperties->setTemporalSource( QgsMapLayerTemporalProperties::TemporalSource::Project );
QCOMPARE( spy.count(), 1 );

temporalProperties->setIsActive( true );
QCOMPARE( spy.count(), 2 );
}

QGSTEST_MAIN( TestQgsRasterLayerTemporalProperties )
#include "testqgsrasterlayertemporalproperties.moc"

0 comments on commit 9845ffa

Please sign in to comment.