ClangTools: Hide file path items without diagnostics

...in case diagnostics are filtered out.

Change-Id: I8a78f8873577ca80fe5a3d4123f64a9432c0fb7f
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2019-02-06 14:22:09 +01:00
parent e25be3d5ee
commit 9cfc4a68db
5 changed files with 33 additions and 4 deletions

View File

@@ -471,6 +471,13 @@ QList<Diagnostic> ClangTidyClazyTool::read(const QString &filePath,
return readSerializedDiagnostics(filePath, projectRootDir, logFilePath, errorMessage); return readSerializedDiagnostics(filePath, projectRootDir, logFilePath, errorMessage);
} }
void ClangTidyClazyTool::onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics)
{
ClangTool::onNewDiagnosticsAvailable(diagnostics);
if (!m_diagnosticFilterModel->filterRegExp().pattern().isEmpty())
m_diagnosticFilterModel->invalidateFilter();
}
} // namespace Internal } // namespace Internal
} // namespace ClangTools } // namespace ClangTools

View File

@@ -58,6 +58,8 @@ public:
const QString &logFilePath, const QString &logFilePath,
QString *errorMessage) const final; QString *errorMessage) const final;
void onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics) override;
private: private:
void handleStateUpdate() final; void handleStateUpdate() final;

View File

@@ -62,7 +62,7 @@ public:
const QString &name() const; const QString &name() const;
void onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics); virtual void onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics);
signals: signals:
void finished(bool success); // For testing. void finished(bool success); // For testing.

View File

@@ -584,14 +584,32 @@ void DiagnosticFilterModel::addSuppressedDiagnostic(
invalidate(); invalidate();
} }
void DiagnosticFilterModel::invalidateFilter()
{
QSortFilterProxyModel::invalidateFilter();
}
bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow, bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const const QModelIndex &sourceParent) const
{ {
auto model = static_cast<ClangToolsDiagnosticModel *>(sourceModel()); auto model = static_cast<ClangToolsDiagnosticModel *>(sourceModel());
Utils::TreeItem *item = model->itemForIndex(sourceParent);
// FilePathItem - hide if no diagnostics match
if (!sourceParent.isValid()) {
const QModelIndex filePathIndex = model->index(sourceRow, 0);
const int rowCount = model->rowCount(filePathIndex);
if (rowCount == 0)
return true; // Children not yet added.
for (int row = 0; row < rowCount; ++row) {
if (filterAcceptsRow(row, filePathIndex))
return true;
}
return false;
}
// DiagnosticItem // DiagnosticItem
if (auto filePathItem = dynamic_cast<FilePathItem *>(item)) { Utils::TreeItem *parentItem = model->itemForIndex(sourceParent);
if (auto filePathItem = dynamic_cast<FilePathItem *>(parentItem)) {
auto diagnosticItem = dynamic_cast<DiagnosticItem *>(filePathItem->childAt(sourceRow)); auto diagnosticItem = dynamic_cast<DiagnosticItem *>(filePathItem->childAt(sourceRow));
QTC_ASSERT(diagnosticItem, return false); QTC_ASSERT(diagnosticItem, return false);
@@ -612,7 +630,7 @@ bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow,
return diag.description.contains(filterRegExp()); return diag.description.contains(filterRegExp());
} }
return true; return true; // ExplainingStepItem
} }
bool DiagnosticFilterModel::lessThan(const QModelIndex &l, const QModelIndex &r) const bool DiagnosticFilterModel::lessThan(const QModelIndex &l, const QModelIndex &r) const

View File

@@ -146,6 +146,8 @@ public:
void addSuppressedDiagnostic(const SuppressedDiagnostic &diag); void addSuppressedDiagnostic(const SuppressedDiagnostic &diag);
ProjectExplorer::Project *project() const { return m_project; } ProjectExplorer::Project *project() const { return m_project; }
void invalidateFilter();
private: private:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &l, const QModelIndex &r) const override; bool lessThan(const QModelIndex &l, const QModelIndex &r) const override;