Skip to content
Permalink
Browse files

[FEATURE][layout] Expose temporal UI for map items

  • Loading branch information
nirvn committed May 9, 2020
1 parent ec32e32 commit f105add69ae5e2050843b5620e413187558117a8
@@ -164,6 +164,8 @@ A base class for objects which belong to a layout.
//table item
AttributeTableSourceLayer,
MapCrs,
StartDateTime,
EndDateTime,
};

enum PropertyValueType
@@ -55,6 +55,7 @@ commonly used property types, such as colors and blend modes.
VerticalAnchor,
SvgPath,
Offset,
DateTime,
Custom,
};

@@ -346,6 +347,29 @@ Calculates the current value of the property, including any transforms which are

.. seealso:: :py:func:`valueAsInt`

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

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

:param context: QgsExpressionContext to evaluate the property for.
:param defaultDateTime: default datetime to return if the property cannot be calculated as a datetime

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

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`

.. seealso:: :py:func:`valueAsDouble`

.. seealso:: :py:func:`valueAsInt`

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

@@ -361,6 +385,8 @@ Calculates the current value of the property and interprets it as a string.

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsColor`

.. seealso:: :py:func:`valueAsDouble`
@@ -382,6 +408,8 @@ Calculates the current value of the property and interprets it as a color.

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsDouble`
@@ -403,6 +431,8 @@ Calculates the current value of the property and interprets it as a double.

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`
@@ -424,6 +454,8 @@ Calculates the current value of the property and interprets it as an integer.

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`
@@ -445,6 +477,8 @@ Calculates the current value of the property and interprets it as an boolean.

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`
@@ -8,6 +8,7 @@




typedef QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition;


@@ -108,6 +109,31 @@ valueAs* variants) refer to the property() and :py:func:`QgsProperty.value()`

.. seealso:: :py:func:`valueAsInt`

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

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.

: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

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

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`

.. seealso:: :py:func:`valueAsDouble`

.. seealso:: :py:func:`valueAsInt`

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

@@ -125,6 +151,8 @@ Calculates the current value of the property with the specified key and interpre

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsColor`

