KChart

KChartTextLabelCache.h
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#ifndef KCHARTTEXTLABELCACHE_H
10#define KCHARTTEXTLABELCACHE_H
11
12#include <QPixmap>
13#include <QFont>
14#include <QBrush>
15#include <QPen>
16
17#include "KChartEnums.h"
18
19/**
20 * @brief base class for prerendered elements like labels, pixmaps, markers, etc.
21 */
23public:
25 virtual ~PrerenderedElement() {}
26
27 /** Returns the rendered element.
28 If any of the properties have change, the element will be
29 regenerated. */
30 virtual const QPixmap& pixmap() const = 0;
31
32 /** Return the location of the reference point relatively to the
33 pixmap's origin. */
35
36 /** Set the position of the element. */
37 void setPosition( const QPointF& position );
38 /** Get the position of the element. */
39 const QPointF& position() const;
40
41 /** Set the reference point of the element.
42 Every element has nine possible reference points (all compass
43 directions, plus the center.
44 */
46 /** Get the reference point of the element. */
48
49protected:
50 /** invalidate() needs to be called if any of the properties that
51 determine the visual appearance of the prerendered element
52 change.
53 It can be called for a const object, as objects may need to
54 force recalculation of the pixmap.
55 */
56 virtual void invalidate() const = 0;
57
58private:
59 QPointF m_position;
60 KChartEnums::PositionValue m_referencePoint;
61};
62
63/**
64 @brief PrerenderedLabel is an internal KChart class that simplifies creation
65 and caching of cached text labels.
66
67 It provides referenze points to anchor the text to other
68 elements. Reference points use the positions defined in
69 KChartEnums.
70
71 Usage:
72 <pre>
73 qreal angle = 90.0;
74 CachedLabel label;
75 label.paint( font, tr("Label"), angle );
76 </pre>
77*/
78
79// FIXME this is merely a prototype
80// FIXME caching could be done by a second layer that can be used to,
81// e.g., query for a prerendered element by id or name, or by changing
82// the pixmap() method to do lazy evaluation.
84{
85public:
87 ~PrerenderedLabel() override;
88
89
90 /**
91 * Sets the label's font to \a font.
92 */
93 void setFont( const QFont& font );
94
95 /**
96 * @return the label's font.
97 */
98 const QFont& font() const;
99
100
101 /**
102 * Sets the label's text to \a text
103 */
104 void setText( const QString& text );
105
106 /**
107 * @return the label's text
108 */
109 const QString& text() const;
110
111
112 /**
113 * Sets the label's brush to \a brush
114 */
115 void setBrush( const QBrush& brush );
116
117 /**
118 * @return the label's brush
119 */
120 const QBrush& brush() const;
121
122 void setPen( const QPen& );
123 const QPen& pen() const;
124
125
126 /**
127 * Sets the angle of the label to \a angle degrees
128 */
129 void setAngle( qreal angle );
130
131 /**
132 * @return the label's angle in degrees
133 */
134 qreal angle() const;
135
136 // reimpl PrerenderedElement:
137 const QPixmap& pixmap() const override;
139 // overload: return location of referencePoint():
140 QPointF referencePointLocation() const;
141
142protected:
143
144 /**
145 * Invalidates the preredendered data, forces re-rendering.
146 */
147 void invalidate() const override;
148
149private:
150 /** Create a label with the given text and the given rotation
151 angle. Needs to be const, otherwise the pixmap() method cannot
152 update when needed. */
153 void paint() const;
154
155 // store the settings (these are used for the painting):
156 mutable bool m_dirty;
157 QFont m_font;
158 QString m_text;
159 QBrush m_brush;
160 QPen m_pen;
161 qreal m_angle;
162
163 // these are valid once the label has been rendered:
164 mutable QPixmap m_pixmap;
165 mutable QPointF m_referenceBottomLeft;
166 mutable QPointF m_textBaseLineVector;
167 mutable QPointF m_textAscendVector;
168};
169
170#endif
Definition of global enums.
PositionValue
Numerical values of the static KChart::Position instances, for using a Position::value() with a switc...
base class for prerendered elements like labels, pixmaps, markers, etc.
virtual QPointF referencePointLocation(KChartEnums::PositionValue) const =0
Return the location of the reference point relatively to the pixmap's origin.
virtual void invalidate() const =0
invalidate() needs to be called if any of the properties that determine the visual appearance of the ...
void setPosition(const QPointF &position)
Set the position of the element.
virtual const QPixmap & pixmap() const =0
Returns the rendered element.
void setReferencePoint(KChartEnums::PositionValue)
Set the reference point of the element.
KChartEnums::PositionValue referencePoint() const
Get the reference point of the element.
const QPointF & position() const
Get the position of the element.
PrerenderedLabel is an internal KChart class that simplifies creation and caching of cached text labe...
void setAngle(qreal angle)
Sets the angle of the label to angle degrees.
const QString & text() const
void setFont(const QFont &font)
Sets the label's font to font.
const QBrush & brush() const
void invalidate() const override
Invalidates the preredendered data, forces re-rendering.
const QFont & font() const
void setBrush(const QBrush &brush)
Sets the label's brush to brush.
const QPixmap & pixmap() const override
Returns the rendered element.
QPointF referencePointLocation(KChartEnums::PositionValue position) const override
Return the location of the reference point relatively to the pixmap's origin.
void setText(const QString &text)
Sets the label's text to text.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 11:55:05 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.