9#include "KChartTernaryAxis.h"
13#include <KChartChart.h>
14#include <KChartPaintContext.h>
16#include "TernaryConstants.h"
17#include "KChartTernaryCoordinatePlane.h"
18#include "KChartAbstractTernaryDiagram.h"
21#include "KChartLayoutItems.h"
22#include "KChartTextLabelCache.h"
35 resetTitleTextAttributes();
36 setPosition( KChartEnums::PositionSouth );
39 diagram->addAxis(
this );
42TernaryAxis::~TernaryAxis()
44 delete m_label; m_label =
nullptr;
45 delete m_fifty; m_fifty =
nullptr;
60 QPainter* p = paintContext->painter();
67 labels << m_label << m_fifty;
69 const QPixmap& pixmap = label->pixmap();
71 - label->referencePointLocation();
76bool TernaryAxis::isEmpty()
const
82QRect TernaryAxis::geometry ()
const
87void TernaryAxis::setGeometry (
const QRect &rect)
92QSize TernaryAxis::minimumSize ()
const
95 return QSize( 100, 100 );
98QSize TernaryAxis::maximumSize ()
const
100 return QSize( 300, 200 );
103QSize TernaryAxis::sizeHint ()
const
105 return QSize( 150, 100 );
113const Position TernaryAxis::position ()
const
118void TernaryAxis::setPosition (
Position p)
120 if ( p == position() )
return;
122 if ( p != KChartEnums::PositionWest
123 && p != KChartEnums::PositionEast
124 && p != KChartEnums::PositionSouth )
126 qDebug() <<
"TernaryAxis::setPosition: only south, east and west are supported "
127 "positions for ternary axes.";
131 if ( m_title.isEmpty() )
132 switch ( p.
value() ) {
133 case KChartEnums::PositionSouth:
134 m_label->setText(
tr(
"A" ) );
136 case KChartEnums::PositionWest:
137 m_label->setText(
tr(
"C" ) );
139 case KChartEnums::PositionEast:
140 m_label->setText(
tr(
"B" ) );
147 updatePrerenderedLabels();
150void TernaryAxis::setTitleText(
const QString& text )
153 m_label->setText( text );
156QString TernaryAxis::titleText()
const
158 return m_label->text();
161void TernaryAxis::setTitleTextAttributes(
const TextAttributes &a )
163 m_titleAttributes = a;
164 updatePrerenderedLabels();
169 return m_titleAttributes;
172void TernaryAxis::resetTitleTextAttributes()
175 m_titleAttributes = a;
176 updatePrerenderedLabels();
179bool TernaryAxis::hasDefaultTitleTextAttributes()
const
182 return m_titleAttributes == a;
185void TernaryAxis::updatePrerenderedLabels()
187 TextAttributes attributes = titleTextAttributes();
188 qreal axisLabelAngle = 0.0;
189 qreal fiftyMarkAngle = 0.0;
190 QPointF axisLabelPosition;
191 QPointF fiftyMarkPosition;
194 switch ( position().value() ) {
195 case KChartEnums::PositionSouth:
197 axisLabelAngle = 0.0;
198 fiftyMarkAngle = 0.0;
199 axisLabelPosition = TriangleTop;
200 fiftyMarkPosition = 0.5 * AxisVector_B_C - RelMarkerLength * Norm_B_C;
201 fiftyMarkReferencePoint = KChartEnums::PositionNorth;
203 case KChartEnums::PositionEast:
205 axisLabelAngle = 240.0;
207 axisLabelPosition = TriangleBottomLeft;
208 fiftyMarkPosition = AxisVector_B_C + 0.5 * AxisVector_C_A - RelMarkerLength * Norm_C_A;
209 fiftyMarkReferencePoint = KChartEnums::PositionSouth;
211 case KChartEnums::PositionWest:
213 axisLabelAngle = 120.0;
214 fiftyMarkAngle = 300.0;
215 axisLabelPosition = TriangleBottomRight;
216 fiftyMarkPosition = 0.5 * AxisVector_B_A + RelMarkerLength * Norm_B_A;
217 fiftyMarkReferencePoint = KChartEnums::PositionSouth;
219 case KChartEnums::PositionUnknown:
222 qDebug() <<
"TernaryAxis::updatePrerenderedLabel: unknown location";
225 m_label->setFont( attributes.
font() );
227 m_label->setAngle( axisLabelAngle );
228 m_label->setPosition( axisLabelPosition );
229 m_label->setReferencePoint( KChartEnums::PositionSouth );
230 QFont font = attributes.
font();
232 m_fifty->setFont( font );
233 m_fifty->setAngle( fiftyMarkAngle );
234 m_fifty->setPosition( fiftyMarkPosition );
235 m_fifty->setReferencePoint( fiftyMarkReferencePoint );
238QPair<QSizeF, QSizeF> TernaryAxis::requiredMargins()
const
240 QSizeF topleft( 0.0, 0.0 );
241 QSizeF bottomRight( 0.0, 0.0 );
243 switch ( position().value() ) {
244 case KChartEnums::PositionSouth:
246 topleft.setHeight( m_label->pixmap().height() );
247 bottomRight.setHeight( m_fifty->pixmap().height() );
249 case KChartEnums::PositionWest:
250 bottomRight.setWidth( m_label->pixmap().width()
251 - m_label->referencePointLocation().x() );
252 bottomRight.setHeight( m_label->pixmap().height()
253 - m_label->referencePointLocation().y() );
255 case KChartEnums::PositionEast:
256 topleft.setWidth( m_label->pixmap().width()
257 - ( m_label->pixmap().width()
258 - m_label->referencePointLocation().x() ) );
259 bottomRight.setHeight( m_label->pixmap().height()
260 - ( m_label->pixmap().height()
261 - m_label->referencePointLocation().y() ) );
264 qDebug() <<
"TernaryAxis::requiredMargins: unknown location";
267 return QPair<QSizeF, QSizeF>( topleft, bottomRight );
Project global class providing some enums needed both by KChartParams and by KChartCustomBox.
PositionValue
Numerical values of the static KChart::Position instances, for using a Position::value() with a switc...
QStringList labels() const
Returns a list of strings, that are used as axis labels, as set via setLabels.
Base class for diagrams based on a ternary coordinate plane.
Stores information about painting diagrams.
Defines a position, using compass terminology.
KChartEnums::PositionValue value() const
Returns an integer value corresponding to this Position.
void paintAll(QPainter &) override
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invo...
void paintCtx(PaintContext *) override
Default impl: Paint the complete item using its layouted position and size.
Ternary coordinate plane.
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.
A set of text attributes.
PrerenderedLabel is an internal KChart class that simplifies creation and caching of cached text labe...
qreal pointSizeF() const const
void setPointSizeF(qreal pointSize)
QString tr(const char *sourceText, const char *disambiguation, int n)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)