Use invokeMethod instead of single shot timer with 0 timeout

Refactor it in coreplugin.

Change-Id: I6aaad1b9270a8ff8a4a0bea6a1fff806b2fe190b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-01-28 11:29:14 +01:00
parent 9c646d55cd
commit be1d33299e
18 changed files with 28 additions and 38 deletions

View File

@@ -408,7 +408,7 @@ void ActionContainerPrivate::scheduleUpdate()
if (m_updateRequested) if (m_updateRequested)
return; return;
m_updateRequested = true; m_updateRequested = true;
QTimer::singleShot(0, this, &ActionContainerPrivate::update); QMetaObject::invokeMethod(this, &ActionContainerPrivate::update, Qt::QueuedConnection);
} }
void ActionContainerPrivate::update() void ActionContainerPrivate::update()

View File

@@ -41,7 +41,6 @@
#include <QPushButton> #include <QPushButton>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStandardItem> #include <QStandardItem>
#include <QTimer>
Q_DECLARE_METATYPE(Core::IWizardFactory*) Q_DECLARE_METATYPE(Core::IWizardFactory*)
@@ -502,8 +501,8 @@ void NewDialog::accept()
if (m_ui->templatesView->currentIndex().isValid()) { if (m_ui->templatesView->currentIndex().isValid()) {
IWizardFactory *wizard = currentWizardFactory(); IWizardFactory *wizard = currentWizardFactory();
if (QTC_GUARD(wizard)) { if (QTC_GUARD(wizard)) {
QTimer::singleShot(0, std::bind(&runWizard, wizard, m_defaultLocation, QMetaObject::invokeMethod(wizard, std::bind(&runWizard, wizard, m_defaultLocation,
selectedPlatform(), m_extraVariables)); selectedPlatform(), m_extraVariables), Qt::QueuedConnection);
} }
} }
QDialog::accept(); QDialog::accept();

View File

@@ -28,7 +28,6 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <QPushButton> #include <QPushButton>
#include <QTimer>
namespace Core { namespace Core {
@@ -41,9 +40,7 @@ RestartDialog::RestartDialog(QWidget *parent, const QString &text)
addButton(tr("Later"), QMessageBox::NoRole); addButton(tr("Later"), QMessageBox::NoRole);
addButton(tr("Restart Now"), QMessageBox::YesRole); addButton(tr("Restart Now"), QMessageBox::YesRole);
connect(this, &QDialog::accepted, this, [] { connect(this, &QDialog::accepted, ICore::instance(), &ICore::restart, Qt::QueuedConnection);
QTimer::singleShot(0, ICore::instance(), [] { ICore::restart(); });
});
} }
} // namespace Core } // namespace Core

View File

@@ -1320,7 +1320,7 @@ void DocumentManager::checkForReload()
d->m_blockActivated = false; d->m_blockActivated = false;
// re-check in case files where modified while the dialog was open // re-check in case files where modified while the dialog was open
QTimer::singleShot(0, this, &DocumentManager::checkForReload); QMetaObject::invokeMethod(this, &DocumentManager::checkForReload, Qt::QueuedConnection);
// dump(); // dump();
} }

View File

@@ -1466,7 +1466,7 @@ void EditorManagerPrivate::addEditor(IEditor *editor)
emit m_instance->documentOpened(document); emit m_instance->documentOpened(document);
} }
emit m_instance->editorOpened(editor); emit m_instance->editorOpened(editor);
QTimer::singleShot(0, d, &EditorManagerPrivate::autoSuspendDocuments); QMetaObject::invokeMethod(d, &EditorManagerPrivate::autoSuspendDocuments, Qt::QueuedConnection);
} }
void EditorManagerPrivate::removeEditor(IEditor *editor, bool removeSuspendedEntry) void EditorManagerPrivate::removeEditor(IEditor *editor, bool removeSuspendedEntry)
@@ -2366,7 +2366,8 @@ void EditorManagerPrivate::handleContextChange(const QList<IContext *> &context)
// the locator line edit) first activates the window and sets focus to its focus widget. // the locator line edit) first activates the window and sets focus to its focus widget.
// Only afterwards the focus is shifted to the widget that received the click. // Only afterwards the focus is shifted to the widget that received the click.
d->m_scheduledCurrentEditor = editor; d->m_scheduledCurrentEditor = editor;
QTimer::singleShot(0, d, &EditorManagerPrivate::setCurrentEditorFromContextChange); QMetaObject::invokeMethod(d, &EditorManagerPrivate::setCurrentEditorFromContextChange,
Qt::QueuedConnection);
} else { } else {
updateActions(); updateActions();
} }

View File

@@ -221,7 +221,9 @@ void FancyTabBar::mousePressEvent(QMouseEvent *event)
m_currentIndex = index; m_currentIndex = index;
update(); update();
// update tab bar before showing widget // update tab bar before showing widget
QTimer::singleShot(0, this, [this]() { emit currentChanged(m_currentIndex); }); QMetaObject::invokeMethod(this, [this]() {
emit currentChanged(m_currentIndex);
}, Qt::QueuedConnection);
} }
} }
} }

