GlobalFileChangeBlocker: Don't install event filter on qApp

Connect to applicationStateChanged() signal instead.

Change-Id: I95ccabd06233902400bda0c01ea89b1c7cdf0e92
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-07-27 08:28:16 +02:00
parent f9ae7c2bc6
commit 94310efa06
2 changed files with 8 additions and 15 deletions

View File

@@ -26,14 +26,15 @@
#include "globalfilechangeblocker.h"
#include "qtcassert.h"
#include <QApplication>
#include <QGuiApplication>
namespace Utils {
GlobalFileChangeBlocker::GlobalFileChangeBlocker()
{
m_blockedState = QApplication::applicationState() != Qt::ApplicationActive;
qApp->installEventFilter(this);
m_blockedState = QGuiApplication::applicationState() != Qt::ApplicationActive;
connect(qApp, &QGuiApplication::applicationStateChanged,
this, &GlobalFileChangeBlocker::applicationStateChanged);
}
GlobalFileChangeBlocker *GlobalFileChangeBlocker::instance()
@@ -48,19 +49,12 @@ void GlobalFileChangeBlocker::forceBlocked(bool blocked)
++m_forceBlocked;
else if (QTC_GUARD(m_forceBlocked > 0))
--m_forceBlocked;
emitIfChanged();
applicationStateChanged(QGuiApplication::applicationState());
}
bool GlobalFileChangeBlocker::eventFilter(QObject *obj, QEvent *e)
void GlobalFileChangeBlocker::applicationStateChanged(Qt::ApplicationState state)
{
if (obj == qApp && e->type() == QEvent::ApplicationStateChange)
emitIfChanged();
return false;
}
void GlobalFileChangeBlocker::emitIfChanged()
{
const bool blocked = m_forceBlocked || (QApplication::applicationState() != Qt::ApplicationActive);
const bool blocked = m_forceBlocked || (state != Qt::ApplicationActive);
if (blocked != m_blockedState) {
emit stateChanged(blocked);
m_blockedState = blocked;

View File

@@ -45,8 +45,7 @@ signals:
private:
GlobalFileChangeBlocker();
bool eventFilter(QObject *obj, QEvent *e) override;
void emitIfChanged();
void applicationStateChanged(Qt::ApplicationState state);
int m_forceBlocked = 0;
bool m_blockedState = false;