From: Alexey Chernobaev Date: Tue, 3 Apr 2018 15:23:50 +0000 (+0300) Subject: show "Nothing to display" if chart is empty to avoid user frustration (QWT) X-Git-Tag: submit/tizen/20180620.112952^2^2~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d3448a91b4858466a6d3ffea512857b738d881d9;p=sdk%2Ftools%2Fheaptrack.git show "Nothing to display" if chart is empty to avoid user frustration (QWT) --- diff --git a/src/analyze/gui/chartwidget.cpp b/src/analyze/gui/chartwidget.cpp index 614d79f..c68cbab 100644 --- a/src/analyze/gui/chartwidget.cpp +++ b/src/analyze/gui/chartwidget.cpp @@ -349,10 +349,10 @@ void ChartWidget::contextMenuEvent(QContextMenuEvent *event) QMenu menu(this); m_plot->setOption(ChartOptions::ShowHelp, ChartOptions::hasOption(ChartOptions::GlobalOptions, ChartOptions::ShowHelp)); - m_contextMenuQwt->initializeMenu(menu, m_plot->options()); + m_contextMenuQwt->initializeMenu(menu, m_plot->options(), m_plot->isEmpty()); menu.exec(event->globalPos()); } -#endif +#endif // QT_NO_CONTEXTMENU void ChartWidget::keyPressEvent(QKeyEvent *event) { diff --git a/src/analyze/gui/chartwidgetqwtplot.cpp b/src/analyze/gui/chartwidgetqwtplot.cpp index e9bc8b3..44dfd0a 100644 --- a/src/analyze/gui/chartwidgetqwtplot.cpp +++ b/src/analyze/gui/chartwidgetqwtplot.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -117,22 +118,11 @@ ChartOptions::Options ChartOptions::toggleOption(Options option) ChartWidgetQwtPlot::ChartWidgetQwtPlot(QWidget *parent, Options options) : QwtPlot(parent), ChartOptions(options), m_model(nullptr), m_isSizeModel(false), - m_zoomer(new Zoomer(this)) + m_zoomer(nullptr), m_panner(nullptr) { setCanvasBackground(Qt::white); - enableAxis(QwtPlot::yRight); enableAxis(QwtPlot::yLeft, false); - // LeftButton for zooming - // Shift+LeftButton: zoom out by 1 - // Ctrl+LeftButton: zoom out to full size - m_zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::ControlModifier); - m_zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::LeftButton, Qt::ShiftModifier); - - // Alt+LeftButton for panning - auto panner = new QwtPlotPanner(canvas()); - panner->setMouseButton(Qt::LeftButton, Qt::AltModifier); - m_vLinePen.setStyle(Qt::DashLine); m_vLinePen.setColor(Qt::gray); } @@ -184,10 +174,6 @@ void ChartWidgetQwtPlot::rebuild(bool resetZoomAndPan) insertLegend(hasOption(ShowLegend) ? new QwtLegend() : nullptr); - auto grid = new QwtPlotGrid(); - grid->setPen(QPen(Qt::lightGray)); - grid->attach(this); - setAxisTitle(QwtPlot::xBottom, m_model->headerData(0).toString()); setAxisTitle(QwtPlot::yRight, m_model->headerData(1).toString()); setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw()); @@ -201,13 +187,18 @@ void ChartWidgetQwtPlot::rebuild(bool resetZoomAndPan) { column += 2; } + int curvesCount = 0; + int curvesAdded = 0; + int unresolvedCount = 0; int columns = m_model->columnCount(); for (; column < columns; column += 2) { + ++curvesCount; QString columnLabel = m_model->getColumnLabel(column); if (!hasOption(ShowUnresolved) && Util::isUnresolvedFunction(columnLabel)) // column label starts with a function name { + ++unresolvedCount; continue; } @@ -242,26 +233,92 @@ void ChartWidgetQwtPlot::rebuild(bool resetZoomAndPan) } curve->attach(this); + + ++curvesAdded; } - if (hasOption(ShowVLines)) + if (curvesAdded > 0) { - int rows = m_model->rowCount(); - for (int row = 1; row < rows; ++row) + enableAxis(QwtPlot::xBottom); + enableAxis(QwtPlot::yRight); + + auto grid = new QwtPlotGrid(); + grid->setPen(QPen(Qt::lightGray)); + grid->attach(this); + + if (hasOption(ShowVLines)) + { + int rows = m_model->rowCount(); + for (int row = 1; row < rows; ++row) + { + auto marker = new QwtPlotMarker(); + marker->setLinePen(m_vLinePen); + marker->setLineStyle(QwtPlotMarker::VLine); + marker->setXValue(m_model->getTimestamp(row)); + marker->attach(this); + } + } + + if (!m_zoomer) + { + m_zoomer = new Zoomer(this); + // LeftButton for zooming + // Shift+LeftButton: zoom out by 1 + // Ctrl+LeftButton: zoom out to full size + m_zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::ControlModifier); + m_zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::LeftButton, Qt::ShiftModifier); + } + + if (!m_panner) { - auto marker = new QwtPlotMarker(); - marker->setLinePen(m_vLinePen); - marker->setLineStyle(QwtPlotMarker::VLine); - marker->setXValue(m_model->getTimestamp(row)); - marker->attach(this); + m_panner = new QwtPlotPanner(canvas()); + // Alt+LeftButton for panning + m_panner->setMouseButton(Qt::LeftButton, Qt::AltModifier); } } + else + { + QString hint = QString("

