summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-02-07 19:31:52 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-11 05:08:47 +0000
commitb4d61e1a8bc4eedbfacbc96678beb8864a911c0b (patch)
treec154bed92fac933bbd384db542c939988d1234d5 /src
parent0575ffc991b7341c2867a03668b963d81800b812 (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. Change-Id: I8c67a9e1c72ac390c24d72d5e229ff0ef9f4aa0d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 3159ac9ff7edf0eea93fa8331ea6cb8abc201ca2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-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 29877d0d7..4d3a756e9 100644
--- a/src/pdfquick/qquickpdfdocument_p.h
+++ b/src/pdfquick/qquickpdfdocument_p.h
@@ -90,6 +90,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(); }
@@ -127,6 +128,7 @@ private:
private:
QUrl m_source;
+ QUrl m_resolvedSource;
QPdfDocument m_doc;
QSizeF m_maxPageWidthHeight;