diff options
author | Alexander Volkov <avolkov@astralinux.ru> | 2018-09-25 18:09:28 +0300 |
---|---|---|
committer | Alexander Volkov <avolkov@astralinux.ru> | 2021-01-12 15:33:10 +0300 |
commit | 376e3bd8ecf40881685714f6f19e12d68e92127e (patch) | |
tree | 8a137b8cea51115b405202ef6c0cffdf6fe78192 /tests/auto/widgets/widgets | |
parent | 9e09677c1dd4da92735736a0fbcb703416bf4d6d (diff) |
Introduce QUrlResourceProvider to load resources for HTML
QTextDocument and the text editor classes suggest to override
their loadResource() methods to provide data associated with
a text document. This approach has the following drawbacks:
- it requires subclassing
- there is no way to set a global resource provider
- QLabel is missing virtual loadResource() method and
it can't be added without breaking ABI
QUrlResourceProvider is designed to solve these issues.
One should create a derived class that implements
QUrlResourceProvider::resource(). The objects of the derived
class then can be set for any text document.
The default resource provider can be set with
QUrlResourceProvider::setDefaultProvider().
This change also adds QLabel::setResourceProvider(),
which doesn't break ABI.
[ChangeLog][QtGui][Text] Introduced QUrlResourceProvider that allows to
load resources for HTML. It is intended to replace the use of
QTextDocument::loadResource().
Change-Id: Iaf19b229f522a73508f20715257450fe58f68daf
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets')
-rw-r--r-- | tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp index ea72c91b0a..5eed823a34 100644 --- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp +++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp @@ -40,6 +40,7 @@ #include <qmessagebox.h> #include <qfontmetrics.h> #include <qmath.h> +#include <qurlresourceprovider.h> #include <private/qlabel_p.h> class Widget : public QWidget @@ -103,6 +104,8 @@ private Q_SLOTS: void taskQTBUG_48157_dprPixmap(); void taskQTBUG_48157_dprMovie(); + void resourceProvider(); + private: QLabel *testWidget; QPointer<Widget> test_box; @@ -596,5 +599,28 @@ void tst_QLabel::taskQTBUG_48157_dprMovie() QCOMPARE(label.sizeHint(), movie.currentPixmap().size() / movie.currentPixmap().devicePixelRatio()); } +class UrlResourceProvider : public QUrlResourceProvider +{ +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"); + label.setText(QStringLiteral("<img src='%1'/>").arg(url.toString())); + label.show(); + QCOMPARE(url, resourceProvider.resourseUrl); +} + QTEST_MAIN(tst_QLabel) #include "tst_qlabel.moc" |