diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2022-05-10 16:08:42 +0200 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2022-05-11 08:06:33 +0200 |
commit | 8d0dcd23fe66a2b08675f79ebcc6df9299de1d0c (patch) | |
tree | 9d3d66cb0a624461b13e93478a8edf0e492ed44b | |
parent | 13740ef2d63503968572be216c9dcd567c6a1b21 (diff) |
Fix qrc case when resolving url to local path
A url containing a qrc path ("qrc:/content/fonts") is not a local
file and we have to handle this as a special case.
If the url is empty we skip any font loading, since we do not want
to scan complete disks.
I also replaced qCInfo with qCDebug.
Task-number: QDS-6912
Change-Id: Iae8292547abc1811243ea33a63550e54aa02a6a8
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r-- | src/imports/application/quickstudioapplication.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/imports/application/quickstudioapplication.cpp b/src/imports/application/quickstudioapplication.cpp index c1f3cf5..3dfd1a1 100644 --- a/src/imports/application/quickstudioapplication.cpp +++ b/src/imports/application/quickstudioapplication.cpp @@ -49,19 +49,36 @@ QuickStudioApplication::QuickStudioApplication(QObject *parent) : QObject(parent static void loadFont(const QString &path) { - qCInfo(texttomodelMergerDebug) << Q_FUNC_INFO << "Load font: " << path; + qCDebug(texttomodelMergerDebug) << Q_FUNC_INFO << "Load font: " << path; QFontDatabase::addApplicationFont(path); } -void QuickStudioApplication::setFontPath(const QUrl &path) { - if (path == fontPath()) +void QuickStudioApplication::setFontPath(const QUrl &url) +{ + if (url == fontPath()) return; - m_fontPath = path; + m_fontPath = url; + + QString localPath; + + if (url.isLocalFile()) + localPath = url.toLocalFile(); + + if (url.scheme() == QStringLiteral("qrc")) { + const QString &path = url.path(); + localPath = QStringLiteral(":") + path; + } + + if (!localPath.isEmpty()) { + QDirIterator it(localPath, + {QStringLiteral("*.ttf"), QStringLiteral("*.otf")}, + QDir::Files, + QDirIterator::Subdirectories); - QDirIterator it(path.toLocalFile(), {QStringLiteral("*.ttf"), QStringLiteral("*.otf") }, QDir::Files, QDirIterator::Subdirectories); - while (it.hasNext()) - loadFont(it.next()); + while (it.hasNext()) + loadFont(it.next()); + } emit fontPathChanged(); } |