From 0a481b5642b73ac879c8eda522013bc866f15378 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Tue, 2 May 2017 23:19:13 +0200 Subject: [PATCH] Disable flamegraph navigation actions when they are not applicable --- src/analyze/gui/flamegraph.cpp | 18 ++++++++++++++++-- src/analyze/gui/flamegraph.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/analyze/gui/flamegraph.cpp b/src/analyze/gui/flamegraph.cpp index 1931e5d..973967f 100644 --- a/src/analyze/gui/flamegraph.cpp +++ b/src/analyze/gui/flamegraph.cpp @@ -530,8 +530,11 @@ FlameGraph::FlameGraph(QWidget* parent, Qt::WindowFlags flags) layout()->addWidget(m_displayLabel); layout()->addWidget(m_searchResultsLabel); - addAction(KStandardAction::back(this, SLOT(navigateBack()), this)); - addAction(KStandardAction::forward(this, SLOT(navigateForward()), this)); + m_backAction = KStandardAction::back(this, SLOT(navigateBack()), this); + addAction(m_backAction); + m_forwardAction = KStandardAction::forward(this, SLOT(navigateForward()), this); + addAction(m_forwardAction); + updateNavigationActions(); setContextMenuPolicy(Qt::ActionsContextMenu); } @@ -552,6 +555,7 @@ bool FlameGraph::eventFilter(QObject* object, QEvent* event) } m_selectedItem = m_selectionHistory.size(); m_selectionHistory.push_back(item); + updateNavigationActions(); } } } else if (event->type() == QEvent::MouseMove) { @@ -647,10 +651,12 @@ void FlameGraph::setData(FrameGraphicsItem* rootItem) { m_scene->clear(); m_buildingScene = false; + m_tooltipItem = nullptr; m_rootItem = rootItem; m_selectionHistory.clear(); m_selectionHistory.push_back(rootItem); m_selectedItem = 0; + updateNavigationActions(); if (!rootItem) { auto text = m_scene->addText(i18n("generating flame graph...")); m_view->centerOn(text); @@ -743,6 +749,7 @@ void FlameGraph::navigateBack() if (m_selectedItem > 0) { --m_selectedItem; } + updateNavigationActions(); selectItem(m_selectionHistory.at(m_selectedItem)); } @@ -751,5 +758,12 @@ void FlameGraph::navigateForward() if ((m_selectedItem + 1) < m_selectionHistory.size()) { ++m_selectedItem; } + updateNavigationActions(); selectItem(m_selectionHistory.at(m_selectedItem)); } + +void FlameGraph::updateNavigationActions() +{ + m_backAction->setEnabled(m_selectedItem > 0); + m_forwardAction->setEnabled(m_selectedItem + 1 < m_selectionHistory.size()); +} diff --git a/src/analyze/gui/flamegraph.h b/src/analyze/gui/flamegraph.h index 8ce4838..45920f6 100644 --- a/src/analyze/gui/flamegraph.h +++ b/src/analyze/gui/flamegraph.h @@ -58,6 +58,7 @@ private: void updateTooltip(); void showData(); void selectItem(FrameGraphicsItem* item); + void updateNavigationActions(); TreeData m_topDownData; TreeData m_bottomUpData; @@ -68,6 +69,8 @@ private: QLabel* m_displayLabel; QLabel* m_searchResultsLabel; QLineEdit* m_searchInput = nullptr; + QAction* m_forwardAction = nullptr; + QAction* m_backAction = nullptr; const FrameGraphicsItem* m_tooltipItem = nullptr; FrameGraphicsItem* m_rootItem = nullptr; QVector m_selectionHistory; -- 2.34.1