diff --git a/python/core/auto_generated/qgspropertycollection.sip.in b/python/core/auto_generated/qgspropertycollection.sip.in index 595b5699bba..4a49c3ad48d 100644 --- a/python/core/auto_generated/qgspropertycollection.sip.in +++ b/python/core/auto_generated/qgspropertycollection.sip.in @@ -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; %Docstring 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 int and used for the key value. diff --git a/src/core/layout/qgslayoutitempicture.cpp b/src/core/layout/qgslayoutitempicture.cpp index 4d2f0acef94..ef6219fe52a 100644 --- a/src/core/layout/qgslayoutitempicture.cpp +++ b/src/core/layout/qgslayoutitempicture.cpp @@ -342,8 +342,10 @@ void QgsLayoutItemPicture::refreshPicture( const QgsExpressionContext *context ) mHasExpressionError = false; if ( mDataDefinedProperties.isActive( QgsLayoutObject::PictureSource ) ) { - source = mDataDefinedProperties.value( QgsLayoutObject::PictureSource, *evalContext, QVariant( source ) ); - if ( !source.canConvert( QMetaType::QString ) ) + bool ok = false; + const QgsProperty &sourceProperty = mDataDefinedProperties.property( QgsLayoutObject::PictureSource ); + source = sourceProperty.value( *evalContext, QVariant( source ), &ok ); + if ( !ok || !source.canConvert( QMetaType::QString ) ) { mHasExpressionError = true; source = QString(); diff --git a/src/core/qgspropertycollection.h b/src/core/qgspropertycollection.h index 777773b22c0..e98ace1541a 100644 --- a/src/core/qgspropertycollection.h +++ b/src/core/qgspropertycollection.h @@ -101,6 +101,8 @@ class CORE_EXPORT QgsAbstractPropertyCollection /** * 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 * int and used for the key value. * \param context expression context to evaluate property against diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index 23bcf61bf52..2f2caa2a26a 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -60,7 +60,8 @@ MACRO (ADD_QGIS_TEST TESTSRC) STRING(REPLACE "qgs" "" TESTNAME ${TESTNAME}) STRING(REPLACE ".cpp" "" TESTNAME ${TESTNAME}) 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) TARGET_LINK_LIBRARIES(${TESTNAME} ${Qt5Core_LIBRARIES} diff --git a/tests/src/core/testqgslayoutpicture.cpp b/tests/src/core/testqgslayoutpicture.cpp index 023c139d700..a89f6ce57c6 100644 --- a/tests/src/core/testqgslayoutpicture.cpp +++ b/tests/src/core/testqgslayoutpicture.cpp @@ -76,6 +76,7 @@ void TestQgsLayoutPicture::initTestCase() { QgsApplication::init(); QgsApplication::initQgis(); + QgsApplication::showSettings(); mPngImage = QStringLiteral( TEST_DATA_DIR ) + "/sample_image.png"; mSvgImage = QStringLiteral( TEST_DATA_DIR ) + "/sample_svg.svg"; diff --git a/tests/testdata/control_images/composer_picture/expected_composerpicture_badexpression/expected_composerpicture_badexpression.png b/tests/testdata/control_images/composer_picture/expected_composerpicture_badexpression/expected_composerpicture_badexpression.png index 499665c2f03..8da4e6e4b63 100644 Binary files a/tests/testdata/control_images/composer_picture/expected_composerpicture_badexpression/expected_composerpicture_badexpression.png and b/tests/testdata/control_images/composer_picture/expected_composerpicture_badexpression/expected_composerpicture_badexpression.png differ