mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: convert chart to QQuickItem
It turns out that the wrong base class was used for the chart. QQuickWidget can only be used on desktop, not in a mobile UI. Therefore, turn this into a QQuickItem and move the container QQuickWidget into desktop-only code. Currently, this code is insane: The chart is rendered onto a QGraphicsScene (as it was before), which is then rendered into a QImage, which is transformed into a QSGTexture, which is then projected onto the device. This is performed on every mouse move event, since these events in general change the position of the info-box. The plan is to slowly convert elements such as the info-box into QQuickItems. Browsing the QtQuick documentation, this will not be much fun. Also note that the rendering currently tears, flickers and has antialiasing artifacts, most likely owing to integer (QImage) to floating point (QGraphicsScene, QQuickItem) conversion problems. The data flow is QGraphicsScene (float) -> QImage (int) -> QQuickItem (float). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f6b857b8fe
commit
e7907c494f
32 changed files with 299 additions and 269 deletions
|
@ -4,8 +4,8 @@
|
|||
#include "zvalues.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QPen>
|
||||
|
||||
static const double legendBorderSize = 2.0;
|
||||
|
@ -16,8 +16,8 @@ static const double legendInternalBorderSize = 2.0;
|
|||
static const QColor legendColor(0x00, 0x8e, 0xcc, 192); // Note: fourth argument is opacity
|
||||
static const QColor legendBorderColor(Qt::black);
|
||||
|
||||
Legend::Legend(QGraphicsWidget *chart, const std::vector<QString> &names) :
|
||||
RoundRectItem(legendBoxBorderRadius, chart), chart(chart),
|
||||
Legend::Legend(const std::vector<QString> &names) :
|
||||
RoundRectItem(legendBoxBorderRadius),
|
||||
displayedItems(0), width(0.0), height(0.0)
|
||||
{
|
||||
setZValue(ZValues::legend);
|
||||
|
@ -40,8 +40,6 @@ Legend::Legend(QGraphicsWidget *chart, const std::vector<QString> &names) :
|
|||
}
|
||||
setPen(QPen(legendBorderColor, legendBorderSize));
|
||||
setBrush(QBrush(legendColor));
|
||||
|
||||
resize(); // Draw initial legend
|
||||
}
|
||||
|
||||
Legend::Entry::Entry(const QString &name, int idx, int numBins, QGraphicsItem *parent) :
|
||||
|
@ -70,7 +68,7 @@ void Legend::resize()
|
|||
if (entries.empty())
|
||||
return hide();
|
||||
|
||||
QSizeF size = chart->size();
|
||||
QSizeF size = scene()->sceneRect().size();
|
||||
|
||||
// Silly heuristics: make the legend at most half as high and half as wide as the chart.
|
||||
// Not sure if that makes sense - this might need some optimization.
|
||||
|
@ -110,7 +108,7 @@ void Legend::updatePosition()
|
|||
if (displayedItems <= 0)
|
||||
return hide();
|
||||
// For now, place the legend in the top right corner.
|
||||
QPointF pos(chart->size().width() - width - 10.0, 10.0);
|
||||
QPointF pos(scene()->sceneRect().width() - width - 10.0, 10.0);
|
||||
setRect(QRectF(pos, QSizeF(width, height)));
|
||||
for (int i = 0; i < displayedItems; ++i) {
|
||||
QPointF itemPos = pos + entries[i].pos;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue