Use typed syntax in calls to QMetaObject::invokeMethod

We do it wherever possible. Some places can't be fixed
since they still rely on dynamic introspection
(mainly QQuickItem cases).

Change-Id: Ia00b4a04d8b995c9a43b7bf2dbe76a60364bb8ca
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2020-11-11 16:34:39 +01:00
parent 3167d23a36
commit 6d5e302157
14 changed files with 36 additions and 35 deletions

View File

@@ -293,7 +293,8 @@ namespace ADS
if (QEvent::EnabledChange == event->type() && m_hideWhenDisabled) { if (QEvent::EnabledChange == event->type() && m_hideWhenDisabled) {
// force setVisible() call // force setVisible() call
// Calling setVisible() directly here doesn't work well when button is expected to be shown first time // Calling setVisible() directly here doesn't work well when button is expected to be shown first time
QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled())); const bool visible = isEnabled();
QMetaObject::invokeMethod(this, [this, visible] { setVisible(visible); }, Qt::QueuedConnection);
} }
return Super::event(event); return Super::event(event);
@@ -352,8 +353,9 @@ namespace ADS
break; break;
} }
} }
bool visible = (hasElidedTabTitle && (d->m_tabBar->count() > 1)); const bool visible = (hasElidedTabTitle && (d->m_tabBar->count() > 1));
QMetaObject::invokeMethod(d->m_tabsMenuButton, "setVisible", Qt::QueuedConnection, Q_ARG(bool, visible)); QMetaObject::invokeMethod(this, [this, visible] {
d->m_tabsMenuButton->setVisible(visible); }, Qt::QueuedConnection);
} }
d->m_menuOutdated = true; d->m_menuOutdated = true;
} }

View File

@@ -1250,8 +1250,7 @@ void ModelManagerInterface::maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document
doc->releaseSourceAndAST(); doc->releaseSourceAndAST();
// delegate actual queuing to the gui thread // delegate actual queuing to the gui thread
QMetaObject::invokeMethod(this, "queueCppQmlTypeUpdate", QMetaObject::invokeMethod(this, [=] { queueCppQmlTypeUpdate(doc, scan); });
Q_ARG(CPlusPlus::Document::Ptr, doc), Q_ARG(bool, scan));
} }
void ModelManagerInterface::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan) void ModelManagerInterface::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan)
@@ -1392,7 +1391,7 @@ void ModelManagerInterface::updateCppQmlTypes(
qmlModelManager->m_cppDeclarationFiles = newDeclarations; qmlModelManager->m_cppDeclarationFiles = newDeclarations;
if (hasNewInfo) if (hasNewInfo)
// one could get away with re-linking the cpp types... // one could get away with re-linking the cpp types...
QMetaObject::invokeMethod(qmlModelManager, "asyncReset"); QMetaObject::invokeMethod(qmlModelManager, &ModelManagerInterface::asyncReset);
} }
ModelManagerInterface::CppDataHash ModelManagerInterface::cppData() const ModelManagerInterface::CppDataHash ModelManagerInterface::cppData() const

View File

@@ -65,24 +65,20 @@ Utils::FileSystemWatcher *PluginDumper::pluginWatcher()
void PluginDumper::loadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info) void PluginDumper::loadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info)
{ {
// move to the owning thread // move to the owning thread
metaObject()->invokeMethod(this, "onLoadBuiltinTypes", metaObject()->invokeMethod(this, [=] { onLoadBuiltinTypes(info); });
Q_ARG(QmlJS::ModelManagerInterface::ProjectInfo, info));
} }
void PluginDumper::loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion) void PluginDumper::loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion)
{ {
// move to the owning thread // move to the owning thread
metaObject()->invokeMethod(this, "onLoadPluginTypes", metaObject()->invokeMethod(this, [=] { onLoadPluginTypes(libraryPath, importPath,
Q_ARG(QString, libraryPath), importUri, importVersion); });
Q_ARG(QString, importPath),
Q_ARG(QString, importUri),
Q_ARG(QString, importVersion));
} }
void PluginDumper::scheduleRedumpPlugins() void PluginDumper::scheduleRedumpPlugins()
{ {
// move to the owning thread // move to the owning thread
metaObject()->invokeMethod(this, "dumpAllPlugins", Qt::QueuedConnection); metaObject()->invokeMethod(this, &PluginDumper::dumpAllPlugins, Qt::QueuedConnection);
} }
void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info, bool force) void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info, bool force)

View File