View File

@@ -32,7 +32,6 @@
#include <QWidget> #include <QWidget>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QTimer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QPainter; class QPainter;

View File

@@ -889,7 +889,7 @@ bool FindToolBar::focusNextPrevChild(bool next)
void FindToolBar::resizeEvent(QResizeEvent *event) void FindToolBar::resizeEvent(QResizeEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
QTimer::singleShot(0, this, &FindToolBar::updateToolBar); QMetaObject::invokeMethod(this, &FindToolBar::updateToolBar, Qt::QueuedConnection);
} }
void FindToolBar::writeSettings() void FindToolBar::writeSettings()

View File

@@ -31,7 +31,6 @@
#include <QScrollBar> #include <QScrollBar>
#include <QStyle> #include <QStyle>
#include <QStyleOptionSlider> #include <QStyleOptionSlider>
#include <QTimer>
using namespace Utils; using namespace Utils;
@@ -105,7 +104,7 @@ void HighlightScrollBarOverlay::scheduleUpdate()
return; return;
m_isCacheUpdateScheduled = true; m_isCacheUpdateScheduled = true;
QTimer::singleShot(0, this, QOverload<>::of(&QWidget::update)); QMetaObject::invokeMethod(this, QOverload<>::of(&QWidget::update), Qt::QueuedConnection);
} }
void HighlightScrollBarOverlay::paintEvent(QPaintEvent *paintEvent) void HighlightScrollBarOverlay::paintEvent(QPaintEvent *paintEvent)

View File

@@ -154,7 +154,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QStatusBar> #include <QStatusBar>
#include <QTimer>
using namespace Core::Internal; using namespace Core::Internal;
using namespace ExtensionSystem; using namespace ExtensionSystem;
@@ -834,7 +833,7 @@ public:
{ {
QTC_ASSERT(watched == m_widget, return false); QTC_ASSERT(watched == m_widget, return false);
if (event->type() == QEvent::Show) if (event->type() == QEvent::Show)
QTimer::singleShot(0, this, &ScreenShooter::helper); QMetaObject::invokeMethod(this, &ScreenShooter::helper, Qt::QueuedConnection);
return false; return false;
} }

View File

@@ -46,7 +46,6 @@
#include <QMutexLocker> #include <QMutexLocker>
#include <QProcess> #include <QProcess>
#include <QRegularExpression> #include <QRegularExpression>
#include <QTimer>
#include <QWaitCondition> #include <QWaitCondition>
using namespace Utils; using namespace Utils;
@@ -147,7 +146,7 @@ Utils::FilePath SpotlightIterator::filePath() const
void SpotlightIterator::scheduleKillProcess() void SpotlightIterator::scheduleKillProcess()
{ {
QTimer::singleShot(0, m_process.get(), [this] { killProcess(); }); QMetaObject::invokeMethod(m_process.get(), [this] { killProcess(); }, Qt::QueuedConnection);
} }
void SpotlightIterator::killProcess() void SpotlightIterator::killProcess()

View File

@@ -90,7 +90,6 @@
#include <QSettings> #include <QSettings>
#include <QStatusBar> #include <QStatusBar>
#include <QStyleFactory> #include <QStyleFactory>
#include <QTimer>
#include <QToolButton> #include <QToolButton>
#include <QUrl> #include <QUrl>
@@ -320,8 +319,8 @@ void MainWindow::extensionsInitialized()
emit m_coreImpl->coreAboutToOpen(); emit m_coreImpl->coreAboutToOpen();
// Delay restoreWindowState, since it is overridden by LayoutRequest event // Delay restoreWindowState, since it is overridden by LayoutRequest event
QTimer::singleShot(0, this, &MainWindow::restoreWindowState); QMetaObject::invokeMethod(this, &MainWindow::restoreWindowState, Qt::QueuedConnection);
QTimer::singleShot(0, m_coreImpl, &ICore::coreOpened); QMetaObject::invokeMethod(m_coreImpl, &ICore::coreOpened, Qt::QueuedConnection);
} }
static void setRestart(bool restart) static void setRestart(bool restart)
@@ -930,7 +929,7 @@ void MainWindow::exit()
// since on close we are going to delete everything // since on close we are going to delete everything
// so to prevent the deleting of that object we // so to prevent the deleting of that object we
// just append it // just append it
QTimer::singleShot(0, this, &QWidget::close); QMetaObject::invokeMethod(this, &QWidget::close, Qt::QueuedConnection);
} }
void MainWindow::openFileWith() void MainWindow::openFileWith()

View File

