From 018efa8e62a901ebb47c6227e83e487eb09c76e6 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Mon, 11 Feb 2019 15:55:47 +0100 Subject: [PATCH] ClangTools: Make use of TreeModels' levels Change-Id: I34ed24a09bac900ca0eca4c6022ef98da1b0a58f Reviewed-by: hjk --- src/plugins/clangtools/clangtidyclazytool.cpp | 4 ++-- src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp | 11 +++++------ src/plugins/clangtools/clangtoolsdiagnosticmodel.h | 6 +++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plugins/clangtools/clangtidyclazytool.cpp b/src/plugins/clangtools/clangtidyclazytool.cpp index e4377fa681b..3453975a9c5 100644 --- a/src/plugins/clangtools/clangtidyclazytool.cpp +++ b/src/plugins/clangtools/clangtidyclazytool.cpp @@ -300,8 +300,8 @@ ClangTidyClazyTool::ClangTidyClazyTool() }); connect(m_applyFixitsButton, &QToolButton::clicked, [this]() { QVector diagnosticItems; - m_diagnosticModel->rootItem()->forChildrenAtLevel(2, [&](TreeItem *item){ - diagnosticItems += static_cast(item); + m_diagnosticModel->forItemsAtLevel<2>([&](DiagnosticItem *item){ + diagnosticItems += item; }); ApplyFixIts(diagnosticItems).apply(m_diagnosticModel); diff --git a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp index ec6195481e0..c52f670e703 100644 --- a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp +++ b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp @@ -81,7 +81,7 @@ private: }; ClangToolsDiagnosticModel::ClangToolsDiagnosticModel(QObject *parent) - : Utils::TreeModel<>(parent) + : ClangToolsDiagnosticModelBase(parent) , m_filesWatcher(std::make_unique()) { setHeader({tr("Diagnostic")}); @@ -146,7 +146,7 @@ void ClangToolsDiagnosticModel::clear() m_filePathToItem.clear(); m_diagnostics.clear(); clearAndSetupCache(); - Utils::TreeModel<>::clear(); + ClangToolsDiagnosticModelBase::clear(); } void ClangToolsDiagnosticModel::updateItems(const DiagnosticItem *changedItem) @@ -174,10 +174,9 @@ void ClangToolsDiagnosticModel::clearAndSetupCache() void ClangToolsDiagnosticModel::onFileChanged(const QString &path) { - rootItem()->forChildrenAtLevel(2, [&](Utils::TreeItem *item){ - auto diagnosticItem = static_cast(item); - if (diagnosticItem->diagnostic().location.filePath == path) - diagnosticItem->setFixItStatus(FixitStatus::Invalidated); + forItemsAtLevel<2>([&](DiagnosticItem *item){ + if (item->diagnostic().location.filePath == path) + item->setFixItStatus(FixitStatus::Invalidated); }); removeWatchedPath(path); } diff --git a/src/plugins/clangtools/clangtoolsdiagnosticmodel.h b/src/plugins/clangtools/clangtoolsdiagnosticmodel.h index a8c4dcd011a..c0d64664bf2 100644 --- a/src/plugins/clangtools/clangtoolsdiagnosticmodel.h +++ b/src/plugins/clangtools/clangtoolsdiagnosticmodel.h @@ -100,7 +100,11 @@ private: ClangToolsDiagnosticModel *m_parentModel = nullptr; }; -class ClangToolsDiagnosticModel : public Utils::TreeModel<> +class ExplainingStepItem; + +using ClangToolsDiagnosticModelBase + = Utils::TreeModel; +class ClangToolsDiagnosticModel : public ClangToolsDiagnosticModelBase { Q_OBJECT