@@ -107,11 +107,11 @@ public:
|| connection->connectionParameters() != sshParams) || connection->connectionParameters() != sshParams)
continue; continue;
if (connection->thread() != QThread::currentThread()) { auto currentThread = QThread::currentThread();
QMetaObject::invokeMethod(this, "switchToCallerThread", if (connection->thread() != currentThread) {
Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(this, [this, connection, currentThread] {
Q_ARG(SshConnection *, connection), switchToCallerThread(connection, currentThread);
Q_ARG(QObject *, QThread::currentThread())); }, Qt::BlockingQueuedConnection);
} }
m_unacquiredConnections.removeOne(c); m_unacquiredConnections.removeOne(c);

View File

@@ -1059,7 +1059,7 @@ void ClearCasePluginPrivate::setStatus(const QString &file, FileStatus::Status s
m_statusMap->insert(file, FileStatus(status, QFileInfo(file).permissions())); m_statusMap->insert(file, FileStatus(status, QFileInfo(file).permissions()));
if (update && currentState().currentFile() == file) if (update && currentState().currentFile() == file)
QMetaObject::invokeMethod(this, "updateStatusActions"); QMetaObject::invokeMethod(this, &ClearCasePluginPrivate::updateStatusActions);
} }
void ClearCasePluginPrivate::undoCheckOutCurrent() void ClearCasePluginPrivate::undoCheckOutCurrent()

View File

@@ -451,6 +451,9 @@ QTextCursor BaseTextFind::findOne(const QRegularExpression &expr,
if (!inScope(candidate.selectionStart(), candidate.selectionEnd())) if (!inScope(candidate.selectionStart(), candidate.selectionEnd()))
return candidate; return candidate;
bool inVerticalFindScope = false; bool inVerticalFindScope = false;
// This code relies on the fact, that we have to keep TextEditorWidget subclass
// inside d->m_plaineditor which is of QPlainTextEdit class. So we can't
// transform it into a typed version now, as it relies on a dynamic match.
QMetaObject::invokeMethod(d->m_plaineditor, "inFindScope", Qt::DirectConnection, QMetaObject::invokeMethod(d->m_plaineditor, "inFindScope", Qt::DirectConnection,
Q_RETURN_ARG(bool, inVerticalFindScope), Q_RETURN_ARG(bool, inVerticalFindScope),
Q_ARG(QTextCursor, candidate)); Q_ARG(QTextCursor, candidate));

View File

@@ -113,7 +113,8 @@ QList<OpenDocumentsFilter::Entry> OpenDocumentsFilter::editors() const
void OpenDocumentsFilter::refresh(QFutureInterface<void> &future) void OpenDocumentsFilter::refresh(QFutureInterface<void> &future)
{ {
Q_UNUSED(future) Q_UNUSED(future)
QMetaObject::invokeMethod(this, "refreshInternally", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(this, &OpenDocumentsFilter::refreshInternally,
Qt::BlockingQueuedConnection);
} }
void OpenDocumentsFilter::accept(LocatorFilterEntry selection, void OpenDocumentsFilter::accept(LocatorFilterEntry selection,

View File

@@ -108,7 +108,8 @@ QString StringTablePrivate::insert(const QString &string)
void StringTable::scheduleGC() void StringTable::scheduleGC()
{ {
QMetaObject::invokeMethod(&m_instance->m_gcCountDown, "start", Qt::QueuedConnection); QMetaObject::invokeMethod(&m_instance->m_gcCountDown, QOverload<>::of(&QTimer::start),
Qt::QueuedConnection);
} }
StringTable::StringTable() StringTable::StringTable()

View File

@@ -765,8 +765,7 @@ void GdbEngine::runCommand(const DebuggerCommand &command)
m_scheduledTestResponses.remove(token); m_scheduledTestResponses.remove(token);
showMessage(QString("FAKING TEST RESPONSE (TOKEN: %2, RESPONSE: %3)") showMessage(QString("FAKING TEST RESPONSE (TOKEN: %2, RESPONSE: %3)")
.arg(token).arg(buffer)); .arg(token).arg(buffer));
QMetaObject::invokeMethod(this, "handleResponse", QMetaObject::invokeMethod(this, [this, buffer] { handleResponse(buffer); });
Q_ARG(QString, buffer));
} else { } else {
m_gdbProc.write(cmd.function.toUtf8() + "\r\n"); m_gdbProc.write(cmd.function.toUtf8() + "\r\n");
if (command.flags & NeedsFlush) if (command.flags & NeedsFlush)

View File

@@ -531,8 +531,8 @@ void UvscEngine::doUpdateLocals(const UpdateParameters &params)
const bool partial = !params.partialVariable.isEmpty(); const bool partial = !params.partialVariable.isEmpty();
// This is a workaround to avoid a strange QVector index assertion // This is a workaround to avoid a strange QVector index assertion
// inside of the watch model. // inside of the watch model.
QMetaObject::invokeMethod(this, "handleUpdateLocals", Qt::QueuedConnection, QMetaObject::invokeMethod(this, [this, partial] { handleUpdateLocals(partial); },
Q_ARG(bool, partial)); Qt::QueuedConnection);
} }
void UvscEngine::updateAll() void UvscEngine::updateAll()

View File

@@ -180,8 +180,8 @@ QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFi
if (forceUpdate) { if (forceUpdate) {
QStringList indices; QStringList indices;
QMetaObject::invokeMethod(this, "allIndices", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(this, [this] { return allIndices(); },
Q_RETURN_ARG(QStringList, indices)); Qt::BlockingQueuedConnection, &indices);
m_mutex.lock(); // guard m_needsUpdate m_mutex.lock(); // guard m_needsUpdate
m_needsUpdate = false; m_needsUpdate = false;
m_mutex.unlock(); m_mutex.unlock();

View File

@@ -155,7 +155,7 @@ void SearchWidget::showEvent(QShowEvent *event)
connect(searchEngine, &QHelpSearchEngine::indexingFinished, this, connect(searchEngine, &QHelpSearchEngine::indexingFinished, this,
&SearchWidget::indexingFinished); &SearchWidget::indexingFinished);
QMetaObject::invokeMethod(&LocalHelpManager::helpEngine(), "setupFinished", QMetaObject::invokeMethod(&LocalHelpManager::helpEngine(), &QHelpEngine::setupFinished,
Qt::QueuedConnection); Qt::QueuedConnection);
} }
} }

