mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
LP-139 fixed erroneous warning about missing pfd.svg
This commit is contained in:
parent
1ea729ecc6
commit
88dcb62ed6
@ -26,12 +26,14 @@
|
||||
*/
|
||||
|
||||
#include "svgimageprovider.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QUrl>
|
||||
#include <QFileInfo>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
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;
|
||||
|
@ -28,12 +28,12 @@
|
||||
#ifndef SVGIMAGEPROVIDER_H_
|
||||
#define SVGIMAGEPROVIDER_H_
|
||||
|
||||
#include <QObject>
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QQuickImageProvider>
|
||||
#include <QSvgRenderer>
|
||||
#include <QMap>
|
||||
|
||||
#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<QString, QSvgRenderer *> m_renderers;
|
||||
QString m_basePath;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user