From a6e03d4195e4da6dc9a0cc6be9fb74f7afcc785d Mon Sep 17 00:00:00 2001 From: Adam Zambrzycki Date: Wed, 24 Jul 2019 09:14:14 +0200 Subject: [PATCH] Fix ClassesWidget sorting by vtable offset (#1686) * Fix ClassesWidget sorting by vtable offset * Force showing base above methods --- src/widgets/ClassesWidget.cpp | 12 ++++++++++++ src/widgets/ClassesWidget.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/widgets/ClassesWidget.cpp b/src/widgets/ClassesWidget.cpp index 741ce18d..7ca17c6f 100644 --- a/src/widgets/ClassesWidget.cpp +++ b/src/widgets/ClassesWidget.cpp @@ -440,6 +440,8 @@ QVariant AnalClassesModel::data(const QModelIndex &index, int role) const return QIcon(new SvgIconEngine(QString(":/img/icons/home.svg"), QPalette::WindowText)); } return QVariant(); + case VTableRole: + return -1; case NameRole: return base.className; case TypeRole: @@ -470,6 +472,8 @@ QVariant AnalClassesModel::data(const QModelIndex &index, int role) const return QIcon(new SvgIconEngine(QString(":/img/icons/fork.svg"), QPalette::WindowText)); } return QVariant(); + case VTableRole: + return QVariant::fromValue(meth.vtableOffset); case OffsetRole: return QVariant::fromValue(meth.addr); case NameRole: @@ -547,6 +551,14 @@ bool ClassesSortFilterProxyModel::lessThan(const QModelIndex &left, const QModel } } // fallthrough + case ClassesModel::VTABLE: { + auto left_vtable = left.data(ClassesModel::VTableRole).toLongLong(); + auto right_vtable = right.data(ClassesModel::VTableRole).toLongLong(); + if (left_vtable != right_vtable) { + return left_vtable < right_vtable; + } + } + // fallthrough case ClassesModel::NAME: default: QString left_name = left.data(ClassesModel::NameRole).toString(); diff --git a/src/widgets/ClassesWidget.h b/src/widgets/ClassesWidget.h index 2a42d734..2e170904 100644 --- a/src/widgets/ClassesWidget.h +++ b/src/widgets/ClassesWidget.h @@ -53,6 +53,14 @@ public: */ static const int TypeRole = Qt::UserRole + 2; + /** + * @brief VTable role of data for QModelIndex + * + * will contain values of type long long for sorting + * by vtable offset + */ + static const int VTableRole = Qt::UserRole + 3; + explicit ClassesModel(QObject *parent = nullptr) : QAbstractItemModel(parent) {} QVariant headerData(int section, Qt::Orientation orientation,