KD Chart 2  [rev.2.7]
KDChartTextLabelCache.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef KDCHARTTEXTLABELCACHE_H
24 #define KDCHARTTEXTLABELCACHE_H
25 
26 #include <QPixmap>
27 #include <QFont>
28 #include <QBrush>
29 #include <QPen>
30 
31 #include "KDChartEnums.h"
32 
37 public:
39  virtual ~PrerenderedElement() {}
40 
44  virtual const QPixmap& pixmap() const = 0;
45 
49 
51  void setPosition( const QPointF& position );
53  const QPointF& position() const;
54 
62 
63 protected:
70  virtual void invalidate() const = 0;
71 
72 private:
73  QPointF m_position;
74  KDChartEnums::PositionValue m_referencePoint;
75 };
76 
93 // FIXME this is merely a prototype
94 // FIXME caching could be done by a second layer that can be used to,
95 // e.g., query for a prerendered element by id or name, or by changing
96 // the pixmap() method to do lazy evaluation.
98 {
99 public:
101  ~PrerenderedLabel() override;
102 
103  void setFont( const QFont& font );
104  const QFont& font() const;
105 
106  void setText( const QString& text );
107  const QString& text() const;
108 
109  void setBrush( const QBrush& brush );
110  const QBrush& brush() const;
111 
112  void setPen( const QPen& );
113  const QPen& pen() const;
114 
115  void setAngle( qreal angle );
116  qreal angle() const;
117 
118  // reimpl PrerenderedElement:
119  const QPixmap& pixmap() const override;
121  // overload: return location of referencePoint():
122  QPointF referencePointLocation() const;
123 
124 protected:
125  void invalidate() const override;
126 
127 private:
131  void paint() const;
132 
133  // store the settings (these are used for the painting):
134  mutable bool m_dirty;
135  QFont m_font;
136  QString m_text;
137  QBrush m_brush;
138  QPen m_pen;
139  qreal m_angle;
140 
141  // these are valid once the label has been rendered:
142  mutable QPixmap m_pixmap;
143  mutable QPointF m_referenceBottomLeft;
144  mutable QPointF m_textBaseLineVector;
145  mutable QPointF m_textAscendVector;
146 };
147 
148 #endif
KDChartEnums::PositionValue
PositionValue
Numerical values of the static KDChart::Position instances, for using a Position::value() with a swit...
Definition: KDChartEnums.h:192
PrerenderedLabel::PrerenderedLabel
PrerenderedLabel()
Definition: KDChartTextLabelCache.cpp:77
PrerenderedElement::PrerenderedElement
PrerenderedElement()
Definition: KDChartTextLabelCache.cpp:52
PrerenderedElement
base class for prerendered elements like labels, pixmaps, markers, etc.
Definition: KDChartTextLabelCache.h:36
PrerenderedLabel::setPen
void setPen(const QPen &)
PrerenderedElement::pixmap
virtual const QPixmap & pixmap() const =0
Returns the rendered element.
PrerenderedLabel::text
const QString & text() const
Definition: KDChartTextLabelCache.cpp:129
PrerenderedElement::~PrerenderedElement
virtual ~PrerenderedElement()
Definition: KDChartTextLabelCache.h:39
PrerenderedLabel::setAngle
void setAngle(qreal angle)
Sets the angle of the label to angle degrees.
Definition: KDChartTextLabelCache.cpp:154
PrerenderedElement::referencePoint
KDChartEnums::PositionValue referencePoint() const
Get the reference point of the element.
Definition: KDChartTextLabelCache.cpp:72
PrerenderedLabel
PrerenderedLabel is an internal KDChart class that simplifies creation and caching of cached text lab...
Definition: KDChartTextLabelCache.h:98
PrerenderedLabel::brush
const QBrush & brush() const
Definition: KDChartTextLabelCache.cpp:146
PrerenderedElement::setReferencePoint
void setReferencePoint(KDChartEnums::PositionValue)
Set the reference point of the element.
Definition: KDChartTextLabelCache.cpp:67
KDChartEnums.h
Definition of global enums.
PrerenderedLabel::referencePointLocation
QPointF referencePointLocation() const
Definition: KDChartTextLabelCache.cpp:285
PrerenderedElement::position
const QPointF & position() const
Get the position of the element.
Definition: KDChartTextLabelCache.cpp:62
PrerenderedElement::invalidate
virtual void invalidate() const =0
invalidate() needs to be called if any of the properties that determine the visual appearance of the ...
PrerenderedLabel::angle
qreal angle() const
Definition: KDChartTextLabelCache.cpp:163
PrerenderedLabel::setBrush
void setBrush(const QBrush &brush)
Sets the label's brush to brush.
Definition: KDChartTextLabelCache.cpp:137
PrerenderedLabel::pen
const QPen & pen() const
PrerenderedLabel::setText
void setText(const QString &text)
Sets the label's text to text.
Definition: KDChartTextLabelCache.cpp:120
PrerenderedLabel::~PrerenderedLabel
~PrerenderedLabel() override
Definition: KDChartTextLabelCache.cpp:87
PrerenderedElement::setPosition
void setPosition(const QPointF &position)
Set the position of the element.
Definition: KDChartTextLabelCache.cpp:57
PrerenderedLabel::setFont
void setFont(const QFont &font)
Sets the label's font to font.
Definition: KDChartTextLabelCache.cpp:103
PrerenderedLabel::font
const QFont & font() const
Definition: KDChartTextLabelCache.cpp:112
PrerenderedElement::referencePointLocation
virtual QPointF referencePointLocation(KDChartEnums::PositionValue) const =0
Return the location of the reference point relatively to the pixmap's origin.
PrerenderedLabel::pixmap
const QPixmap & pixmap() const override
Returns the rendered element.
Definition: KDChartTextLabelCache.cpp:168
PrerenderedLabel::invalidate
void invalidate() const override
Invalidates the preredendered data, forces re-rendering.
Definition: KDChartTextLabelCache.cpp:95

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/