KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
KDChartTernaryAxis.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
11#include "KDChartTernaryAxis.h"
12
13#include <QPainter>
14
15#include <KDChartChart.h>
16#include <KDChartPaintContext.h>
17
20#include "TernaryConstants.h"
21
22#include "KDChartLayoutItems.h"
24
25using namespace KDChart;
26
27// m_label and m_fifty do not have to be pointers, once the class is
28// pimpled (PrerenderedLabel is not published API)
29
31 : AbstractAxis(diagram)
32 , m_position(KDChartEnums::PositionUnknown)
33 , m_label(new PrerenderedLabel)
34 , m_fifty(new PrerenderedLabel)
35{
38 m_fifty->setText(QObject::tr("50%")); // const
39 // FIXME is this consistent with other diagram/axis/plane implementations?
40 diagram->addAxis(this);
41}
42
44{
45 delete m_label;
46 m_label = nullptr;
47 delete m_fifty;
48 m_fifty = nullptr;
49}
50
52{
53 // not used
54}
55
57{
58 // not used
59}
60
62{
63 QPainter *p = paintContext->painter();
64 auto *plane =
65 ( TernaryCoordinatePlane * )paintContext->coordinatePlane();
66 // QObject* refArea = plane->parent();
67
68 // paint the axis label (across the triangle, that one):
70 m_label,
71 m_fifty,
72 };
74 const QPixmap &pixmap = label->pixmap();
75 QPointF point = plane->translate(label->position())
76 - label->referencePointLocation();
77 p->drawPixmap(point, pixmap);
78 }
79}
80
82{
83 // todo: what's this method for?
84 return false;
85}
86
88{
89 return m_geometry;
90}
91
93{
94 m_geometry = rect;
95}
96
98{
99 // todo: return realistic sizes
100 return QSize(100, 100);
101}
102
104{
105 return QSize(300, 200);
106}
107
109{
110 return QSize(150, 100);
111}
112
117
119{
120 return m_position;
121}
122
124{
125 if (p == position())
126 return;
127
131 qDebug() << "TernaryAxis::setPosition: only south, east and west are supported "
132 "positions for ternary axes.";
133 return;
134 }
135
136 if (m_title.isEmpty())
137 switch (p.value()) {
139 m_label->setText(tr("A"));
140 break;
142 m_label->setText(tr("C"));
143 break;
145 m_label->setText(tr("B"));
146 break;
147 default:
148 break;
149 }
150
151 m_position = p;
152 updatePrerenderedLabels(); // position has changed
153}
154
156{
157 m_title = text; // do not remove
158 m_label->setText(text);
159}
160
162{
163 return m_label->text();
164}
165
167{
168 m_titleAttributes = a;
169 updatePrerenderedLabels();
170}
171
173{
174 return m_titleAttributes;
175}
176
178{
180 m_titleAttributes = a;
181 updatePrerenderedLabels();
182}
183
185{
187 return m_titleAttributes == a;
188}
189
190void TernaryAxis::updatePrerenderedLabels()
191{
192 TextAttributes attributes = titleTextAttributes();
193 qreal axisLabelAngle = 0.0;
194 qreal fiftyMarkAngle = 0.0;
198
199 switch (position().value()) {
201 // this is the axis on the other side of A
202 axisLabelAngle = 0.0;
203 fiftyMarkAngle = 0.0;
207 break;
209 // this is the axis on the other side of B
210 axisLabelAngle = 240.0;
211 fiftyMarkAngle = 60;
215 break;
217 // this is the axis on the other side of C
218 axisLabelAngle = 120.0;
219 fiftyMarkAngle = 300.0;
223 break;
225 break; // initial value
226 default:
227 qDebug() << "TernaryAxis::updatePrerenderedLabel: unknown location";
228 };
229
230 m_label->setFont(attributes.font());
231 // m_label->setText( titleText() ); // done by setTitleText()
232 m_label->setAngle(axisLabelAngle);
235 QFont font = attributes.font();
236 font.setPointSizeF(0.85 * font.pointSizeF());
237 m_fifty->setFont(font);
238 m_fifty->setAngle(fiftyMarkAngle);
241}
242
244{
245 QSizeF topleft(0.0, 0.0);
246 QSizeF bottomRight(0.0, 0.0);
247
248 switch (position().value()) {
250 // the label of the south axis is, in fact, up north.
251 topleft.setHeight(m_label->pixmap().height());
252 bottomRight.setHeight(m_fifty->pixmap().height());
253 break;
255 bottomRight.setWidth(m_label->pixmap().width()
256 - m_label->referencePointLocation().x());
257 bottomRight.setHeight(m_label->pixmap().height()
258 - m_label->referencePointLocation().y());
259 break;
261 topleft.setWidth(m_label->pixmap().width()
262 - (m_label->pixmap().width()
263 - m_label->referencePointLocation().x()));
264 bottomRight.setHeight(m_label->pixmap().height()
265 - (m_label->pixmap().height()
266 - m_label->referencePointLocation().y()));
267 break;
268 default:
269 qDebug() << "TernaryAxis::requiredMargins: unknown location";
270 }
271 // qDebug() << "TernaryAxis::requiredMargins:" << topleft << bottomRight;
272 return QPair<QSizeF, QSizeF>(topleft, bottomRight);
273}
const QPointF TriangleBottomLeft(0.0, 0.0)
const QPointF AxisVector_B_C(TriangleBottomRight)
const qreal RelMarkerLength
const QPointF TriangleBottomRight(1.0, 0.0)
const QPointF AxisVector_B_A(TriangleTop)
const QPointF TriangleTop(0.5, TriangleHeight)
const QPointF Norm_B_C
const QPointF Norm_C_A
const QPointF Norm_B_A
const QPointF AxisVector_C_A
const AbstractDiagram * diagram() const
Base class for diagrams based on a ternary coordinate plane.
Stores information about painting diagrams.
Defines a position, using compass terminology.
KDChartEnums::PositionValue value() const
bool isEmpty() const override
void paintAll(QPainter &) override
virtual const Position position() const
void paintCtx(PaintContext *) override
void paint(QPainter *) override
QPair< QSizeF, QSizeF > requiredMargins() const
QSize sizeHint() const override
bool hasDefaultTitleTextAttributes() const
virtual void setPosition(Position p)
Qt::Orientations expandingDirections() const override
void setTitleTextAttributes(const TextAttributes &a)
QRect geometry() const override
void setTitleText(const QString &text)
void setGeometry(const QRect &rect) override
TernaryAxis(AbstractTernaryDiagram *diagram=nullptr)
QSize minimumSize() const override
QSize maximumSize() const override
TextAttributes titleTextAttributes() const
A set of text attributes.
void setReferencePoint(KDChartEnums::PositionValue)
void setPosition(const QPointF &position)
PrerenderedLabel is an internal KDChart class that simplifies creation and caching of cached text lab...
void setAngle(qreal angle)
const QString & text() const
void setFont(const QFont &font)
QPointF referencePointLocation(KDChartEnums::PositionValue position) const override
const QPixmap & pixmap() const override
void setText(const QString &text)
qreal pointSizeF() const const
void setPointSizeF(qreal pointSize)
T qobject_cast(QObject *object)
QString tr(const char *sourceText, const char *disambiguation, int n)
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
int height() const const
int width() const const
qreal x() const const
qreal y() const const
void setHeight(qreal height)
void setWidth(qreal width)
bool isEmpty() const const
typedef Orientations

© 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 Wed May 1 2024 00:01:10 for KD Chart API Documentation by doxygen 1.9.8