KD Chart API Documentation 3.0
Loading...
Searching...
No Matches
KDChartTernaryLineDiagram.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 "KDChartTernaryLineDiagram_p.h"
13
14#include <limits>
15
16#include <QPainter>
17
18#include <KDChartPaintContext.h>
19
23#include "KDChartPainterSaver_p.h"
24#include "TernaryConstants.h"
25#include "TernaryPoint.h"
26
27using namespace KDChart;
28
29#define d d_func()
30
31TernaryLineDiagram::Private::Private()
32 : AbstractTernaryDiagram::Private()
33{
34}
35
53
57
58void TernaryLineDiagram::init()
59{
60}
61
63{
64 Q_UNUSED(area);
65}
66
68{
69 d->reverseMapper.clear();
70
71 d->paint(paintContext);
72 // sanity checks:
73 if (model() == nullptr)
74 return;
75
76 QPainter *p = paintContext->painter();
77 PainterSaver s(p);
78
79 auto *plane =
80 ( TernaryCoordinatePlane * )paintContext->coordinatePlane();
81 Q_ASSERT(plane);
82
83 qreal x, y, z;
84
85 // for some reason(?) TernaryPointDiagram is using per-diagram DVAs only:
87
88 d->forgetAlreadyPaintedDataValues();
89
90 int columnCount = model()->columnCount(rootIndex());
91 QPointF start;
92 for (int column = 0; column < columnCount; column += datasetDimension()) {
93 int numrows = model()->rowCount(rootIndex());
94 for (int row = 0; row < numrows; row++) {
95 // see if there is data otherwise skip
96 QModelIndex base = model()->index(row, column); // checked
97 if (!model()->data(base).isNull()) {
99 p->setBrush(brush(base));
100
101 // retrieve data
102 x = qMax(model()->data(model()->index(row, column, rootIndex())).toReal(), // checked
103 ( qreal )0.0);
104 y = qMax(model()->data(model()->index(row, column + 1, rootIndex())).toReal(), // checked
105 ( qreal )0.0);
106 z = qMax(model()->data(model()->index(row, column + 2, rootIndex())).toReal(), // checked
107 ( qreal )0.0);
108
109 qreal total = x + y + z;
110 if (fabs(total) > 3 * std::numeric_limits<qreal>::epsilon()) {
113 QPointF widgetLocation = plane->translate(diagramLocation);
114
115 if (row > 0) {
116 p->drawLine(start, widgetLocation);
117 }
118 paintMarker(p, model()->index(row, column, rootIndex()), widgetLocation); // checked
119 start = widgetLocation;
120 // retrieve text and data value attributes
121 // FIXME use data model DisplayRole text
122 QString text = tr("(%1, %2, %3)")
123 .arg(x * 100, 0, 'f', 0)
124 .arg(y * 100, 0, 'f', 0)
125 .arg(z * 100, 0, 'f', 0);
126 d->paintDataValueText(p, attrs, widgetLocation, true, text, true);
127 } else {
128 // ignore and do not paint this point, garbage data
129 qDebug() << "TernaryPointDiagram::paint: data point x/y/z:"
130 << x << "/" << y << "/" << z << "ignored, unusable.";
131 }
132 }
133 }
134 }
135}
136
138{
139 // this is a constant, because we defined it to be one:
143 return Boundaries;
144}
Declaring the class KDChart::DataValueAttributes.
const QPointF TriangleBottomLeft(0.0, 0.0)
const qreal TriangleHeight
const QPointF TriangleBottomRight(1.0, 0.0)
QPointF translate(const TernaryPoint &point)
virtual AttributesModel * attributesModel() const
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.
void setDefaultForRole(int role, const QVariant &value)
Diagram attributes dealing with data value labels.
void setMarkerAttributes(const MarkerAttributes &a)
A set of attributes controlling the appearance of data set markers.
Stores information about painting diagrams.
static QPen scalePen(const QPen &pen)
const QPair< QPointF, QPointF > calculateDataBoundaries() const override
TernaryLineDiagram(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.
@ DataValueLabelAttributesRole
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 drawLine(const QLineF &line)
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
QVariant fromValue(const T &value)

© 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