From: Alexey Chernobaev Date: Mon, 2 Apr 2018 19:37:49 +0000 (+0300) Subject: some tricks for flame graph: X-Git-Tag: submit/tizen/20180620.112952^2^2~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0a833090f5eed6876587bef588585bb7b68ae5c;p=sdk%2Ftools%2Fheaptrack.git some tricks for flame graph: - implementing back/forward actions in NO_K_LIB mode; - trying to fix a floating bug with wrong initial graph display position --- diff --git a/src/analyze/gui/chartwidget.cpp b/src/analyze/gui/chartwidget.cpp index 0d2e5bd..614d79f 100644 --- a/src/analyze/gui/chartwidget.cpp +++ b/src/analyze/gui/chartwidget.cpp @@ -356,7 +356,10 @@ void ChartWidget::contextMenuEvent(QContextMenuEvent *event) void ChartWidget::keyPressEvent(QKeyEvent *event) { - m_contextMenuQwt->handleKeyPress(event); + if (!m_contextMenuQwt->handleKeyPress(event)) + { + QWidget::keyPressEvent(event); + } } void ChartWidget::resetZoom() diff --git a/src/analyze/gui/contextmenuqwt.cpp b/src/analyze/gui/contextmenuqwt.cpp index db1e1c7..da3182b 100644 --- a/src/analyze/gui/contextmenuqwt.cpp +++ b/src/analyze/gui/contextmenuqwt.cpp @@ -133,7 +133,7 @@ void ContextMenuQwt::initializeMenu(QMenu& menu, ChartOptions::Options options) } } -void ContextMenuQwt::handleKeyPress(QKeyEvent *event) +bool ContextMenuQwt::handleKeyPress(QKeyEvent *event) { if (event->modifiers() & Qt::AltModifier) { @@ -188,13 +188,10 @@ void ContextMenuQwt::handleKeyPress(QKeyEvent *event) } break; default: - event->ignore(); - return; + return false; } event->accept(); + return true; } - else - { - event->ignore(); - } + return false; } diff --git a/src/analyze/gui/contextmenuqwt.h b/src/analyze/gui/contextmenuqwt.h index b2327da..f6a54db 100644 --- a/src/analyze/gui/contextmenuqwt.h +++ b/src/analyze/gui/contextmenuqwt.h @@ -24,7 +24,7 @@ public: void initializeMenu(QMenu& menu, ChartOptions::Options options) const; - void handleKeyPress(QKeyEvent *event); + bool handleKeyPress(QKeyEvent *event); private: QAction* m_resetZoomAction; diff --git a/src/analyze/gui/flamegraph.cpp b/src/analyze/gui/flamegraph.cpp index b9ebfc6..136f45c 100644 --- a/src/analyze/gui/flamegraph.cpp +++ b/src/analyze/gui/flamegraph.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -651,9 +652,7 @@ FlameGraph::FlameGraph(QWidget* parent, Qt::WindowFlags flags) layout()->addWidget(m_displayLabel); layout()->addWidget(m_searchResultsLabel); -#ifdef NO_K_LIB - // TODO!! implement back and forward -#else +#ifndef NO_K_LIB m_backAction = KStandardAction::back(this, SLOT(navigateBack()), this); addAction(m_backAction); m_forwardAction = KStandardAction::forward(this, SLOT(navigateForward()), this); @@ -718,6 +717,38 @@ bool FlameGraph::eventFilter(QObject* object, QEvent* event) return ret; } +#if NO_K_LIB +bool FlameGraph::handleKeyPress(QKeyEvent *event) +{ + if (m_view->hasFocus() || (qApp->focusWidget() == nullptr)) + { + if (event->modifiers() & Qt::AltModifier) + { + switch (event->key()) + { + case Qt::Key_Backspace: + case Qt::Key_Right: + navigateForward(); + return true; + case Qt::Key_Left: + navigateBack(); + return true; + } + } + else + { + switch (event->key()) + { + case Qt::Key_Backspace: + navigateBack(); + return true; + } + } + } + return false; +} +#endif + void FlameGraph::setTopDownData(const TreeData& topDownData) { m_topDownData = topDownData; @@ -809,6 +840,15 @@ void FlameGraph::setData(FrameGraphicsItem* rootItem) if (isVisible()) { selectItem(m_rootItem); + // trying to fix a bug (?): sometimes the flamegraph is displayed at wrong position initially + // (observed after switching to the flamegraph tab soon after the application starts with + // a data file specified in the command line) + static bool firstTime = true; + if (firstTime) + { + m_view->updateGeometry(); + firstTime = false; + } } } diff --git a/src/analyze/gui/flamegraph.h b/src/analyze/gui/flamegraph.h index 973f32f..65ef505 100644 --- a/src/analyze/gui/flamegraph.h +++ b/src/analyze/gui/flamegraph.h @@ -43,10 +43,14 @@ public: void setBottomUpData(const TreeData& bottomUpData); void clearData(); - +#if NO_K_LIB + // handling back and forward shortcuts: + // keyPressEvent doesn't receive arrow keys so the main window calls + // this function from its event filter + bool handleKeyPress(QKeyEvent* event); +#endif protected: bool eventFilter(QObject* object, QEvent* event) override; - private slots: void setData(FrameGraphicsItem* rootItem); void setSearchValue(const QString& value); diff --git a/src/analyze/gui/histogramwidget.cpp b/src/analyze/gui/histogramwidget.cpp index dedc79e..846b054 100644 --- a/src/analyze/gui/histogramwidget.cpp +++ b/src/analyze/gui/histogramwidget.cpp @@ -247,7 +247,10 @@ void HistogramWidget::contextMenuEvent(QContextMenuEvent *event) void HistogramWidget::keyPressEvent(QKeyEvent *event) { - m_contextMenuQwt->handleKeyPress(event); + if (!m_contextMenuQwt->handleKeyPress(event)) + { + QWidget::keyPressEvent(event); + } } void HistogramWidget::toggleShowTotal() diff --git a/src/analyze/gui/mainwindow.cpp b/src/analyze/gui/mainwindow.cpp index 5affcde..4f8fcde 100644 --- a/src/analyze/gui/mainwindow.cpp +++ b/src/analyze/gui/mainwindow.cpp @@ -621,6 +621,8 @@ MainWindow::MainWindow(QWidget* parent) connect(m_closeAction, &QAction::triggered, this, &MainWindow::close); m_quitAction = new QAction(i18n("&Quit"), this); connect(m_quitAction, &QAction::triggered, qApp, &QApplication::quit); + + qApp->installEventFilter(this); #else m_openAction = KStandardAction::open(this, SLOT(closeFile()), this); m_openAction->setEnabled(false); @@ -636,7 +638,9 @@ MainWindow::MainWindow(QWidget* parent) MainWindow::~MainWindow() { -#ifndef NO_K_LIB +#ifdef NO_K_LIB + qApp->removeEventFilter(this); +#else auto state = saveState(MAINWINDOW_VERSION); auto group = m_config->group(Config::Groups::MainWindow); group.writeEntry(Config::Entries::State, state); @@ -768,6 +772,25 @@ void MainWindow::closeEvent(QCloseEvent *event) #endif // QWT_FOUND } +bool MainWindow::eventFilter(QObject* object, QEvent* event) +{ + // could process arrow keys (left/right) for flamegraph (to implement back/forward) only from here + if ((event->type() == QEvent::KeyPress) && + (m_ui->tabWidget->currentWidget() == m_ui->flameGraphTab)) + { + // Qt5: sometimes (e.g. if Alt is pressed) 'object' is QWidgetWindow which is not a part + // of Qt public API so trying to detect it indirectly (see 2nd condition below) + if ((object == this) || (object->parent() == nullptr)) + { + if (m_ui->flameGraphTab->handleKeyPress(static_cast(event))) + { + return true; + } + } + } + return QMainWindow::eventFilter(object, event); +} + static void selectFile(QWidget *parent, QLineEdit *fileNameEdit) { QString fileName = QFileDialog::getOpenFileName(parent, "Select Data File", diff --git a/src/analyze/gui/mainwindow.h b/src/analyze/gui/mainwindow.h index 63d87e7..5cd2254 100644 --- a/src/analyze/gui/mainwindow.h +++ b/src/analyze/gui/mainwindow.h @@ -54,6 +54,7 @@ signals: #ifdef NO_K_LIB protected: virtual void closeEvent(QCloseEvent *event) override; + virtual bool eventFilter(QObject* object, QEvent* event) override; public slots: void selectOpenFile(); void selectCompareToFile();