diff --git a/python/core/auto_generated/qgsmaplayertemporalproperties.sip.in b/python/core/auto_generated/qgsmaplayertemporalproperties.sip.in index 077abcc232ce..edaaf8d5a8bf 100644 --- a/python/core/auto_generated/qgsmaplayertemporalproperties.sip.in +++ b/python/core/auto_generated/qgsmaplayertemporalproperties.sip.in @@ -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. diff --git a/python/core/auto_generated/qgstemporalproperty.sip.in b/python/core/auto_generated/qgstemporalproperty.sip.in index b3666aa89b71..350809a08495 100644 --- a/python/core/auto_generated/qgstemporalproperty.sip.in +++ b/python/core/auto_generated/qgstemporalproperty.sip.in @@ -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. diff --git a/python/core/auto_generated/raster/qgsrasterlayertemporalproperties.sip.in b/python/core/auto_generated/raster/qgsrasterlayertemporalproperties.sip.in index f86a3b4d3566..67d34866901e 100644 --- a/python/core/auto_generated/raster/qgsrasterlayertemporalproperties.sip.in +++ b/python/core/auto_generated/raster/qgsrasterlayertemporalproperties.sip.in @@ -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. diff --git a/src/app/qgslayertreeviewtemporalindicator.cpp b/src/app/qgslayertreeviewtemporalindicator.cpp index c3d221968ede..bd46b13ade64 100644 --- a/src/app/qgslayertreeviewtemporalindicator.cpp +++ b/src/app/qgslayertreeviewtemporalindicator.cpp @@ -32,9 +32,8 @@ void QgsLayerTreeViewTemporalIndicatorProvider::connectSignals( QgsMapLayer *lay { if ( !( qobject_cast( layer ) || qobject_cast( 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 ) diff --git a/src/core/qgsmaplayertemporalproperties.cpp b/src/core/qgsmaplayertemporalproperties.cpp index 3849bc0c47d0..fa4b1e5bdc69 100644 --- a/src/core/qgsmaplayertemporalproperties.cpp +++ b/src/core/qgsmaplayertemporalproperties.cpp @@ -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 diff --git a/src/core/qgsmaplayertemporalproperties.h b/src/core/qgsmaplayertemporalproperties.h index c3081437158c..6ca92810516d 100644 --- a/src/core/qgsmaplayertemporalproperties.h +++ b/src/core/qgsmaplayertemporalproperties.h @@ -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; diff --git a/src/core/qgstemporalproperty.cpp b/src/core/qgstemporalproperty.cpp index 8de2f6881527..25416e0dcbd3 100644 --- a/src/core/qgstemporalproperty.cpp +++ b/src/core/qgstemporalproperty.cpp @@ -18,8 +18,9 @@ #include "qgstemporalproperty.h" -QgsTemporalProperty::QgsTemporalProperty( bool enabled ) - : mActive( enabled ) +QgsTemporalProperty::QgsTemporalProperty( QObject *parent, bool enabled ) + : QObject( parent ) + , mActive( enabled ) { } diff --git a/src/core/qgstemporalproperty.h b/src/core/qgstemporalproperty.h index b75efed19d6d..7374b4e4a1a2 100644 --- a/src/core/qgstemporalproperty.h +++ b/src/core/qgstemporalproperty.h @@ -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. diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index 52264a9376c1..d28a351aa643 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -577,7 +577,7 @@ void QgsRasterLayer::init() mLastViewPort.mWidth = 0; mLastViewPort.mHeight = 0; - mTemporalProperties = qgis::make_unique(); + 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 ) diff --git a/src/core/raster/qgsrasterlayer.h b/src/core/raster/qgsrasterlayer.h index f1e71c3a2c65..c1eb65c5299c 100644 --- a/src/core/raster/qgsrasterlayer.h +++ b/src/core/raster/qgsrasterlayer.h @@ -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; diff --git a/src/core/raster/qgsrasterlayertemporalproperties.cpp b/src/core/raster/qgsrasterlayertemporalproperties.cpp index 5fc7a414a3d8..6bc939729f16 100644 --- a/src/core/raster/qgsrasterlayertemporalproperties.cpp +++ b/src/core/raster/qgsrasterlayertemporalproperties.cpp @@ -17,8 +17,8 @@ #include "qgsrasterlayertemporalproperties.h" -QgsRasterLayerTemporalProperties::QgsRasterLayerTemporalProperties( bool enabled ) - : QgsMapLayerTemporalProperties( enabled ) +QgsRasterLayerTemporalProperties::QgsRasterLayerTemporalProperties( QObject *parent, bool enabled ) + : QgsMapLayerTemporalProperties( parent, enabled ) { } diff --git a/src/core/raster/qgsrasterlayertemporalproperties.h b/src/core/raster/qgsrasterlayertemporalproperties.h index 6078156a9b9b..5d12aedc63ff 100644 --- a/src/core/raster/qgsrasterlayertemporalproperties.h +++ b/src/core/raster/qgsrasterlayertemporalproperties.h @@ -33,6 +33,8 @@ */ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalProperties { + Q_OBJECT + public: /** @@ -40,7 +42,7 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP * * 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; diff --git a/tests/src/core/testqgsrasterlayertemporalproperties.cpp b/tests/src/core/testqgsrasterlayertemporalproperties.cpp index 415ba22452dc..b420128f5698 100644 --- a/tests/src/core/testqgsrasterlayertemporalproperties.cpp +++ b/tests/src/core/testqgsrasterlayertemporalproperties.cpp @@ -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"