From 6c7c11e934f2b7d50da7817054c34c986ff7599f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 1 Dec 2008 14:35:02 +0000 Subject: [PATCH] exactly the same delayed cache insertion did for framesvg, now the thing is really faster svn path=/trunk/KDE/kdelibs/; revision=891275 --- svg.cpp | 34 +++++++++++++++++++++++++++++++++- svg.h | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/svg.cpp b/svg.cpp index 77353112e..0d948b774 100644 --- a/svg.cpp +++ b/svg.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -65,6 +66,7 @@ class SvgPrivate public: SvgPrivate(Svg *svg) : q(svg), + saveTimer(0), renderer(0), multipleImages(false), themed(false), @@ -191,10 +193,33 @@ class SvgPrivate p = p.fromImage(itmp); } - theme->insertIntoCache(id, p); + itemsToSave[elementId] = p; + saveTimer->start(300); return p; } + void scheduledCacheUpdate() + { + QHash::iterator i = itemsToSave.begin(); + + while (i != itemsToSave.end()) { + QPixmap p = i.value(); + + QString id = QString::fromLatin1("%3_%2_%1_"). + arg(p.size().width()).arg(p.size().height()).arg(path); + + if (!i.key().isEmpty()) { + id.append(i.key()); + } + + //kDebug()<<"Saving item to cache: "<insertIntoCache(id, p); + ++i; + } + itemsToSave.clear(); + } + void createRenderer() { if (renderer) { @@ -332,6 +357,8 @@ class SvgPrivate Svg *q; static QHash s_renderers; + QHash itemsToSave; + QTimer *saveTimer; SharedSvgRenderer::Ptr renderer; QString themePath; QString path; @@ -348,6 +375,9 @@ Svg::Svg(QObject *parent) : QObject(parent), d(new SvgPrivate(this)) { + d->saveTimer = new QTimer(this); + d->saveTimer->setSingleShot(true); + connect(d->saveTimer, SIGNAL(timeout()), this, SLOT(scheduledCacheUpdate())); } Svg::~Svg() @@ -448,6 +478,8 @@ bool Svg::hasElement(const QString &elementId) const QString Svg::elementAtPoint(const QPoint &point) const { + Q_UNUSED(point) + return QString(); /* FIXME: implement when Qt can support us! diff --git a/svg.h b/svg.h index c192a2a02..d73ed33e8 100644 --- a/svg.h +++ b/svg.h @@ -225,6 +225,7 @@ class PLASMA_EXPORT Svg : public QObject Q_PRIVATE_SLOT(d, void themeChanged()) Q_PRIVATE_SLOT(d, void colorsChanged()) + Q_PRIVATE_SLOT(d, void scheduledCacheUpdate()) friend class SvgPrivate; friend class FrameSvgPrivate;