forked from qt-creator/qt-creator
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:
@@ -471,6 +471,13 @@ QList<Diagnostic> ClangTidyClazyTool::read(const QString &filePath,
|
||||
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 ClangTools
|
||||
|
||||
|
@@ -58,6 +58,8 @@ public:
|
||||
const QString &logFilePath,
|
||||
QString *errorMessage) const final;
|
||||
|
||||
void onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics) override;
|
||||
|
||||
private:
|
||||
void handleStateUpdate() final;
|
||||
|
||||
|
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
const QString &name() const;
|
||||
|
||||
void onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics);
|
||||
virtual void onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics);
|
||||
|
||||
signals:
|
||||
void finished(bool success); // For testing.
|
||||
|
@@ -584,14 +584,32 @@ void DiagnosticFilterModel::addSuppressedDiagnostic(
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void DiagnosticFilterModel::invalidateFilter()
|
||||
{
|
||||
QSortFilterProxyModel::invalidateFilter();
|
||||
}
|
||||
|
||||
bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
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
|
||||
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));
|
||||
QTC_ASSERT(diagnosticItem, return false);
|
||||
|
||||
@@ -612,7 +630,7 @@ bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow,
|
||||
return diag.description.contains(filterRegExp());
|
||||
}
|
||||
|
||||
return true;
|
||||
return true; // ExplainingStepItem
|
||||
}
|
||||
|
||||
bool DiagnosticFilterModel::lessThan(const QModelIndex &l, const QModelIndex &r) const
|
||||
|
@@ -146,6 +146,8 @@ public:
|
||||
void addSuppressedDiagnostic(const SuppressedDiagnostic &diag);
|
||||
ProjectExplorer::Project *project() const { return m_project; }
|
||||
|
||||
void invalidateFilter();
|
||||
|
||||
private:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||
bool lessThan(const QModelIndex &l, const QModelIndex &r) const override;
|
||||
|
Reference in New Issue
Block a user