From: Alexey Chernobaev Date: Tue, 20 Mar 2018 12:57:25 +0000 (+0300) Subject: "Show Unresolved" and "Show Curve Borders" options implemented for charts, tooltips... X-Git-Tag: submit/tizen/20180620.112952^2^2~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4999f79baad146f2dd66af6e431eb46089c7b780;p=sdk%2Ftools%2Fheaptrack.git "Show Unresolved" and "Show Curve Borders" options implemented for charts, tooltips improved (QWT) --- diff --git a/src/analyze/gui/chartmodel.cpp b/src/analyze/gui/chartmodel.cpp index 38bb979..45d34db 100644 --- a/src/analyze/gui/chartmodel.cpp +++ b/src/analyze/gui/chartmodel.cpp @@ -269,12 +269,7 @@ QString ChartModel::getColumnLabel(int column) const const QPen& ChartModel::getColumnDataSetPen(int column) const { -#ifdef QWT_FOUND - static QPen blackPen; - return blackPen; -#else return m_columnDataSetPens[column]; -#endif } const QBrush& ChartModel::getColumnDataSetBrush(int column) const diff --git a/src/analyze/gui/chartwidget.cpp b/src/analyze/gui/chartwidget.cpp index 6a59023..52dad56 100644 --- a/src/analyze/gui/chartwidget.cpp +++ b/src/analyze/gui/chartwidget.cpp @@ -84,7 +84,9 @@ public: }; } #elif defined(QWT_FOUND) -ChartWidgetQwtPlot::Options ChartWidget::globalOptions(ChartWidgetQwtPlot::ShowTotal | ChartWidgetQwtPlot::ShowLegend); +ChartWidgetQwtPlot::Options ChartWidget::globalOptions( + ChartWidgetQwtPlot::ShowTotal | ChartWidgetQwtPlot::ShowUnresolved | + ChartWidgetQwtPlot::ShowLegend | ChartWidgetQwtPlot::ShowCurveBorders); #endif ChartWidget::ChartWidget(QWidget* parent) @@ -134,22 +136,32 @@ void ChartWidget::createActions() 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 = 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_showLegendAction = new QAction(i18n("Show Legend"), this); + 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_showSymbolsAction = new QAction(i18n("Show Symbols"), this); + m_showCurveBorders = new QAction(i18n("Show Curve &Borders"), this); + m_showCurveBorders->setStatusTip(i18n("Show curve borders (as black lines)")); + m_showCurveBorders->setCheckable(true); + connect(m_showCurveBorders, &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 = 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); @@ -159,13 +171,17 @@ void ChartWidget::createActions() 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_showCurveBorders->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_showTotalAction->setShortcutVisibleInContextMenu(true); + m_showUnresolvedAction->setShortcutVisibleInContextMenu(true); m_showLegendAction->setShortcutVisibleInContextMenu(true); + m_showCurveBorders->setShortcutVisibleInContextMenu(true); m_showSymbolsAction->setShortcutVisibleInContextMenu(true); m_showVLinesAction->setShortcutVisibleInContextMenu(true); #endif @@ -311,9 +327,13 @@ void ChartWidget::contextMenuEvent(QContextMenuEvent *event) 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_showCurveBorders->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowCurveBorders)); + menu.addAction(m_showCurveBorders); m_showSymbolsAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowSymbols)); menu.addAction(m_showSymbolsAction); m_showVLinesAction->setChecked(m_plot->hasOption(ChartWidgetQwtPlot::ShowVLines)); @@ -334,9 +354,15 @@ void ChartWidget::keyPressEvent(QKeyEvent *event) 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; @@ -370,11 +396,21 @@ void ChartWidget::toggleShowTotal(bool checked) globalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowTotal, checked); } +void ChartWidget::toggleShowUnresolved(bool checked) +{ + globalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowUnresolved, checked); +} + void ChartWidget::toggleShowLegend(bool checked) { globalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowLegend, checked); } +void ChartWidget::toggleShowCurveBorders(bool checked) +{ + globalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowCurveBorders, checked); +} + void ChartWidget::toggleShowSymbols(bool checked) { globalOptions = m_plot->setOption(ChartWidgetQwtPlot::ShowSymbols, checked); diff --git a/src/analyze/gui/chartwidget.h b/src/analyze/gui/chartwidget.h index 55968c0..05f01f6 100644 --- a/src/analyze/gui/chartwidget.h +++ b/src/analyze/gui/chartwidget.h @@ -74,7 +74,9 @@ private: 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); private: @@ -84,9 +86,11 @@ private: QAction* m_resetZoomAction; QAction* m_showTotalAction; + QAction* m_showUnresolvedAction; QAction* m_showLegendAction; QAction* m_showSymbolsAction; QAction* m_showVLinesAction; + QAction* m_showCurveBorders; static ChartWidgetQwtPlot::Options globalOptions; #endif // QWT_FOUND, KChart_FOUND diff --git a/src/analyze/gui/chartwidgetqwtplot.cpp b/src/analyze/gui/chartwidgetqwtplot.cpp index 52b059e..e1ba57e 100644 --- a/src/analyze/gui/chartwidgetqwtplot.cpp +++ b/src/analyze/gui/chartwidgetqwtplot.cpp @@ -52,10 +52,19 @@ protected: { return {}; } - QString s; - if (m_plot->getCurveTooltip(pos, s)) + QwtText text; + text.setRenderFlags(text.renderFlags() & ~Qt::AlignHorizontal_Mask | Qt::AlignLeft); + text.setBorderRadius(6); + QString tooltip; + if (m_plot->getCurveTooltip(pos, tooltip)) { - s = "

" + s + "

"; + text.setText("

" + tooltip + "

"); + text.setColor(Qt::white); + QPen bandPen = rubberBandPen(); + text.setBorderPen(bandPen); + QColor c = bandPen.color(); + c.setAlpha(170); + text.setBackgroundBrush(c); m_plot->clearTooltip(); } else // show default text @@ -69,17 +78,16 @@ protected: { value = QString::number((qint64)pos.y()); } - s = QString(" %1 : %2 ").arg(Util::formatTime((qint64)pos.x())).arg(value); + text.setText(QString("

%1 : %2

") + .arg(Util::formatTime((qint64)pos.x())).arg(value)); + text.setColor(Qt::yellow); + static QPen bluePen(QColor(0, 0, 0xA0)); + text.setBorderPen(bluePen); + QColor c = bluePen.color(); + c.setAlpha(190); + text.setBackgroundBrush(c); m_plot->restoreTooltip(); } - QwtText text(s); - text.setRenderFlags(text.renderFlags() & ~Qt::AlignHorizontal_Mask | Qt::AlignLeft); - text.setColor(Qt::white); - QColor c = rubberBandPen().color(); - text.setBorderPen(QPen(c)); - text.setBorderRadius(6); - c.setAlpha(170); - text.setBackgroundBrush(c); return text; } private: @@ -130,8 +138,9 @@ void ChartWidgetQwtPlot::setOptions(Options options) if (m_options != options) { bool oldShowTotal = hasOption(ShowTotal); + bool oldShowUnresolved = hasOption(ShowUnresolved); m_options = options; - rebuild(oldShowTotal != hasOption(ShowTotal)); + rebuild(oldShowTotal != hasOption(ShowTotal) || (oldShowUnresolved != hasOption(ShowUnresolved))); } } @@ -182,6 +191,12 @@ void ChartWidgetQwtPlot::rebuild(bool resetZoomAndPan) int columns = m_model->columnCount(); for (; column < columns; column += 2) { + QString columnLabel = m_model->getColumnLabel(column); + if (!hasOption(ShowUnresolved) && columnLabel.startsWith("")) + { + continue; + } + auto adapter = new ChartModel2QwtSeriesData(m_model, column); QRectF bounds = adapter->boundingRect(); @@ -191,12 +206,16 @@ void ChartWidgetQwtPlot::rebuild(bool resetZoomAndPan) ? Util::formatByteSize(maxCost) : QString::number(maxCost)); int lastLineExtra = titleEnd.length() - 2 * 3; // minus the two "" tags length auto curve = new QwtPlotCurve( - Util::wrapLabel(m_model->getColumnLabel(column), MaxTitleLineLength, lastLineExtra) + + Util::wrapLabel(columnLabel, MaxTitleLineLength, lastLineExtra) + titleEnd); curve->setRenderHint(QwtPlotItem::RenderAntialiased, true); curve->setYAxis(QwtPlot::yRight); - curve->setPen(m_model->getColumnDataSetPen(column - 1)); + static QPen blackPen; + + curve->setPen(hasOption(ShowCurveBorders) + ? blackPen : m_model->getColumnDataSetPen(column - 1)); + curve->setBrush(m_model->getColumnDataSetBrush(column - 1)); curve->setSamples(adapter); @@ -274,7 +293,7 @@ bool ChartWidgetQwtPlot::getCurveTooltip(const QPointF &position, QString &toolt qint64 rowTimestamp = m_model->getTimestamp(row); // rowTimestamp <= timestamp // find a column which value (cost) for the row found is greater than or equal to // 'cost' and at the same time this value is the smallest from all such values - qint64 minCostFound = std::numeric_limits::max(); + qreal minCostFound = std::numeric_limits::max(); int columnFound = -1; int column = 1; if (!hasOption(ShowTotal)) @@ -285,32 +304,34 @@ bool ChartWidgetQwtPlot::getCurveTooltip(const QPointF &position, QString &toolt int rowCount = m_model->rowCount(); for (; column < columns; column += 2) { + if (!hasOption(ShowUnresolved) && + m_model->getColumnLabel(column).startsWith("")) + { + continue; + } qint64 columnCost = m_model->getCost(row, column); - if (columnCost <= minCostFound) + qreal intermediateCost = columnCost; + if ((rowTimestamp < timestamp) && (row + 1 < rowCount)) { - qreal intermediateCost = columnCost; - if ((rowTimestamp < timestamp) && (row + 1 < rowCount)) + // solve linear equation to find line-approximated 'intermediateCost' + qreal x1, y1, x2, y2; + x1 = rowTimestamp; + y1 = columnCost; + x2 = m_model->getTimestamp(row + 1); + y2 = m_model->getCost(row + 1, column); + qreal dx = x2 - x1; + if (dx > 1e-9) // avoid division by zero or near-zero { - // solve linear equation to find line-approximated 'intermediateCost' - qreal x1, y1, x2, y2; - x1 = rowTimestamp; - y1 = columnCost; - x2 = m_model->getTimestamp(row + 1); - y2 = m_model->getCost(row + 1, column); - qreal dx = x2 - x1; - if (dx > 1e-9) // avoid division by zero or near-zero - { - qreal a = (y2 - y1) / dx; - qreal b = (x2 * y1 - x1 * y2) / dx; - intermediateCost = a * timestamp + b; - } - } - if (cost <= intermediateCost) - { - minCostFound = columnCost; - columnFound = column; + qreal a = (y2 - y1) / dx; + qreal b = (x2 * y1 - x1 * y2) / dx; + intermediateCost = a * timestamp + b; } } + if ((cost <= intermediateCost) && (intermediateCost <= minCostFound)) + { + minCostFound = intermediateCost; + columnFound = column; + } } if (columnFound >= 0) { diff --git a/src/analyze/gui/chartwidgetqwtplot.h b/src/analyze/gui/chartwidgetqwtplot.h index 1eb0cc2..d1c5d72 100644 --- a/src/analyze/gui/chartwidgetqwtplot.h +++ b/src/analyze/gui/chartwidgetqwtplot.h @@ -16,9 +16,11 @@ public: { None = 0, ShowTotal = 0x01, + ShowUnresolved = 0x02, ShowLegend = 0x10, - ShowSymbols = 0x20, - ShowVLines = 0x40 + ShowCurveBorders = 0x20, + ShowSymbols = 0x40, + ShowVLines = 0x80 }; explicit ChartWidgetQwtPlot(QWidget *parent, Options options);