idian: Debounce widget repolishing

Uses Qt's QGlobalStatic macro to create a shared Utils singleton for
repolishing widgets. This means that multiple calls to the Utils'
styling class helpers only trigger a single repolish per widget during
a one tick of the Qt event loop.
This commit is contained in:
Warchamp7
2026-09-18 15:24:10 -04:00
committed by Ryan Foster
parent ab197847da
commit 737625160c
2 changed files with 40 additions and 2 deletions
+33 -1
View File
@@ -26,6 +26,38 @@
#include <QStyleOptionFrame>
namespace idian {
Q_GLOBAL_STATIC(Utils, utils);
Utils::Utils() : QObject(nullptr) {}
void Utils::addToPolishQueue(QWidget *widget)
{
widgetPolishQueue.push_back(widget);
if (isPolishPending) {
return;
}
isPolishPending = true;
QMetaObject::invokeMethod(this, &Utils::processPolishQueue, Qt::QueuedConnection);
}
void Utils::processPolishQueue()
{
widgetPolishQueue.sort();
widgetPolishQueue.unique();
for (QPointer<QWidget> widget : widgetPolishQueue) {
if (widget) {
widget->style()->polish(widget);
}
}
isPolishPending = false;
widgetPolishQueue.clear();
}
void Utils::polishChildren(QWidget *widget)
{
for (QWidget *child : widget->findChildren<QWidget *>()) {
@@ -35,7 +67,7 @@ void Utils::polishChildren(QWidget *widget)
void Utils::repolish(QWidget *widget)
{
widget->style()->polish(widget);
utils->addToPolishQueue(widget);
}
void Utils::addClass(QWidget *widget, const QString &classname)
+7 -1
View File
@@ -17,6 +17,7 @@
#pragma once
#include <QPointer>
#include <QRegularExpression>
#include <QStyle>
#include <QWidget>
@@ -38,7 +39,12 @@ class Utils : public QObject {
}
public:
Utils(QObject *parent = nullptr) {};
Utils();
bool isPolishPending{false};
std::list<QPointer<QWidget>> widgetPolishQueue;
void addToPolishQueue(QWidget *widget);
void processPolishQueue();
// Force all children widgets to repaint
static void polishChildren(QWidget *widget);