summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-02-07 19:31:52 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2022-02-10 16:54:44 +0000
commit3159ac9ff7edf0eea93fa8331ea6cb8abc201ca2 (patch)
tree7e904af5e96c52b1bef2088fabbbd0250c0975d3
parentfd4c82da90213a15130f2478617ad6a7ab441447 (diff)
downloadqtwebengine-3159ac9ff7edf0eea93fa8331ea6cb8abc201ca2.tar.gz
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>
-rw-r--r--src/pdfquick/qquickpdfdocument.cpp17
-rw-r--r--src/pdfquick/qquickpdfdocument_p.h2
2 files changed, 12 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());
}
/*!
diff --git a/src/pdfquick/qquickpdfdocument_p.h b/src/pdfquick/qquickpdfdocument_p.h
index 140832236..2d6f2ca3b 100644
--- a/src/pdfquick/qquickpdfdocument_p.h
+++ b/src/pdfquick/qquickpdfdocument_p.h
@@ -94,6 +94,7 @@ public:
QUrl source() const { return m_source; }
void setSource(QUrl source);
+ QUrl resolvedSource() const { return m_resolvedSource; }
int pageCount() const { return m_doc.pageCount(); }
QPdfDocument::Status status() const { return m_doc.status(); }
@@ -131,6 +132,7 @@ private:
private:
QUrl m_source;
+ QUrl m_resolvedSource;
QPdfDocument m_doc;
QSizeF m_maxPageWidthHeight;