Skip to content
Permalink
Browse files

updates on temporal source changes

  • Loading branch information
Samweli authored and nyalldawson committed Mar 8, 2020
1 parent 86a336c commit 2aaac598ed66bfa7899c0f5c2631b8200b025d06
@@ -34,7 +34,7 @@ Constructor for QgsMapLayerTemporalProperties.
The ``enabled`` argument specifies whether the temporal properties are initially enabled or not (see isActive()).
%End

virtual ~QgsMapLayerTemporalProperties();
~QgsMapLayerTemporalProperties();

virtual QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) = 0;
%Docstring
@@ -69,6 +69,7 @@ Sets the temporal properties temporal range ``source``.

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

};

/************************************************************************
@@ -12,7 +12,7 @@



class QgsTemporalProperty
class QgsTemporalProperty : QObject
{
%Docstring
Base class for temporal property.
@@ -25,15 +25,13 @@ Base class for temporal property.
%End
public:

QgsTemporalProperty( bool active = false );
QgsTemporalProperty( bool enabled = false );
%Docstring
Constructor for QgsTemporalProperty.

The ``active`` argument specifies whether the property is initially active (see isActive()).
%End

virtual ~QgsTemporalProperty();

void setIsActive( bool active );
%Docstring
Sets whether the temporal property is ``active``.
@@ -46,6 +44,13 @@ Sets whether the temporal property is ``active``.
Returns ``True`` if the temporal property is active.

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

signals:

void changed();
%Docstring
Emitted when the temporal properties have changed.
%End

};
@@ -33,27 +33,29 @@ void QgsLayerTreeViewTemporalIndicatorProvider::connectSignals( QgsMapLayer *lay
if ( !( qobject_cast<QgsVectorLayer *>( layer ) || qobject_cast<QgsRasterLayer *>( layer ) ) )
return;
QgsMapLayer *mapLayer = layer;
connect( mapLayer, &QgsMapLayer::dataSourceChanged, this, &QgsLayerTreeViewTemporalIndicatorProvider::onLayerChanged );
connect( mapLayer->temporalProperties(), &QgsMapLayerTemporalProperties::changed, this, [ this, mapLayer ]( ) { this->onLayerChanged( mapLayer ); } );

if ( mapLayer && mapLayer->dataProvider() )
{
mLayer = mapLayer;
QgsRasterDataProvider *provider = qobject_cast<QgsRasterDataProvider *>( mapLayer->dataProvider() );
connect( provider, &QgsRasterDataProvider::statusChanged,
this, &QgsLayerTreeViewTemporalIndicatorProvider::onLayerChanged );
}
}

void QgsLayerTreeViewTemporalIndicatorProvider::onIndicatorClicked( const QModelIndex &index )
{
Q_UNUSED( index )
QgsLayerTreeNode *node = mLayerTreeView->layerTreeModel()->index2node( index );
if ( !QgsLayerTree::isLayer( node ) )
return;

QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( QgsLayerTree::toLayer( node )->layer() );
if ( !rasterLayer || !rasterLayer->isValid() )
return;

QgisApp::instance()->showLayerProperties( rasterLayer );
}

bool QgsLayerTreeViewTemporalIndicatorProvider::acceptLayer( QgsMapLayer *layer )
{
if ( !layer )
return false;
if ( layer->temporalProperties() )
if ( layer->temporalProperties() &&
layer->temporalProperties()->isActive() )
return true;
return false;
}
@@ -71,23 +73,14 @@ QString QgsLayerTreeViewTemporalIndicatorProvider::tooltipText( QgsMapLayer *lay
{
if ( layer->temporalProperties()->temporalSource() ==
QgsMapLayerTemporalProperties::TemporalSource::Project )
return tr( "<b>Temporal layer using Project time </b>" );
return tr( "<b>Temporal layer using project's time range</b>" );

return tr( "<b>Temporal layer</b>" );
}

void QgsLayerTreeViewTemporalIndicatorProvider::onLayerChanged()
void QgsLayerTreeViewTemporalIndicatorProvider::onLayerChanged( QgsMapLayer *layer )
{
QgsMapLayer *mapLayer = qobject_cast<QgsMapLayer *>( sender() );
QgsMapLayer *mapLayerFromIndicator = qobject_cast<QgsMapLayer *>( mLayer );

if ( !mapLayer )
{
if ( !mapLayerFromIndicator )
return;
else
updateLayerIndicator( mapLayerFromIndicator );
}
else
updateLayerIndicator( mapLayer );
if ( !layer )
return;
updateLayerIndicator( layer );
}
@@ -36,14 +36,13 @@ class QgsLayerTreeViewTemporalIndicatorProvider : public QgsLayerTreeViewIndicat
void onIndicatorClicked( const QModelIndex &index ) override;

//! Adds/removes indicator of a layer
void onLayerChanged();
void onLayerChanged( QgsMapLayer *layer );

private:
bool acceptLayer( QgsMapLayer *layer ) override;
QString iconName( QgsMapLayer *layer ) override;
QString tooltipText( QgsMapLayer *layer ) override;

QgsMapLayer *mLayer = nullptr;
};

#endif // QGSLAYERTREEVIEWTEMPORALINDICATOR_H
@@ -22,13 +22,17 @@ QgsMapLayerTemporalProperties::QgsMapLayerTemporalProperties( bool enabled )
{
}

QgsMapLayerTemporalProperties::~QgsMapLayerTemporalProperties()
{
}

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

QgsMapLayerTemporalProperties::TemporalSource QgsMapLayerTemporalProperties::temporalSource() const
{
return mSource;
}

@@ -38,6 +38,7 @@
*/
class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
{

public:

/**
@@ -47,7 +48,7 @@ class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
*/
QgsMapLayerTemporalProperties( bool enabled = false );

virtual ~QgsMapLayerTemporalProperties() = default;
~QgsMapLayerTemporalProperties() override;

/**
* Writes the properties to a DOM \a element, to be used later with readXml().
@@ -85,8 +86,10 @@ class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
*\see temporalSource()
**/
void setTemporalSource( TemporalSource source );

private:

//! Source of the properties temporal range
TemporalSource mSource = Layer;

};
@@ -18,14 +18,18 @@

