setToolTip(i18n("<qt>Shows the number of instances allocated from specific functions over time.</qt>"));
break;
case ChartModel::Allocated:
- setToolTip(i18n("<qt>Displays total memory allocated over time. "
+ setToolTip(i18n("<qt>Displays the total memory allocated over time. "
"This value ignores deallocations and just measures heap "
"allocation throughput.</qt>"));
break;
case ChartModel::Allocations:
- setToolTip(i18n("<qt>Shows number of memory allocations over time.</qt>"));
+ setToolTip(i18n("<qt>Shows the number of memory allocations over time.</qt>"));
break;
case ChartModel::Temporary:
- setToolTip(i18n("<qt>Shows number of temporary memory allocations over time. "
+ setToolTip(i18n("<qt>Shows the number of temporary memory allocations over time. "
"A temporary allocation is one that is followed immediately by its "
"corresponding deallocation, without other allocations happening "
"in-between.</qt>"));
return;
}
- int columns = m_model->columnCount();
- int rows = m_model->rowCount();
-
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());
setAxisScaleDraw(QwtPlot::yRight, new SizeScaleDraw());
}
- auto grid = new QwtPlotGrid();
- grid->attach(this);
-
int column = 1;
if (!hasOption(ShowTotal))
{
column += 2;
}
+ int columns = m_model->columnCount();
for (; column < columns; column += 2)
{
auto adapter = new ChartModel2QwtSeriesData(m_model, column);
if (hasOption(ShowVLines))
{
+ int rows = m_model->rowCount();
for (int row = 1; row < rows; ++row)
{
auto marker = new QwtPlotMarker();
#include "noklib.h"
#include <qwt_column_symbol.h>
+#include <qwt_plot_grid.h>
#include <qwt_plot_multi_barchart.h>
+#include <qwt_scale_draw.h>
+
+class HistogramScaleDraw: public QwtScaleDraw
+{
+public:
+ HistogramScaleDraw(QVector<QString>& rowNames) : m_rowNames(rowNames) { }
+
+ virtual QwtText label(double value) const
+ {
+ qint64 index = (qint64)value;
+ if ((index >= 0) && (index < m_rowNames.size()))
+ {
+ return m_rowNames[index];
+ }
+ return QwtScaleDraw::label(value);
+ }
+
+private:
+ QVector<QString> m_rowNames;
+};
HistogramWidgetQwtPlot::HistogramWidgetQwtPlot(QWidget *parent)
- : QwtPlot(parent),
- m_barChart(nullptr)
+ : QwtPlot(parent), m_model(nullptr)
{
setCanvasBackground(Qt::white);
enableAxis(QwtPlot::yRight);
void HistogramWidgetQwtPlot::rebuild(bool resetZoomAndPan)
{
detachItems();
- m_barChart = nullptr;
if (!m_model)
{
return;
}
- m_barChart = new QwtPlotMultiBarChart();
- m_barChart->setSpacing(40); // TODO!! use dynamic spacing
- m_barChart->setStyle(QwtPlotMultiBarChart::Stacked);
+ auto grid = new QwtPlotGrid();
+ grid->setPen(QPen(Qt::lightGray));
+ grid->attach(this);
- int columns = m_model->columnCount();
- int rows = m_model->rowCount();
+ setAxisAutoScale(QwtPlot::yRight);
- int maxColumn = 0;
+ auto totalBarChart = new QwtPlotMultiBarChart();
+ totalBarChart->setStyle(QwtPlotMultiBarChart::Stacked);
+ totalBarChart->setLayoutHint(0.33);
+ totalBarChart->setLayoutPolicy(QwtPlotMultiBarChart::ScaleSamplesToAxes);
+
+ auto barChart = new QwtPlotMultiBarChart();
+ barChart->setStyle(QwtPlotMultiBarChart::Stacked);
+ barChart->setLayoutHint(totalBarChart->layoutHint());
+ barChart->setLayoutPolicy(QwtPlotMultiBarChart::ScaleSamplesToAxes);
+
+ QVector<QString> rowNames;
+ QVector<QVector<double>> totalSeries;
QVector<QVector<double>> series;
+ int rows = m_model->rowCount();
+ int columns = m_model->columnCount();
+ int maxColumn = 0;
for (int row = 0; row < rows; ++row)
{
- QString rowName = m_model->headerData(row, Qt::Vertical).toString();
+ rowNames.append(m_model->headerData(row, Qt::Vertical).toString());
+
+ QVector<double> totalValues;
+ totalValues.append(m_model->data(m_model->index(row, 0)).toDouble());
+ totalSeries.append(totalValues);
+
QVector<double> values;
for (int column = 1; column < columns; ++column)
{
series.append(values);
}
- for (int column = 1; column <= maxColumn; ++column)
+ for (int column = 0; column <= maxColumn; ++column)
{
auto symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
symbol->setLineWidth(2);
symbol->setPalette(QPalette(m_model->getColumnColor(column)));
- m_barChart->setSymbol(column - 1, symbol);
+ if (column > 0)
+ {
+ barChart->setSymbol(column - 1, symbol);
+ }
+ else
+ {
+ totalBarChart->setSymbol(0, symbol);
+ }
}
- m_barChart->setSamples(series);
+ totalBarChart->setSamples(totalSeries);
+ barChart->setSamples(series);
- setAxisAutoScale(QwtPlot::yRight);
- m_barChart->setAxes(QwtPlot::xBottom, QwtPlot::yRight);
+ auto bottomScale = new HistogramScaleDraw(rowNames);
+ bottomScale->enableComponent(QwtScaleDraw::Backbone, false);
+ bottomScale->enableComponent(QwtScaleDraw::Ticks, false);
+ setAxisScaleDraw(QwtPlot::xBottom, bottomScale);
+
+ totalBarChart->setAxes(QwtPlot::xBottom, QwtPlot::yRight);
+ barChart->setAxes(QwtPlot::xBottom, QwtPlot::yRight);
- m_barChart->attach(this);
+ totalBarChart->attach(this);
+ barChart->attach(this);
}