diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/analyze/gui/chartwidget.cpp | 177 | ||||
-rw-r--r-- | src/analyze/gui/chartwidget.h | 30 | ||||
-rw-r--r-- | src/analyze/gui/chartwidgetqwtplot.cpp | 17 | ||||
-rw-r--r-- | src/analyze/gui/chartwidgetqwtplot.h | 31 | ||||
-rw-r--r-- | src/analyze/gui/contextmenuqwt.cpp | 199 | ||||
-rw-r--r-- | src/analyze/gui/contextmenuqwt.h | 41 | ||||
-rw-r--r-- | src/heaptrack_gui.pro | 2 |
7 files changed, 320 insertions, 177 deletions
diff --git a/src/analyze/gui/chartwidget.cpp b/src/analyze/gui/chartwidget.cpp index a33f9f0..bf4e3a5 100644 --- a/src/analyze/gui/chartwidget.cpp +++ b/src/analyze/gui/chartwidget.cpp @@ -132,15 +132,14 @@ protected: virtual void closeEvent(QCloseEvent *event) override { QMainWindow::closeEvent(event); - ChartWidget::GlobalOptions = ChartWidgetQwtPlot::setOption(ChartWidget::GlobalOptions, - ChartWidgetQwtPlot::ShowHelp, false); + ChartWidget::GlobalOptions = ChartOptions::setOption(ChartWidget::GlobalOptions, ChartOptions::ShowHelp, false); } }; -ChartWidgetQwtPlot::Options ChartWidget::GlobalOptions( - ChartWidgetQwtPlot::ShowHelp | - ChartWidgetQwtPlot::ShowTotal | ChartWidgetQwtPlot::ShowUnresolved | - ChartWidgetQwtPlot::ShowLegend | ChartWidgetQwtPlot::ShowCurveBorders); +ChartOptions::Options ChartWidget::GlobalOptions( + ChartOptions::ShowHelp | + ChartOptions::ShowTotal | ChartOptions::ShowUnresolved | + ChartOptions::ShowLegend | ChartOptions::ShowCurveBorders); QWidget* ChartWidget::HelpWindow; QWidget* ChartWidget::MainWindow; @@ -152,6 +151,7 @@ ChartWidget::ChartWidget(QWidget* parent) , m_chart(new Chart(this)) #elif defined(QWT_FOUND) , m_plot(new ChartWidgetQwtPlot(this, GlobalOptions)) + , m_contextMenuQwt(new ContextMenuQwt(this, false)) #endif #ifdef SHOW_TABLES , m_tableViewTotal(new QTableView(this)) @@ -199,70 +199,16 @@ void ChartWidget::updateOnSelected(QWidget *mainWindow) void ChartWidget::createActions() { - m_resetZoomAction = new QAction(i18n("Reset Zoom and Pan"), this); - m_resetZoomAction->setStatusTip(i18n("Reset the chart zoom and pan")); - connect(m_resetZoomAction, &QAction::triggered, this, &ChartWidget::resetZoom); - - m_showTotalAction = new QAction(i18n("Show &Total"), this); - m_showTotalAction->setStatusTip(i18n("Show the total amount curve")); - m_showTotalAction->setCheckable(true); - connect(m_showTotalAction, &QAction::triggered, this, &ChartWidget::toggleShowTotal); - - m_showUnresolvedAction = new QAction(i18n("Show &Unresolved"), this); - m_showUnresolvedAction->setStatusTip(i18n("Show unresolved functions' curves")); - m_showUnresolvedAction->setCheckable(true); - connect(m_showUnresolvedAction, &QAction::triggered, this, &ChartWidget::toggleShowUnresolved); - - m_showLegendAction = new QAction(i18n("Show &Legend"), this); - m_showLegendAction->setStatusTip(i18n("Show the chart legend")); - m_showLegendAction->setCheckable(true); - connect(m_showLegendAction, &QAction::triggered, this, &ChartWidget::toggleShowLegend); - - m_showCurveBordersAction = new QAction(i18n("Show Curve &Borders"), this); - m_showCurveBordersAction->setStatusTip(i18n("Show curve borders (as black lines)")); - m_showCurveBordersAction->setCheckable(true); - connect(m_showCurveBordersAction, &QAction::triggered, this, &ChartWidget::toggleShowCurveBorders); - - m_showSymbolsAction = new QAction(i18n("Show &Symbols"), this); - m_showSymbolsAction->setStatusTip(i18n("Show symbols (the chart data points)")); - m_showSymbolsAction->setCheckable(true); - connect(m_showSymbolsAction, &QAction::triggered, this, &ChartWidget::toggleShowSymbols); - - m_showVLinesAction = new QAction(i18n("Show &Vertical Lines"), this); - m_showVLinesAction->setStatusTip(i18n("Show vertical lines corresponding to timestamps")); - m_showVLinesAction->setCheckable(true); - connect(m_showVLinesAction, &QAction::triggered, this, &ChartWidget::toggleShowVLines); - - m_exportChartAction = new QAction(i18n("&Export Chart..."), this); - m_exportChartAction->setStatusTip(i18n("Export the current chart to a file.")); - connect(m_exportChartAction, &QAction::triggered, this, &ChartWidget::exportChart); - - m_showHelpAction = new QAction(i18n("Show Chart &Help"), this); - m_showHelpAction->setStatusTip(i18n("Show a window with breif help information inside the chart.")); - m_showHelpAction->setCheckable(true); - connect(m_showHelpAction, &QAction::triggered, this, &ChartWidget::toggleShowHelp); - - // shortcuts don't work under Windows (Qt 5.10.0) so using a workaround (manual processing - // in keyPressEvent) - - m_resetZoomAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_R)); - m_showTotalAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_T)); - m_showUnresolvedAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_U)); - m_showLegendAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_L)); - m_showCurveBordersAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_B)); - m_showSymbolsAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_S)); - m_showVLinesAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_V)); - m_exportChartAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_E)); -#if QT_VERSION >= 0x050A00 - m_resetZoomAction->setShortcutVisibleInContextMenu(true); - m_showTotalAction->setShortcutVisibleInContextMenu(true); - m_showUnresolvedAction->setShortcutVisibleInContextMenu(true); - m_showLegendAction->setShortcutVisibleInContextMenu(true); - m_showSymbolsAction->setShortcutVisibleInContextMenu(true); - m_showVLinesAction->setShortcutVisibleInContextMenu(true); - m_showCurveBordersAction->setShortcutVisibleInContextMenu(true); - m_exportChartAction->setShortcutVisibleInContextMenu(true); -#endif + connect(m_contextMenuQwt->resetZoomAction(), &QAction::triggered, this, &ChartWidget::resetZoom); + connect(m_contextMenuQwt->showTotalAction(), &QAction::triggered, this, &ChartWidget::toggleShowTotal); + connect(m_contextMenuQwt->showUnresolvedAction(), &QAction::triggered, this, &ChartWidget::toggleShowUnresolved); + connect(m_contextMenuQwt->showLegendAction(), &QAction::triggered, this, &ChartWidget::toggleShowLegend); + connect(m_contextMenuQwt->showCurveBordersAction(), &QAction::triggered, this, &ChartWidget::toggleShowCurveBorders); + connect(m_contextMenuQwt->showSymbolsAction(), &QAction::triggered, this, &ChartWidget::toggleShowSymbols); + connect(m_contextMenuQwt->showVLinesAction(), &QAction::triggered, this, &ChartWidget::toggleShowVLines); + connect(m_contextMenuQwt->exportChartAction(), &QAction::triggered, this, &ChartWidget::exportChart); + connect(m_contextMenuQwt->showHelpAction(), &QAction::triggered, this, &ChartWidget::toggleShowHelp); + setFocusPolicy(Qt::StrongFocus); } #endif @@ -401,70 +347,16 @@ void ChartWidget::modelReset() void ChartWidget::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); - menu.addAction(m_resetZoomAction); - menu.addSeparator(); - m_showTotalAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowTotal)); - menu.addAction(m_showTotalAction); - m_showUnresolvedAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowUnresolved)); - menu.addAction(m_showUnresolvedAction); - menu.addSeparator(); - m_showLegendAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowLegend)); - menu.addAction(m_showLegendAction); - m_showCurveBordersAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowCurveBorders)); - menu.addAction(m_showCurveBordersAction); - m_showSymbolsAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowSymbols)); - menu.addAction(m_showSymbolsAction); - m_showVLinesAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowVLines)); - menu.addAction(m_showVLinesAction); - menu.addSeparator(); - menu.addAction(m_exportChartAction); - menu.addSeparator(); - m_showHelpAction->setChecked(ChartWidgetQwtPlot::hasOption(GlobalOptions, ChartWidgetQwtPlot::ShowHelp)); - menu.addAction(m_showHelpAction); + m_plot->setOption(ChartWidgetQwtPlot::ShowHelp, + ChartWidgetQwtPlot::hasOption(GlobalOptions, ChartWidgetQwtPlot::ShowHelp)); + m_contextMenuQwt->initializeMenu(menu, m_plot->options()); menu.exec(event->globalPos()); } #endif void ChartWidget::keyPressEvent(QKeyEvent *event) { - if (event->modifiers() & Qt::AltModifier) - { - switch (event->key()) - { - case Qt::Key_R: - resetZoom(); - break; - case Qt::Key_T: - toggleShowTotal(!m_plot->hasOption(ChartWidgetQwtPlot::ShowTotal)); - break; - case Qt::Key_U: - toggleShowUnresolved(!m_plot->hasOption(ChartWidgetQwtPlot::ShowUnresolved)); - break; - case Qt::Key_L: - toggleShowLegend(!m_plot->hasOption(ChartWidgetQwtPlot::ShowLegend)); - break; - case Qt::Key_B: - toggleShowCurveBorders(!m_plot->hasOption(ChartWidgetQwtPlot::ShowCurveBorders)); - break; - case Qt::Key_S: - toggleShowSymbols(!m_plot->hasOption(ChartWidgetQwtPlot::ShowSymbols)); - break; - case Qt::Key_V: - toggleShowVLines(!m_plot->hasOption(ChartWidgetQwtPlot::ShowVLines)); - break; - case Qt::Key_E: - exportChart(); - break; - default: - event->ignore(); - return; - } - event->accept(); - } - else - { - event->ignore(); - } + m_contextMenuQwt->handleKeyPress(event, m_plot->options()); } void ChartWidget::resetZoom() @@ -472,38 +364,39 @@ void ChartWidget::resetZoom() m_plot->resetZoom(); } -void ChartWidget::toggleShowTotal(bool checked) +void ChartWidget::toggleShowTotal() { - GlobalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowTotal, checked); + GlobalOptions = m_plot->toggleOption(ChartWidgetQwtPlot::ShowTotal); } -void ChartWidget::toggleShowUnresolved(bool checked) +void ChartWidget::toggleShowUnresolved() { - GlobalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowUnresolved, checked); + GlobalOptions = m_plot->toggleOption(ChartWidgetQwtPlot::ShowUnresolved); } -void ChartWidget::toggleShowLegend(bool checked) +void ChartWidget::toggleShowLegend() { - GlobalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowLegend, checked); + GlobalOptions = m_plot->toggleOption(ChartWidgetQwtPlot::ShowLegend); } -void ChartWidget::toggleShowCurveBorders(bool checked) +void ChartWidget::toggleShowCurveBorders() { - GlobalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowCurveBorders, checked); + GlobalOptions = m_plot->toggleOption(ChartWidgetQwtPlot::ShowCurveBorders); } -void ChartWidget::toggleShowSymbols(bool checked) +void ChartWidget::toggleShowSymbols() { - GlobalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowSymbols, checked); + GlobalOptions = m_plot->toggleOption(ChartWidgetQwtPlot::ShowSymbols); } -void ChartWidget::toggleShowVLines(bool checked) +void ChartWidget::toggleShowVLines() { - GlobalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowVLines, checked); + GlobalOptions = m_plot->toggleOption(ChartWidgetQwtPlot::ShowVLines); } -void ChartWidget::toggleShowHelp(bool checked) +void ChartWidget::toggleShowHelp() { + bool checked = !ChartOptions::hasOption(GlobalOptions, ChartOptions::ShowHelp); if (checked) { showHelp(); @@ -516,7 +409,7 @@ void ChartWidget::toggleShowHelp(bool checked) HelpWindow = nullptr; } } - GlobalOptions = ChartWidgetQwtPlot::setOption(GlobalOptions, ChartWidgetQwtPlot::ShowHelp, checked); + GlobalOptions = ChartOptions::setOption(GlobalOptions, ChartOptions::ShowHelp, checked); } void ChartWidget::showHelp() diff --git a/src/analyze/gui/chartwidget.h b/src/analyze/gui/chartwidget.h index 7bda480..c797613 100644 --- a/src/analyze/gui/chartwidget.h +++ b/src/analyze/gui/chartwidget.h @@ -20,6 +20,9 @@ #define CHARTWIDGET_H #include "gui_config.h" +#include "contextmenuqwt.h" + +#include <memory> #include <QWidget> @@ -57,7 +60,7 @@ public: #if defined(QWT_FOUND) void updateOnSelected(QWidget *mainWindow); - static ChartWidgetQwtPlot::Options GlobalOptions; + static ChartOptions::Options GlobalOptions; static QWidget* HelpWindow; static QWidget* MainWindow; @@ -77,13 +80,13 @@ private: #elif defined(QWT_FOUND) private slots: void resetZoom(); - void toggleShowTotal(bool checked); - void toggleShowUnresolved(bool checked); - void toggleShowLegend(bool checked); - void toggleShowCurveBorders(bool checked); - void toggleShowSymbols(bool checked); - void toggleShowVLines(bool checked); - void toggleShowHelp(bool checked); + void toggleShowTotal(); + void toggleShowUnresolved(); + void toggleShowLegend(); + void toggleShowCurveBorders(); + void toggleShowSymbols(); + void toggleShowVLines(); + void toggleShowHelp(); void exportChart(); private: void createActions(); @@ -91,16 +94,7 @@ private: void showHelp(); ChartWidgetQwtPlot* m_plot; - - QAction* m_resetZoomAction; - QAction* m_showTotalAction; - QAction* m_showUnresolvedAction; - QAction* m_showLegendAction; - QAction* m_showSymbolsAction; - QAction* m_showVLinesAction; - QAction* m_showCurveBordersAction; - QAction* m_exportChartAction; - QAction* m_showHelpAction; + std::unique_ptr<ContextMenuQwt> m_contextMenuQwt; #endif // QWT_FOUND, KChart_FOUND #ifdef SHOW_TABLES QTableView* m_tableViewTotal; diff --git a/src/analyze/gui/chartwidgetqwtplot.cpp b/src/analyze/gui/chartwidgetqwtplot.cpp index 82f0919..eab0613 100644 --- a/src/analyze/gui/chartwidgetqwtplot.cpp +++ b/src/analyze/gui/chartwidgetqwtplot.cpp @@ -94,8 +94,13 @@ private: ChartWidgetQwtPlot *m_plot; }; +ChartOptions::Options ChartOptions::setOption(Options options, Options option, bool isOn) +{ + return (isOn ? (options | option) : Options(options & ~option)); +} + ChartWidgetQwtPlot::ChartWidgetQwtPlot(QWidget *parent, Options options) - : QwtPlot(parent), m_model(nullptr), m_isSizeModel(false), m_options(options), + : QwtPlot(parent), m_model(nullptr), m_isSizeModel(false), ChartOptions(options), m_zoomer(new Zoomer(this)) { setCanvasBackground(Qt::white); @@ -125,15 +130,15 @@ void ChartWidgetQwtPlot::setModel(ChartModel* model) model->type() == ChartModel::Temporary); } -ChartWidgetQwtPlot::Options ChartWidgetQwtPlot::setOption(Options options, Options option, bool isOn) +ChartOptions::Options ChartWidgetQwtPlot::setOption(Options option, bool isOn) { - return (isOn ? (options | option) : Options(options & ~option)); + setOptions(ChartOptions::setOption(m_options, option, isOn)); + return m_options; } -ChartWidgetQwtPlot::Options ChartWidgetQwtPlot::setOption(Options option, bool isOn) +ChartOptions::Options ChartWidgetQwtPlot::toggleOption(Options option) { - setOptions(setOption(m_options, option, isOn)); - return m_options; + return setOption(option, !hasOption(option)); } void ChartWidgetQwtPlot::setOptions(Options options) diff --git a/src/analyze/gui/chartwidgetqwtplot.h b/src/analyze/gui/chartwidgetqwtplot.h index ac17d45..e64410e 100644 --- a/src/analyze/gui/chartwidgetqwtplot.h +++ b/src/analyze/gui/chartwidgetqwtplot.h @@ -9,7 +9,7 @@ class ChartModel; class Zoomer; -class ChartWidgetQwtPlot : public QwtPlot +class ChartOptions { public: enum Options @@ -24,24 +24,35 @@ public: ShowVLines = 0x80 }; - explicit ChartWidgetQwtPlot(QWidget *parent, Options options); - - void setModel(ChartModel* model); + explicit ChartOptions(Options options) { m_options = options; } - ChartModel* model() const { return m_model; } + static bool hasOption(Options options, Options option) { return (options & option) != 0; } - bool isSizeModel() const { return m_isSizeModel; } + static Options setOption(Options options, Options option, bool isOn); Options options() const { return m_options; } - static bool hasOption(Options options, Options option) { return (options & option) != 0; } - bool hasOption(Options option) const { return hasOption(m_options, option); } - static Options setOption(Options options, Options option, bool isOn); +protected: + Options m_options; +}; + +class ChartWidgetQwtPlot : public QwtPlot, public ChartOptions +{ +public: + explicit ChartWidgetQwtPlot(QWidget *parent, Options options); + + void setModel(ChartModel* model); + + ChartModel* model() const { return m_model; } + + bool isSizeModel() const { return m_isSizeModel; } Options setOption(Options option, bool isOn); + Options toggleOption(Options option); + void setOptions(Options options); void rebuild(bool resetZoomAndPan); @@ -61,8 +72,6 @@ private: bool m_isSizeModel; - Options m_options; - QPen m_vLinePen; Zoomer *m_zoomer; diff --git a/src/analyze/gui/contextmenuqwt.cpp b/src/analyze/gui/contextmenuqwt.cpp new file mode 100644 index 0000000..3defe7e --- /dev/null +++ b/src/analyze/gui/contextmenuqwt.cpp @@ -0,0 +1,199 @@ +#include "contextmenuqwt.h" +#include "noklib.h" + +#include <QKeyEvent> +#include <QMenu> + +ContextMenuQwt::ContextMenuQwt(QObject *parent, bool isHistogram) +{ + m_showTotalAction = new QAction(i18n("Show &Total"), parent); + m_showTotalAction->setStatusTip(i18n("Show the total amount curve")); + m_showTotalAction->setCheckable(true); + + m_showUnresolvedAction = new QAction(i18n("Show &Unresolved"), parent); + m_showUnresolvedAction->setStatusTip(i18n("Show unresolved functions' curves")); + m_showUnresolvedAction->setCheckable(true); + + m_exportChartAction = new QAction(i18n("&Export Chart..."), parent); + m_exportChartAction->setStatusTip(i18n("Export the current chart to a file.")); + + // shortcuts don't work under Windows (Qt 5.10.0) so need to use a workaround (manual + // processing in keyPressEvent) + m_showTotalAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_T)); + m_showUnresolvedAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_U)); + m_exportChartAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_E)); + +#if QT_VERSION >= 0x050A00 + m_showTotalAction->setShortcutVisibleInContextMenu(true); + m_showUnresolvedAction->setShortcutVisibleInContextMenu(true); + m_exportChartAction->setShortcutVisibleInContextMenu(true); +#endif + + if (!isHistogram) + { + m_resetZoomAction = new QAction(i18n("Reset Zoom and Pan"), parent); + m_resetZoomAction->setStatusTip(i18n("Reset the chart zoom and pan")); + + m_showLegendAction = new QAction(i18n("Show &Legend"), parent); + m_showLegendAction->setStatusTip(i18n("Show the chart legend")); + m_showLegendAction->setCheckable(true); + + m_showCurveBordersAction = new QAction(i18n("Show Curve &Borders"), parent); + m_showCurveBordersAction->setStatusTip(i18n("Show curve borders (as black lines)")); + m_showCurveBordersAction->setCheckable(true); + + m_showSymbolsAction = new QAction(i18n("Show &Symbols"), parent); + m_showSymbolsAction->setStatusTip(i18n("Show symbols (the chart data points)")); + m_showSymbolsAction->setCheckable(true); + + m_showVLinesAction = new QAction(i18n("Show &Vertical Lines"), parent); + m_showVLinesAction->setStatusTip(i18n("Show vertical lines corresponding to timestamps")); + m_showVLinesAction->setCheckable(true); + + m_showHelpAction = new QAction(i18n("Show Chart &Help"), parent); + m_showHelpAction->setStatusTip(i18n("Show a window with breif help information inside the chart.")); + m_showHelpAction->setCheckable(true); + + m_resetZoomAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_R)); + m_showLegendAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_L)); + m_showCurveBordersAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_B)); + m_showSymbolsAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_S)); + m_showVLinesAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_V)); + +#if QT_VERSION >= 0x050A00 + m_resetZoomAction->setShortcutVisibleInContextMenu(true); + m_showLegendAction->setShortcutVisibleInContextMenu(true); + m_showCurveBordersAction->setShortcutVisibleInContextMenu(true); + m_showSymbolsAction->setShortcutVisibleInContextMenu(true); + m_showVLinesAction->setShortcutVisibleInContextMenu(true); +#endif + } + else + { + m_resetZoomAction = nullptr; + m_showLegendAction = nullptr; + m_showCurveBordersAction = nullptr; + m_showSymbolsAction = nullptr; + m_showVLinesAction = nullptr; + m_showHelpAction = nullptr; + } +} + +void ContextMenuQwt::initializeMenu(QMenu& menu, ChartOptions::Options options) const +{ + if (m_resetZoomAction) + { + menu.addAction(m_resetZoomAction); + menu.addSeparator(); + } + if (m_showTotalAction) + { + m_showTotalAction->setChecked(ChartOptions::hasOption(options, ChartOptions::ShowTotal)); + menu.addAction(m_showTotalAction); + } + if (m_showUnresolvedAction) + { + m_showUnresolvedAction->setChecked(ChartOptions::hasOption(options, ChartOptions::ShowUnresolved)); + menu.addAction(m_showUnresolvedAction); + } + if ((m_showTotalAction != nullptr) || (m_showUnresolvedAction != nullptr)) + { + menu.addSeparator(); + } + if (m_showLegendAction) + { + m_showLegendAction->setChecked(ChartOptions::hasOption(options, ChartOptions::ShowLegend)); + menu.addAction(m_showLegendAction); + } + if (m_showCurveBordersAction) + { + m_showCurveBordersAction->setChecked(ChartOptions::hasOption(options, ChartOptions::ShowCurveBorders)); + menu.addAction(m_showCurveBordersAction); + } + if (m_showSymbolsAction) + { + m_showSymbolsAction->setChecked(ChartOptions::hasOption(options, ChartOptions::ShowSymbols)); + menu.addAction(m_showSymbolsAction); + } + if (m_showVLinesAction) + { + m_showVLinesAction->setChecked(ChartOptions::hasOption(options, ChartOptions::ShowVLines)); + menu.addAction(m_showVLinesAction); + } + if (m_exportChartAction) + { + menu.addSeparator(); + menu.addAction(m_exportChartAction); + } + if (m_showHelpAction) + { + menu.addSeparator(); + m_showHelpAction->setChecked(ChartOptions::hasOption(options, ChartOptions::ShowHelp)); + menu.addAction(m_showHelpAction); + } +} + +void ContextMenuQwt::handleKeyPress(QKeyEvent *event, ChartOptions::Options options) +{ + if (event->modifiers() & Qt::AltModifier) + { + switch (event->key()) + { + case Qt::Key_R: + if (m_resetZoomAction) + { + m_resetZoomAction->activate(QAction::Trigger); + } + break; + case Qt::Key_T: + if (m_showTotalAction) + { + m_showTotalAction->activate(QAction::Trigger); + } + break; + case Qt::Key_U: + if (m_showUnresolvedAction) + { + m_showUnresolvedAction->activate(QAction::Trigger); + } + break; + case Qt::Key_L: + if (m_showLegendAction) + { + m_showLegendAction->activate(QAction::Trigger); + } + break; + case Qt::Key_S: + if (m_showSymbolsAction) + { + m_showSymbolsAction->activate(QAction::Trigger); + } + break; + case Qt::Key_V: + if (m_showVLinesAction) + { + m_showVLinesAction->activate(QAction::Trigger); + } + case Qt::Key_B: + if (m_showCurveBordersAction) + { + m_showCurveBordersAction->activate(QAction::Trigger); + } + break; + case Qt::Key_E: + if (m_exportChartAction) + { + m_exportChartAction->activate(QAction::Trigger); + } + break; + default: + event->ignore(); + return; + } + event->accept(); + } + else + { + event->ignore(); + } +} diff --git a/src/analyze/gui/contextmenuqwt.h b/src/analyze/gui/contextmenuqwt.h new file mode 100644 index 0000000..e15fa80 --- /dev/null +++ b/src/analyze/gui/contextmenuqwt.h @@ -0,0 +1,41 @@ +#ifndef CONTEXTMENUQWT_H +#define CONTEXTMENUQWT_H + +#include "chartwidgetqwtplot.h" + +#include <QAction> +#include <QKeyEvent> +#include <QMenu> + +class ContextMenuQwt +{ +public: + ContextMenuQwt(QObject *parent, bool isHistogram); + + QAction* resetZoomAction() const { return m_resetZoomAction; } + QAction* showTotalAction() const { return m_showTotalAction; } + QAction* showUnresolvedAction() const { return m_showUnresolvedAction; } + QAction* showLegendAction() const { return m_showLegendAction; } + QAction* showSymbolsAction() const { return m_showSymbolsAction; } + QAction* showVLinesAction() const { return m_showVLinesAction; } + QAction* showCurveBordersAction() const { return m_showCurveBordersAction; } + QAction* exportChartAction() const { return m_exportChartAction; } + QAction* showHelpAction() const { return m_showHelpAction; } + + void initializeMenu(QMenu& menu, ChartOptions::Options options) const; + + void handleKeyPress(QKeyEvent *event, ChartOptions::Options options); + +private: + QAction* m_resetZoomAction; + QAction* m_showTotalAction; + QAction* m_showUnresolvedAction; + QAction* m_showLegendAction; + QAction* m_showSymbolsAction; + QAction* m_showVLinesAction; + QAction* m_showCurveBordersAction; + QAction* m_exportChartAction; + QAction* m_showHelpAction; +}; + +#endif // CONTEXTMENUQWT_H diff --git a/src/heaptrack_gui.pro b/src/heaptrack_gui.pro index 8f51e10..504ee34 100644 --- a/src/heaptrack_gui.pro +++ b/src/heaptrack_gui.pro @@ -85,11 +85,13 @@ QWT_CHART { SOURCES += \ analyze/gui/chartmodel2qwtseriesdata.cpp \ analyze/gui/chartwidgetqwtplot.cpp \ + analyze/gui/contextmenuqwt.cpp \ analyze/gui/histogramwidgetqwtplot.cpp HEADERS += \ analyze/gui/chartmodel2qwtseriesdata.h \ analyze/gui/chartwidgetqwtplot.h \ + analyze/gui/contextmenuqwt.h \ analyze/gui/histogramwidgetqwtplot.h } |