KChart

KChartTernaryPointDiagram.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "KChartTernaryPointDiagram.h"
10#include "KChartTernaryPointDiagram_p.h"
11
12#include <limits>
13
14#include <QPainter>
15
16#include <KChartPaintContext.h>
17
18#include "TernaryPoint.h"
19#include "TernaryConstants.h"
20
21using namespace KChart;
22
23#define d d_func()
24
25TernaryPointDiagram::Private::Private()
26 : AbstractTernaryDiagram::Private()
27{
28}
29
30TernaryPointDiagram::TernaryPointDiagram ( QWidget* parent,
32 : AbstractTernaryDiagram( new Private(), parent, plane )
33{
34 init();
35 setDatasetDimensionInternal( 3 ); // the third column is implicit
36}
37
38TernaryPointDiagram::~TernaryPointDiagram()
39{
40}
41
42void TernaryPointDiagram::init()
43{
44 d->reverseMapper.setDiagram( this );
45}
46
51
53{
54 d->reverseMapper.clear();
55
56 d->paint( paintContext );
57
58 // sanity checks:
59 if ( model() == nullptr ) return;
60
61 QPainter* p = paintContext->painter();
62 PainterSaver s( p );
63
65 static_cast< TernaryCoordinatePlane* >( paintContext->coordinatePlane() );
66 Q_ASSERT( plane );
67
68 qreal x, y, z;
69
70
71 // for some reason(?) TernaryPointDiagram is using per-diagram DVAs only:
73
74 d->forgetAlreadyPaintedDataValues();
75
76 int columnCount = model()->columnCount( rootIndex() );
77 for (int column=0; column<columnCount; column+=datasetDimension() )
78 {
79 int numrows = model()->rowCount( rootIndex() );
80 for ( int row = 0; row < numrows; row++ )
81 {
82 QModelIndex base = model()->index( row, column, rootIndex() ); // checked
83 // see if there is data otherwise skip
84 if ( ! model()->data( base ).isNull() )
85 {
86 p->setPen( PrintingParameters::scalePen( pen( base ) ) );
87 p->setBrush( brush( base ) );
88
89 // retrieve data
90 x = qMax<qreal>( model()->data( model()->index( row, column+0, rootIndex() ) ).toReal(), // checked
91 0.0 );
92 y = qMax<qreal>( model()->data( model()->index( row, column+1, rootIndex() ) ).toReal(), // checked
93 0.0 );
94 z = qMax<qreal>( model()->data( model()->index( row, column+2, rootIndex() ) ).toReal(), // checked
95 0.0 );
96
97 // fix messed up data values (paint as much as possible)
98 qreal total = x + y + z;
99 if ( fabs( total ) > 3 * std::numeric_limits<qreal>::epsilon() ) {
101 QPointF diagramLocation = translate( tPunkt );
103
104 paintMarker( p, model()->index( row, column, rootIndex() ), widgetLocation ); // checked
105 QString text = tr( "(%1, %2, %3)", "(x, y, z) values of the data point" )
106 .arg( x * 100, 0, 'f', 0 )
107 .arg( y * 100, 0, 'f', 0 )
108 .arg( z * 100, 0, 'f', 0 );
109 d->paintDataValueText( p, attrs, widgetLocation, true, text, true );
110 } else {
111 // ignore and do not paint this point, garbage data
112 qDebug() << "TernaryPointDiagram::paint: data point x/y/z:"
113 << x << "/" << y << "/" << z << "ignored, unusable.";
114 }
115 }
116 }
117 }
118}
119
120const QPair< QPointF, QPointF > TernaryPointDiagram::calculateDataBoundaries () const
121{
122 // this is a constant, because we defined it to be one:
124 TriangleBottomLeft,
125 QPointF( TriangleBottomRight.x(), TriangleHeight ) );
126 return Boundaries;
127}
128
DataValueAttributes dataValueAttributes() const
Retrieve the DataValueAttributes specified globally.
QPen pen() const
Retrieve the pen to be used for painting datapoints globally.
QBrush brush() const
Retrieve the brush to be used for painting datapoints globally.
int datasetDimension() const
The dataset dimension of a diagram determines how many value dimensions it expects each datapoint to ...
Base class for diagrams based on a ternary coordinate plane.
Diagram attributes dealing with data value labels.
Stores information about painting diagrams.
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.
void resize(const QSizeF &area) override
Called by the widget's sizeEvent.
void paint(PaintContext *paintContext) override
Draw the diagram contents to the rectangle and painter, that are passed in as part of the paint conte...
TernaryPoint defines a point within a ternary coordinate plane.
QCA_EXPORT void init()
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(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
qreal x() const const
QString arg(Args &&... args) const const
void resize(const QSize &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:54:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.