Skip to content
Permalink
Browse files

added tests for changed signal in temporal properties

  • Loading branch information
Samweli authored and nyalldawson committed Mar 9, 2020
1 parent 2aaac59 commit 9845ffa591683978d3510c3be589fab712f3cb51
@@ -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.

@@ -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.

@@ -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.

@@ -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 )
@@ -17,8 +17,8 @@

#include "qgsmaplayertemporalproperties.h"

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

@@ -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
@@ -38,6 +38,7 @@
*/
class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
{
Q_OBJECT

public:

@@ -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;

@@ -18,8 +18,9 @@

#include "qgstemporalproperty.h"

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

@@ -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.
@@ -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 )
@@ -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 )
@@ -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;
@@ -17,8 +17,8 @@

#include "qgsrasterlayertemporalproperties.h"

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

@@ -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;

@@ -39,6 +39,7 @@ class TestQgsRasterLayerTemporalProperties : public QObject
void cleanup(); // will be called after every testfunction.

void checkSettingTemporalRange();
void testChangedSignal();

private:
QgsRasterLayerTemporalProperties *temporalProperties = nullptr;
@@ -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.
You can’t perform that action at this time.