KD Chart 2  [rev.2.6]
KDChartTextLabelCache.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2019 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 
48  virtual QPointF referencePointLocation( KDChartEnums::PositionValue ) const = 0;
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();
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;
121  // overload: return location of referencePoint():
122  QPointF referencePointLocation() const;
123 
124 protected:
125  void invalidate() const;
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
virtual QPointF referencePointLocation(KDChartEnums::PositionValue) const =0
Return the location of the reference point relatively to the pixmap&#39;s origin.
virtual const QPixmap & pixmap() const =0
Returns the rendered element.
Definition of global enums.
const QPointF & position() const
Get the position of the element.
virtual void invalidate() const =0
invalidate() needs to be called if any of the properties that determine the visual appearance of the ...
KDChartEnums::PositionValue referencePoint() const
Get the reference point of the element.
PrerenderedLabel is an internal KDChart class that simplifies creation and caching of cached text lab...
base class for prerendered elements like labels, pixmaps, markers, etc.
void setReferencePoint(KDChartEnums::PositionValue)
Set the reference point of the element.
PositionValue
Numerical values of the static KDChart::Position instances, for using a Position::value() with a swit...
Definition: KDChartEnums.h:192
void setPosition(const QPointF &position)
Set the position of the element.

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
https://www.kdab.com/
https://www.kdab.com/products/kd-chart/