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
};
}
#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)
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);
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
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));
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;
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);
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:
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
{
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
{
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:
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)));
}
}
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();
? 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);
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))
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)
{
{
None = 0,
ShowTotal = 0x01,
+ ShowUnresolved = 0x02,
ShowLegend = 0x10,
- ShowSymbols = 0x20,
- ShowVLines = 0x40
+ ShowCurveBorders = 0x20,
+ ShowSymbols = 0x40,
+ ShowVLines = 0x80
};
explicit ChartWidgetQwtPlot(QWidget *parent, Options options);