aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickfontloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/util/qquickfontloader.cpp')
-rw-r--r--src/quick/util/qquickfontloader.cpp86
1 files changed, 13 insertions, 73 deletions
diff --git a/src/quick/util/qquickfontloader.cpp b/src/quick/util/qquickfontloader.cpp
index e3915723fa..9972071408 100644
--- a/src/quick/util/qquickfontloader.cpp
+++ b/src/quick/util/qquickfontloader.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick 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) 2016 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 "qquickfontloader_p.h"
@@ -58,13 +22,12 @@
#endif
#include <QtCore/QCoreApplication>
+#include <QtCore/private/qduplicatetracker_p.h>
#include <QtGui/private/qfontdatabase_p.h>
QT_BEGIN_NAMESPACE
-#define FONTLOADER_MAXIMUM_REDIRECT_RECURSION 16
-
class QQuickFontObject : public QObject
{
Q_OBJECT
@@ -79,7 +42,6 @@ Q_SIGNALS:
void fontDownloaded(int id);
private:
- int redirectCount = 0;
QNetworkReply *reply = nullptr;
private Q_SLOTS:
@@ -109,20 +71,6 @@ void QQuickFontObject::download(const QUrl &url, QNetworkAccessManager *manager)
void QQuickFontObject::replyFinished()
{
if (reply) {
- redirectCount++;
- if (redirectCount < FONTLOADER_MAXIMUM_REDIRECT_RECURSION) {
- QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
- if (redirect.isValid()) {
- QUrl url = reply->url().resolved(redirect.toUrl());
- QNetworkAccessManager *manager = reply->manager();
- reply->deleteLater();
- reply = nullptr;
- download(url, manager);
- return;
- }
- }
- redirectCount = 0;
-
if (!reply->error()) {
id = QFontDatabase::addApplicationFontFromData(reply->readAll());
emit fontDownloaded(id);
@@ -172,13 +120,10 @@ public:
void reset()
{
- QVector<QQuickFontObject *> deleted;
- QHash<QUrl, QQuickFontObject*>::iterator it;
- for (it = map.begin(); it != map.end(); ++it) {
- if (!deleted.contains(it.value())) {
- deleted.append(it.value());
- delete it.value();
- }
+ QDuplicateTracker<QQuickFontObject *, 256> deleted(map.size());
+ for (QQuickFontObject *fo : std::as_const(map)) {
+ if (!deleted.hasSeen(fo))
+ delete fo;
}
map.clear();
}
@@ -223,10 +168,6 @@ QQuickFontLoader::QQuickFontLoader(QObject *parent)
connect(this, &QQuickFontLoader::fontChanged, this, &QQuickFontLoader::nameChanged);
}
-QQuickFontLoader::~QQuickFontLoader()
-{
-}
-
/*!
\qmlproperty url QtQuick::FontLoader::source
The URL of the font to load.
@@ -354,7 +295,7 @@ void QQuickFontLoader::updateFontInfo(int id)
text: "Fancy font"
font.family: webFont.font.family
font.weight: webFont.font.weight
- font.style: webFont.font.style
+ font.styleName: webFont.font.styleName
font.pixelSize: 24
}
}
@@ -423,12 +364,11 @@ QString QQuickFontLoader::name() const
\qmlproperty enumeration QtQuick::FontLoader::status
This property holds the status of font loading. It can be one of:
- \list
- \li FontLoader.Null - no font has been set
- \li FontLoader.Ready - the font has been loaded
- \li FontLoader.Loading - the font is currently being loaded
- \li FontLoader.Error - an error occurred while loading the font
- \endlist
+
+ \value FontLoader.Null no font has been set
+ \value FontLoader.Ready the font has been loaded
+ \value FontLoader.Loading the font is currently being loaded
+ \value FontLoader.Error an error occurred while loading the font
Use this status to provide an update or respond to the status change in some way.
For example, you could: