Fix layout picture item test (alternate fix to #31382) (#31383)

* Fix layout picture item test (alternate fix to #31382)
* doxygen: add pointer to QgsProperty::value() to QgsAbstractPropertyCollection::value()
This commit is contained in:
Jürgen Fischer 2019-08-24 23:49:22 +02:00 committed by GitHub
parent a90bee24a4
commit 596ffd06fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 3 deletions

View File

@ -89,6 +89,8 @@ Returns a matching property from the collection, if one exists.
virtual QVariant value( int key, const QgsExpressionContext &context, const QVariant &defaultValue = QVariant() ) const = 0; virtual QVariant value( int key, const QgsExpressionContext &context, const QVariant &defaultValue = QVariant() ) const = 0;
%Docstring %Docstring
Returns the calculated value of the property with the specified key from within the collection. Returns the calculated value of the property with the specified key from within the collection.
If you need the validity of the value (like ok provided from the
valueAs* variants) refer to the property() and :py:func:`QgsProperty.value()`
:param key: integer key for property to return. The intended use case is that a context specific enum is cast to :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. int and used for the key value.

View File

@ -342,8 +342,10 @@ void QgsLayoutItemPicture::refreshPicture( const QgsExpressionContext *context )
mHasExpressionError = false; mHasExpressionError = false;
if ( mDataDefinedProperties.isActive( QgsLayoutObject::PictureSource ) ) if ( mDataDefinedProperties.isActive( QgsLayoutObject::PictureSource ) )
{ {
source = mDataDefinedProperties.value( QgsLayoutObject::PictureSource, *evalContext, QVariant( source ) ); bool ok = false;
if ( !source.canConvert( QMetaType::QString ) ) const QgsProperty &sourceProperty = mDataDefinedProperties.property( QgsLayoutObject::PictureSource );
source = sourceProperty.value( *evalContext, QVariant( source ), &ok );
if ( !ok || !source.canConvert( QMetaType::QString ) )
{ {
mHasExpressionError = true; mHasExpressionError = true;
source = QString(); source = QString();

View File

@ -101,6 +101,8 @@ class CORE_EXPORT QgsAbstractPropertyCollection
/** /**
* Returns the calculated value of the property with the specified key from within the collection. * Returns the calculated value of the property with the specified key from within the collection.
* If you need the validity of the value (like ok provided from the
* valueAs* variants) refer to the property() and QgsProperty::value()
* \param key integer key for property to return. The intended use case is that a context specific enum is cast to * \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. * int and used for the key value.
* \param context expression context to evaluate property against * \param context expression context to evaluate property against

View File

@ -60,7 +60,8 @@ MACRO (ADD_QGIS_TEST TESTSRC)
STRING(REPLACE "qgs" "" TESTNAME ${TESTNAME}) STRING(REPLACE "qgs" "" TESTNAME ${TESTNAME})
STRING(REPLACE ".cpp" "" TESTNAME ${TESTNAME}) STRING(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
SET (TESTNAME "qgis_${TESTNAME}test") SET (TESTNAME "qgis_${TESTNAME}test")
ADD_EXECUTABLE(${TESTNAME} ${TESTSRC} ${util_SRCS}) QT5_ADD_RESOURCES(IMAGES_RCC_SRC ${CMAKE_SOURCE_DIR}/images/images.qrc)
ADD_EXECUTABLE(${TESTNAME} ${TESTSRC} ${util_SRCS} ${IMAGES_RCC_SRC})
SET_TARGET_PROPERTIES(${TESTNAME} PROPERTIES AUTOMOC TRUE) SET_TARGET_PROPERTIES(${TESTNAME} PROPERTIES AUTOMOC TRUE)
TARGET_LINK_LIBRARIES(${TESTNAME} TARGET_LINK_LIBRARIES(${TESTNAME}
${Qt5Core_LIBRARIES} ${Qt5Core_LIBRARIES}

View File

@ -76,6 +76,7 @@ void TestQgsLayoutPicture::initTestCase()
{ {
QgsApplication::init(); QgsApplication::init();
QgsApplication::initQgis(); QgsApplication::initQgis();
QgsApplication::showSettings();
mPngImage = QStringLiteral( TEST_DATA_DIR ) + "/sample_image.png"; mPngImage = QStringLiteral( TEST_DATA_DIR ) + "/sample_image.png";
mSvgImage = QStringLiteral( TEST_DATA_DIR ) + "/sample_svg.svg"; mSvgImage = QStringLiteral( TEST_DATA_DIR ) + "/sample_svg.svg";

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 32 KiB