Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 10, 2020
1 parent f105add commit 3675af1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgsproperty.sip.in
Expand Up @@ -371,6 +371,8 @@ Calculates the current value of the property and interprets it as a datetime.
.. seealso:: :py:func:`valueAsInt`

.. seealso:: :py:func:`valueAsBool`

.. versionadded:: 3.14
%End

QString valueAsString( const QgsExpressionContext &context, const QString &defaultString = QString(), bool *ok /Out/ = 0 ) const;
Expand Down
8 changes: 5 additions & 3 deletions python/core/auto_generated/qgspropertycollection.sip.in
Expand Up @@ -114,14 +114,14 @@ valueAs* variants) refer to the property() and :py:func:`QgsProperty.value()`

QDateTime valueAsDateTime( int key, const QgsExpressionContext &context, const QDateTime &defaultDateTime = QDateTime(), bool *ok /Out/ = 0 ) const;
%Docstring
Calculates the current value of the property with the specified key and interprets it as a string.
Calculates the current value of the property with the specified key and interprets it as a datetime.

:param key: integer key for property to return. The intended use case is that a context specific enum is cast to
int and used for the key value.
:param context: QgsExpressionContext to evaluate the property for.
:param defaultString: default string to return if the property cannot be calculated as a string
:param defaultDateTime: default datetime to return if the property cannot be calculated as a datetime

:return: - value parsed to string
:return: - value parsed to datetime
- ok: will be set to ``True`` if conversion was successful

.. seealso:: :py:func:`value`
Expand All @@ -135,6 +135,8 @@ Calculates the current value of the property with the specified key and interpre
.. seealso:: :py:func:`valueAsInt`

.. seealso:: :py:func:`valueAsBool`

.. versionadded:: 3.14
%End

QString valueAsString( int key, const QgsExpressionContext &context, const QString &defaultString = QString(), bool *ok /Out/ = 0 ) const;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsproperty.h
Expand Up @@ -77,7 +77,7 @@ class CORE_EXPORT QgsPropertyDefinition
VerticalAnchor, //!< Vertical anchor point
SvgPath, //!< Path to an SVG file
Offset, //!< 2D offset
DateTime, //!< 2D offset
DateTime, //!< DateTime value
Custom = 3000, //!< Custom property types
};

Expand Down Expand Up @@ -392,6 +392,7 @@ class CORE_EXPORT QgsProperty
* \see valueAsDouble()
* \see valueAsInt()
* \see valueAsBool()
* \since QGIS 3.14
*/
QDateTime valueAsDateTime( const QgsExpressionContext &context, const QDateTime &defaultDateTime = QDateTime(), bool *ok SIP_OUT = nullptr ) const;

Expand Down
7 changes: 4 additions & 3 deletions src/core/qgspropertycollection.h
Expand Up @@ -120,19 +120,20 @@ class CORE_EXPORT QgsAbstractPropertyCollection
virtual QVariant value( int key, const QgsExpressionContext &context, const QVariant &defaultValue = QVariant() ) const = 0;

/**
* Calculates the current value of the property with the specified key and interprets it as a string.
* Calculates the current value of the property with the specified key and interprets it as a datetime.
* \param key integer key for property to return. The intended use case is that a context specific enum is cast to
* int and used for the key value.
* \param context QgsExpressionContext to evaluate the property for.
* \param defaultString default string to return if the property cannot be calculated as a string
* \param defaultDateTime default datetime to return if the property cannot be calculated as a datetime
* \param ok if specified, will be set to TRUE if conversion was successful
* \returns value parsed to string
* \returns value parsed to datetime
* \see value()
* \see valueAsString()
* \see valueAsColor()
* \see valueAsDouble()
* \see valueAsInt()
* \see valueAsBool()
* \since QGIS 3.14
*/
QDateTime valueAsDateTime( int key, const QgsExpressionContext &context, const QDateTime &defaultDateTime = QDateTime(), bool *ok SIP_OUT = nullptr ) const;

