summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocument.h
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 /src/gui/text/qtextdocument.h
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 'src/gui/text/qtextdocument.h')
-rw-r--r--src/gui/text/qtextdocument.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h
index 286b1ed299..dc4d15f3a8 100644
--- a/src/gui/text/qtextdocument.h
+++ b/src/gui/text/qtextdocument.h
@@ -68,8 +68,6 @@ class QVariant;
class QRectF;
class QTextOption;
class QTextCursor;
-class QTextDocumentResourceProvider;
-
namespace Qt
{
@@ -240,8 +238,13 @@ public:
QVariant resource(int type, const QUrl &name) const;
void addResource(int type, const QUrl &name, const QVariant &resource);
- QTextDocumentResourceProvider *resourceProvider() const;
- void setResourceProvider(QTextDocumentResourceProvider *provider);
+ using ResourceProvider = std::function<QVariant(const QUrl&)>;
+
+ QTextDocument::ResourceProvider resourceProvider() const;
+ void setResourceProvider(const ResourceProvider &provider);
+
+ static QTextDocument::ResourceProvider defaultResourceProvider();
+ static void setDefaultResourceProvider(const ResourceProvider &provider);
QList<QTextFormat> allFormats() const;