Skip to content

Commit

Permalink
[temporal] Update the identify tool to take temporal range context in…
Browse files Browse the repository at this point in the history
…to account
  • Loading branch information
nirvn committed Nov 9, 2020
1 parent 19bd397 commit dcc5385
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 57 deletions.
61 changes: 61 additions & 0 deletions python/core/auto_generated/qgsidentifycontext.sip.in
@@ -0,0 +1,61 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsidentifycontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsIdentifyContext
{
%Docstring
Identify contexts are used to encapsulate the settings to be used to perform
an identify action.

.. versionadded:: 3.16.1
%End

%TypeHeaderCode
#include "qgsidentifycontext.h"
%End
public:

QgsIdentifyContext();
%Docstring
Constructor for QgsIdentifyContext
%End

void setTemporalRange( const QgsDateTimeRange &range );
%Docstring
Set datetime ``range`` to be used with the identify action.

.. seealso:: :py:func:`temporalRange`

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

const QgsDateTimeRange &temporalRange() const;
%Docstring
Returns the datetime range to be used with the identify action.

.. seealso:: :py:func:`setTemporalRange`

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

bool isTemporal() const;
%Docstring
Returns ``True`` if the temporal range setting is enabled.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsidentifycontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -91,6 +91,7 @@
%Include auto_generated/qgshistogram.sip %Include auto_generated/qgshistogram.sip
%Include auto_generated/qgshstoreutils.sip %Include auto_generated/qgshstoreutils.sip
%Include auto_generated/qgshtmlutils.sip %Include auto_generated/qgshtmlutils.sip
%Include auto_generated/qgsidentifycontext.sip
%Include auto_generated/qgsimagecache.sip %Include auto_generated/qgsimagecache.sip
%Include auto_generated/qgsinterval.sip %Include auto_generated/qgsinterval.sip
%Include auto_generated/qgsjsonutils.sip %Include auto_generated/qgsjsonutils.sip
Expand Down
40 changes: 31 additions & 9 deletions python/gui/auto_generated/qgsmaptoolidentify.sip.in
Expand Up @@ -85,19 +85,20 @@ constructor
virtual void deactivate(); virtual void deactivate();




QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting ); QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring %Docstring
Performs the identification. Performs the identification.


:param x: x coordinates of mouseEvent :param x: x coordinates of mouseEvent
:param y: y coordinates of mouseEvent :param y: y coordinates of mouseEvent
:param layerList: Performs the identification within the given list of layers. Default value is an empty list, i.e. uses all the layers. :param layerList: Performs the identification within the given list of layers. Default value is an empty list, i.e. uses all the layers.
:param mode: Identification mode. Can use QGIS default settings or a defined mode. Default mode is DefaultQgsSetting. :param mode: Identification mode. Can use QGIS default settings or a defined mode. Default mode is DefaultQgsSetting.
:param identifyContext: Identify context object.


:return: a list of IdentifyResult :return: a list of IdentifyResult
%End %End


QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers ); QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring %Docstring
Performs the identification. Performs the identification.
To avoid being forced to specify IdentifyMode with a list of layers To avoid being forced to specify IdentifyMode with a list of layers
Expand All @@ -107,15 +108,16 @@ this has been made private and two publics methods are offered
:param y: y coordinates of mouseEvent :param y: y coordinates of mouseEvent
:param mode: Identification mode. Can use QGIS default settings or a defined mode. :param mode: Identification mode. Can use QGIS default settings or a defined mode.
:param layerType: Only performs identification in a certain type of layers (raster, vector, mesh). Default value is AllLayers. :param layerType: Only performs identification in a certain type of layers (raster, vector, mesh). Default value is AllLayers.
:param identifyContext: Identify context object.


:return: a list of IdentifyResult :return: a list of IdentifyResult
%End %End


QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType ); QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring %Docstring
Performs identification based on a geometry (in map coordinates) Performs identification based on a geometry (in map coordinates)
%End %End
QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType ); QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring %Docstring
Performs identification based on a geometry (in map coordinates) Performs identification based on a geometry (in map coordinates)
%End %End
Expand All @@ -137,7 +139,7 @@ this menu can also be customized


protected: protected:


QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers ); QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring %Docstring
Performs the identification. Performs the identification.
To avoid being forced to specify IdentifyMode with a list of layers To avoid being forced to specify IdentifyMode with a list of layers
Expand All @@ -148,20 +150,40 @@ this has been made private and two publics methods are offered
:param mode: Identification mode. Can use QGIS default settings or a defined mode. :param mode: Identification mode. Can use QGIS default settings or a defined mode.
:param layerList: Performs the identification within the given list of layers. :param layerList: Performs the identification within the given list of layers.
:param layerType: Only performs identification in a certain type of layers (raster, vector, mesh). :param layerType: Only performs identification in a certain type of layers (raster, vector, mesh).
:param identifyContext: Identify context object.


:return: a list of IdentifyResult :return: a list of IdentifyResult
%End %End




bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers ); bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring %Docstring
Call the right method depending on layer type Call the right method depending on layer type
%End %End


bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel ); bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point ); %Docstring
Performs the identification against a given raster layer.

