Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal layers indicators #34909

Merged
merged 7 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,8 @@
<file>themes/default/mActionEditModelComponent.svg</file>
<file>themes/default/mIconModelOutput.svg</file>
<file>themes/default/mIconModelInput.svg</file>
<file>themes/default/mIndicatorTemporal.svg</file>
<file>themes/default/mIndicatorTimeFromProject.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
62 changes: 62 additions & 0 deletions images/themes/default/mIndicatorTemporal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions images/themes/default/mIndicatorTimeFromProject.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions python/core/auto_generated/qgsmaplayertemporalproperties.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ 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.

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 All @@ -48,6 +48,26 @@ Writes the properties to a DOM ``element``, to be used later with readXml().
Reads temporal properties from a DOM ``element`` previously written by writeXml().

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

enum TemporalSource
{
Layer,
Project
};

TemporalSource temporalSource() const;
%Docstring
Returns the temporal properties temporal range source, can be layer or project.

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

void setTemporalSource( TemporalSource source );
%Docstring
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
Original file line number Diff line number Diff line change
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( QObject *parent = 0, 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
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ SET(QGIS_APP_SRCS
qgslayertreeviewnocrsindicator.cpp
qgslayertreeviewnonremovableindicator.cpp
qgslayertreeviewbadlayerindicator.cpp
qgslayertreeviewtemporalindicator.cpp
qgsmapcanvasdockwidget.cpp
qgsmapsavedialog.cpp
qgsprojectlistitemdelegate.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgslayertreeviewbadlayerindicator.h"
#include "qgslayertreeviewnonremovableindicator.h"
#include "qgslayertreeviewnocrsindicator.h"
#include "qgslayertreeviewtemporalindicator.h"
#include "qgslayout.h"
#include "qgslayoutatlas.h"
#include "qgslayoutcustomdrophandler.h"
Expand Down Expand Up @@ -4501,6 +4502,7 @@ void QgisApp::initLayerTreeView()
new QgsLayerTreeViewFilterIndicatorProvider( mLayerTreeView ); // gets parented to the layer view
new QgsLayerTreeViewEmbeddedIndicatorProvider( mLayerTreeView ); // gets parented to the layer view
new QgsLayerTreeViewMemoryIndicatorProvider( mLayerTreeView ); // gets parented to the layer view
new QgsLayerTreeViewTemporalIndicatorProvider( mLayerTreeView ); // gets parented to the layer view
new QgsLayerTreeViewNoCrsIndicatorProvider( mLayerTreeView ); // gets parented to the layer view
QgsLayerTreeViewBadLayerIndicatorProvider *badLayerIndicatorProvider = new QgsLayerTreeViewBadLayerIndicatorProvider( mLayerTreeView ); // gets parented to the layer view
connect( badLayerIndicatorProvider, &QgsLayerTreeViewBadLayerIndicatorProvider::requestChangeDataSource, this, &QgisApp::changeDataSource );
Expand Down
85 changes: 85 additions & 0 deletions src/app/qgslayertreeviewtemporalindicator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/***************************************************************************
qgslayertreeviewtemporalindicator.cpp
---------------
begin : February 2020
copyright : (C) 2020 by Samweli Mwakisambwe
email : samweli at kartoza dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgslayertreeviewtemporalindicator.h"
#include "qgslayertreeview.h"
#include "qgslayertree.h"
#include "qgslayertreemodel.h"
#include "qgslayertreeutils.h"
#include "qgsrasterlayer.h"
#include "qgisapp.h"

QgsLayerTreeViewTemporalIndicatorProvider::QgsLayerTreeViewTemporalIndicatorProvider( QgsLayerTreeView *view )
: QgsLayerTreeViewIndicatorProvider( view )
{
}

void QgsLayerTreeViewTemporalIndicatorProvider::connectSignals( QgsMapLayer *layer )
{
if ( !( qobject_cast<QgsVectorLayer *>( layer ) || qobject_cast<QgsRasterLayer *>( layer ) ) )
return;

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

void QgsLayerTreeViewTemporalIndicatorProvider::onIndicatorClicked( const QModelIndex &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() &&
layer->temporalProperties()->isActive() )
return true;
return false;
}

QString QgsLayerTreeViewTemporalIndicatorProvider::iconName( QgsMapLayer *layer )
{
if ( layer->temporalProperties()->temporalSource() ==
QgsMapLayerTemporalProperties::TemporalSource::Project )
return QStringLiteral( "/mIndicatorTimeFromProject.svg" );

return QStringLiteral( "/mIndicatorTemporal.svg" );
}

QString QgsLayerTreeViewTemporalIndicatorProvider::tooltipText( QgsMapLayer *layer )
{
if ( layer->temporalProperties()->temporalSource() ==
QgsMapLayerTemporalProperties::TemporalSource::Project )
return tr( "<b>Temporal layer using project's time range</b>" );

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

void QgsLayerTreeViewTemporalIndicatorProvider::onLayerChanged( QgsMapLayer *layer )
{
if ( !layer )
return;
updateLayerIndicator( layer );
}
Loading