KPlotting

kplotobject.h
1 /* -*- C++ -*-
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2003 Jason Harris <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KPLOTOBJECT_H
9 #define KPLOTOBJECT_H
10 
11 #include <kplotting_export.h>
12 
13 #include <QColor>
14 #include <QString>
15 
16 class QBrush;
17 class QPainter;
18 class QPen;
19 class QPointF;
20 class KPlotWidget;
21 class KPlotPoint;
22 
23 /**
24  * @class KPlotObject
25  * @short Encapsulates a data set to be plotted in a KPlotWidget.
26  *
27  * Think of a KPlotObject as a set of data displayed as a group in the plot.
28  * Each KPlotObject consists of a list of KPlotPoints, a "type" controlling
29  * how the data points are displayed (some combination of Points, Lines, or
30  * Bars), a color, and a size. There is also a parameter which controls the
31  * shape of the points used to display the KPlotObject.
32  *
33  * @note KPlotObject will take care of the points added to it, so when clearing
34  * the points list (eg with clearPoints()) any previous reference to a KPlotPoint
35  * already added to a KPlotObject will be invalid.
36  *
37  * @author Jason Harris
38  * @version 1.1
39  */
40 class KPLOTTING_EXPORT KPlotObject
41 {
42 public:
43  /**
44  * The type classification of the KPlotObject.
45  *
46  * These are bitmask values that can be OR'd together, so that a set
47  * of points can be represented in the plot in multiple ways.
48  *
49  * @note points should be added in order of increasing x-coordinate
50  * when using Bars.
51  */
52  enum PlotType {
53  UnknownType = 0,
54  Points = 1, ///< each KPlotPoint is represented with a drawn point
55  Lines = 2, ///< each KPlotPoint is connected with a line
56  Bars = 4, ///< each KPlotPoint is shown as a vertical bar
57  };
58  Q_DECLARE_FLAGS(PlotTypes, PlotType)
59 
60  /**
61  * The available shape styles for plotted points.
62  */
63  enum PointStyle {
64  NoPoints = 0,
65  Circle = 1,
66  Letter = 2,
67  Triangle = 3,
68  Square = 4,
69  Pentagon = 5,
70  Hexagon = 6,
71  Asterisk = 7,
72  Star = 8,
73  UnknownPoint,
74  };
75 
76  /**
77  * Constructor.
78  * @param color The color for plotting this object. By default this sets
79  * the color for Points, Lines and Bars, but there are functions to
80  * override any of these.
81  * @param otype the PlotType for this object (Points, Lines or Bars)
82  * @param size the size to use for plotted points, in pixels
83  * @param ps The PointStyle describing the shape for plotted points
84  */
85  explicit KPlotObject(const QColor &color = Qt::white, PlotType otype = Points, double size = 2.0, PointStyle ps = Circle);
86 
87  /**
88  * Destructor.
89  */
90  ~KPlotObject();
91 
92  /**
93  * @return the plot flags of the object
94  */
95  PlotTypes plotTypes() const;
96 
97  /**
98  * Set whether points will be drawn for this object
99  * @param b if true, points will be drawn
100  */
101  void setShowPoints(bool b);
102 
103  /**
104  * Set whether lines will be drawn for this object
105  * @param b if true, lines will be drawn
106  */
107  void setShowLines(bool b);
108 
109  /**
110  * Set whether bars will be drawn for this object
111  * @param b if true, bars will be drawn
112  */
113  void setShowBars(bool b);
114 
115  /**
116  * @return the size of the plotted points in this object, in pixels
117  */
118  double size() const;
119 
120  /**
121  * Set the size for plotted points in this object, in pixels
122  * @param s the new size
123  */
124  void setSize(double s);
125 
126  /**
127  * @return the style used for drawing the points in this object
128  */
129  PointStyle pointStyle() const;
130 
131  /**
132  * Set a new style for drawing the points in this object
133  * @param p the new style
134  */
135  void setPointStyle(PointStyle p);
136 
137  /**
138  * @return the default pen for this Object.
139  * If no other pens are set, this pen will be used for
140  * points, lines, bars and labels (this pen is always used for points).
141  */
142  const QPen &pen() const;
143 
144  /**
145  * Set the default pen for this object
146  * @p The pen to use
147  */
148  void setPen(const QPen &p);
149 
150  /**
151  * @return the pen to use for drawing lines for this Object.
152  */
153  const QPen &linePen() const;
154 
155  /**
156  * Set the pen to use for drawing lines for this object
157  * @p The pen to use
158  */
159  void setLinePen(const QPen &p);
160 
161  /**
162  * @return the pen to use for drawing bars for this Object.
163  */
164  const QPen &barPen() const;
165 
166  /**
167  * Set the pen to use for drawing bars for this object
168  * @p The pen to use
169  */
170  void setBarPen(const QPen &p);
171 
172  /**
173  * @return the pen to use for drawing labels for this Object.
174  */
175  const QPen &labelPen() const;
176 
177  /**
178  * Set the pen to use for labels for this object
179  * @p The pen to use
180  */
181  void setLabelPen(const QPen &p);
182 
183  /**
184  * @return the default Brush to use for this Object.
185  */
186  const QBrush brush() const;
187 
188  /**
189  * Set the default brush to use for this object
190  * @b The brush to use
191  */
192  void setBrush(const QBrush &b);
193 
194  /**
195  * @return the brush to use for filling bars for this Object.
196  */
197  const QBrush barBrush() const;
198 
199  /**
200  * Set the brush to use for drawing bars for this object
201  * @b The brush to use
202  */
203  void setBarBrush(const QBrush &b);
204 
205  /**
206  * @return the list of KPlotPoints that make up this object
207  */
208  QList<KPlotPoint *> points() const;
209 
210  /**
211  * Add a point to the object's list of points, using input data to construct a KPlotPoint.
212  * @param p the QPointF to add.
213  * @param label the optional text label for this point
214  * @param barWidth the width of the bar, if this object is to be drawn with bars
215  * @note if @param barWidth is left at its default value of 0.0, then the width will be
216  * automatically set to the distance between this point and the one to its right.
217  */
218  void addPoint(const QPointF &p, const QString &label = QString(), double barWidth = 0.0);
219 
220  /**
221  * Add a given KPlotPoint to the object's list of points.
222  * @overload
223  * @param p pointer to the KPlotPoint to add.
224  */
225  void addPoint(KPlotPoint *p);
226 
227  /**
228  * Add a point to the object's list of points, using input data to construct a KPlotPoint.
229  * @overload
230  * @param x the X-coordinate of the point to add.
231  * @param y the Y-coordinate of the point to add.
232  * @param label the optional text label
233  * @param barWidth the width of the bar, if this object is to be drawn with bars
234  * @note if @param barWidth is left at its default value of 0.0, then the width will be
235  * automatically set to the distance between this point and the one to its right.
236  */
237  void addPoint(double x, double y, const QString &label = QString(), double barWidth = 0.0);
238 
239  /**
240  * Remove the QPointF at position index from the list of points
241  * @param index the index of the point to be removed.
242  */
243  void removePoint(int index);
244 
245  /**
246  * Remove and destroy the points of this object
247  */
248  void clearPoints();
249 
250  /**
251  * Draw this KPlotObject on the given QPainter
252  * @param p The QPainter to draw on
253  * @param pw the KPlotWidget to draw on (this is needed
254  * for the KPlotWidget::mapToWidget() function)
255  */
256  void draw(QPainter *p, KPlotWidget *pw);
257 
258 private:
259  class Private;
260  Private *const d;
261 
262  Q_DISABLE_COPY(KPlotObject)
263 };
264 Q_DECLARE_OPERATORS_FOR_FLAGS(KPlotObject::PlotTypes)
265 
266 #endif
Encapsulates a point in the plot. A KPlotPoint consists of X and Y coordinates (in Data units),...
Definition: kplotpoint.h:27
Encapsulates a data set to be plotted in a KPlotWidget.
Definition: kplotobject.h:40
Generic data plotting widget.
Definition: kplotwidget.h:67
PlotType
The type classification of the KPlotObject.
Definition: kplotobject.h:52
PointStyle
The available shape styles for plotted points.
Definition: kplotobject.h:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Oct 3 2023 04:10:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.