TextEditor: Use invokeMethod instead of singleShot timer with 0 delay

Use QCoreApplication::instance() as a context object for the
IAssistProposal deleter.

Change-Id: Idf8cd1955dca146a500da1ea036298455c8a5da1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-02-01 14:57:40 +01:00
parent 2081038953
commit e3ae92bc5f
4 changed files with 14 additions and 11 deletions

View File

@@ -254,7 +254,9 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
case IAssistProvider::Asynchronous: { case IAssistProvider::Asynchronous: {
processor->setAsyncCompletionAvailableHandler([this, reason, processor](IAssistProposal *newProposal) { processor->setAsyncCompletionAvailableHandler([this, reason, processor](IAssistProposal *newProposal) {
// do not delete this processor directly since this function is called from within the processor // do not delete this processor directly since this function is called from within the processor
QTimer::singleShot(0, [processor]() { delete processor; }); QMetaObject::invokeMethod(QCoreApplication::instance(), [processor]() {
delete processor;
}, Qt::QueuedConnection);
if (processor != m_asyncProcessor) if (processor != m_asyncProcessor)
return; return;
invalidateCurrentRequestData(); invalidateCurrentRequestData();

View File

@@ -34,7 +34,6 @@
#include <QTextDocument> #include <QTextDocument>
#include <QPointer> #include <QPointer>
#include <qtimer.h>
#include <cmath> #include <cmath>
@@ -310,7 +309,8 @@ void SyntaxHighlighter::setDocument(QTextDocument *doc)
if (!d->noAutomaticHighlighting) { if (!d->noAutomaticHighlighting) {
connect(d->doc, &QTextDocument::contentsChange, this, &SyntaxHighlighter::reformatBlocks); connect(d->doc, &QTextDocument::contentsChange, this, &SyntaxHighlighter::reformatBlocks);
d->rehighlightPending = true; d->rehighlightPending = true;
QTimer::singleShot(0, this, &SyntaxHighlighter::delayedRehighlight); QMetaObject::invokeMethod(this, &SyntaxHighlighter::delayedRehighlight,
Qt::QueuedConnection);
} }
d->foldValidator.setup(qobject_cast<TextDocumentLayout *>(doc->documentLayout())); d->foldValidator.setup(qobject_cast<TextDocumentLayout *>(doc->documentLayout()));
} }

View File

@@ -51,7 +51,6 @@
#include <QScrollBar> #include <QScrollBar>
#include <QStringList> #include <QStringList>
#include <QTextCodec> #include <QTextCodec>
#include <QTimer>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -1014,7 +1013,8 @@ void TextDocument::removeMarkFromMarksCache(TextMark *mark)
auto scheduleLayoutUpdate = [documentLayout](){ auto scheduleLayoutUpdate = [documentLayout](){
// make sure all destructors that may directly or indirectly call this function are // make sure all destructors that may directly or indirectly call this function are
// completed before updating. // completed before updating.
QTimer::singleShot(0, documentLayout, &QPlainTextDocumentLayout::requestUpdate); QMetaObject::invokeMethod(documentLayout, &QPlainTextDocumentLayout::requestUpdate,
Qt::QueuedConnection);
}; };
if (d->m_marksCache.isEmpty()) { if (d->m_marksCache.isEmpty()) {

View File

@@ -177,12 +177,12 @@ public:
connect(m_editor, &QPlainTextEdit::cursorPositionChanged, this, &LineColumnLabel::update); connect(m_editor, &QPlainTextEdit::cursorPositionChanged, this, &LineColumnLabel::update);
connect(this, &FixedSizeClickLabel::clicked, ActionManager::instance(), [this] { connect(this, &FixedSizeClickLabel::clicked, ActionManager::instance(), [this] {
emit m_editor->activateEditor(EditorManager::IgnoreNavigationHistory); emit m_editor->activateEditor(EditorManager::IgnoreNavigationHistory);
QTimer::singleShot(0, ActionManager::instance(), [] { QMetaObject::invokeMethod(ActionManager::instance(), [] {
if (Command *cmd = ActionManager::command(Core::Constants::GOTO)) { if (Command *cmd = ActionManager::command(Core::Constants::GOTO)) {
if (QAction *act = cmd->action()) if (QAction *act = cmd->action())
act->trigger(); act->trigger();
} }
}); }, Qt::QueuedConnection);
}); });
} }
@@ -5421,7 +5421,7 @@ void TextEditorWidgetPrivate::updateHighlights()
} }
if (m_highlightAutoComplete && !m_autoCompleteHighlightPos.isEmpty()) { if (m_highlightAutoComplete && !m_autoCompleteHighlightPos.isEmpty()) {
QTimer::singleShot(0, this, [this](){ QMetaObject::invokeMethod(this, [this]() {
const QTextCursor &cursor = q->textCursor(); const QTextCursor &cursor = q->textCursor();
auto popAutoCompletion = [&]() { auto popAutoCompletion = [&]() {
return !m_autoCompleteHighlightPos.isEmpty() return !m_autoCompleteHighlightPos.isEmpty()
@@ -5432,7 +5432,7 @@ void TextEditorWidgetPrivate::updateHighlights()
m_autoCompleteHighlightPos.pop_back(); m_autoCompleteHighlightPos.pop_back();
updateAutoCompleteHighlight(); updateAutoCompleteHighlight();
} }
}); }, Qt::QueuedConnection);
} }
updateCurrentLineHighlight(); updateCurrentLineHighlight();
@@ -6287,7 +6287,7 @@ void TextEditorWidgetPrivate::requestUpdateLink(QMouseEvent *e)
if (onText) { if (onText) {
m_pendingLinkUpdate = cursor; m_pendingLinkUpdate = cursor;
QTimer::singleShot(0, this, &TextEditorWidgetPrivate::updateLink); QMetaObject::invokeMethod(this, &TextEditorWidgetPrivate::updateLink, Qt::QueuedConnection);
return; return;
} }
@@ -6444,7 +6444,8 @@ void TextEditorWidgetPrivate::scheduleUpdateHighlightScrollBar()
return; return;
m_scrollBarUpdateScheduled = true; m_scrollBarUpdateScheduled = true;
QTimer::singleShot(0, this, &TextEditorWidgetPrivate::updateHighlightScrollBarNow); QMetaObject::invokeMethod(this, &TextEditorWidgetPrivate::updateHighlightScrollBarNow,
Qt::QueuedConnection);
} }
Highlight::Priority textMarkPrioToScrollBarPrio(const TextMark::Priority &prio) Highlight::Priority textMarkPrioToScrollBarPrio(const TextMark::Priority &prio)