exactly the same delayed cache insertion did for framesvg,

now the thing is really faster

svn path=/trunk/KDE/kdelibs/; revision=891275
This commit is contained in:
Marco Martin 2008-12-01 14:35:02 +00:00
parent 9fd8a3298d
commit 6c7c11e934
2 changed files with 34 additions and 1 deletions

34
svg.cpp
View File

@ -23,6 +23,7 @@
#include <QMatrix>
#include <QPainter>
#include <QSharedData>
#include <QTimer>
#include <kcolorscheme.h>
#include <kconfiggroup.h>
@ -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<QString, QPixmap>::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: "<<id;
Theme::defaultTheme()->insertIntoCache(id, p);
++i;
}
itemsToSave.clear();
}
void createRenderer()
{
if (renderer) {
@ -332,6 +357,8 @@ class SvgPrivate
Svg *q;
static QHash<QString, SharedSvgRenderer::Ptr> s_renderers;
QHash <QString, QPixmap> 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!

1
svg.h
View File

@ -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;