@@ -39,7 +39,6 @@
#include <QMenuBar> #include <QMenuBar>
#include <QPointer> #include <QPointer>
#include <QRegularExpression> #include <QRegularExpression>
#include <QTimer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Utils::QHashValueType qHash(const QPointer<QAction> &p, Utils::QHashValueType seed) Utils::QHashValueType qHash(const QPointer<QAction> &p, Utils::QHashValueType seed)
@@ -84,10 +83,10 @@ void MenuBarFilter::accept(LocatorFilterEntry selection, QString *newText,
Q_UNUSED(selectionStart) Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength) Q_UNUSED(selectionLength)
if (auto action = selection.internalData.value<QPointer<QAction>>()) { if (auto action = selection.internalData.value<QPointer<QAction>>()) {
QTimer::singleShot(0, action, [action] { QMetaObject::invokeMethod(action, [action] {
if (action->isEnabled()) if (action->isEnabled())
action->trigger(); action->trigger();
}); }, Qt::QueuedConnection);
} }
} }

View File

@@ -33,7 +33,6 @@
#include <QFont> #include <QFont>
#include <QThread> #include <QThread>
#include <QTime> #include <QTime>
#include <QTimer>
/*! /*!
\class Core::MessageManager \class Core::MessageManager
@@ -90,7 +89,9 @@ static void write(const QString &text, Flag flags)
if (QThread::currentThread() == m_instance->thread()) if (QThread::currentThread() == m_instance->thread())
doWrite(text, flags); doWrite(text, flags);
else else
QTimer::singleShot(0, m_instance, [text, flags] { doWrite(text, flags); }); QMetaObject::invokeMethod(m_instance, [text, flags] {
doWrite(text, flags);
}, Qt::QueuedConnection);
} }
/*! /*!

View File

@@ -343,7 +343,7 @@ bool ProgressManagerPrivate::eventFilter(QObject *obj, QEvent *event)
progress = m_taskList.last(); progress = m_taskList.last();
// don't send signal directly from an event filter, event filters should // don't send signal directly from an event filter, event filters should
// do as little a possible // do as little a possible
QTimer::singleShot(0, progress, &FutureProgress::clicked); QMetaObject::invokeMethod(progress, &FutureProgress::clicked, Qt::QueuedConnection);
event->accept(); event->accept();
return true; return true;
} }

View File

@@ -80,7 +80,7 @@ ProcessReaper::ProcessReaper(QProcess *p, int timeoutMs) : m_process(p)
m_iterationTimer.setSingleShot(true); m_iterationTimer.setSingleShot(true);
connect(&m_iterationTimer, &QTimer::timeout, this, &ProcessReaper::nextIteration); connect(&m_iterationTimer, &QTimer::timeout, this, &ProcessReaper::nextIteration);
QTimer::singleShot(0, this, &ProcessReaper::nextIteration); QMetaObject::invokeMethod(this, &ProcessReaper::nextIteration, Qt::QueuedConnection);
} }
ProcessReaper::~ProcessReaper() ProcessReaper::~ProcessReaper()

View File

@@ -29,7 +29,6 @@
#include <QFile> #include <QFile>
#include <QObject> #include <QObject>
#include <QTimer>
#include <QCoreApplication> #include <QCoreApplication>
#include <cstdio> #include <cstdio>
@@ -109,7 +108,7 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
case ArgumentsCollector::RequestTypePaste: { case ArgumentsCollector::RequestTypePaste: {
PasteReceiver pr(argsCollector.protocol(), argsCollector.inputFilePath()); PasteReceiver pr(argsCollector.protocol(), argsCollector.inputFilePath());
QTimer::singleShot(0, &pr, &PasteReceiver::paste); QMetaObject::invokeMethod(&pr, &PasteReceiver::paste, Qt::QueuedConnection);
return app.exec(); return app.exec();
} }
} }

View File

@@ -27,7 +27,6 @@
#include "cppeditorconstants.h" #include "cppeditorconstants.h"
#include <QTimer>
#include <QToolButton> #include <QToolButton>
#include <cpptools/cpptoolssettings.h> #include <cpptools/cpptoolssettings.h>
@@ -142,10 +141,8 @@ static InfoBarEntry createMinimizableInfo(const Id &id,
// The minimizer() might delete the "Minimize" button immediately and as // The minimizer() might delete the "Minimize" button immediately and as
// result invalid reads will happen in QToolButton::mouseReleaseEvent(). // result invalid reads will happen in QToolButton::mouseReleaseEvent().
// Avoid this by running the minimizer in the next event loop iteration. // Avoid this by running the minimizer in the next event loop iteration.
info.setCustomButtonInfo(MinimizableInfoBars::tr("Minimize"), [=](){ info.setCustomButtonInfo(MinimizableInfoBars::tr("Minimize"), [minimizer] {
QTimer::singleShot(0, [=] { QMetaObject::invokeMethod(settings(), [minimizer] { minimizer(); }, Qt::QueuedConnection);
minimizer();
});
}); });
return info; return info;