On Thursday 16 July 2009, Marco Martin wrote:
> On Thursday 16 July 2009, Aaron J. Seigo wrote:
> > On Wednesday 15 July 2009, Marco Martin wrote:
> > > a way could be like now, parsing the key and throwing away other sizes
> > > of the same framesvg, or just revert that commit...
> >
> > i think the patch you attached will also kill other valid pixmaps to be
> > cached: two plasmoids with the same svg but rendered at different sizes
> > == only one gets cached == not good.
> >
> > sooo .. yes, that commit should probably just be reverted. unfortunate,
> > as it means more overhead per FrameSvg object which is something that is
> > used quite a lot.
> >
> > some per-caching-object accounting in Theme could help prevent this (and
> > others from falling into the same trap) but that's more work and similar
> > overhead (not to mention API changes)...
> >
> > +1 on reverting.
>
> ok, i'll revert (at least for 4.3), too bad because the code is way more
> clean now :(
> what would be better is theme::insertIntoCache(const QString& key, const
> QPixmap& pix, QObject *sender)
> but api change, big nono
> sigh :(
>
> but a sick idea come to my mind: what about encoding the pointer value (or
> another random number, whatever) into the key? :p
> a key will have the form
> 7635865:path_300_200_blahblah
>
> in the cache only stuff after : will be saved as key, the first part (that
> can't be saved since wll change between sessions) just used to discard the
> useless ones :)

here we go, now only problem i see besides looking a bit perverse is assuming 
a length for the pointer (is there a way to make this always correct? 
otherwise another random number could be picked)
and assuming that the key is done this way, there should be some sort of 
fallback to the old key?

Index: framesvg.cpp
===================================================================
--- framesvg.cpp	(revision 995762)
+++ framesvg.cpp	(working copy)
@@ -616,16 +616,16 @@
     }
 
     QSizeF size = frameSize(frame);
-    QString id = QString::fromLatin1("%7_%6_%5_%4_%3_%2_%1_").
-        arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(size.width()).arg(size.height()).arg(prefixToSave).arg(q->imagePath());
+    QString id = QString::fromLatin1("%8:%7_%6_%5_%4_%3_%2_%1_").
+        arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(size.width()).arg(size.height()).arg(prefixToSave).arg(q->imagePath()).arg(QString::number((int)q));
 
     //kDebug()<<"Saving to cache frame"<<id;
 
     Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground);
 
     //insert overlay
-    id = QString::fromLatin1("overlay_%7_%6_%5_%4_%3_%2_%1_").
-        arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(size.width()).arg(size.height()).arg(prefixToSave).arg(q->imagePath());
+    id = QString::fromLatin1("%8overlay:overlay_%7_%6_%5_%4_%3_%2_%1_").
+        arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(size.width()).arg(size.height()).arg(prefixToSave).arg(q->imagePath()).arg(QString::number((int)q));
 
     Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground);
 }
Index: popupapplet.cpp
===================================================================
--- popupapplet.cpp	(revision 995762)
+++ popupapplet.cpp	(working copy)
@@ -157,7 +157,7 @@
         }
 
         QSizeF minimum;
-        QSizeF containmentSize;
+        QSizeF parentSize;
 
         QGraphicsWidget *gWidget = q->graphicsWidget();
         //kDebug() << "graphics widget is" << (QObject*)gWidget;
@@ -175,14 +175,13 @@
             minimum = qWidget->minimumSizeHint();
         }
 
-        if (q->containment()) {
-            containmentSize = q->containment()->size();
+        if (q->parentWidget()) {
+            parentSize = q->parentWidget()->size();
         }
 
         //Applet on desktop
-        if (icon && !icon->icon().isNull() && ((f != Plasma::Vertical && f != Plasma::Horizontal) ||
-            ((f == Plasma::Vertical && containmentSize.width() >= minimum.width()) ||
-             (f == Plasma::Horizontal && containmentSize.height() >= minimum.height())))) {
+        if (icon && !icon->icon().isNull() && ((parentSize.width() >= minimum.width()) &&
+             (parentSize.height() >= minimum.height()))) {
             //kDebug() << "we are expanding the popupapplet";
 
             // we only switch to expanded if we aren't horiz/vert constrained and
Index: svg.cpp
===================================================================
--- svg.cpp	(revision 995762)
+++ svg.cpp	(working copy)
@@ -98,9 +98,9 @@
         //This function is meant for the pixmap cache
         QString cachePath(const QString &path, const QSize &size)
         {
-             return QString("%3_%2_%1_").arg(int(size.height()))
+             return QString("%4:%3_%2_%1_").arg(int(size.height()))
                                         .arg(int(size.width()))
-                                        .arg(path);
+                                        .arg(path).arg(QString::number((int)q));
         }
 
         bool setImagePath(const QString &imagePath)
Index: theme.cpp
===================================================================
--- theme.cpp	(revision 995762)
+++ theme.cpp	(working copy)
@@ -152,6 +152,7 @@
     KSharedConfigPtr svgElementsCache;
     QHash<QString, QSet<QString> > invalidElements;
     QHash<QString, QPixmap> pixmapsToCache;
+    QHash<QString, QString> keysToCache;
     QTimer *saveTimer;
 
 #ifdef Q_WS_X11
@@ -238,13 +239,8 @@
 
 void ThemePrivate::scheduledCacheUpdate()
 {
-    //kDebug()<< "Saving to cache:";
-    QHash<QString, QPixmap>::const_iterator it = pixmapsToCache.constBegin();
-
-    while (it != pixmapsToCache.constEnd()) {
-        //kDebug()<< "Saving item to cache: " << it.key();
-        pixmapCache->insert(it.key(), it.value());
-        ++it;
+    foreach (QString key, keysToCache) {
+        pixmapCache->insert(key, pixmapsToCache[key]);
     }
 
     pixmapsToCache.clear();
@@ -696,7 +692,13 @@
 void Theme::insertIntoCache(const QString& key, const QPixmap& pix)
 {
     if (d->useCache()) {
-        d->pixmapsToCache.insert(key, pix);
+        QStringList tokens = key.split(":");
+
+        Q_ASSERT(tokens.count() == 2);
+
+        d->keysToCache[tokens.first()] = tokens.last();
+
+        d->pixmapsToCache.insert(tokens.last(), pix);
         d->saveTimer->start(500);
     }
 }
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to