"Show Unresolved" and "Show Curve Borders" options implemented for charts, tooltips...
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Tue, 20 Mar 2018 12:57:25 +0000 (15:57 +0300)
committerAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Tue, 20 Mar 2018 12:57:25 +0000 (15:57 +0300)
src/analyze/gui/chartmodel.cpp
src/analyze/gui/chartwidget.cpp
src/analyze/gui/chartwidget.h
src/analyze/gui/chartwidgetqwtplot.cpp
src/analyze/gui/chartwidgetqwtplot.h

index 38bb979f98b99041b543dcd856b436846fd2e180..45d34db6db8db3f38a159365c1f7922c4a357e77 100644 (file)
@@ -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
index 6a590235d4af996e596d25a0cc2de9b4be0cf3f8..52dad56c1de3babe7652353789ef5e94926fc824 100644 (file)
@@ -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);
index 55968c0f984fbcdb328791ff2fd4a1cb81158918..05f01f63baed11d93e90c74e6f832f289fbb792b 100644 (file)
@@ -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
index 52b059e55cf377ecb07398e2073e263b23b7b963..e1ba57ecaf6e75d44b8185e391e24e310a84c6d5 100644 (file)
@@ -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 = "<p style='margin-left:4px'>" + s + "</p> ";
+            text.setText("<p style='margin-left:4px'>" + tooltip + "</p> ");
+            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("<p style='margin-left:4px'><b>%1 : %2</b></p> ")
+                         .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("<unresolved function>"))
+        {
+            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 "<b>" 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<qint64>::max();
+    qreal minCostFound = std::numeric_limits<qreal>::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("<unresolved function>"))
+        {
+            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)
     {
index 1eb0cc22024fd4dd7ccc9aeebda11fad5a68657c..d1c5d724647cf700a6abcd8d8e601fc58e97b826 100644 (file)
@@ -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);