Skip to content

Commit

Permalink
updates on temporal source changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Mar 10, 2020
1 parent 86a336c commit 2aaac59
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 40 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -69,6 +69,7 @@ Sets the temporal properties temporal range ``source``.

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

};

/************************************************************************
Expand Down
13 changes: 9 additions & 4 deletions python/core/auto_generated/qgstemporalproperty.sip.in
Expand Up @@ -12,7 +12,7 @@



class QgsTemporalProperty
class QgsTemporalProperty : QObject
{
%Docstring
Base class for temporal property.
Expand All @@ -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``.
Expand All @@ -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

};
Expand Down
41 changes: 17 additions & 24 deletions src/app/qgslayertreeviewtemporalindicator.cpp
Expand Up @@ -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;
}
Expand All @@ -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 );
}
3 changes: 1 addition & 2 deletions src/app/qgslayertreeviewtemporalindicator.h
Expand Up @@ -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
6 changes: 5 additions & 1 deletion src/core/qgsmaplayertemporalproperties.cpp
Expand Up @@ -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;
}

5 changes: 4 additions & 1 deletion src/core/qgsmaplayertemporalproperties.h
Expand Up @@ -38,6 +38,7 @@
*/
class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
{

public:

/**
Expand All @@ -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().
Expand Down Expand Up @@ -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;

};
Expand Down
10 changes: 7 additions & 3 deletions src/core/qgstemporalproperty.cpp
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions src/core/qgstemporalproperty.h
Expand Up @@ -22,6 +22,7 @@
#include "qgis_core.h"
#include "qgis_sip.h"

#include <QObject>

/**
* \class QgsTemporalProperty
Expand All @@ -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.
Expand All @@ -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;

};
Expand Down

0 comments on commit 2aaac59

Please sign in to comment.