Plasma::Svg: Replace use of KSharedPtr with QWeakPointer and QSharedPointer
This removes the last dependency from plasma-framework on kde4support. This change is a bit more involved than other kde4support removals because QSharedPointer does not provide a count() method. I therefore reworked the code to store the SharedSvgRenderer as a QWeakPointer in s_renderers, making it possible to detect when the last one goes away by creating a QWeakPointer guard in SvgPrivate::eraseRenderer(). REVIEW: 114912
This commit is contained in:
parent
18def6e560
commit
e7e2eeddc0
@ -46,7 +46,7 @@ find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Quick X11Extras Sql UiTools Qml W
|
||||
find_package(KF5 CONFIG REQUIRED IdleTime ItemModels WidgetsAddons WindowSystem Codecs Archive CoreAddons Solid ThreadWeaver GlobalAccel
|
||||
Config Auth JS Wallet DBusAddons I18n GuiAddons ConfigWidgets
|
||||
Service ItemViews Notifications IconThemes Completion JobWidgets Sonnet TextWidgets XmlGui Crash
|
||||
Bookmarks Declarative UnitConversion Parts Kross KIO DNSSD KDE4Support)
|
||||
Bookmarks Declarative UnitConversion Parts Kross KIO DNSSD)
|
||||
|
||||
|
||||
find_package(KActivities 5.0.0 CONFIG REQUIRED)
|
||||
|
@ -148,7 +148,6 @@ PRIVATE
|
||||
KF5::XmlGui
|
||||
KF5::GlobalAccel
|
||||
KF5::DNSSD
|
||||
KF5::KDE4Support #ksharedptr
|
||||
${PLASMA_EXTRA_LIBS}
|
||||
)
|
||||
|
||||
|
@ -21,21 +21,19 @@
|
||||
#define PLASMA_SVG_P_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QSharedData>
|
||||
#include <QSharedPointer>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
#include "ksharedptr.h"
|
||||
#include <QWeakPointer>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Svg;
|
||||
|
||||
class SharedSvgRenderer : public QSvgRenderer, public QSharedData
|
||||
class SharedSvgRenderer : public QSvgRenderer
|
||||
{
|
||||
public:
|
||||
typedef KSharedPtr<SharedSvgRenderer> Ptr;
|
||||
|
||||
typedef QSharedPointer<SharedSvgRenderer> Ptr;
|
||||
SharedSvgRenderer(QObject *parent = 0);
|
||||
SharedSvgRenderer(
|
||||
const QString &filename,
|
||||
@ -94,7 +92,7 @@ public:
|
||||
void themeChanged();
|
||||
void colorsChanged();
|
||||
|
||||
static QHash<QString, SharedSvgRenderer::Ptr> s_renderers;
|
||||
static QHash<QString, QWeakPointer<SharedSvgRenderer> > s_renderers;
|
||||
static QWeakPointer<Theme> s_systemColorsCache;
|
||||
|
||||
Svg *q;
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <QDebug>
|
||||
#include <kfilterdev.h>
|
||||
#include <kiconeffect.h>
|
||||
#include <ksharedptr.h>
|
||||
|
||||
#include "applet.h"
|
||||
#include "package.h"
|
||||
@ -419,17 +418,15 @@ void SvgPrivate::createRenderer()
|
||||
QString styleSheet = cacheAndColorsTheme()->d->svgStyleSheet();
|
||||
styleCrc = qChecksum(styleSheet.toUtf8(), styleSheet.size());
|
||||
|
||||
QHash<QString, SharedSvgRenderer::Ptr>::const_iterator it = s_renderers.constFind(styleCrc + path);
|
||||
QHash<QString, QWeakPointer<SharedSvgRenderer> >::const_iterator it = s_renderers.constFind(styleCrc + path);
|
||||
|
||||
if (it != s_renderers.constEnd()) {
|
||||
//qDebug() << "gots us an existing one!";
|
||||
renderer = it.value();
|
||||
} else {
|
||||
renderer = it == s_renderers.constEnd() ? QWeakPointer<SharedSvgRenderer>() : it.value();
|
||||
if (!renderer) {
|
||||
if (path.isEmpty()) {
|
||||
renderer = new SharedSvgRenderer();
|
||||
renderer.reset(new SharedSvgRenderer());
|
||||
} else {
|
||||
QHash<QString, QRectF> interestingElements;
|
||||
renderer = new SharedSvgRenderer(path, styleSheet, interestingElements);
|
||||
renderer.reset(new SharedSvgRenderer(path, styleSheet, interestingElements));
|
||||
|
||||
// Add interesting elements to the theme's rect cache.
|
||||
QHashIterator<QString, QRectF> i(interestingElements);
|
||||
@ -455,16 +452,15 @@ void SvgPrivate::createRenderer()
|
||||
|
||||
void SvgPrivate::eraseRenderer()
|
||||
{
|
||||
if (renderer && renderer.count() == 2) {
|
||||
// this and the cache reference it
|
||||
s_renderers.erase(s_renderers.find(styleCrc + path));
|
||||
|
||||
if (theme) {
|
||||
if (renderer) {
|
||||
QWeakPointer<SharedSvgRenderer> guard = renderer;
|
||||
renderer.reset();
|
||||
if (guard.isNull() && theme) {
|
||||
// no SvgPrivate instance references this anymore
|
||||
theme.data()->releaseRectsCache(path);
|
||||
}
|
||||
}
|
||||
|
||||
renderer = 0;
|
||||
styleCrc = 0;
|
||||
localRectCache.clear();
|
||||
elementsWithSizeHints.clear();
|
||||
@ -646,7 +642,7 @@ void SvgPrivate::colorsChanged()
|
||||
emit q->repaintNeeded();
|
||||
}
|
||||
|
||||
QHash<QString, SharedSvgRenderer::Ptr> SvgPrivate::s_renderers;
|
||||
QHash<QString, QWeakPointer<SharedSvgRenderer> > SvgPrivate::s_renderers;
|
||||
QWeakPointer<Theme> SvgPrivate::s_systemColorsCache;
|
||||
|
||||
Svg::Svg(QObject *parent)
|
||||
|
Loading…
Reference in New Issue
Block a user