Skip to content

Commit

Permalink
Initial Tags UI refactor to address performance issues and UI blocking.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpotchik committed Nov 21, 2024
1 parent 9229ebd commit 7f1a310
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions ui/taglist.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QDialog>
#include "binaryninjaapi.h"
#include "notificationsdispatcher.h"
#include "sidebar.h"
#include "viewframe.h"
#include "filter.h"
Expand All @@ -26,16 +27,23 @@ class BINARYNINJAUIAPI TagListModel : public QAbstractItemModel
{
Q_OBJECT

protected:
using TagStorage = std::vector<std::tuple<TagTypeRef, QString, std::vector<BinaryNinja::TagReference>>>;
using TagTypeStorage = std::vector<std::pair<TagTypeRef, QString>>;
using TagTypeIndices = std::map<TagTypeRef, size_t>;

protected:
QWidget* m_owner;
BinaryViewRef m_data;
std::map<TagTypeRef, size_t> m_typeIndexes;
std::vector<std::pair<TagTypeRef, std::vector<BinaryNinja::TagReference>>> m_refs;
NotificationsDispatcher* m_dispatcher = nullptr;
TagTypeStorage m_tagTypes;
std::vector<std::string> m_tagTypeIds;
std::unordered_map<std::string, uint64_t> m_tagTypeCounts;
TagStorage m_tagStorage;
TagTypeIndices m_tagTypeIndices;
std::map<int, QSize> m_sectionSizeHints;
std::map<std::string, uint64_t> m_count;
DisassemblySettingsRef m_settings;

private:
private:
void AddDisassemblyTokens(QList<QVariant>& line, std::vector<BinaryNinja::InstructionTextToken> tokens) const;

void TrimLeadingWhitespace(QList<QVariant>& line) const;
Expand All @@ -50,10 +58,13 @@ class BINARYNINJAUIAPI TagListModel : public QAbstractItemModel
QVariant GetDataColumn(const TagTypeRef& ref) const;
QVariant GetPreviewColumn(const TagTypeRef& ref) const;

public:
public:
TagListModel(QWidget* parent, BinaryViewRef data);
virtual ~TagListModel();

void connectDataStore();
void disconnectDataStore();

BinaryNinja::TagReference& GetRef(const QModelIndex& index);
const BinaryNinja::TagReference& GetRef(const QModelIndex& index) const;

Expand All @@ -73,8 +84,11 @@ class BINARYNINJAUIAPI TagListModel : public QAbstractItemModel
virtual Qt::ItemFlags flags(const QModelIndex& i) const override;
virtual void sort(int column, Qt::SortOrder order) override;

bool setModelData(const std::vector<std::pair<TagTypeRef, std::vector<BinaryNinja::TagReference>>>& refs,
QItemSelectionModel* selectionModel, int sortColumn, Qt::SortOrder sortOrder, bool& selectionUpdated);
void backgroundSort(int column, Qt::SortOrder order, TagStorage& tagStorage, TagTypeStorage& tagTypeStorage, TagTypeIndices& tagTypeIndices);
void refresh();

Q_SIGNALS:
void notifyUpdateComplete(bool complete);
};

/*!
Expand Down Expand Up @@ -105,7 +119,7 @@ class BINARYNINJAUIAPI TagItemDelegate : public QStyledItemDelegate
\ingroup taglist
*/
class BINARYNINJAUIAPI TagList : public QTreeView, public BinaryNinja::BinaryDataNotification, public FilterTarget
class BINARYNINJAUIAPI TagList : public QTreeView, public FilterTarget
{
Q_OBJECT

Expand All @@ -119,7 +133,12 @@ class BINARYNINJAUIAPI TagList : public QTreeView, public BinaryNinja::BinaryDat
ContextMenuManager* m_contextMenuManager;
FilteredView* m_filterView;
Menu* m_menu;
std::unordered_map<std::string, bool> m_expandedItems;
std::mutex m_filterMutex;

// view state
std::set<QString> m_expandedItems;
bool m_editing = false;
std::vector<std::pair<TagTypeRef, std::vector<BinaryNinja::TagReference>>> m_savedSelections;

public:
typedef std::function<bool(const BinaryNinja::TagReference&)> FilterFn;
Expand All @@ -130,11 +149,9 @@ class BINARYNINJAUIAPI TagList : public QTreeView, public BinaryNinja::BinaryDat
std::string m_searchFilter;

QTimer* m_hoverTimer;
QTimer* m_updateTimer;
QPoint m_hoverPos;

uint64_t m_curRefTarget = 0;
bool m_needsUpdate;
bool m_navToNextOrPrevStarted = false;

protected:
Expand All @@ -148,22 +165,12 @@ class BINARYNINJAUIAPI TagList : public QTreeView, public BinaryNinja::BinaryDat

void setFilter(const std::string& filter) override;

virtual void OnAnalysisFunctionUpdated(BinaryNinja::BinaryView* view, BinaryNinja::Function* func) override;
virtual void OnTagAdded(BinaryNinja::BinaryView*, const BinaryNinja::TagReference&) override;
virtual void OnTagUpdated(BinaryNinja::BinaryView*, const BinaryNinja::TagReference&) override;
virtual void OnTagRemoved(BinaryNinja::BinaryView*, const BinaryNinja::TagReference&) override;
virtual void OnTagTypeUpdated(BinaryNinja::BinaryView*, TagTypeRef) override;

virtual void showEvent(QShowEvent* event) override;
virtual void hideEvent(QHideEvent* event) override;

private Q_SLOTS:
void hoverTimerEvent();
void updateTimerEvent();
void referenceActivated(const QModelIndex& idx);

void saveExpanded();
void restoreExpanded();
void saveViewState();
void restoreViewState();

public Q_SLOTS:
void showContextMenu();
Expand All @@ -179,12 +186,11 @@ class BINARYNINJAUIAPI TagList : public QTreeView, public BinaryNinja::BinaryDat
void removeSelection();
void copySelection();

void filterTagReferences(std::vector<BinaryNinja::TagReference>& refs);
void clearFilter();
void setFilter(FilterFn filter);
void setFilterView(FilteredView* filterView) { m_filterView = filterView; }

void updateTags();

bool hasSelection();
void navigateToNext();
void navigateToPrev();
Expand Down

0 comments on commit 7f1a310

Please sign in to comment.