.. seealso:: :py:func:`valueAsDouble`
@@ -148,6 +176,8 @@ Calculates the current value of the property with the specified key and interpre

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsDouble`
@@ -171,6 +201,8 @@ Calculates the current value of the property with the specified key and interpre

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`
@@ -194,6 +226,8 @@ Calculates the current value of the property with the specified key and interpre

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`
@@ -217,6 +251,8 @@ Calculates the current value of the property with the specified key and interpre

.. seealso:: :py:func:`value`

.. seealso:: :py:func:`valueAsDateTime`

.. seealso:: :py:func:`valueAsString`

.. seealso:: :py:func:`valueAsColor`
@@ -818,7 +818,7 @@ bool QgsLayoutItemMap::readPropertiesFromElement( const QDomElement &itemElem, c
if ( isTemporal() )
{
QDateTime begin = QDateTime::fromString( itemElem.attribute( QStringLiteral( "temporalRangeBegin" ) ), Qt::ISODate );
QDateTime end = QDateTime::fromString( itemElem.attribute( QStringLiteral( "temporalRangeBegin" ) ), Qt::ISODate );
QDateTime end = QDateTime::fromString( itemElem.attribute( QStringLiteral( "temporalRangeEnd" ) ), Qt::ISODate );
setTemporalRange( QgsDateTimeRange( begin, end ) );
}

@@ -1766,6 +1766,19 @@ void QgsLayoutItemMap::refreshDataDefinedProperty( const QgsLayoutObject::DataDe
emit themeChanged( mLastEvaluatedThemeName );
}

if ( isTemporal() && ( property == QgsLayoutObject::StartDateTime || property == QgsLayoutObject::EndDateTime || property == QgsLayoutObject::AllProperties ) )
{
QDateTime begin = temporalRange().begin();
QDateTime end = temporalRange().end();

if ( property == QgsLayoutObject::StartDateTime || property == QgsLayoutObject::AllProperties )
begin = mDataDefinedProperties.valueAsDateTime( QgsLayoutObject::StartDateTime, context, temporalRange().begin() );
if ( property == QgsLayoutObject::EndDateTime || property == QgsLayoutObject::AllProperties )
end = mDataDefinedProperties.valueAsDateTime( QgsLayoutObject::EndDateTime, context, temporalRange().end() );

setTemporalRange( QgsDateTimeRange( begin, end ) );
}

//force redraw
mCacheInvalidated = true;

@@ -91,6 +91,8 @@ void QgsLayoutObject::initPropertyDefinitions()
{ QgsLayoutObject::ScalebarLineWidth, QgsPropertyDefinition( "dataDefinedScalebarLineWidth", QObject::tr( "Line width" ), QgsPropertyDefinition::StrokeWidth ) },
{ QgsLayoutObject::AttributeTableSourceLayer, QgsPropertyDefinition( "dataDefinedAttributeTableSourceLayer", QObject::tr( "Table source layer" ), QgsPropertyDefinition::String ) },
{ QgsLayoutObject::MapCrs, QgsPropertyDefinition( "dataDefinedCrs", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map CRS" ), QObject::tr( "string representing a CRS, either an authority/id pair (e.g. \"EPSG:4326\"), a proj string prefixes by \"PROJ:\" (e.g. \"PROJ: +proj=...\") or a WKT string prefixed by \"WKT:\" (e.g. \"WKT:GEOGCS[\"WGS 84\"...)" ) ) },
{ QgsLayoutObject::StartDateTime, QgsPropertyDefinition( "dataDefinedStartDateTime", QObject::tr( "Temporal range start date / time" ), QgsPropertyDefinition::DateTime ) },
{ QgsLayoutObject::EndDateTime, QgsPropertyDefinition( "dataDefinedEndDateTime", QObject::tr( "Temporal range end date / time" ), QgsPropertyDefinition::DateTime ) },
};
}

@@ -192,6 +192,8 @@ class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGe
//table item
AttributeTableSourceLayer, //!< Attribute table source layer
MapCrs, //!< Map CRS
StartDateTime, //!< Temporal range's start DateTime
EndDateTime, //!< Temporal range's end DateTime
};

/**
@@ -167,6 +167,11 @@ QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, const QString
mHelpText = QObject::tr( "string of doubles '<b>x,y</b>' or array of doubles <b>[x, y]</b>" );
break;

case DateTime:
mTypes = DataTypeString;
mHelpText = QObject::tr( "DateTime or string representation of a DateTime" );
break;

case Custom:
mTypes = DataTypeString;
}
@@ -534,6 +539,34 @@ QVariant QgsProperty::value( const QgsExpressionContext &context, const QVariant
return val;
}

QDateTime QgsProperty::valueAsDateTime( const QgsExpressionContext &context, const QDateTime &defaultDateTime, bool *ok ) const
{
bool valOk = false;
QVariant val = value( context, defaultDateTime, &valOk );

if ( !valOk || !val.isValid() )
return defaultDateTime;

QDateTime dateTime;
if ( val.type() == QVariant::DateTime )
{
dateTime = val.value<QDateTime>();
}
else
{
dateTime = val.toDateTime();
}

if ( !dateTime.isValid() )
return defaultDateTime;
else
{
if ( ok )
*ok = true;
return dateTime;
}
}

QString QgsProperty::valueAsString( const QgsExpressionContext &context, const QString &defaultString, bool *ok ) const
{
bool valOk = false;
@@ -28,6 +28,7 @@
#include <QDomElement>
#include <QDomDocument>
#include <QColor>
#include <QDateTime>

class QgsPropertyTransformer;
class QgsPropertyPrivate;
@@ -76,6 +77,7 @@ class CORE_EXPORT QgsPropertyDefinition
VerticalAnchor, //!< Vertical anchor point
SvgPath, //!< Path to an SVG file
Offset, //!< 2D offset
DateTime, //!< 2D offset
Custom = 3000, //!< Custom property types
};

@@ -378,13 +380,29 @@ class CORE_EXPORT QgsProperty
*/
QVariant value( const QgsExpressionContext &context, const QVariant &defaultValue = QVariant(), bool *ok SIP_OUT = nullptr ) const;

/**
* Calculates the current value of the property and interprets it as a datetime.
* \param context QgsExpressionContext to evaluate the property for.
* \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 datetime
* \see value()
* \see valueAsString()
* \see valueAsColor()
* \see valueAsDouble()
* \see valueAsInt()
* \see valueAsBool()
*/
QDateTime valueAsDateTime( const QgsExpressionContext &context, const QDateTime &defaultDateTime = QDateTime(), bool *ok SIP_OUT = nullptr ) const;

/**
* Calculates the current value of the property and interprets it as a string.
* \param context QgsExpressionContext to evaluate the property for.
* \param defaultString default string to return if the property cannot be calculated as a string
* \param ok if specified, will be set to TRUE if conversion was successful
* \returns value parsed to string
* \see value()
* \see valueAsDateTime()
* \see valueAsColor()
* \see valueAsDouble()
* \see valueAsInt()
@@ -399,6 +417,7 @@ class CORE_EXPORT QgsProperty
* \param ok if specified, will be set to TRUE if conversion was successful
* \returns value parsed to color
* \see value()
* \see valueAsDateTime()
* \see valueAsString()
* \see valueAsDouble()
* \see valueAsInt()
@@ -413,6 +432,7 @@ class CORE_EXPORT QgsProperty
* \param ok if specified, will be set to TRUE if conversion was successful
* \returns value parsed to double
* \see value()
* \see valueAsDateTime()
* \see valueAsString()
* \see valueAsColor()
* \see valueAsInt()
@@ -427,6 +447,7 @@ class CORE_EXPORT QgsProperty
* \param ok if specified, will be set to TRUE if conversion was successful
* \returns value parsed to integer
* \see value()
* \see valueAsDateTime()
* \see valueAsString()
* \see valueAsColor()
* \see valueAsDouble()
@@ -441,6 +462,7 @@ class CORE_EXPORT QgsProperty
* \param ok if specified, will be set to TRUE if conversion was successful
* \returns value parsed to boolean
* \see value()
* \see valueAsDateTime()
* \see valueAsString()
* \see valueAsColor()
* \see valueAsDouble()
@@ -27,6 +27,18 @@ QgsAbstractPropertyCollection::QgsAbstractPropertyCollection( const QString &nam

}

QDateTime QgsAbstractPropertyCollection::valueAsDateTime( int key, const QgsExpressionContext &context, const QDateTime &defaultDateTime, bool *ok ) const
{
if ( ok )
*ok = false;

QgsProperty prop = property( key );
if ( !prop || !prop.isActive() )
return defaultDateTime;

return prop.valueAsDateTime( context, defaultDateTime, ok );
}

QString QgsAbstractPropertyCollection::valueAsString( int key, const QgsExpressionContext &context, const QString &defaultString, bool *ok ) const
{
if ( ok )

0 comments on commit f105add

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