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:
parent
71999d4aac
commit
a9d3d9a81a
@ -37,6 +37,28 @@ const QString plasmarc = QStringLiteral("plasmarc");
|
|||||||
const QString groupName = QStringLiteral("Units");
|
const QString groupName = QStringLiteral("Units");
|
||||||
const int defaultLongDuration = 120;
|
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)
|
Units::Units(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_gridUnit(-1),
|
m_gridUnit(-1),
|
||||||
@ -45,12 +67,16 @@ Units::Units(QObject *parent)
|
|||||||
m_largeSpacing(-1),
|
m_largeSpacing(-1),
|
||||||
m_longDuration(defaultLongDuration) // default base value for animations
|
m_longDuration(defaultLongDuration) // default base value for animations
|
||||||
{
|
{
|
||||||
|
if (!s_sharedAppFilter) {
|
||||||
|
s_sharedAppFilter = new SharedAppFilter();
|
||||||
|
}
|
||||||
|
|
||||||
m_iconSizes = new QQmlPropertyMap(this);
|
m_iconSizes = new QQmlPropertyMap(this);
|
||||||
updateDevicePixelRatio(); // also updates icon sizes
|
updateDevicePixelRatio(); // also updates icon sizes
|
||||||
updateSpacing(); // updates gridUnit and *Spacing properties
|
updateSpacing(); // updates gridUnit and *Spacing properties
|
||||||
|
|
||||||
connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, &Units::iconLoaderSettingsChanged);
|
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;
|
const QString configFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + plasmarc;
|
||||||
KDirWatch::self()->addFile(configFile);
|
KDirWatch::self()->addFile(configFile);
|
||||||
@ -236,13 +262,5 @@ int Units::shortDuration() const
|
|||||||
return m_longDuration / 5;
|
return m_longDuration / 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Units::eventFilter(QObject *watched, QEvent *event)
|
#include "moc_units.cpp"
|
||||||
{
|
|
||||||
if (watched == QCoreApplication::instance()) {
|
|
||||||
if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) {
|
|
||||||
updateSpacing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QObject::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -28,6 +28,20 @@
|
|||||||
|
|
||||||
class QQuickItem;
|
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
|
* @class Units
|
||||||
* @short Expose sizes to QML
|
* @short Expose sizes to QML
|
||||||
@ -106,8 +120,6 @@ public:
|
|||||||
Units(QObject *parent = 0);
|
Units(QObject *parent = 0);
|
||||||
~Units();
|
~Units();
|
||||||
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return pixel value for a grid Unit. Depends on DPI and font size.
|
* @return pixel value for a grid Unit. Depends on DPI and font size.
|
||||||
*/
|
*/
|
||||||
@ -166,10 +178,10 @@ Q_SIGNALS:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void iconLoaderSettingsChanged();
|
void iconLoaderSettingsChanged();
|
||||||
void settingsFileChanged(const QString &file);
|
void settingsFileChanged(const QString &file);
|
||||||
|
void updateSpacing();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateDevicePixelRatio();
|
void updateDevicePixelRatio();
|
||||||
void updateSpacing();
|
|
||||||
void updatePlasmaRCSettings();
|
void updatePlasmaRCSettings();
|
||||||
/**
|
/**
|
||||||
* @return The dpi-adjusted size for a given icon size
|
* @return The dpi-adjusted size for a given icon size
|
||||||
@ -181,6 +193,7 @@ private:
|
|||||||
qreal m_dpi;
|
qreal m_dpi;
|
||||||
|
|
||||||
QQmlPropertyMap *m_iconSizes;
|
QQmlPropertyMap *m_iconSizes;
|
||||||
|
static SharedAppFilter *s_sharedAppFilter;
|
||||||
|
|
||||||
int m_smallSpacing;
|
int m_smallSpacing;
|
||||||
int m_largeSpacing;
|
int m_largeSpacing;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <QSharedData>
|
#include <QSharedData>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QExplicitlySharedDataPointer>
|
#include <QExplicitlySharedDataPointer>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
@ -363,6 +363,7 @@ void ThemePrivate::colorsChanged()
|
|||||||
buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors);
|
buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors);
|
||||||
viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors);
|
viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors);
|
||||||
scheduleThemeChangeNotification(PixmapCache);
|
scheduleThemeChangeNotification(PixmapCache);
|
||||||
|
emit applicationPaletteChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemePrivate::scheduleThemeChangeNotification(CacheTypes caches)
|
void ThemePrivate::scheduleThemeChangeNotification(CacheTypes caches)
|
||||||
|
@ -95,6 +95,7 @@ Q_SIGNALS:
|
|||||||
void themeChanged();
|
void themeChanged();
|
||||||
void defaultFontChanged();
|
void defaultFontChanged();
|
||||||
void smallestFontChanged();
|
void smallestFontChanged();
|
||||||
|
void applicationPaletteChange();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const char defaultTheme[];
|
static const char defaultTheme[];
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
SharedSvgRenderer::SharedSvgRenderer(QObject *parent)
|
SharedSvgRenderer::SharedSvgRenderer(QObject *parent)
|
||||||
: QSvgRenderer(parent)
|
: QSvgRenderer(parent)
|
||||||
{
|
{
|
||||||
@ -579,20 +580,15 @@ void SvgPrivate::checkColorHints()
|
|||||||
// a colorscheme
|
// a colorscheme
|
||||||
if (qApp) {
|
if (qApp) {
|
||||||
if (usesColors && (!themed || !actualTheme()->colorScheme())) {
|
if (usesColors && (!themed || !actualTheme()->colorScheme())) {
|
||||||
qApp->installEventFilter(q);
|
QObject::connect(actualTheme()->d, SIGNAL(applicationPaletteChange()), q, SLOT(colorsChanged()));
|
||||||
} else {
|
} else {
|
||||||
qApp->removeEventFilter(q);
|
QObject::disconnect(actualTheme()->d, SIGNAL(applicationPaletteChange()), q, SLOT(colorsChanged()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Svg::eventFilter(QObject *watched, QEvent *event)
|
bool Svg::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (watched == QCoreApplication::instance()) {
|
|
||||||
if (event->type() == QEvent::ApplicationPaletteChange) {
|
|
||||||
d->colorsChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QObject::eventFilter(watched, event);
|
return QObject::eventFilter(watched, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,4 +974,5 @@ Theme *Svg::theme() const
|
|||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
|
||||||
|
#include "private/moc_svg_p.cpp"
|
||||||
#include "moc_svg.cpp"
|
#include "moc_svg.cpp"
|
||||||
|
Loading…
Reference in New Issue
Block a user