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)
return;
m_updateRequested = true;
QTimer::singleShot(0, this, &ActionContainerPrivate::update);
QMetaObject::invokeMethod(this, &ActionContainerPrivate::update, Qt::QueuedConnection);
}
void ActionContainerPrivate::update()

View File

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

View File

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

View File

@@ -1320,7 +1320,7 @@ void DocumentManager::checkForReload()
d->m_blockActivated = false;
// 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();
}

View File

@@ -1466,7 +1466,7 @@ void EditorManagerPrivate::addEditor(IEditor *editor)
emit m_instance->documentOpened(document);
}
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)
@@ -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.
// Only afterwards the focus is shifted to the widget that received the click.
d->m_scheduledCurrentEditor = editor;
QTimer::singleShot(0, d, &EditorManagerPrivate::setCurrentEditorFromContextChange);
QMetaObject::invokeMethod(d, &EditorManagerPrivate::setCurrentEditorFromContextChange,
Qt::QueuedConnection);
} else {
updateActions();
}

View File

@@ -221,7 +221,9 @@ void FancyTabBar::mousePressEvent(QMouseEvent *event)
m_currentIndex = index;
update();
// 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 <QPropertyAnimation>
#include <QTimer>
QT_BEGIN_NAMESPACE
class QPainter;

View File

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

View File

@@ -31,7 +31,6 @@
#include <QScrollBar>
#include <QStyle>
#include <QStyleOptionSlider>
#include <QTimer>
using namespace Utils;
@@ -105,7 +104,7 @@ void HighlightScrollBarOverlay::scheduleUpdate()
return;
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)

View File

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

View File

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

View File

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

View File

@@ -39,7 +39,6 @@
#include <QMenuBar>
#include <QPointer>
#include <QRegularExpression>
#include <QTimer>
QT_BEGIN_NAMESPACE
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(selectionLength)
if (auto action = selection.internalData.value<QPointer<QAction>>()) {
QTimer::singleShot(0, action, [action] {
QMetaObject::invokeMethod(action, [action] {
if (action->isEnabled())
action->trigger();
});
}, Qt::QueuedConnection);
}
}

View File

@@ -33,7 +33,6 @@
#include <QFont>
#include <QThread>
#include <QTime>
#include <QTimer>
/*!
\class Core::MessageManager
@@ -90,7 +89,9 @@ static void write(const QString &text, Flag flags)
if (QThread::currentThread() == m_instance->thread())
doWrite(text, flags);
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();
// don't send signal directly from an event filter, event filters should
// do as little a possible
QTimer::singleShot(0, progress, &FutureProgress::clicked);
QMetaObject::invokeMethod(progress, &FutureProgress::clicked, Qt::QueuedConnection);
event->accept();
return true;
}

View File

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

View File

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

View File

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