diff --git a/python/server/auto_generated/qgsserverapiutils.sip.in b/python/server/auto_generated/qgsserverapiutils.sip.in index 527ff729bf6..020fd003309 100644 --- a/python/server/auto_generated/qgsserverapiutils.sip.in +++ b/python/server/auto_generated/qgsserverapiutils.sip.in @@ -42,29 +42,16 @@ Returns a list of temporal dimensions information for the given ``layer`` (eithe .. versionadded:: 3.12 %End - - struct TemporalDateInterval - { - QDate begin; - QDate end; - }; - - struct TemporalDateTimeInterval - { - QDateTime begin; - QDateTime end; - }; - - static TemporalDateInterval parseTemporalDateInterval( const QString &interval ) throw( QgsServerApiBadRequestException ); + static QgsDateRange parseTemporalDateInterval( const QString &interval ) throw( QgsServerApiBadRequestException ); %Docstring -Parse a date ``interval`` and returns a TemporalDateInterval +Parse a date ``interval`` and returns a :py:class:`QgsDateRange` :raises QgsServerApiBadRequestException: if interval cannot be parsed %End - static TemporalDateTimeInterval parseTemporalDateTimeInterval( const QString &interval ) throw( QgsServerApiBadRequestException ); + static QgsDateTimeRange parseTemporalDateTimeInterval( const QString &interval ) throw( QgsServerApiBadRequestException ); %Docstring -Parse a datetime ``interval`` and returns a TemporalDateTimeInterval +Parse a datetime ``interval`` and returns a :py:class:`QgsDateTimeRange` :raises QgsServerApiBadRequestException: if interval cannot be parsed %End diff --git a/src/server/qgsserverapiutils.cpp b/src/server/qgsserverapiutils.cpp index d422cbeca6f..633d03144c2 100644 --- a/src/server/qgsserverapiutils.cpp +++ b/src/server/qgsserverapiutils.cpp @@ -121,14 +121,14 @@ template T QgsServerApiUtils::parseTemporalInterval( const } -QgsServerApiUtils::TemporalDateInterval QgsServerApiUtils::parseTemporalDateInterval( const QString &interval ) +QgsDateRange QgsServerApiUtils::parseTemporalDateInterval( const QString &interval ) { - return QgsServerApiUtils::parseTemporalInterval( interval ); + return QgsServerApiUtils::parseTemporalInterval( interval ); } -QgsServerApiUtils::TemporalDateTimeInterval QgsServerApiUtils::parseTemporalDateTimeInterval( const QString &interval ) +QgsDateTimeRange QgsServerApiUtils::parseTemporalDateTimeInterval( const QString &interval ) { - return QgsServerApiUtils::parseTemporalInterval( interval ); + return QgsServerApiUtils::parseTemporalInterval( interval ); } QgsExpression QgsServerApiUtils::temporalFilterExpression( const QgsVectorLayer *layer, const QString &interval ) @@ -257,7 +257,7 @@ QgsExpression QgsServerApiUtils::temporalFilterExpression( const QgsVectorLayer { if ( ! inputQueryIsDateTime ) { - TemporalDateInterval dateInterval { QgsServerApiUtils::parseTemporalDateInterval( interval ) }; + QgsDateRange dateInterval { QgsServerApiUtils::parseTemporalDateInterval( interval ) }; for ( const auto &dimension : qgis::as_const( dimensions ) ) { @@ -272,7 +272,7 @@ QgsExpression QgsServerApiUtils::temporalFilterExpression( const QgsVectorLayer } // This may be empty: const auto fieldRefEnd { refFieldValue( dimension.endFieldName, queryType, fieldType ) }; - if ( ! dateInterval.begin.isValid( ) && ! dateInterval.end.isValid( ) ) + if ( ! dateInterval.begin().isValid( ) && ! dateInterval.end().isValid( ) ) { // Nothing to do here: log? } @@ -280,15 +280,15 @@ QgsExpression QgsServerApiUtils::temporalFilterExpression( const QgsVectorLayer { conditions.push_back( makeFilter( fieldRefBegin, fieldRefEnd, - dateInterval.begin.toString( Qt::DateFormat::ISODate ), - dateInterval.end.toString( Qt::DateFormat::ISODate ) ) ); + dateInterval.begin().toString( Qt::DateFormat::ISODate ), + dateInterval.end().toString( Qt::DateFormat::ISODate ) ) ); } } } else // try datetime { - TemporalDateTimeInterval dateTimeInterval { QgsServerApiUtils::parseTemporalDateTimeInterval( interval ) }; + QgsDateTimeRange dateTimeInterval { QgsServerApiUtils::parseTemporalDateTimeInterval( interval ) }; for ( const auto &dimension : qgis::as_const( dimensions ) ) { @@ -303,7 +303,7 @@ QgsExpression QgsServerApiUtils::temporalFilterExpression( const QgsVectorLayer // This may be empty: const auto fieldRefEnd { refFieldValue( dimension.endFieldName, queryType, fieldType ) }; - if ( ! dateTimeInterval.begin.isValid( ) && ! dateTimeInterval.end.isValid( ) ) + if ( ! dateTimeInterval.begin().isValid( ) && ! dateTimeInterval.end().isValid( ) ) { // Nothing to do here: log? } @@ -315,13 +315,13 @@ QgsExpression QgsServerApiUtils::temporalFilterExpression( const QgsVectorLayer // Drop the time if ( fieldType == QVariant::Type::Date ) { - beginQuery = dateTimeInterval.begin.date().toString( Qt::DateFormat::ISODate ); - endQuery = dateTimeInterval.end.date().toString( Qt::DateFormat::ISODate ); + beginQuery = dateTimeInterval.begin().date().toString( Qt::DateFormat::ISODate ); + endQuery = dateTimeInterval.end().date().toString( Qt::DateFormat::ISODate ); } else { - beginQuery = dateTimeInterval.begin.toString( Qt::DateFormat::ISODate ); - endQuery = dateTimeInterval.end.toString( Qt::DateFormat::ISODate ); + beginQuery = dateTimeInterval.begin().toString( Qt::DateFormat::ISODate ); + endQuery = dateTimeInterval.end().toString( Qt::DateFormat::ISODate ); } conditions.push_back( makeFilter( fieldRefBegin, fieldRefEnd, diff --git a/src/server/qgsserverapiutils.h b/src/server/qgsserverapiutils.h index 2901197b06b..279d558393c 100644 --- a/src/server/qgsserverapiutils.h +++ b/src/server/qgsserverapiutils.h @@ -28,6 +28,7 @@ #include "qgsserverapicontext.h" #include "qgsserverexception.h" #include "qgsvectorlayerserverproperties.h" +#include "qgsrange.h" #ifdef HAVE_SERVER_PYTHON_PLUGINS #include "qgsaccesscontrol.h" @@ -66,40 +67,19 @@ class SERVER_EXPORT QgsServerApiUtils */ static QList< QgsVectorLayerServerProperties::WmsDimensionInfo > temporalDimensions( const QgsVectorLayer *layer ); - /** - * A temporal date interval, if only one of "begin" or "end" are valid, the interval is open. - * If both "begin" and "end" are invalid the interval is invalid. - */ - struct TemporalDateInterval - { - QDate begin; - QDate end; - }; - - /** - * A temporal datetime interval, if only one of "begin" or "end" are valid, the interval is open. - * If both "begin" and "end" are invalid the interval is invalid. - */ - struct TemporalDateTimeInterval - { - QDateTime begin; - QDateTime end; - }; - - /** - * Parse a date \a interval and returns a TemporalDateInterval + * Parse a date \a interval and returns a QgsDateRange * * \throws QgsServerApiBadRequestException if interval cannot be parsed */ - static TemporalDateInterval parseTemporalDateInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException ); + static QgsDateRange parseTemporalDateInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException ); /** - * Parse a datetime \a interval and returns a TemporalDateTimeInterval + * Parse a datetime \a interval and returns a QgsDateTimeRange * * \throws QgsServerApiBadRequestException if interval cannot be parsed */ - static TemporalDateTimeInterval parseTemporalDateTimeInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException ); + static QgsDateTimeRange parseTemporalDateTimeInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException ); ///@cond PRIVATE // T is TemporalDateInterval|TemporalDateTimeInterval, T2 is QDate|QdateTime diff --git a/tests/testdata/qgis_server/test_project_api_timefilters.gpkg b/tests/testdata/qgis_server/test_project_api_timefilters.gpkg index c949d35bd66..e65d714ac83 100644 Binary files a/tests/testdata/qgis_server/test_project_api_timefilters.gpkg and b/tests/testdata/qgis_server/test_project_api_timefilters.gpkg differ diff --git a/tests/testdata/qgis_server/test_project_api_timefilters.qgs b/tests/testdata/qgis_server/test_project_api_timefilters.qgs index 9e23218b19c..cec0df22588 100644 --- a/tests/testdata/qgis_server/test_project_api_timefilters.qgs +++ b/tests/testdata/qgis_server/test_project_api_timefilters.qgs @@ -19,16 +19,16 @@ - + points_47ad3bc8_35bd_4392_8994_2dc5ff04be60 - + - + @@ -58,17 +58,17 @@ - + - + - 7.15874910354614258 + 7.15825748443603516 44.79768753051757813 7.30355501174926758 44.82162857055664063 @@ -119,11 +119,11 @@ - false + true - + @@ -143,18 +143,18 @@ - - + + 1 1 1 - + - - + + @@ -175,9 +175,9 @@ @@ -187,9 +187,7 @@ - - name - + @@ -197,22 +195,22 @@ 0 0 1 - - - - + + + + - + - + @@ -259,14 +257,14 @@ - + - + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - + - @@ -363,24 +361,24 @@ def my_form_open(dialog, layer, feature): 0 generatedlayout - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + name @@ -571,12 +569,12 @@ def my_form_open(dialog, layer, feature): - - - + + + - - + + @@ -590,28 +588,28 @@ def my_form_open(dialog, layer, feature): - - - + + + - - + + @@ -625,9 +623,9 @@ def my_form_open(dialog, layer, feature): @@ -635,25 +633,25 @@ def my_form_open(dialog, layer, feature): - - - + + + - + - + - - + + @@ -672,17 +670,17 @@ def my_form_open(dialog, layer, feature): - - + + @@ -703,48 +701,48 @@ def my_form_open(dialog, layer, feature): - + - + - - - + + + - + - + - - + + @@ -763,17 +761,17 @@ def my_form_open(dialog, layer, feature): - - + + @@ -794,31 +792,31 @@ def my_form_open(dialog, layer, feature): - + - + - +