Don't access static functions/fields via instance

Courtesy of readability-static-accessed-through-instance

Amends: b2a766a79a

Round #2: This time done with Qt Creator's Analyzer, which
found other occurences than run-clang-tidy.py

Change-Id: I479e280c7abcf2d24baccbb0af69ae4bda05198e
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Alessandro Portale
2020-11-27 13:12:23 +01:00
parent 0cc5ee12c5
commit a3857a996a
35 changed files with 52 additions and 56 deletions

View File

@@ -47,7 +47,7 @@ QString Theme::name() const
QString Theme::translatedName() const
{
return m_data ? QCoreApplication::instance()->translate("Theme", m_data->name().toUtf8().constData()) : QString();
return m_data ? QCoreApplication::translate("Theme", m_data->name().toUtf8().constData()) : QString();
}
bool Theme::isReadOnly() const

View File

@@ -288,7 +288,7 @@ bool ConnectionClient::waitForConnected()
return isConnected;
else {
QThread::msleep(30);
QCoreApplication::instance()->processEvents();
QCoreApplication::processEvents();
}
}

View File

@@ -114,7 +114,7 @@ void TestCodeParser::syncTestFrameworks(const QList<ITestFramework *> &framework
// there's a running parse
m_fullUpdatePostponed = m_partialUpdatePostponed = false;
m_postponedFiles.clear();
Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE);
Core::ProgressManager::cancelTasks(Constants::TASK_PARSE);
}
m_testCodeParsers.clear();
qCDebug(LOG) << "Setting" << frameworks << "as current parsers";
@@ -206,7 +206,7 @@ void TestCodeParser::onStartupProjectChanged(Project *project)
{
if (m_parserState == FullParse || m_parserState == PartialParse) {
qCDebug(LOG) << "Canceling scanForTest (startup project changed)";
Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE);
Core::ProgressManager::cancelTasks(Constants::TASK_PARSE);
}
emit aboutToPerformFullParse();
if (project)
@@ -271,7 +271,7 @@ bool TestCodeParser::postponed(const QStringList &fileList)
m_postponedFiles.clear();
m_fullUpdatePostponed = true;
qCDebug(LOG) << "Canceling scanForTest (full parse triggered while running a scan)";
Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE);
Core::ProgressManager::cancelTasks(Constants::TASK_PARSE);
} else {
// partial parse triggered, but full parse is postponed already, ignoring this
if (m_fullUpdatePostponed)
@@ -393,7 +393,7 @@ void TestCodeParser::onTaskStarted(Utils::Id type)
m_partialUpdatePostponed = !m_fullUpdatePostponed;
qCDebug(LOG) << "Canceling scan for test (CppModelParsing started)";
parsingHasFailed = true;
Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE);
Core::ProgressManager::cancelTasks(Constants::TASK_PARSE);
}
}
}

View File

@@ -55,7 +55,7 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
this, &ConfigurationDialog::updateDocumentation);
// Set palette and font according to settings
const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::instance()->fontSettings();
const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::fontSettings();
const QTextCharFormat tf = fs.toTextCharFormat(TextEditor::C_TEXT);
const QTextCharFormat selectionFormat = fs.toTextCharFormat(TextEditor::C_SELECTION);

View File

