Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added temporal layer indicators
  • Loading branch information
Samweli authored and nyalldawson committed Mar 10, 2020
1 parent 89b654e commit 1b53cbc
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 0 deletions.
2 changes: 2 additions & 0 deletions images/images.qrc
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
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
90 changes: 90 additions & 0 deletions src/app/qgslayertreeviewprojecttimeindicator.cpp
@@ -0,0 +1,90 @@
/***************************************************************************
qgslayertreeviewprojecttimeindicator.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 "qgslayertreeviewprojecttimeindicator.h"
#include "qgslayertreeview.h"
#include "qgslayertree.h"
#include "qgslayertreemodel.h"
#include "qgslayertreeutils.h"
#include "qgsrasterlayer.h"
#include "qgisapp.h"

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

void QgsLayerTreeViewProjectTimeIndicatorProvider::connectSignals( QgsMapLayer *layer )
{
if ( !( qobject_cast<QgsVectorLayer *>( layer ) || qobject_cast<QgsRasterLayer *>( layer ) ) )
return;
QgsMapLayer *mapLayer = layer;
connect( mapLayer, &QgsMapLayer::dataSourceChanged, this, &QgsLayerTreeViewProjectTimeIndicatorProvider::onLayerChanged );

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

void QgsLayerTreeViewProjectTimeIndicatorProvider::onIndicatorClicked( const QModelIndex &index )
{
Q_UNUSED( index )
}

bool QgsLayerTreeViewProjectTimeIndicatorProvider::acceptLayer( QgsMapLayer *layer )
{
if ( !layer )
return false;
if ( layer->temporalProperties() &&
layer->temporalProperties()->temporalSource() ==
QgsMapLayerTemporalProperties::TemporalSource::Project )
return true;
return false;
}

QString QgsLayerTreeViewProjectTimeIndicatorProvider::iconName( QgsMapLayer *layer )
{
Q_UNUSED( layer )
return QStringLiteral( "/mIndicatorTimeFromProject.svg" );
}

QString QgsLayerTreeViewProjectTimeIndicatorProvider::tooltipText( QgsMapLayer *layer )
{
Q_UNUSED( layer )
return tr( "<b>Temporal layer using Project time </b>" );
}

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

if ( !mapLayer )
{
if ( !mapLayerFromIndicator )
return;
else
updateLayerIndicator( mapLayerFromIndicator );
}
else
updateLayerIndicator( mapLayer );
}

53 changes: 53 additions & 0 deletions src/app/qgslayertreeviewprojecttimeindicator.h
@@ -0,0 +1,53 @@
/***************************************************************************
qgslayertreeviewprojecttimeindicator.h
---------------
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. *
* *
***************************************************************************/


#ifndef QGSLAYERTREEVIEWPROJECTTIMEINDICATOR_H
#define QGSLAYERTREEVIEWPROJECTTIMEINDICATOR_H


#include "qgslayertreeviewindicatorprovider.h"

/**
* Adds indicators for showing temporal layers that are using project time to set their
* current active temporal range.
*/
class QgsLayerTreeViewProjectTimeIndicatorProvider : public QgsLayerTreeViewIndicatorProvider
{
Q_OBJECT
public:
explicit QgsLayerTreeViewProjectTimeIndicatorProvider( QgsLayerTreeView *view );

protected:
void connectSignals( QgsMapLayer *layer ) override;

protected slots:

void onIndicatorClicked( const QModelIndex &index ) override;

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

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

QgsMapLayer *mLayer = nullptr;
};

#endif // QGSLAYERTREEVIEWPROJECTTIMEINDICATOR_H
89 changes: 89 additions & 0 deletions src/app/qgslayertreeviewtemporalindicator.cpp
@@ -0,0 +1,89 @@
/***************************************************************************
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;
QgsMapLayer *mapLayer = layer;
connect( mapLayer, &QgsMapLayer::dataSourceChanged, this, &QgsLayerTreeViewTemporalIndicatorProvider::onLayerChanged );

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 )
}

bool QgsLayerTreeViewTemporalIndicatorProvider::acceptLayer( QgsMapLayer *layer )
{
if ( !layer )
return false;
if ( layer->temporalProperties() &&
layer->temporalProperties()->temporalSource() ==
QgsMapLayerTemporalProperties::TemporalSource::Layer )
return true;
return false;
}

QString QgsLayerTreeViewTemporalIndicatorProvider::iconName( QgsMapLayer *layer )
{
Q_UNUSED( layer );
return QStringLiteral( "/mIndicatorTemporal.svg" );
}

QString QgsLayerTreeViewTemporalIndicatorProvider::tooltipText( QgsMapLayer *layer )
{
Q_UNUSED( layer );
return tr( "<b>Temporal layer</b>" );
}

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

if ( !mapLayer )
{
if ( !mapLayerFromIndicator )
return;
else
updateLayerIndicator( mapLayerFromIndicator );
}
else
updateLayerIndicator( mapLayer );
}

0 comments on commit 1b53cbc

Please sign in to comment.