aboutsummaryrefslogtreecommitdiffstats
path: root/stats/statsgrid.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-05 13:51:39 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-06 12:31:22 -0800
commitab324ed769b4d39816020bf649defb61cb4bff41 (patch)
tree066dfab03a5d3a370b7928d53eb0c18d96cda62e /stats/statsgrid.cpp
parent8dfa3f6db3eda8bce432afb7407efe2d8822ebbd (diff)
downloadsubsurface-ab324ed769b4d39816020bf649defb61cb4bff41.tar.gz
statistics: paint custom grid
With removal of QtCharts' axes, the grid was lost. Readd it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsgrid.cpp')
-rw-r--r--stats/statsgrid.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/stats/statsgrid.cpp b/stats/statsgrid.cpp
new file mode 100644
index 000000000..fe99b1762
--- /dev/null
+++ b/stats/statsgrid.cpp
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "statsgrid.h"
+#include "statsaxis.h"
+#include "statscolors.h"
+#include "zvalues.h"
+
+#include <QChart>
+#include <QGraphicsLineItem>
+
+static const double gridWidth = 1.0;
+static const Qt::PenStyle gridStyle = Qt::SolidLine;
+
+StatsGrid::StatsGrid(QtCharts::QChart *chart, const StatsAxis &xAxis, const StatsAxis &yAxis)
+ : chart(chart), xAxis(xAxis), yAxis(yAxis)
+{
+}
+
+void StatsGrid::updatePositions()
+{
+ std::vector<double> xtics = xAxis.ticksPositions();
+ std::vector<double> ytics = yAxis.ticksPositions();
+ lines.clear();
+ if (xtics.empty() || ytics.empty())
+ return;
+
+ for (double x: xtics) {
+ lines.emplace_back(new QGraphicsLineItem(x, ytics.front(), x, ytics.back(), chart));
+ lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
+ lines.back()->setZValue(ZValues::grid);
+ }
+ for (double y: ytics) {
+ lines.emplace_back(new QGraphicsLineItem(xtics.front(), y, xtics.back(), y, chart));
+ lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
+ lines.back()->setZValue(ZValues::grid);
+ }
+}