diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-02-07 19:31:52 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-02-10 16:54:44 +0000 |
commit | 3159ac9ff7edf0eea93fa8331ea6cb8abc201ca2 (patch) | |
tree | 7e904af5e96c52b1bef2088fabbbd0250c0975d3 /src/pdfquick/qquickpdfdocument.cpp | |
parent | fd4c82da90213a15130f2478617ad6a7ab441447 (diff) |
PdfDocument: resolve the source URL
Similar to qtdeclarative 0a1e4cc7ec7548f6273befff9cdddb0bc7a58961
except here, setting the source calls QPdfDocument::load() immediately,
so we need to resolve the URL right before doing that.
The results are visible in most of the manual tests: they again load
test.pdf immediately, as in Qt 5.
Pick-to: 6.3
Change-Id: I8c67a9e1c72ac390c24d72d5e229ff0ef9f4aa0d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/pdfquick/qquickpdfdocument.cpp')
-rw-r--r-- | src/pdfquick/qquickpdfdocument.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/pdfquick/qquickpdfdocument.cpp b/src/pdfquick/qquickpdfdocument.cpp index b9ee0b725..64ad0071a 100644 --- a/src/pdfquick/qquickpdfdocument.cpp +++ b/src/pdfquick/qquickpdfdocument.cpp @@ -38,9 +38,10 @@ ****************************************************************************/ #include "qquickpdfdocument_p.h" -#include <QQuickItem> -#include <QQmlEngine> -#include <QStandardPaths> +#include <QtCore/qstandardpaths.h> +#include <QtQml/qqmlcontext.h> +#include <QtQml/qqmlengine.h> +#include <QtQuick/qquickitem.h> QT_BEGIN_NAMESPACE @@ -99,10 +100,12 @@ void QQuickPdfDocument::setSource(QUrl source) m_source = source; m_maxPageWidthHeight = QSizeF(); emit sourceChanged(); + const QQmlContext *context = qmlContext(this); + m_resolvedSource = context ? context->resolvedUrl(source) : source; if (source.scheme() == QLatin1String("qrc")) - m_doc.load(QLatin1Char(':') + source.path()); + m_doc.load(QLatin1Char(':') + m_resolvedSource.path()); else - m_doc.load(source.toLocalFile()); + m_doc.load(m_resolvedSource.toLocalFile()); } /*! @@ -152,8 +155,8 @@ void QQuickPdfDocument::setPassword(const QString &password) if (m_doc.password() == password) return; m_doc.setPassword(password); - if (source().isValid() && source().isLocalFile()) - m_doc.load(source().path()); + if (resolvedSource().isValid() && resolvedSource().isLocalFile()) + m_doc.load(resolvedSource().path()); } /*! |