mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: turn ChartGrid into QSGNodes
Turn the background grid into QSGNodes. Each grid line is represented by a QSG line item. An alternative would be drawing the grid into a QImage and blasting that onto the screen. It is unclear which one is preferred. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c74975632e
commit
9b7565e81a
4 changed files with 17 additions and 20 deletions
|
@ -33,7 +33,6 @@ private:
|
||||||
std::vector<std::unique_ptr<QCheckBox>> features;
|
std::vector<std::unique_ptr<QCheckBox>> features;
|
||||||
|
|
||||||
ChartListModel charts;
|
ChartListModel charts;
|
||||||
//QStringListModel charts;
|
|
||||||
void showEvent(QShowEvent *) override;
|
void showEvent(QShowEvent *) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "statsgrid.h"
|
#include "statsgrid.h"
|
||||||
|
#include "chartitem.h"
|
||||||
#include "statsaxis.h"
|
#include "statsaxis.h"
|
||||||
#include "statscolors.h"
|
#include "statscolors.h"
|
||||||
#include "statshelper.h"
|
#include "statsview.h"
|
||||||
#include "zvalues.h"
|
#include "zvalues.h"
|
||||||
|
|
||||||
#include <QGraphicsLineItem>
|
|
||||||
|
|
||||||
static const double gridWidth = 1.0;
|
static const double gridWidth = 1.0;
|
||||||
static const Qt::PenStyle gridStyle = Qt::SolidLine;
|
|
||||||
|
|
||||||
StatsGrid::StatsGrid(QGraphicsScene *scene, const StatsAxis &xAxis, const StatsAxis &yAxis)
|
StatsGrid::StatsGrid(StatsView &view, const StatsAxis &xAxis, const StatsAxis &yAxis)
|
||||||
: scene(scene), xAxis(xAxis), yAxis(yAxis)
|
: view(view), xAxis(xAxis), yAxis(yAxis)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,18 +17,19 @@ void StatsGrid::updatePositions()
|
||||||
{
|
{
|
||||||
std::vector<double> xtics = xAxis.ticksPositions();
|
std::vector<double> xtics = xAxis.ticksPositions();
|
||||||
std::vector<double> ytics = yAxis.ticksPositions();
|
std::vector<double> ytics = yAxis.ticksPositions();
|
||||||
|
|
||||||
|
// We probably should be smarter and reuse existing lines.
|
||||||
|
// For now, this does it.
|
||||||
lines.clear();
|
lines.clear();
|
||||||
if (xtics.empty() || ytics.empty())
|
if (xtics.empty() || ytics.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (double x: xtics) {
|
for (double x: xtics) {
|
||||||
lines.emplace_back(createItem<QGraphicsLineItem>(scene, x, ytics.front(), x, ytics.back()));
|
lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, gridColor, gridWidth));
|
||||||
lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
|
lines.back()->setLine(QPointF(x, ytics.front()), QPointF(x, ytics.back()));
|
||||||
lines.back()->setZValue(ZValues::grid);
|
|
||||||
}
|
}
|
||||||
for (double y: ytics) {
|
for (double y: ytics) {
|
||||||
lines.emplace_back(createItem<QGraphicsLineItem>(scene, xtics.front(), y, xtics.back(), y));
|
lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, gridColor, gridWidth));
|
||||||
lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
|
lines.back()->setLine(QPointF(xtics.front(), y), QPointF(xtics.back(), y));
|
||||||
lines.back()->setZValue(ZValues::grid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,17 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QVector>
|
|
||||||
#include <QGraphicsLineItem>
|
|
||||||
|
|
||||||
class StatsAxis;
|
class StatsAxis;
|
||||||
class QGraphicsScene;
|
class StatsView;
|
||||||
|
class ChartLineItem;
|
||||||
|
|
||||||
class StatsGrid {
|
class StatsGrid {
|
||||||
public:
|
public:
|
||||||
StatsGrid(QGraphicsScene *scene, const StatsAxis &xAxis, const StatsAxis &yAxis);
|
StatsGrid(StatsView &view, const StatsAxis &xAxis, const StatsAxis &yAxis);
|
||||||
void updatePositions();
|
void updatePositions();
|
||||||
private:
|
private:
|
||||||
QGraphicsScene *scene;
|
StatsView &view;
|
||||||
const StatsAxis &xAxis, &yAxis;
|
const StatsAxis &xAxis, &yAxis;
|
||||||
std::vector<std::unique_ptr<QGraphicsLineItem>> lines;
|
std::vector<std::unique_ptr<ChartLineItem>> lines;
|
||||||
};
|
};
|
||||||
|
|
|
@ -317,7 +317,7 @@ void StatsView::setAxes(StatsAxis *x, StatsAxis *y)
|
||||||
xAxis = x;
|
xAxis = x;
|
||||||
yAxis = y;
|
yAxis = y;
|
||||||
if (x && y)
|
if (x && y)
|
||||||
grid = std::make_unique<StatsGrid>(&scene, *x, *y);
|
grid = std::make_unique<StatsGrid>(*this, *x, *y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatsView::reset()
|
void StatsView::reset()
|
||||||
|
|
Loading…
Add table
Reference in a new issue