Expand Down
1 change: 1 addition & 0 deletions src/gui/layout/qgslayoutmapwidget.cpp
Expand Up @@ -981,6 +981,7 @@ void QgsLayoutMapWidget::blockAllSignals( bool b )
mKeepLayerStylesCheckBox->blockSignals( b );
mActionSetToCanvasExtent->blockSignals( b );
mActionUpdatePreview->blockSignals( b );
mTemporalCheckBox->blockSignals( b );
mStartDateTime->blockSignals( b );
mEndDateTime->blockSignals( b );

Expand Down
29 changes: 29 additions & 0 deletions tests/src/core/testqgslayoutmap.cpp
Expand Up @@ -33,6 +33,8 @@
#include "qgsrenderedfeaturehandlerinterface.h"
#include "qgspallabeling.h"
#include "qgsvectorlayerlabeling.h"
#include "qgstemporalrangeobject.h"

#include <QObject>
#include "qgstest.h"

Expand All @@ -57,6 +59,7 @@ class TestQgsLayoutMap : public QObject
void dataDefinedLayers(); //test data defined layer string
void dataDefinedStyles(); //test data defined styles
void dataDefinedCrs(); //test data defined crs
void dataDefinedTemporalRange(); //test data defined temporal range's start and end values
void rasterized();
void layersToRender();
void mapRotation();
Expand Down Expand Up @@ -486,6 +489,32 @@ void TestQgsLayoutMap::dataDefinedCrs()

}

void TestQgsLayoutMap::dataDefinedTemporalRange()
{
QList<QgsMapLayer *> layers = QList<QgsMapLayer *>() << mRasterLayer << mPolysLayer << mPointsLayer << mLinesLayer;

QgsLayout l( QgsProject::instance() );
l.initializeDefaults();

QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptMove( QgsLayoutPoint( 20, 20 ) );
map->attemptResize( QgsLayoutSize( 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( layers );
l.addLayoutItem( map );

QDateTime dt1 = QDateTime( QDate( 2010, 1, 1 ) );
QDateTime dt2 = QDateTime( QDate( 2020, 1, 1 ) );
map->setIsTemporal( true );
map->dataDefinedProperties().setProperty( QgsLayoutObject::StartDateTime, QgsProperty::fromValue( dt1 ) );
map->dataDefinedProperties().setProperty( QgsLayoutObject::EndDateTime, QgsProperty::fromValue( dt2 ) );
map->refreshDataDefinedProperty( QgsLayoutObject::StartDateTime );
map->refreshDataDefinedProperty( QgsLayoutObject::EndDateTime );
QCOMPARE( map->temporalRange(), QgsDateTimeRange( dt1, dt2 ) );
QgsMapSettings ms = map->mapSettings( map->extent(), map->rect().size(), 300, false );
QCOMPARE( ms.temporalRange(), QgsDateTimeRange( dt1, dt2 ) );
}

void TestQgsLayoutMap::rasterized()
{
// test a map which must be rasterized
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgsproperty.cpp
Expand Up @@ -268,6 +268,10 @@ void TestQgsProperty::conversions()
collection.property( 5 ).setStaticValue( dt2 ); //datetime in qvariant
QCOMPARE( d1.valueAsDateTime( context, dt ), dt2 );
QCOMPARE( collection.valueAsDateTime( 5, context, dt ), dt2 );
d1.setStaticValue( "2010-01-01" ); //datetime as string
collection.property( 5 ).setStaticValue( "2010-01-01" ); //datetime as string
QCOMPARE( d1.valueAsDateTime( context, dt ), dt2 );
QCOMPARE( collection.valueAsDateTime( 5, context, dt ), dt2 );
d1.setStaticValue( "i am not a datetime" ); //not a datetime, should return default value
collection.property( 5 ).setStaticValue( "i am not a datetime" ); //not a double, should return default value
QCOMPARE( d1.valueAsDateTime( context, dt ), dt );
Expand Down

0 comments on commit 3675af1

Please sign in to comment.