From baa6b7eab3c19f0fc0dce7806c48186d15611e4b Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Mon, 11 Feb 2019 15:39:41 +0100 Subject: [PATCH] ClangTools: Get rid of some dynamic_casts Change-Id: I5b6ebbf993fdf9954f7c5df66a09266b6b155aaf Reviewed-by: hjk --- .../clangtools/clangtoolsdiagnosticmodel.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp index 4225970221d..ec6195481e0 100644 --- a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp +++ b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp @@ -623,9 +623,10 @@ bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow, // DiagnosticItem Utils::TreeItem *parentItem = model->itemForIndex(sourceParent); - if (auto filePathItem = dynamic_cast(parentItem)) { - auto diagnosticItem = dynamic_cast(filePathItem->childAt(sourceRow)); - QTC_ASSERT(diagnosticItem, return false); + QTC_ASSERT(parentItem, return true); + if (parentItem->level() == 1) { + auto filePathItem = static_cast(parentItem); + auto diagnosticItem = static_cast(filePathItem->childAt(sourceRow)); // Is the diagnostic explicitly suppressed? const Diagnostic &diag = diagnosticItem->diagnostic(); @@ -651,11 +652,12 @@ bool DiagnosticFilterModel::lessThan(const QModelIndex &l, const QModelIndex &r) { auto model = static_cast(sourceModel()); Utils::TreeItem *itemLeft = model->itemForIndex(l); - const bool isComparingDiagnostics = !dynamic_cast(itemLeft); + QTC_ASSERT(itemLeft, return QSortFilterProxyModel::lessThan(l, r)); + const bool isComparingDiagnostics = itemLeft->level() > 1; if (sortColumn() == Debugger::DetailedErrorView::DiagnosticColumn && isComparingDiagnostics) { bool result = false; - if (dynamic_cast(itemLeft)) { + if (itemLeft->level() == 2) { using Debugger::DiagnosticLocation; const int role = Debugger::DetailedErrorView::LocationRole; @@ -669,8 +671,11 @@ bool DiagnosticFilterModel::lessThan(const QModelIndex &l, const QModelIndex &r) result = std::tie(leftLoc.line, leftLoc.column, leftText) < std::tie(rightLoc.line, rightLoc.column, rightText); - } else if (auto left = dynamic_cast(itemLeft)) { - const auto right = dynamic_cast(model->itemForIndex(r)); + } else if (itemLeft->level() == 3) { + Utils::TreeItem *itemRight = model->itemForIndex(r); + QTC_ASSERT(itemRight, QSortFilterProxyModel::lessThan(l, r)); + const auto left = static_cast(itemLeft); + const auto right = static_cast(itemRight); result = left->index() < right->index(); } else { QTC_CHECK(false && "Unexpected item");