Commit bd5a3548 authored by Milian Wolff's avatar Milian Wolff
Browse files

Use correct axis and labels in time charts.

parent 65a4e0a4
......@@ -71,6 +71,19 @@ QVariant ChartModel::headerData(int section, Qt::Orientation orientation, int ro
} else if (role == KChart::DatasetBrushRole) {
return QVariant::fromValue(QBrush(colorForColumn(section, columnCount())));
}
if (role == Qt::DisplayRole || Qt::ToolTipRole) {
switch (section) {
case ChartModel::AllocatedColumn:
return i18n("Memory Allocated");
case ChartModel::AllocationsColumn:
return i18n("Memory Allocations");
case ChartModel::LeakedColumn:
return i18n("Memory Leaked");
case ChartModel::TimeStampColumn:
return i18n("Elapsed Time");
}
}
}
return {};
}
......
......@@ -57,7 +57,7 @@ public:
NUM_COLUMNS
};
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation = Qt::Horizontal, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
......
......@@ -20,11 +20,12 @@
#include "chartproxy.h"
#include "chartmodel.h"
#include <KLocalizedString>
#include <QDebug>
ChartProxy::ChartProxy(const QString& label, int column, QObject* parent)
ChartProxy::ChartProxy(ChartModel::Columns column, QObject* parent)
: QSortFilterProxyModel(parent)
, m_label(label)
, m_column(column)
{}
......@@ -33,9 +34,6 @@ ChartProxy::~ChartProxy() = default;
QVariant ChartProxy::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_ASSERT(orientation != Qt::Horizontal || section < columnCount());
if (section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole) {
return m_label;
}
return QSortFilterProxyModel::headerData(section, orientation, role);
}
......
......@@ -21,12 +21,13 @@
#define CHARTPROXY_H
#include <QSortFilterProxyModel>
#include "chartmodel.h"
class ChartProxy : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit ChartProxy(const QString& label, int column, QObject* parent = nullptr);
explicit ChartProxy(ChartModel::Columns column, QObject* parent = nullptr);
virtual ~ChartProxy();
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
......@@ -36,8 +37,7 @@ protected:
bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const override;
private:
QString m_label;
int m_column;
ChartModel::Columns m_column;
};
#endif //CHARTPROXY_H
......@@ -36,7 +36,7 @@
#include <KLocalizedString>
#include <KColorScheme>
#include "chartmodel.h"
#include "chartproxy.h"
using namespace KChart;
......@@ -52,8 +52,7 @@ public:
virtual const QString customizedLabel(const QString& label) const
{
// squeeze large numbers here
// TODO: when the unit is 'b' also use prettyCost() here
return QString::number(label.toDouble());
return QString::number(label.toDouble() / 1000, 'g', 2) + QLatin1Char('s');
}
};
......@@ -86,8 +85,30 @@ ChartWidget::ChartWidget(QWidget* parent)
m_plotter->setAntiAliasing(true);
m_plotter->setType(KChart::Plotter::Stacked);
auto* coordinatePlane = dynamic_cast<CartesianCoordinatePlane*>(m_chart->coordinatePlane());
Q_ASSERT(coordinatePlane);
coordinatePlane->addDiagram(m_plotter);
}
ChartWidget::~ChartWidget() = default;
void ChartWidget::setModel(ChartModel* model, ChartModel::Columns costColumn)
{
if (m_plotter->model()) {
delete m_plotter->model();
}
Q_ASSERT(costColumn != ChartModel::TimeStampColumn);
auto proxy = new ChartProxy(costColumn, this);
proxy->setSourceModel(model);
foreach (auto axis, m_plotter->axes()) {
m_plotter->takeAxis(axis);
delete axis;
}
KColorScheme scheme(QPalette::Active, KColorScheme::Window);
QPen foreground(scheme.foreground().color());
const QPen foreground(scheme.foreground().color());
auto bottomAxis = new TimeAxis(m_plotter);
auto axisTextAttributes = bottomAxis->textAttributes();
axisTextAttributes.setPen(foreground);
......@@ -95,27 +116,18 @@ ChartWidget::ChartWidget(QWidget* parent)
auto axisTitleTextAttributes = bottomAxis->titleTextAttributes();
axisTitleTextAttributes.setPen(foreground);
bottomAxis->setTitleTextAttributes(axisTitleTextAttributes);
bottomAxis->setTitleText(i18n("time in ms"));
bottomAxis->setTitleText(model->headerData(ChartModel::TimeStampColumn).toString());
bottomAxis->setPosition(KChart::CartesianAxis::Bottom);
m_plotter->addAxis(bottomAxis);
auto* rightAxis = new SizeAxis(m_plotter);
CartesianAxis* rightAxis = costColumn == ChartModel::AllocationsColumn ? new CartesianAxis(m_plotter) : new SizeAxis(m_plotter);
rightAxis->setTextAttributes(axisTextAttributes);
rightAxis->setTitleTextAttributes(axisTitleTextAttributes);
rightAxis->setTitleText(i18n("memory heap size"));
rightAxis->setTitleText(model->headerData(costColumn).toString());
rightAxis->setPosition(CartesianAxis::Right);
m_plotter->addAxis(rightAxis);
auto* coordinatePlane = dynamic_cast<CartesianCoordinatePlane*>(m_chart->coordinatePlane());
Q_ASSERT(coordinatePlane);
coordinatePlane->addDiagram(m_plotter);
}
ChartWidget::~ChartWidget() = default;
void ChartWidget::setModel(QAbstractItemModel* model)
{
m_plotter->setModel(model);
m_plotter->setModel(proxy);
}
#include "chartwidget.moc"
......@@ -21,13 +21,13 @@
#define CHARTWIDGET_H
#include <QWidget>
#include "chartmodel.h"
namespace KChart {
class Chart;
class Plotter;
}
class ChartModel;
class QAbstractItemModel;
class ChartWidget : public QWidget
......@@ -37,7 +37,7 @@ public:
explicit ChartWidget(QWidget* parent = nullptr);
virtual ~ChartWidget();
void setModel(QAbstractItemModel* model);
void setModel(ChartModel* model, ChartModel::Columns costColumn);
private:
KChart::Chart* m_chart;
......
......@@ -50,17 +50,9 @@ MainWindow::MainWindow(QWidget* parent)
m_ui->loadingProgress->setMinimum(0);
m_ui->loadingProgress->setMaximum(0);
auto leakedProxy = new ChartProxy(i18n("Memory Leaked"), ChartModel::LeakedColumn, this);
leakedProxy->setSourceModel(m_chartModel);
m_ui->leakedTab->setModel(leakedProxy);
auto allocationsProxy = new ChartProxy(i18n("Memory Allocations"), ChartModel::AllocationsColumn, this);
allocationsProxy->setSourceModel(m_chartModel);
m_ui->allocationsTab->setModel(allocationsProxy);
auto allocatedProxy = new ChartProxy(i18n("Memory Allocated"), ChartModel::AllocatedColumn, this);
allocatedProxy->setSourceModel(m_chartModel);
m_ui->allocatedTab->setModel(allocatedProxy);
m_ui->leakedTab->setModel(m_chartModel, ChartModel::LeakedColumn);
m_ui->allocationsTab->setModel(m_chartModel, ChartModel::AllocationsColumn);
m_ui->allocatedTab->setModel(m_chartModel, ChartModel::AllocatedColumn);
connect(m_parser, &Parser::bottomUpDataAvailable,
m_bottomUpModel, &TreeModel::resetData);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment