Add a dock widget with the important graphs.
authorMilian Wolff <mail@milianw.de>
Thu, 28 Apr 2016 17:11:43 +0000 (19:11 +0200)
committerMilian Wolff <mail@milianw.de>
Thu, 28 Apr 2016 17:18:42 +0000 (19:18 +0200)
This allows the data to be visible when looking at other data
and that makes it easier to correlate then.

gui/chartwidget.cpp
gui/chartwidget.h
gui/mainwindow.cpp
gui/mainwindow.ui

index b56d1bf..4d7bfcc 100644 (file)
@@ -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<CartesianCoordinatePlane*>(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("<qt>Shows the heap memory consumption over time.</qt>"));
+            break;
+        case ChartModel::Allocated:
+            setToolTip(i18n("<qt>Displays 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>"));
+            break;
+        case ChartModel::Temporary:
+            setToolTip(i18n("<qt>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.</qt>"));
+            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"
index 3b2ffd0..0abb65f 100644 (file)
@@ -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;
index 333f242..9107d51 100644 (file)
@@ -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);
 }
index ad83c97..1594385 100644 (file)
   </property>
   <widget class="QWidget" name="centralwidget">
    <layout class="QVBoxLayout" name="verticalLayout_6">
+    <property name="leftMargin">
+     <number>0</number>
+    </property>
+    <property name="topMargin">
+     <number>0</number>
+    </property>
+    <property name="rightMargin">
+     <number>0</number>
+    </property>
+    <property name="bottomMargin">
+     <number>0</number>
+    </property>
     <item>
      <widget class="KMessageWidget" name="messages">
       <property name="messageType">
       </widget>
       <widget class="QWidget" name="resultsPage">
        <layout class="QVBoxLayout" name="verticalLayout_2">
+        <property name="leftMargin">
+         <number>0</number>
+        </property>
+        <property name="topMargin">
+         <number>0</number>
+        </property>
+        <property name="rightMargin">
+         <number>0</number>
+        </property>
+        <property name="bottomMargin">
+         <number>0</number>
+        </property>
         <item>
          <widget class="QTabWidget" name="tabWidget">
           <property name="currentIndex">
    </layout>
   </widget>
   <widget class="QDockWidget" name="stacksDock">
+   <property name="features">
+    <set>QDockWidget::NoDockWidgetFeatures</set>
+   </property>
    <property name="windowTitle">
     <string>S&amp;tacks</string>
    </property>
     </layout>
    </widget>
   </widget>
+  <widget class="QDockWidget" name="graphDock">
+   <property name="toolTip">
+    <string>Shows the heap memory consumption over time.</string>
+   </property>
+   <property name="features">
+    <set>QDockWidget::AllDockWidgetFeatures</set>
+   </property>
+   <property name="windowTitle">
+    <string>&amp;Graphs</string>
+   </property>
+   <attribute name="dockWidgetArea">
+    <number>8</number>
+   </attribute>
+   <widget class="QWidget" name="graphs">
+    <layout class="QVBoxLayout" name="verticalLayout_14">
+     <item>
+      <widget class="ChartWidget" name="consumedGraph" native="true"/>
+     </item>
+     <item>
+      <widget class="ChartWidget" name="allocationsGraph" native="true"/>
+     </item>
+     <item>
+      <widget class="ChartWidget" name="temporaryGraph" native="true"/>
+     </item>
+    </layout>
+   </widget>
+  </widget>
  </widget>
  <customwidgets>
   <customwidget>