From 88dcb62ed64299682a7d75b1dfe98b63a59aef03 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Fri, 2 Oct 2015 22:09:03 +0200 Subject: [PATCH] LP-139 fixed erroneous warning about missing pfd.svg --- ground/gcs/src/libs/utils/svgimageprovider.cpp | 15 +++++++-------- ground/gcs/src/libs/utils/svgimageprovider.h | 10 +++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ground/gcs/src/libs/utils/svgimageprovider.cpp b/ground/gcs/src/libs/utils/svgimageprovider.cpp index 14804dbc5..991ac34a4 100644 --- a/ground/gcs/src/libs/utils/svgimageprovider.cpp +++ b/ground/gcs/src/libs/utils/svgimageprovider.cpp @@ -26,12 +26,14 @@ */ #include "svgimageprovider.h" + #include #include #include +#include +#include SvgImageProvider::SvgImageProvider(const QString &basePath) : - QObject(), QQuickImageProvider(QQuickImageProvider::Image), m_basePath(basePath) {} @@ -46,15 +48,12 @@ QSvgRenderer *SvgImageProvider::loadRenderer(const QString &svgFile) QSvgRenderer *renderer = m_renderers.value(svgFile); if (!renderer) { - renderer = new QSvgRenderer(svgFile); + QFileInfo fi(svgFile); - QString fn = QUrl::fromLocalFile(m_basePath).resolved(svgFile).toLocalFile(); - - // convert path to be relative to base - if (!renderer->isValid()) { - renderer->load(fn); - } + // if svgFile is relative, make it relative to base + QString fn = fi.isRelative() ? QUrl::fromLocalFile(m_basePath).resolved(svgFile).toLocalFile() : svgFile; + renderer = new QSvgRenderer(fn); if (!renderer->isValid()) { qWarning() << "Failed to load svg file:" << svgFile << fn; delete renderer; diff --git a/ground/gcs/src/libs/utils/svgimageprovider.h b/ground/gcs/src/libs/utils/svgimageprovider.h index a58b312b5..9837f0ffb 100644 --- a/ground/gcs/src/libs/utils/svgimageprovider.h +++ b/ground/gcs/src/libs/utils/svgimageprovider.h @@ -28,12 +28,12 @@ #ifndef SVGIMAGEPROVIDER_H_ #define SVGIMAGEPROVIDER_H_ -#include +#include "utils_global.h" + #include -#include #include -#include "utils_global.h" +class QSvgRenderer; class QTCREATOR_UTILS_EXPORT SvgImageProvider : public QObject, public QQuickImageProvider { Q_OBJECT @@ -41,14 +41,14 @@ public: SvgImageProvider(const QString &basePath); ~SvgImageProvider(); - QSvgRenderer *loadRenderer(const QString &svgFile); - QImage requestImage(const QString &id, QSize *size, const QSize & requestedSize); QPixmap requestPixmap(const QString &id, QSize *size, const QSize & requestedSize); Q_INVOKABLE QRectF scaledElementBounds(const QString &svgFile, const QString &elementName); private: + QSvgRenderer *loadRenderer(const QString &svgFile); + QMap m_renderers; QString m_basePath; };