#include "qgstemporalproperty.h"

QgsTemporalProperty::QgsTemporalProperty( bool active )
: mActive( active )
QgsTemporalProperty::QgsTemporalProperty( bool enabled )
: mActive( enabled )
{
}

void QgsTemporalProperty::setIsActive( bool active )
{
mActive = active;
if ( mActive != active )
{
mActive = active;
emit changed();
}
}

bool QgsTemporalProperty::isActive() const
@@ -22,6 +22,7 @@
#include "qgis_core.h"
#include "qgis_sip.h"

#include <QObject>

/**
* \class QgsTemporalProperty
@@ -31,18 +32,18 @@
* \since QGIS 3.14
*/

class CORE_EXPORT QgsTemporalProperty
class CORE_EXPORT QgsTemporalProperty : public QObject
{
Q_OBJECT

public:

/**
* Constructor for QgsTemporalProperty.
*
* The \a active argument specifies whether the property is initially active (see isActive()).
*/
QgsTemporalProperty( bool active = false );

virtual ~QgsTemporalProperty() = default;
QgsTemporalProperty( bool enabled = false );

/**
* Sets whether the temporal property is \a active.
@@ -58,8 +59,16 @@ class CORE_EXPORT QgsTemporalProperty
*/
bool isActive() const;

signals:

/**
* Emitted when the temporal properties have changed.
*/
void changed();

private:

//! Active status of the properties
bool mActive = false;

};

0 comments on commit 2aaac59

Please sign in to comment.
You can’t perform that action at this time.