KD Chart API Documentation 3.0
Loading...
Searching...
No Matches
KDChartTernaryPointDiagram.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
12#include "KDChartTernaryPointDiagram_p.h"
13
14#include <limits>
15
16#include <QPainter>
17
18#include <KDChartPaintContext.h>
19
20#include "TernaryConstants.h"
21#include "TernaryPoint.h"
22
23using namespace KDChart;
24
25#define d d_func()
26
27TernaryPointDiagram::Private::Private()
28 : AbstractTernaryDiagram::Private()
29{
30}
31
34 : AbstractTernaryDiagram(new Private(), parent, plane)
35{
36 init();
37 setDatasetDimensionInternal(3); // the third column is implicit
38}
39
43
44void TernaryPointDiagram::init()
45{
46 d->reverseMapper.setDiagram(this);
47}
48
50{
51 Q_UNUSED(area);
52}
53
55{
56 d->reverseMapper.clear();
57
58 d->paint(paintContext);
59
60 // sanity checks:
61 if (model() == nullptr)
62 return;
63
64 QPainter *p = paintContext->painter();
65 PainterSaver s(p);
66
67 auto *plane =
68 static_cast<TernaryCoordinatePlane *>(paintContext->coordinatePlane());
69 Q_ASSERT(plane);
70
71 qreal x, y, z;
72
73 // for some reason(?) TernaryPointDiagram is using per-diagram DVAs only:
75
76 d->forgetAlreadyPaintedDataValues();
77
78 int columnCount = model()->columnCount(rootIndex());
79 for (int column = 0; column < columnCount; column += datasetDimension()) {
80 int numrows = model()->rowCount(rootIndex());
81 for (int row = 0; row < numrows; row++) {
82 QModelIndex base = model()->index(row, column, rootIndex()); // checked
83 // see if there is data otherwise skip
84 if (!model()->data(base).isNull()) {
86 p->setBrush(brush(base));
87
88 // retrieve data
89 x = qMax(model()->data(model()->index(row, column + 0, rootIndex())).toReal(), // checked
90 ( qreal )0.0);
91 y = qMax(model()->data(model()->index(row, column + 1, rootIndex())).toReal(), // checked
92 ( qreal )0.0);
93 z = qMax(model()->data(model()->index(row, column + 2, rootIndex())).toReal(), // checked
94 ( qreal )0.0);
95
96 // fix messed up data values (paint as much as possible)
97 qreal total = x + y + z;
98 if (fabs(total) > 3 * std::numeric_limits<qreal>::epsilon()) {
101 QPointF widgetLocation = plane->translate(diagramLocation);
102
103 paintMarker(p, model()->index(row, column, rootIndex()), widgetLocation); // checked
104 QString text = tr("(%1, %2, %3)")
105 .arg(x * 100, 0, 'f', 0)
106 .arg(y * 100, 0, 'f', 0)
107 .arg(z * 100, 0, 'f', 0);
108 d->paintDataValueText(p, attrs, widgetLocation, true, text, true);
109 } else {
110 // ignore and do not paint this point, garbage data
111 qDebug() << "TernaryPointDiagram::paint: data point x/y/z:"
112 << x << "/" << y << "/" << z << "ignored, unusable.";
113 }
114 }
115 }
116 }
117}
118
120{
121 // this is a constant, because we defined it to be one:
125 return Boundaries;
126}
const QPointF TriangleBottomLeft(0.0, 0.0)
const qreal TriangleHeight
const QPointF TriangleBottomRight(1.0, 0.0)
QPointF translate(const TernaryPoint &point)
virtual void paintMarker(QPainter *painter, const MarkerAttributes &markerAttributes, const QBrush &brush, const QPen &, const QPointF &point, const QSizeF &size)
DataValueAttributes dataValueAttributes() const
void setDatasetDimensionInternal(int dimension)
Base class for diagrams based on a ternary coordinate plane.
Diagram attributes dealing with data value labels.
Stores information about painting diagrams.
static QPen scalePen(const QPen &pen)
const QPair< QPointF, QPointF > calculateDataBoundaries() const override
TernaryPointDiagram(QWidget *parent=nullptr, TernaryCoordinatePlane *plane=nullptr)
void resize(const QSizeF &area) override
void paint(PaintContext *paintContext) override
TernaryPoint defines a point within a ternary coordinate plane.
virtual int columnCount(const QModelIndex &parent) const const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual int rowCount(const QModelIndex &parent) const const=0
QAbstractItemModel * model() const const
QModelIndex rootIndex() const const
T qobject_cast(QObject *object)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setBrush(const QBrush &brush)
void setPen(const QColor &color)
qreal x() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Fri Feb 23 2024 00:02:59 for KD Chart API Documentation by doxygen 1.9.8