diff options
Diffstat (limited to 'examples/triage/exports.cpp')
| -rw-r--r-- | examples/triage/exports.cpp | 68 |
1 files changed, 53 insertions, 15 deletions
diff --git a/examples/triage/exports.cpp b/examples/triage/exports.cpp index 4d274b1a..04547144 100644 --- a/examples/triage/exports.cpp +++ b/examples/triage/exports.cpp @@ -25,13 +25,10 @@ GenericExportsModel::GenericExportsModel(QWidget* parent, BinaryViewRef data): Q } m_updateTimer = new QTimer(this); - m_updateTimer->setSingleShot(true); m_updateTimer->setInterval(500); connect(m_updateTimer, &QTimer::timeout, this, &GenericExportsModel::updateModel); - connect(this, &GenericExportsModel::modelUpdate, this, [=, this]() { - if (m_updateTimer->isActive()) - return; - m_updateTimer->start(); + connect(this, &GenericExportsModel::updateTimerOnUIThread, this, [=, this]() { + updateTimer(m_needsUpdate); }); m_data->RegisterNotification(this); @@ -49,6 +46,10 @@ GenericExportsModel::~GenericExportsModel() void GenericExportsModel::updateModel() { + if (!m_needsUpdate) + return; + + setNeedsUpdate(false); beginResetModel(); m_allEntries.clear(); for (auto& sym : m_data->GetSymbolsOfType(FunctionSymbol)) @@ -237,40 +238,64 @@ void GenericExportsModel::setFilter(const std::string& filterText) endResetModel(); } - -void GenericExportsModel::OnAnalysisFunctionAdded(BinaryNinja::BinaryView* view, BinaryNinja::Function* func) +void GenericExportsModel::setNeedsUpdate(bool needed) { - emit modelUpdate(); + if (m_needsUpdate.exchange(needed) == needed) + return; + + updateTimer(needed); } +void GenericExportsModel::updateTimer(bool needsUpdate) +{ + if (needsUpdate && !m_updateTimer->isActive()) + m_updateTimer->start(); + if (!needsUpdate && m_updateTimer->isActive()) + m_updateTimer->stop(); +} -void GenericExportsModel::OnAnalysisFunctionRemoved(BinaryNinja::BinaryView* view, BinaryNinja::Function* func) +void GenericExportsModel::pauseUpdates() { - emit modelUpdate(); + m_updatesPaused = true; + setNeedsUpdate(false); } +void GenericExportsModel::resumeUpdates() +{ + m_updatesPaused = false; + setNeedsUpdate(true); +} -void GenericExportsModel::OnAnalysisFunctionUpdated(BinaryNinja::BinaryView* view, BinaryNinja::Function* func) +void GenericExportsModel::onBinaryViewNotification() { - emit modelUpdate(); + if (m_updatesPaused) + return; + + // This can be called from any thread so we cannot directly + // update the timer. Emitting a signal is relatively expensive + // given how frequently we receive notifications, so we only + // emit a signal if we didn't already need an update. + if (!m_needsUpdate.exchange(true)) + emit updateTimerOnUIThread(); } void GenericExportsModel::OnSymbolAdded(BinaryNinja::BinaryView* view, BinaryNinja::Symbol* sym) { - emit modelUpdate(); + if ((sym->GetBinding() == GlobalBinding) || (sym->GetBinding() == WeakBinding)) + onBinaryViewNotification(); } void GenericExportsModel::OnSymbolUpdated(BinaryNinja::BinaryView* view, BinaryNinja::Symbol* sym) { - emit modelUpdate(); + onBinaryViewNotification(); } void GenericExportsModel::OnSymbolRemoved(BinaryNinja::BinaryView* view, BinaryNinja::Symbol* sym) { - emit modelUpdate(); + onBinaryViewNotification(); } @@ -403,6 +428,19 @@ void ExportsTreeView::keyPressEvent(QKeyEvent* event) QTreeView::keyPressEvent(event); } +void ExportsTreeView::showEvent(QShowEvent* event) +{ + QTreeView::showEvent(event); + m_model->resumeUpdates(); +} + + +void ExportsTreeView::hideEvent(QHideEvent* event) +{ + QTreeView::hideEvent(event); + m_model->pauseUpdates(); +} + ExportsWidget::ExportsWidget(QWidget* parent, TriageView* view, BinaryViewRef data) : QWidget(parent) { |
