From 5e77ba9e7065018b28f55ecc858b1bee76a52398 Mon Sep 17 00:00:00 2001 From: Shawn Starr Date: Wed, 19 Dec 2007 20:29:22 +0000 Subject: [PATCH] Add some convenience methods file(), to get the svg image path and setFile, to set the image path svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=750651 --- svg.cpp | 28 ++++++++++++++++++++++------ svg.h | 13 +++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/svg.cpp b/svg.cpp index 0ec021d4f..e6f126020 100644 --- a/svg.cpp +++ b/svg.cpp @@ -79,12 +79,7 @@ class Svg::Private ~Private() { - if (renderer.count() == 2) { - // this and the cache reference it; and boy is this not thread safe ;) - renderers.erase(renderers.find(themePath)); - } - - renderer = 0; + eraseRenderer(); } void removeFromCache() @@ -163,6 +158,16 @@ class Svg::Private size = renderer->defaultSize(); } + void eraseRenderer() + { + if (renderer.count() == 2) { + // this and the cache reference it; and boy is this not thread safe ;) + renderers.erase(renderers.find(themePath)); + } + + renderer = 0; + } + QSize elementSize(const QString& elementId) { createRenderer(); @@ -311,6 +316,17 @@ Svg::ContentType Svg::contentType() return d->contentType; } +void Svg::setFile(const QString &svgFilePath) +{ + d->themePath = svgFilePath; + d->eraseRenderer(); +} + +QString Svg::file() const +{ + return d->themePath; +} + void Svg::themeChanged() { d->removeFromCache(); diff --git a/svg.h b/svg.h index 992559190..6da5882fd 100644 --- a/svg.h +++ b/svg.h @@ -50,6 +50,7 @@ class PLASMA_EXPORT Svg : public QObject Q_ENUMS( ContentType ) Q_PROPERTY( QSize size READ size ) Q_PROPERTY( ContentType contentType READ contentType WRITE setContentType ) + Q_PROPERTY( QString file READ file WRITE setFile ) public: /** @@ -199,6 +200,18 @@ class PLASMA_EXPORT Svg : public QObject */ ContentType contentType(); + /** + * Convenience method for setting the svg file to use for the Svg. + * @arg svgFilePath the filepath including name of the svg. + */ + void setFile(const QString &svgFilePath); + + /** + * Convenience method to get the svg filepath and name of svg. + * @return the svg's filepath including name of the svg. + */ + QString file() const; + Q_SIGNALS: void repaintNeeded();