Skip to content
Permalink
Browse files

Address review

  • Loading branch information
nirvn committed May 9, 2020
1 parent f105add commit 3675af1778a2f707947a9fcf90e9625d49dde885
@@ -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;
@@ -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`
@@ -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;
@@ -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
};

@@ -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;

@@ -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;

@@ -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 );

@@ -33,6 +33,8 @@
#include "qgsrenderedfeaturehandlerinterface.h"
#include "qgspallabeling.h"
#include "qgsvectorlayerlabeling.h"
#include "qgstemporalrangeobject.h"

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

@@ -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();
@@ -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
@@ -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 );

0 comments on commit 3675af1

Please sign in to comment.
You can’t perform that action at this time.