make event filters static to decrease installed filters on qApp

since seems there are so many event filters installed
on the QApplication installed that may give performanc
 issues, try to use separate, singleton watchers for them
to decrease the amount of eventfilters called

REVIEW:126113
This commit is contained in:
Marco Martin 2015-11-20 14:26:16 +01:00
parent 71999d4aac
commit a9d3d9a81a
6 changed files with 51 additions and 20 deletions

View File

@ -37,6 +37,28 @@ const QString plasmarc = QStringLiteral("plasmarc");
const QString groupName = QStringLiteral("Units");
const int defaultLongDuration = 120;
SharedAppFilter::SharedAppFilter(QObject *parent)
: QObject(parent)
{
QCoreApplication::instance()->installEventFilter(this);
}
SharedAppFilter::~SharedAppFilter()
{}
bool SharedAppFilter::eventFilter(QObject *watched, QEvent *event)
{
if (watched == QCoreApplication::instance()) {
if (event->type() == QEvent::ApplicationFontChange) {
emit fontChanged();
}
}
return QObject::eventFilter(watched, event);
}
SharedAppFilter *Units::s_sharedAppFilter = nullptr;
Units::Units(QObject *parent)
: QObject(parent),
m_gridUnit(-1),
@ -45,12 +67,16 @@ Units::Units(QObject *parent)
m_largeSpacing(-1),
m_longDuration(defaultLongDuration) // default base value for animations
{
if (!s_sharedAppFilter) {
s_sharedAppFilter = new SharedAppFilter();
}
m_iconSizes = new QQmlPropertyMap(this);
updateDevicePixelRatio(); // also updates icon sizes
updateSpacing(); // updates gridUnit and *Spacing properties
connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, &Units::iconLoaderSettingsChanged);
QCoreApplication::instance()->installEventFilter(this);
QObject::connect(s_sharedAppFilter, SIGNAL(fontChanged()), this, SLOT(updateSpacing()));
const QString configFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + plasmarc;
KDirWatch::self()->addFile(configFile);
@ -236,13 +262,5 @@ int Units::shortDuration() const
return m_longDuration / 5;
}
bool Units::eventFilter(QObject *watched, QEvent *event)
{
if (watched == QCoreApplication::instance()) {
if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) {
updateSpacing();
}
}
return QObject::eventFilter(watched, event);
}
#include "moc_units.cpp"

View File

@ -28,6 +28,20 @@
class QQuickItem;
class SharedAppFilter : public QObject
{
Q_OBJECT
public:
SharedAppFilter(QObject *parent = 0);
~SharedAppFilter();
Q_SIGNALS:
void fontChanged();
protected:
bool eventFilter(QObject *watched, QEvent *event);
};
/**
* @class Units
* @short Expose sizes to QML
@ -106,8 +120,6 @@ public:
Units(QObject *parent = 0);
~Units();
bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
/**
* @return pixel value for a grid Unit. Depends on DPI and font size.
*/
@ -166,10 +178,10 @@ Q_SIGNALS:
private Q_SLOTS:
void iconLoaderSettingsChanged();
void settingsFileChanged(const QString &file);
void updateSpacing();
private:
void updateDevicePixelRatio();
void updateSpacing();
void updatePlasmaRCSettings();
/**
* @return The dpi-adjusted size for a given icon size
@ -181,6 +193,7 @@ private:
qreal m_dpi;
QQmlPropertyMap *m_iconSizes;
static SharedAppFilter *s_sharedAppFilter;
int m_smallSpacing;
int m_largeSpacing;

View File

@ -24,6 +24,7 @@
#include <QSharedData>
#include <QSvgRenderer>
#include <QExplicitlySharedDataPointer>
#include <QObject>
namespace Plasma
{

View File

@ -363,6 +363,7 @@ void ThemePrivate::colorsChanged()
buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors);
viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors);
scheduleThemeChangeNotification(PixmapCache);
emit applicationPaletteChange();
}
void ThemePrivate::scheduleThemeChangeNotification(CacheTypes caches)

View File

@ -95,6 +95,7 @@ Q_SIGNALS:
void themeChanged();
void defaultFontChanged();
void smallestFontChanged();
void applicationPaletteChange();
public:
static const char defaultTheme[];

View File

@ -44,6 +44,7 @@
namespace Plasma
{
SharedSvgRenderer::SharedSvgRenderer(QObject *parent)
: QSvgRenderer(parent)
{
@ -579,20 +580,15 @@ void SvgPrivate::checkColorHints()
// a colorscheme
if (qApp) {
if (usesColors && (!themed || !actualTheme()->colorScheme())) {
qApp->installEventFilter(q);
QObject::connect(actualTheme()->d, SIGNAL(applicationPaletteChange()), q, SLOT(colorsChanged()));
} else {
qApp->removeEventFilter(q);
QObject::disconnect(actualTheme()->d, SIGNAL(applicationPaletteChange()), q, SLOT(colorsChanged()));
}
}
}
bool Svg::eventFilter(QObject *watched, QEvent *event)
{
if (watched == QCoreApplication::instance()) {
if (event->type() == QEvent::ApplicationPaletteChange) {
d->colorsChanged();
}
}
return QObject::eventFilter(watched, event);
}
@ -978,4 +974,5 @@ Theme *Svg::theme() const
} // Plasma namespace
#include "private/moc_svg_p.cpp"
#include "moc_svg.cpp"