ClangTools: Make use of TreeModels' levels

Change-Id: I34ed24a09bac900ca0eca4c6022ef98da1b0a58f
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Nikolai Kosjar
2019-02-11 15:55:47 +01:00
parent baa6b7eab3
commit 018efa8e62
3 changed files with 12 additions and 9 deletions

View File

@@ -300,8 +300,8 @@ ClangTidyClazyTool::ClangTidyClazyTool()
}); });
connect(m_applyFixitsButton, &QToolButton::clicked, [this]() { connect(m_applyFixitsButton, &QToolButton::clicked, [this]() {
QVector<DiagnosticItem *> diagnosticItems; QVector<DiagnosticItem *> diagnosticItems;
m_diagnosticModel->rootItem()->forChildrenAtLevel(2, [&](TreeItem *item){ m_diagnosticModel->forItemsAtLevel<2>([&](DiagnosticItem *item){
diagnosticItems += static_cast<DiagnosticItem *>(item); diagnosticItems += item;
}); });
ApplyFixIts(diagnosticItems).apply(m_diagnosticModel); ApplyFixIts(diagnosticItems).apply(m_diagnosticModel);

View File

@@ -81,7 +81,7 @@ private:
}; };
ClangToolsDiagnosticModel::ClangToolsDiagnosticModel(QObject *parent) ClangToolsDiagnosticModel::ClangToolsDiagnosticModel(QObject *parent)
: Utils::TreeModel<>(parent) : ClangToolsDiagnosticModelBase(parent)
, m_filesWatcher(std::make_unique<QFileSystemWatcher>()) , m_filesWatcher(std::make_unique<QFileSystemWatcher>())
{ {
setHeader({tr("Diagnostic")}); setHeader({tr("Diagnostic")});
@@ -146,7 +146,7 @@ void ClangToolsDiagnosticModel::clear()
m_filePathToItem.clear(); m_filePathToItem.clear();
m_diagnostics.clear(); m_diagnostics.clear();
clearAndSetupCache(); clearAndSetupCache();
Utils::TreeModel<>::clear(); ClangToolsDiagnosticModelBase::clear();
} }
void ClangToolsDiagnosticModel::updateItems(const DiagnosticItem *changedItem) void ClangToolsDiagnosticModel::updateItems(const DiagnosticItem *changedItem)
@@ -174,10 +174,9 @@ void ClangToolsDiagnosticModel::clearAndSetupCache()
void ClangToolsDiagnosticModel::onFileChanged(const QString &path) void ClangToolsDiagnosticModel::onFileChanged(const QString &path)
{ {
rootItem()->forChildrenAtLevel(2, [&](Utils::TreeItem *item){ forItemsAtLevel<2>([&](DiagnosticItem *item){
auto diagnosticItem = static_cast<DiagnosticItem *>(item); if (item->diagnostic().location.filePath == path)
if (diagnosticItem->diagnostic().location.filePath == path) item->setFixItStatus(FixitStatus::Invalidated);
diagnosticItem->setFixItStatus(FixitStatus::Invalidated);
}); });
removeWatchedPath(path); removeWatchedPath(path);
} }

View File

@@ -100,7 +100,11 @@ private:
ClangToolsDiagnosticModel *m_parentModel = nullptr; ClangToolsDiagnosticModel *m_parentModel = nullptr;
}; };
class ClangToolsDiagnosticModel : public Utils::TreeModel<> class ExplainingStepItem;
using ClangToolsDiagnosticModelBase
= Utils::TreeModel<Utils::TreeItem, FilePathItem, DiagnosticItem, ExplainingStepItem>;
class ClangToolsDiagnosticModel : public ClangToolsDiagnosticModelBase
{ {
Q_OBJECT Q_OBJECT