@@ -42,7 +42,7 @@ namespace Internal {
ConfigurationSyntaxHighlighter::ConfigurationSyntaxHighlighter(QTextDocument *parent) :
QSyntaxHighlighter(parent)
{
const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::instance()->fontSettings();
const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::fontSettings();
m_formatKeyword = fs.toTextCharFormat(TextEditor::C_FIELD);
m_formatComment = fs.toTextCharFormat(TextEditor::C_COMMENT);

View File

@@ -1469,7 +1469,7 @@ void BinEditorWidget::zoomF(float delta)
else if (step < 0 && step > -1)
step = -1;
const int newZoom = TextEditor::TextEditorSettings::instance()->increaseFontZoom(int(step));
const int newZoom = TextEditor::TextEditorSettings::increaseFontZoom(int(step));
showZoomIndicator(this, newZoom);
}

View File

@@ -220,7 +220,7 @@ void ClangAssistProposalItem::apply(TextDocumentManipulatorInterface &manipulato
textToBeInserted.chop(2);
} else if (!ccr.text.isEmpty()) {
const CompletionSettings &completionSettings =
TextEditorSettings::instance()->completionSettings();
TextEditorSettings::completionSettings();
const bool autoInsertBrackets = completionSettings.m_autoInsertBrackets;
if (autoInsertBrackets &&

View File

@@ -156,7 +156,7 @@ void addWarningSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diag
QTextDocument *textDocument,
QList<QTextEdit::ExtraSelection> &extraSelections)
{
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const auto fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat warningFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
@@ -169,7 +169,7 @@ void addErrorSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagno
QTextDocument *textDocument,
QList<QTextEdit::ExtraSelection> &extraSelections)
{
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const auto fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
QTextCharFormat errorContextFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR_CONTEXT);

View File

@@ -570,7 +570,7 @@ void FancyTabWidget::paintEvent(QPaintEvent *event)
QPainter painter(this);
QRect rect = m_selectionWidget->rect().adjusted(0, 0, 1, 0);
rect = style()->visualRect(layoutDirection(), geometry(), rect);
rect = QStyle::visualRect(layoutDirection(), geometry(), rect);
const QRectF boderRect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
if (creatorTheme()->flag(Theme::FlatToolBars)) {

View File

@@ -122,7 +122,7 @@ namespace Core {
*/
IMode::IMode(QObject *parent) : IContext(parent)
{
ModeManager::instance()->addMode(this);
ModeManager::addMode(this);
}
/*!
@@ -130,7 +130,7 @@ IMode::IMode(QObject *parent) : IContext(parent)
*/
IMode::~IMode()
{
ModeManager::instance()->removeMode(this);
ModeManager::removeMode(this);
}
void IMode::setEnabled(bool enabled)

View File

@@ -71,7 +71,7 @@ QString AbstractEditorSupport::licenseTemplate(const QString &file, const QStrin
bool AbstractEditorSupport::usePragmaOnce()
{
return Internal::CppToolsPlugin::instance()->usePragmaOnce();
return Internal::CppToolsPlugin::usePragmaOnce();
}
} // namespace CppTools

View File

@@ -55,7 +55,7 @@ QList<QTextEdit::ExtraSelection> toTextEditorSelections(
const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics,
QTextDocument *textDocument)
{
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat warningFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);

View File

@@ -244,7 +244,7 @@ QStringList highlightExceptionCode(int lineNumber, const QString &filePath, cons
const QList<IEditor *> editors = DocumentModel::editorsForFilePath(
Utils::FilePath::fromString(filePath));
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
for (IEditor *editor : editors) {

View File

@@ -106,10 +106,8 @@ bool LogChangeWidget::init(const QString &repository, const QString &commit, Log
return false;
if (m_model->rowCount() > 0)
return true;
if (!(flags & Silent)) {
VcsOutputWindow::appendError(
GitClient::instance()->msgNoCommits(flags & IncludeRemotes));
}
if (!(flags & Silent))
VcsOutputWindow::appendError(GitClient::msgNoCommits(flags & IncludeRemotes));
return false;
}

View File

@@ -277,7 +277,7 @@ void GlslEditorWidget::updateDocumentNow()
CreateRanges createRanges(document(), doc);
createRanges(ast);
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat warningFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);

View File

@@ -436,7 +436,7 @@ void SimulatorControlPrivate::startSimulator(QFutureInterface<SimulatorControl::
auto start = chrono::high_resolution_clock::now();
while (simInfo.isShuttingDown() && !checkForTimeout(start, simulatorStartTimeout)) {
// Wait till the simulator shuts down, if doing so.
QThread::currentThread()->msleep(100);
QThread::msleep(100);
simInfo = deviceInfo(simUdid);
}

View File

@@ -103,7 +103,7 @@ static QTextEdit::ExtraSelection toDiagnosticsSelections(const Diagnostic &diagn
cursor.setPosition(diagnostic.range().end().toPositionInDocument(textDocument),
QTextCursor::KeepAnchor);
const FontSettings &fontSettings = TextEditorSettings::instance()->fontSettings();
const FontSettings &fontSettings = TextEditorSettings::fontSettings();
const DiagnosticSeverity severity = diagnostic.severity().value_or(DiagnosticSeverity::Warning);
const TextStyle style = severity == DiagnosticSeverity::Error ? C_ERROR : C_WARNING;

View File

@@ -97,7 +97,7 @@ bool TextEditorMacroHandler::executeEvent(const MacroEvent &macroEvent)
macroEvent.value(TEXT).toString(),
macroEvent.value(AUTOREP).toBool(),
macroEvent.value(COUNT).toInt());
QApplication::instance()->sendEvent(m_currentEditor->widget(), &keyEvent);
QCoreApplication::sendEvent(m_currentEditor->widget(), &keyEvent);
return true;
}

View File

@@ -290,7 +290,7 @@ void ExtraCompilerPrivate::updateIssues()
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
selection.cursor = cursor;
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const auto fontSettings = TextEditor::TextEditorSettings::fontSettings();
selection.format = fontSettings.toTextCharFormat(issue.type == Task::Warning ?
TextEditor::C_WARNING : TextEditor::C_ERROR);
selection.format.setToolTip(issue.description());

View File

@@ -681,7 +681,7 @@ void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index)
{
const QStringList projectFiles = projectsInDirectory(index);
if (!projectFiles.isEmpty())
Core::ICore::instance()->openFiles(projectFiles);
Core::ICore::openFiles(projectFiles);
}
void FolderNavigationWidget::createNewFolder(const QModelIndex &parent)

View File

@@ -452,7 +452,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
}
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
ProjectExplorerPlugin::OpenProjectResult result
= ProjectExplorerPlugin::instance()->openProject(file.path());
= ProjectExplorerPlugin::openProject(file.path());
if (!result) {
errorMessage = result.errorMessage();
if (errorMessage.isEmpty()) {

View File

@@ -114,7 +114,7 @@ bool JsonWizardGenerator::formatFile(const JsonWizard *wizard, GeneratedFile *fi
if (TextEditorSettings::storageSettings().m_cleanWhitespace) {
QTextBlock block = doc.firstBlock();
while (block.isValid()) {
codeStylePrefs->currentTabSettings().removeTrailingWhitespace(cursor, block);
TabSettings::removeTrailingWhitespace(cursor, block);
block = block.next();
}
}

View File

@@ -274,7 +274,7 @@ void ProjectFileWizardExtension::applyCodeStyle(GeneratedFile *file) const
if (TextEditorSettings::storageSettings().m_cleanWhitespace) {
QTextBlock block = doc.firstBlock();
while (block.isValid()) {
codeStylePrefs->currentTabSettings().removeTrailingWhitespace(cursor, block);
TabSettings::removeTrailingWhitespace(cursor, block);
block = block.next();
}
}

View File

@@ -693,8 +693,8 @@ void NavigatorTreeModel::handleItemLibraryItemDrop(const QMimeData *mimeData, in
// Files are copied into the same directory as the current qml document
for (const auto &copyFile : copyFiles) {
QFileInfo fi(copyFile);
const QString targetFile = QmlDesignerPlugin::instance()->documentManager()
.currentFilePath().toFileInfo().dir().absoluteFilePath(fi.fileName());
const QString targetFile = DocumentManager::currentFilePath().toFileInfo().dir()
.absoluteFilePath(fi.fileName());
// We don't want to overwrite existing default files
if (!QFileInfo::exists(targetFile)) {
if (!QFile::copy(copyFile, targetFile))
@@ -717,7 +717,7 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
ModelNode targetNode(modelNodeForIndex(rowModelIndex));
const QString imageSource = QString::fromUtf8(mimeData->data("application/vnd.bauhaus.libraryresource")); // absolute path
const QString imagePath = QmlDesignerPlugin::instance()->documentManager().currentFilePath().toFileInfo().dir().relativeFilePath(imageSource); // relative to .ui.qml file
const QString imagePath = DocumentManager::currentFilePath().toFileInfo().dir().relativeFilePath(imageSource); // relative to .ui.qml file
ModelNode newModelNode;

View File

@@ -270,7 +270,7 @@ void TextEditorView::reformatFile()
QByteArray editorState = m_widget->textEditor()->saveState();
auto document =
qobject_cast<QmlJSEditor::QmlJSEditorDocument *>(Core::EditorManager::instance()->currentDocument());
qobject_cast<QmlJSEditor::QmlJSEditorDocument *>(Core::EditorManager::currentDocument());
/* Reformat document if we have a .ui.qml file */
if (document

View File

@@ -992,7 +992,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
m_rewriterView->model()->clearMetaInfoCache();
try {
Snapshot snapshot = m_rewriterView->textModifier()->qmljsSnapshot();
Snapshot snapshot = TextModifier::qmljsSnapshot();
QList<DocumentMessage> errors;
QList<DocumentMessage> warnings;

View File

@@ -209,7 +209,7 @@ static void appendExtraSelectionsForMessages(
sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.loc.length);
}
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const auto fontSettings = TextEditor::TextEditorSettings::fontSettings();
if (d.isWarning())
sel.format = fontSettings.toTextCharFormat(TextEditor::C_WARNING);

View File

@@ -404,7 +404,7 @@ protected:
length = end-begin;
}
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat format;
if (d.isWarning())
@@ -441,7 +441,7 @@ protected:
length = end-begin;
}
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat format;
if (d.severity == Severity::Warning

View File

@@ -255,10 +255,10 @@ void PixmapCacheModelTest::testConsistency()
break;
}
QString filename = details[model.tr("File")].toString();
QString filename = details[PixmapCacheModel::tr("File")].toString();
QVERIFY(filename == QString("dings.png") || filename == QString("blah.png"));
QVERIFY(details.contains(model.tr("Width")));
QVERIFY(details.contains(model.tr("Height")));
QVERIFY(details.contains(PixmapCacheModel::tr("Width")));
QVERIFY(details.contains(PixmapCacheModel::tr("Height")));
}
}

View File

@@ -48,13 +48,13 @@ void QmlProfilerAttachDialogTest::testAccessors()
ProjectExplorer::KitManager *kitManager = ProjectExplorer::KitManager::instance();
QVERIFY(kitManager);
ProjectExplorer::Kit * const newKit = kitManager->registerKit({}, "dings");
ProjectExplorer::Kit * const newKit = ProjectExplorer::KitManager::registerKit({}, "dings");
QVERIFY(newKit);
dialog.setKitId("dings");
QCOMPARE(dialog.kit(), newKit);
kitManager->deregisterKit(newKit);
ProjectExplorer::KitManager::deregisterKit(newKit);
}
} // namespace Internal

View File

@@ -46,7 +46,7 @@ void QmlProfilerToolTest::testAttachToWaitingApplication()
{
ProjectExplorer::KitManager *kitManager = ProjectExplorer::KitManager::instance();
QVERIFY(kitManager);
ProjectExplorer::Kit * const newKit = kitManager->registerKit({}, "fookit");
ProjectExplorer::Kit * const newKit = ProjectExplorer::KitManager::registerKit({}, "fookit");
QVERIFY(newKit);
QSettings *settings = Core::ICore::settings();
QVERIFY(settings);

View File

@@ -221,7 +221,7 @@ Kit *TestQtProjectImporter::createKit(void *directoryData) const
const DirectoryData *dd = static_cast<const DirectoryData *>(directoryData);
assert(dd->importPath == m_path);
if (KitManager::instance()->kit(dd->kit->id())) // known kit
if (KitManager::kit(dd->kit->id())) // known kit
return dd->kit;
// New temporary kit:

View File

@@ -6220,13 +6220,13 @@ void TextEditorWidget::zoomF(float delta)
else if (step < 0 && step > -1)
step = -1;
const int newZoom = TextEditorSettings::instance()->increaseFontZoom(int(step));
const int newZoom = TextEditorSettings::increaseFontZoom(int(step));
showZoomIndicator(this, newZoom);
}
void TextEditorWidget::zoomReset()
{
TextEditorSettings::instance()->resetFontZoom();
TextEditorSettings::resetFontZoom();
showZoomIndicator(this, 100);
}

View File

@@ -415,8 +415,7 @@ void tst_Differ::merge()
QFETCH(QList<Diff>, input);
QFETCH(QList<Diff>, expected);
Differ differ;
QList<Diff> result = differ.merge(input);
QList<Diff> result = Differ::merge(input);
QCOMPARE(result, expected);
}
@@ -651,8 +650,7 @@ void tst_Differ::cleanupSemantics()
QFETCH(QList<Diff>, input);
QFETCH(QList<Diff>, expected);
Differ differ;
QList<Diff> result = differ.cleanupSemantics(input);
QList<Diff> result = Differ::cleanupSemantics(input);
QCOMPARE(result, expected);
}
@@ -793,8 +791,7 @@ void tst_Differ::cleanupSemanticsLossless()
QFETCH(QList<Diff>, input);
QFETCH(QList<Diff>, expected);
Differ differ;
QList<Diff> result = differ.cleanupSemanticsLossless(input);
QList<Diff> result = Differ::cleanupSemanticsLossless(input);
QCOMPARE(result, expected);
}

View File

@@ -574,14 +574,15 @@ void tst_LanguageServerProtocol::jsonObject()
ErrorHierarchy errorHierarchy;
QVERIFY(!obj.check<int>(&errorHierarchy, "doesNotExist"));
ErrorHierarchy errorDoesNotExists;
errorDoesNotExists.setError(obj.errorString(QJsonValue::Double, QJsonValue::Undefined));
errorDoesNotExists.setError(
JsonTestObject::errorString(QJsonValue::Double, QJsonValue::Undefined));
errorDoesNotExists.prependMember("doesNotExist");
QCOMPARE(errorHierarchy, errorDoesNotExists);
errorHierarchy.clear();
QVERIFY(!obj.check<int>(&errorHierarchy, "bool"));
ErrorHierarchy errorWrongType;
errorWrongType.setError(obj.errorString(QJsonValue::Double, QJsonValue::Bool));
errorWrongType.setError(JsonTestObject::errorString(QJsonValue::Double, QJsonValue::Bool));
errorWrongType.prependMember("bool");
QCOMPARE(errorHierarchy, errorWrongType);
errorHierarchy.clear();