diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-04 21:41:30 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-06 12:31:22 -0800 |
commit | 90129aa26f991676be8b0f94a5c1cffe123ffbb6 (patch) | |
tree | b93de819524fad37f11da28e041018fb42350e19 /stats/statsview.cpp | |
parent | ccc95f938a8538bde005b2865dc2868ffa8946c8 (diff) | |
download | subsurface-90129aa26f991676be8b0f94a5c1cffe123ffbb6.tar.gz |
statistics: render title
Since we want to get rid of QtCharts, we have to render our own
title. Simply keep around a QGraphicsSimpleTextItem and put in
the center of the chart. Define the borders to the scene as
constants.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'stats/statsview.cpp')
-rw-r--r-- | stats/statsview.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/stats/statsview.cpp b/stats/statsview.cpp index 11dbe4f1e..6709407e1 100644 --- a/stats/statsview.cpp +++ b/stats/statsview.cpp @@ -18,11 +18,14 @@ #include <QAbstractSeries> #include <QChart> #include <QGraphicsSceneHoverEvent> +#include <QGraphicsSimpleTextItem> #include <QLocale> // Constants that control the graph layouts static const QColor quartileMarkerColor(Qt::red); -static const double quartileMarkerSize = 15; +static const double quartileMarkerSize = 15.0; +static const double sceneBorder = 5.0; // Border between scene edges and statitistics view +static const double titleBorder = 2.0; // Border between title and chart static const QUrl urlStatsView = QUrl(QStringLiteral("qrc:/qml/statsview.qml")); @@ -77,6 +80,9 @@ StatsView::StatsView(QWidget *parent) : QQuickWidget(parent), chart->setAcceptHoverEvents(true); chart->legend()->setVisible(false); } + + QFont font; + titleFont = QFont(font.family(), font.pointSize(), QFont::Light); // Make configurable } StatsView::~StatsView() @@ -95,6 +101,7 @@ void StatsView::plotAreaChanged(const QRectF &) marker.updatePosition(); if (legend) legend->resize(); + updateTitlePos(); } void StatsView::replotIfVisible() @@ -136,7 +143,21 @@ T *StatsView::createSeries(Args&&... args) void StatsView::setTitle(const QString &s) { - chart->setTitle(s); + if (s.isEmpty()) { + title.reset(); + return; + } + title = std::make_unique<QGraphicsSimpleTextItem>(s, chart); + title->setFont(titleFont); +} + +void StatsView::updateTitlePos() +{ + if (!title) + return; + QRectF rect = chart->plotArea(); + title->setPos((rect.width() - title->boundingRect().width()) / 2.0, + sceneBorder); } template <typename T, class... Args> @@ -166,11 +187,18 @@ void StatsView::reset() lineMarkers.clear(); chart->removeAllSeries(); axes.clear(); + title.reset(); } void StatsView::plot(const StatsState &stateIn) { state = stateIn; + plotChart(); + plotAreaChanged(chart->plotArea()); +} + +void StatsView::plotChart() +{ if (!chart || !state.var1) return; reset(); |