Nothing to display.

"); + if (curvesCount > 0) + { + QString reason; + if (!hasOption(ShowTotal)) + { + reason = "Show total is off"; + } + if (unresolvedCount > 0) + { + if (!reason.isEmpty()) + { + reason += ". "; + } + reason += QString("Skipped %1 unresolved functions").arg(unresolvedCount); + } + hint += QString("

%1.

").arg(reason); + hint += QString("

Please use the context menu to control the chart display options.

"); + } + auto hintLabel = new QwtPlotTextLabel(); + hintLabel->setText(hint); + hintLabel->attach(this); + + delete m_zoomer; + m_zoomer = nullptr; + + delete m_panner; + m_panner = nullptr; + + enableAxis(QwtPlot::xBottom, false); + enableAxis(QwtPlot::yRight, false); + } replot(); if (resetZoomAndPan) { - m_zoomer->setZoomBase(false); + if (m_zoomer) + { + m_zoomer->setZoomBase(false); + } m_xScaleDiv = axisScaleDiv(QwtPlot::xBottom); m_yScaleDiv = axisScaleDiv(QwtPlot::yRight); } @@ -270,7 +327,7 @@ void ChartWidgetQwtPlot::rebuild(bool resetZoomAndPan) void ChartWidgetQwtPlot::resetZoom() { bool doReplot = false; - if (m_zoomer->zoomRectIndex() != 0) + if (m_zoomer && (m_zoomer->zoomRectIndex() != 0)) { m_zoomer->zoom(0); doReplot = true; diff --git a/src/analyze/gui/chartwidgetqwtplot.h b/src/analyze/gui/chartwidgetqwtplot.h index 3bffea5..071f278 100644 --- a/src/analyze/gui/chartwidgetqwtplot.h +++ b/src/analyze/gui/chartwidgetqwtplot.h @@ -8,6 +8,7 @@ class ChartModel; class Zoomer; +class QwtPanner; class ChartOptions { @@ -60,6 +61,8 @@ public: bool isSizeModel() const { return m_isSizeModel; } + bool isEmpty() const { return (m_zoomer == nullptr); } + virtual void setOptions(Options options) override; void rebuild(bool resetZoomAndPan); @@ -83,6 +86,8 @@ private: Zoomer *m_zoomer; + QwtPanner *m_panner; + QwtScaleDiv m_xScaleDiv, m_yScaleDiv; QString m_plotTooltip; diff --git a/src/analyze/gui/contextmenuqwt.cpp b/src/analyze/gui/contextmenuqwt.cpp index da3182b..e90c480 100644 --- a/src/analyze/gui/contextmenuqwt.cpp +++ b/src/analyze/gui/contextmenuqwt.cpp @@ -79,10 +79,11 @@ ContextMenuQwt::ContextMenuQwt(QObject *parent, bool isHistogram) } } -void ContextMenuQwt::initializeMenu(QMenu& menu, ChartOptions::Options options) const +void ContextMenuQwt::initializeMenu(QMenu& menu, ChartOptions::Options options, bool isEmpty) const { if (m_resetZoomAction) { + m_resetZoomAction->setEnabled(!isEmpty); menu.addAction(m_resetZoomAction); menu.addSeparator(); } @@ -123,6 +124,7 @@ void ContextMenuQwt::initializeMenu(QMenu& menu, ChartOptions::Options options) if (m_exportChartAction) { menu.addSeparator(); + m_exportChartAction->setEnabled(!isEmpty); menu.addAction(m_exportChartAction); } if (m_showHelpAction) diff --git a/src/analyze/gui/contextmenuqwt.h b/src/analyze/gui/contextmenuqwt.h index f6a54db..aaaf2e8 100644 --- a/src/analyze/gui/contextmenuqwt.h +++ b/src/analyze/gui/contextmenuqwt.h @@ -22,7 +22,7 @@ public: QAction* exportChartAction() const { return m_exportChartAction; } QAction* showHelpAction() const { return m_showHelpAction; } - void initializeMenu(QMenu& menu, ChartOptions::Options options) const; + void initializeMenu(QMenu& menu, ChartOptions::Options options, bool isEmpty) const; bool handleKeyPress(QKeyEvent *event); diff --git a/src/analyze/gui/histogramwidget.cpp b/src/analyze/gui/histogramwidget.cpp index 846b054..1d4f23f 100644 --- a/src/analyze/gui/histogramwidget.cpp +++ b/src/analyze/gui/histogramwidget.cpp @@ -240,7 +240,7 @@ void HistogramWidget::connectContextMenu() void HistogramWidget::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); - m_contextMenuQwt->initializeMenu(menu, m_plot->options()); + m_contextMenuQwt->initializeMenu(menu, m_plot->options(), false); menu.exec(event->globalPos()); } #endif