View File

@@ -388,10 +388,8 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) : QWidget(parent
// QTimer::singleShot only posts directly onto the event loop if you use the SLOT("...") // QTimer::singleShot only posts directly onto the event loop if you use the SLOT("...")
// notation, so using a singleShot with a lambda would flicker // notation, so using a singleShot with a lambda would flicker
// QTimer::singleShot(0, this, [this, filePath]() { setCrumblePath(filePath); }); // QTimer::singleShot(0, this, [this, filePath]() { setCrumblePath(filePath); });
QMetaObject::invokeMethod(this, QMetaObject::invokeMethod(this, [this, filePath] { setCrumblePath(filePath); },
"setCrumblePath", Qt::QueuedConnection);
Qt::QueuedConnection,
Q_ARG(Utils::FilePath, filePath));
}); });
connect(m_crumbLabel, &Utils::FileCrumbLabel::pathClicked, [this](const Utils::FilePath &path) { connect(m_crumbLabel, &Utils::FileCrumbLabel::pathClicked, [this](const Utils::FilePath &path) {
const QModelIndex rootIndex = m_sortProxyModel->mapToSource(m_listView->rootIndex()); const QModelIndex rootIndex = m_sortProxyModel->mapToSource(m_listView->rootIndex());

View File

@@ -832,7 +832,8 @@ void GraphicsScene::addWarningItem(WarningItem *item)
if (!m_allWarnings.contains(item)) { if (!m_allWarnings.contains(item)) {
m_allWarnings << item; m_allWarnings << item;
if (!m_autoLayoutRunning && !m_initializing) if (!m_autoLayoutRunning && !m_initializing)
QMetaObject::invokeMethod(this, "warningVisibilityChanged", Qt::QueuedConnection, Q_ARG(int, 0)); QMetaObject::invokeMethod(this, [this] { warningVisibilityChanged(0); },
Qt::QueuedConnection);
} }
} }
@@ -841,7 +842,8 @@ void GraphicsScene::removeWarningItem(WarningItem *item)
m_allWarnings.removeAll(item); m_allWarnings.removeAll(item);
if (!m_autoLayoutRunning && !m_initializing) if (!m_autoLayoutRunning && !m_initializing)
QMetaObject::invokeMethod(this, "warningVisibilityChanged", Qt::QueuedConnection, Q_ARG(int, 0)); QMetaObject::invokeMethod(this, [this] { warningVisibilityChanged(0); },
Qt::QueuedConnection);
} }
void GraphicsScene::warningVisibilityChanged(int type, WarningItem *item) void GraphicsScene::warningVisibilityChanged(int type, WarningItem *item)