:param results: list of identify results
:param layer: raster layer to identify from
:param point: point coordinate to identify
:param viewExtent: view extent
:param mapUnitsPerPixel: map units per pixel value
:param identifyContext: identify context object
%End

bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring
Performs the identification against a given vector layer.

:param results: list of identify results
:param layer: raster layer to identify from
:param point: point coordinate to identify
:param identifyContext: identify context object
%End


bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point ); bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
%Docstring %Docstring
Identifies data from active scalar and vector dataset from the mesh layer Identifies data from active scalar and vector dataset from the mesh layer


Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsmaptoolidentifyaction.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsfields.h" #include "qgsfields.h"
#include "qgsgeometry.h" #include "qgsgeometry.h"
#include "qgslogger.h" #include "qgslogger.h"
#include "qgsidentifycontext.h"
#include "qgsidentifyresultsdialog.h" #include "qgsidentifyresultsdialog.h"
#include "qgsidentifymenu.h" #include "qgsidentifymenu.h"
#include "qgsmapcanvas.h" #include "qgsmapcanvas.h"
Expand Down Expand Up @@ -129,7 +130,10 @@ void QgsMapToolIdentifyAction::identifyFromGeometry()
identifyMenu()->setShowFeatureActions( extendedMenu ); identifyMenu()->setShowFeatureActions( extendedMenu );
IdentifyMode mode = extendedMenu ? LayerSelection : DefaultQgsSetting; IdentifyMode mode = extendedMenu ? LayerSelection : DefaultQgsSetting;


QList<IdentifyResult> results = QgsMapToolIdentify::identify( geometry, mode, AllLayers ); QgsIdentifyContext identifyContext;
if ( mCanvas->mapSettings().isTemporal() )
identifyContext.setTemporalRange( mCanvas->temporalRange() );
QList<IdentifyResult> results = QgsMapToolIdentify::identify( geometry, mode, AllLayers, identifyContext );


disconnect( this, &QgsMapToolIdentifyAction::identifyMessage, QgisApp::instance(), &QgisApp::showStatusMessage ); disconnect( this, &QgsMapToolIdentifyAction::identifyMessage, QgisApp::instance(), &QgisApp::showStatusMessage );


Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -317,6 +317,7 @@ SET(QGIS_CORE_SRCS
qgshistogram.cpp qgshistogram.cpp
qgshstoreutils.cpp qgshstoreutils.cpp
qgshtmlutils.cpp qgshtmlutils.cpp
qgsidentifycontext.cpp
qgsimagecache.cpp qgsimagecache.cpp
qgsinterval.cpp qgsinterval.cpp
qgsjsonutils.cpp qgsjsonutils.cpp
Expand Down Expand Up @@ -892,6 +893,7 @@ SET(QGIS_CORE_HDRS
qgshistogram.h qgshistogram.h
qgshstoreutils.h qgshstoreutils.h
qgshtmlutils.h qgshtmlutils.h
qgsidentifycontext.h
qgsimagecache.h qgsimagecache.h
qgsindexedfeature.h qgsindexedfeature.h
qgsinterval.h qgsinterval.h
Expand Down
32 changes: 32 additions & 0 deletions src/core/qgsidentifycontext.cpp
@@ -0,0 +1,32 @@
/***************************************************************************
qgsidentifycontext.cpp
----------------------
Date : November 2020
Copyright : (C) 2020 by Mathieu Pellerin
Email : nirvn dot asia at gmail 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 "qgsidentifycontext.h"


void QgsIdentifyContext::setTemporalRange( const QgsDateTimeRange &range )
{
mTemporalRange = range;
}

const QgsDateTimeRange &QgsIdentifyContext::temporalRange() const
{
return mTemporalRange;
}

bool QgsIdentifyContext::isTemporal() const
{
return mTemporalRange.begin().isValid() || mTemporalRange.end().isValid();
}
65 changes: 65 additions & 0 deletions src/core/qgsidentifycontext.h
@@ -0,0 +1,65 @@
/***************************************************************************
qgsidentifycontext.h
--------------------
Date : November 2020
Copyright : (C) 2020 by Mathieu Pellerin
Email : nirvn dot asia at gmail 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 QGSIDENTIFYCONTEXT_H
#define QGSIDENTIFYCONTEXT_H

#include "qgis_core.h"
#include "qgis_sip.h"

#include "qgsrange.h"

/**
* \ingroup core
* \class QgsIdentifyContext
* \brief Identify contexts are used to encapsulate the settings to be used to perform
* an identify action.
*
* \since QGIS 3.16.1
*/
class CORE_EXPORT QgsIdentifyContext
{
public:

//! Constructor for QgsIdentifyContext
QgsIdentifyContext() = default;

/**
* Set datetime \a range to be used with the identify action.
*
* \see temporalRange()
* \see isTemporal()
*/
void setTemporalRange( const QgsDateTimeRange &range );

/**
* Returns the datetime range to be used with the identify action.
*
* \see setTemporalRange()
* \see isTemporal()
*/
const QgsDateTimeRange &temporalRange() const;

/**
* Returns TRUE if the temporal range setting is enabled.
*/
bool isTemporal() const;

private:

QgsDateTimeRange mTemporalRange;

};

#endif // QGSEXPRESSIONCONTEXT_H

0 comments on commit dcc5385

Please sign in to comment.