diff options
Diffstat (limited to 'src/pdfquick/qquickpdfdocument.cpp')
-rw-r--r-- | src/pdfquick/qquickpdfdocument.cpp | 87 |
1 files changed, 26 insertions, 61 deletions
diff --git a/src/pdfquick/qquickpdfdocument.cpp b/src/pdfquick/qquickpdfdocument.cpp index cda72b2c8..9770900db 100644 --- a/src/pdfquick/qquickpdfdocument.cpp +++ b/src/pdfquick/qquickpdfdocument.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2022 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtPDF module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qquickpdfdocument_p.h" #include <private/qpdffile_p.h> @@ -44,6 +8,7 @@ #include <QtQml/qqmlcontext.h> #include <QtQml/qqmlengine.h> #include <QtQuick/qquickitem.h> +#include <QtQml/qqmlfile.h> QT_BEGIN_NAMESPACE @@ -71,22 +36,25 @@ QQuickPdfDocument::QQuickPdfDocument(QObject *parent) /*! \internal */ -QQuickPdfDocument::~QQuickPdfDocument() = default; +QQuickPdfDocument::~QQuickPdfDocument() +{ + delete m_carrierFile; +}; void QQuickPdfDocument::classBegin() { m_doc = static_cast<QPdfDocument *>(qmlExtendedObject(this)); Q_ASSERT(m_doc); - connect(m_doc, &QPdfDocument::passwordChanged, this, [this]() { - if (resolvedSource().isValid() && resolvedSource().isLocalFile()) - m_doc->load(resolvedSource().path()); + connect(m_doc, &QPdfDocument::passwordChanged, this, [this]() -> void { + if (resolvedSource().isValid()) + m_doc->load(QQmlFile::urlToLocalFileOrQrc(resolvedSource())); }); connect(m_doc, &QPdfDocument::statusChanged, this, [this] (QPdfDocument::Status status) { emit errorChanged(); - if (status == QPdfDocument::Ready) + if (status == QPdfDocument::Status::Ready) emit metaDataChanged(); }); - if (m_doc->error() == QPdfDocument::IncorrectPasswordError) + if (m_doc->error() == QPdfDocument::Error::IncorrectPassword) emit m_doc->passwordRequired(); } @@ -104,15 +72,14 @@ void QQuickPdfDocument::setSource(QUrl source) m_source = source; m_maxPageWidthHeight = QSizeF(); - m_carrierFile->deleteLater(); + if (m_carrierFile) + m_carrierFile->deleteLater(); m_carrierFile = nullptr; emit sourceChanged(); const QQmlContext *context = qmlContext(this); m_resolvedSource = context ? context->resolvedUrl(source) : source; - if (source.scheme() == QLatin1String("qrc")) - m_doc->load(QLatin1Char(':') + m_resolvedSource.path()); - else - m_doc->load(m_resolvedSource.toLocalFile()); + if (m_resolvedSource.isValid()) + m_doc->load(QQmlFile::urlToLocalFileOrQrc(m_resolvedSource)); } /*! @@ -126,24 +93,24 @@ void QQuickPdfDocument::setSource(QUrl source) QString QQuickPdfDocument::error() const { switch (m_doc->error()) { - case QPdfDocument::NoError: + case QPdfDocument::Error::None: return tr("no error"); break; - case QPdfDocument::UnknownError: + case QPdfDocument::Error::Unknown: break; - case QPdfDocument::DataNotYetAvailableError: + case QPdfDocument::Error::DataNotYetAvailable: return tr("data not yet available"); break; - case QPdfDocument::FileNotFoundError: + case QPdfDocument::Error::FileNotFound: return tr("file not found"); break; - case QPdfDocument::InvalidFileFormatError: + case QPdfDocument::Error::InvalidFileFormat: return tr("invalid file format"); break; - case QPdfDocument::IncorrectPasswordError: + case QPdfDocument::Error::IncorrectPassword: return tr("incorrect password"); break; - case QPdfDocument::UnsupportedSecuritySchemeError: + case QPdfDocument::Error::UnsupportedSecurityScheme: return tr("unsupported security scheme"); break; } @@ -177,10 +144,6 @@ QString QQuickPdfDocument::error() const Returns the size of the given \a page in points. */ -QSizeF QQuickPdfDocument::pagePointSize(int page) const -{ - return m_doc->pageSize(page); -} qreal QQuickPdfDocument::maxPageWidth() const { @@ -219,7 +182,7 @@ void QQuickPdfDocument::updateMaxPageSize() const qreal h = 0; const int count = m_doc->pageCount(); for (int i = 0; i < count; ++i) { - auto size = pagePointSize(i); + auto size = m_doc->pagePointSize(i); w = qMax(w, size.width()); h = qMax(w, size.height()); } @@ -304,3 +267,5 @@ void QQuickPdfDocument::updateMaxPageSize() const */ QT_END_NAMESPACE + +#include "moc_qquickpdfdocument_p.cpp" |