From a404a18c419c1e5d4ae2c713841d48d73b567fd7 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 28 Apr 2016 19:11:43 +0200 Subject: [PATCH] Add a dock widget with the important graphs. This allows the data to be visible when looking at other data and that makes it easier to correlate then. --- gui/chartwidget.cpp | 38 ++++++++++++++++++++++++++++++++++++- gui/chartwidget.h | 4 +++- gui/mainwindow.cpp | 14 +++++++++++++- gui/mainwindow.ui | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 3 deletions(-) diff --git a/gui/chartwidget.cpp b/gui/chartwidget.cpp index b56d1bf..4d7bfcc 100644 --- a/gui/chartwidget.cpp +++ b/gui/chartwidget.cpp @@ -84,7 +84,7 @@ ChartWidget::ChartWidget(QWidget* parent) ChartWidget::~ChartWidget() = default; -void ChartWidget::setModel(ChartModel* model) +void ChartWidget::setModel(ChartModel* model, bool minimalMode) { auto* coordinatePlane = dynamic_cast(m_chart->coordinatePlane()); Q_ASSERT(coordinatePlane); @@ -93,6 +93,30 @@ void ChartWidget::setModel(ChartModel* model) delete diagram; } + if (minimalMode) { + KChart::GridAttributes grid; + grid.setSubGridVisible(false); + coordinatePlane->setGlobalGridAttributes(grid); + } + + switch (model->type()) { + case ChartModel::Consumed: + setToolTip(i18n("Shows the heap memory consumption over time.")); + break; + case ChartModel::Allocated: + setToolTip(i18n("Displays total memory allocated over time. " + "This value ignores deallocations and just measures heap allocation throughput.")); + break; + case ChartModel::Allocations: + setToolTip(i18n("Shows number of memory allocations over time.")); + break; + case ChartModel::Temporary: + setToolTip(i18n("Shows 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.")); + break; + } + { auto totalPlotter = new Plotter(this); totalPlotter->setAntiAliasing(true); @@ -109,6 +133,14 @@ void ChartWidget::setModel(ChartModel* model) bottomAxis->setTextAttributes(axisTextAttributes); auto axisTitleTextAttributes = bottomAxis->titleTextAttributes(); axisTitleTextAttributes.setPen(foreground); + auto fontSize = axisTitleTextAttributes.fontSize(); + fontSize.setCalculationMode(KChartEnums::MeasureCalculationModeAbsolute); + if (minimalMode) { + fontSize.setValue(font().pointSizeF() - 2); + } else { + fontSize.setValue(font().pointSizeF() + 2); + } + axisTitleTextAttributes.setFontSize(fontSize); bottomAxis->setTitleTextAttributes(axisTitleTextAttributes); bottomAxis->setTitleText(model->headerData(0).toString()); bottomAxis->setPosition(CartesianAxis::Bottom); @@ -135,7 +167,11 @@ void ChartWidget::setModel(ChartModel* model) plotter->setModel(proxy); coordinatePlane->addDiagram(plotter); } +} +QSize ChartWidget::sizeHint() const +{ + return {400, 50}; } #include "chartwidget.moc" diff --git a/gui/chartwidget.h b/gui/chartwidget.h index 3b2ffd0..0abb65f 100644 --- a/gui/chartwidget.h +++ b/gui/chartwidget.h @@ -37,7 +37,9 @@ public: explicit ChartWidget(QWidget* parent = nullptr); virtual ~ChartWidget(); - void setModel(ChartModel* model); + void setModel(ChartModel* model, bool minimalMode = false); + + QSize sizeHint() const override; private: KChart::Chart* m_chart; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 333f242..9107d51 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -91,12 +91,15 @@ MainWindow::MainWindow(QWidget* parent) auto consumedModel = new ChartModel(ChartModel::Consumed, this); m_ui->consumedTab->setModel(consumedModel); + m_ui->consumedGraph->setModel(consumedModel, true); auto allocationsModel = new ChartModel(ChartModel::Allocations, this); m_ui->allocationsTab->setModel(allocationsModel); + m_ui->allocationsGraph->setModel(allocationsModel, true); auto allocatedModel = new ChartModel(ChartModel::Allocated, this); m_ui->allocatedTab->setModel(allocatedModel); auto temporaryModel = new ChartModel(ChartModel::Temporary, this); m_ui->temporaryTab->setModel(temporaryModel); + m_ui->temporaryGraph->setModel(temporaryModel, true); auto sizeHistogramModel = new HistogramModel(this); m_ui->sizesTab->setModel(sizeHistogramModel); @@ -134,6 +137,8 @@ MainWindow::MainWindow(QWidget* parent) this, [=] (const ChartData& data) { consumedModel->resetData(data); m_ui->tabWidget->setTabEnabled(m_ui->tabWidget->indexOf(m_ui->consumedTab), true); + m_ui->graphDock->setVisible(true); + m_ui->consumedGraph->setVisible(true); }); connect(m_parser, &Parser::allocatedChartDataAvailable, this, [=] (const ChartData& data) { @@ -144,11 +149,15 @@ MainWindow::MainWindow(QWidget* parent) this, [=] (const ChartData& data) { allocationsModel->resetData(data); m_ui->tabWidget->setTabEnabled(m_ui->tabWidget->indexOf(m_ui->allocationsTab), true); + m_ui->graphDock->setVisible(true); + m_ui->allocationsGraph->setVisible(true); }); connect(m_parser, &Parser::temporaryChartDataAvailable, this, [=] (const ChartData& data) { temporaryModel->resetData(data); m_ui->tabWidget->setTabEnabled(m_ui->tabWidget->indexOf(m_ui->temporaryTab), true); + m_ui->graphDock->setVisible(true); + m_ui->temporaryGraph->setVisible(true); }); connect(m_parser, &Parser::sizeHistogramDataAvailable, this, [=] (const HistogramData& data) { @@ -383,5 +392,8 @@ void MainWindow::setupStacks() this, [tabChanged] () { tabChanged(0); }); m_ui->stacksDock->setVisible(false); - m_ui->stacksDock->setFeatures(QDockWidget::DockWidgetMovable); + m_ui->graphDock->setVisible(false); + m_ui->consumedGraph->setVisible(false); + m_ui->allocationsGraph->setVisible(false); + m_ui->temporaryGraph->setVisible(false); } diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index ad83c97..1594385 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -15,6 +15,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -104,6 +116,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -565,6 +589,9 @@ + + QDockWidget::NoDockWidgetFeatures + S&tacks @@ -614,6 +641,33 @@ + + + Shows the heap memory consumption over time. + + + QDockWidget::AllDockWidgetFeatures + + + &Graphs + + + 8 + + + + + + + + + + + + + + + -- 2.7.4