summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-03-27 12:29:24 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-03-30 08:11:27 +0200
commitccf1a1a9536be7b904494f5b3243202d71a33b06 (patch)
tree7fa14e4c2f0322f0d32a1fcecf00564afd00e82e /tests/auto/widgets
parentb050d4867f68c3d35493221d65d343749504c988 (diff)
Replace QTextDocumentResourceProvider with a std::function
376e3bd8ecf40881685714f6f19e12d68e92127e added the new class for Qt 6.1, but during header review we concluded that using a class introduces complexity wrt instance ownership and API design that can be avoided by using a std::function instead. The functionality is tied to QTextDocument, so the type definition and the default provider API is added there. Since std::function is not trivially copyable, the atomicity of the previous implementation is not maintained, and concurrent modifications of and access to the global default provider from multiple threads is not allowed. The relevant use case can be supported by implementing a resource provider that is thread safe. Task-number: QTBUG-90211 Fixes: QTBUG-92208 Pick-to: 6.1 Change-Id: I39215c5e51c7bd27f1dd29e1d9d908aecf754fb7 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
index e4e9d12fb4..c9e71d8388 100644
--- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
+++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
@@ -40,7 +40,6 @@
#include <qmessagebox.h>
#include <qfontmetrics.h>
#include <qmath.h>
-#include <qtextdocumentresourceprovider.h>
#include <private/qlabel_p.h>
class Widget : public QWidget
@@ -599,27 +598,22 @@ void tst_QLabel::taskQTBUG_48157_dprMovie()
QCOMPARE(label.sizeHint(), movie.currentPixmap().size() / movie.currentPixmap().devicePixelRatio());
}
-class UrlResourceProvider : public QTextDocumentResourceProvider
-{
-public:
- QVariant resource(const QUrl &url) override
- {
- resourseUrl = url;
- return QVariant();
- }
-
- QUrl resourseUrl;
-};
-
void tst_QLabel::resourceProvider()
{
QLabel label;
- UrlResourceProvider resourceProvider;
- label.setResourceProvider(&resourceProvider);
- QUrl url("test://img");
+ int providerCalled = 0;
+ QUrl providerUrl;
+ label.setResourceProvider([&](const QUrl &url){
+ providerUrl = url;
+ ++providerCalled;
+ return QVariant();
+ });
+
+ const QUrl url("test://img");
label.setText(QStringLiteral("<img src='%1'/>").arg(url.toString()));
label.show();
- QCOMPARE(url, resourceProvider.resourseUrl);
+ QCOMPARE(providerUrl, url);
+ QVERIFY(providerCalled > 0);
}
QTEST_MAIN(tst_QLabel)