KChart

KChartWidget.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 __KCHARTWIDGET_H__
10 #define __KCHARTWIDGET_H__
11 
12 #include "KChartGlobal.h"
13 
14 #include <QWidget>
15 
16 #include "KChartEnums.h"
17 #include "KChartHeaderFooter.h"
18 
19 QT_BEGIN_NAMESPACE
20 template <typename T> class QVector;
21 template <typename T1, typename T2> struct QPair;
22 QT_END_NAMESPACE
23 
24 namespace KChart {
25 
26  // some forward declarations
27  class AbstractDiagram;
28  class Chart;
29  class AbstractCoordinatePlane;
30  class TableModel;
31  class BarDiagram;
32  class LineDiagram;
33  class Plotter;
34  class PieDiagram;
35  class RingDiagram;
36  class PolarDiagram;
37  class Legend;
38  class Position;
39 
40  /**
41  * \class Widget KChartWidget.h
42  * \brief The KChart widget for usage without Interwiev.
43  *
44  * If you want to use KChart with Interview, use KChart::Chart instead.
45  */
46  class KCHART_EXPORT Widget : public QWidget
47  {
48  Q_OBJECT
49 
50  Q_DISABLE_COPY( Widget )
51  KCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( Widget )
52 
53  public:
54  /**
55  * Standard Qt-style Constructor
56  *
57  * Creates a new widget with all data initialized empty.
58  *
59  * \param parent the widget parent; passed on to QWidget
60  */
61  explicit Widget( QWidget* parent = nullptr );
62 
63  /** Destructor. */
64  ~Widget();
65  /** Sets the data in the given column using a QVector of qreal for the Y values. */
66  void setDataset( int column, const QVector< qreal > & data, const QString& title = QString() );
67  /** Sets the data in the given column using a QVector of QPairs
68  * of qreal for the (X, Y) values. */
69  void setDataset( int column, const QVector< QPair< qreal, qreal > > & data, const QString& title = QString() );
70  /** Sets the Y value data for a given cell. */
71  void setDataCell( int row, int column, qreal data );
72  /** Sets the data for a given column using an (X, Y) QPair of qreals. */
73  void setDataCell( int row, int column, QPair< qreal, qreal > data );
74  /** Resets all data. */
75  void resetData();
76 
77  public Q_SLOTS:
78  /** Sets all global leadings (borders). */
79  void setGlobalLeading( int left, int top, int right, int bottom );
80  /** Sets the left leading (border). */
81  void setGlobalLeadingLeft( int leading );
82  /** Sets the top leading (border). */
83  void setGlobalLeadingTop( int leading );
84  /** Sets the right leading (border). */
85  void setGlobalLeadingRight( int leading );
86  /** Sets the bottom leading (border). */
87  void setGlobalLeadingBottom( int leading );
88 
89  public:
90  /** Returns the left leading (border). */
91  int globalLeadingLeft() const;
92  /** Returns the top leading (border). */
93  int globalLeadingTop() const;
94  /** Returns the right leading (border). */
95  int globalLeadingRight() const;
96  /** Returns the bottom leading (border). */
97  int globalLeadingBottom() const;
98 
99  /** Returns the first of all headers. */
100  HeaderFooter* firstHeaderFooter();
101  /** Returns a list with all headers. */
102  QList<HeaderFooter*> allHeadersFooters();
103 
104  /** Adds a new header/footer with the given text to the position. */
105  void addHeaderFooter( const QString& text,
106  HeaderFooter::HeaderFooterType type,
107  Position position );
108 
109  /**
110  * Adds the existing header / footer object \a header.
111  * \sa replaceHeaderFooter, takeHeaderFooter
112  */
113  void addHeaderFooter( HeaderFooter* header );
114 
115  /**
116  * Replaces the old header (or footer, resp.), or appends the
117  * new header or footer, it there is none yet.
118  *
119  * @param header The header or footer to be used instead of the old one.
120  * This parameter must not be zero, or the method will do nothing.
121  *
122  * @param oldHeader The header or footer to be removed by the new one. This
123  * header or footer will be deleted automatically. If the parameter is omitted,
124  * the very first header or footer will be replaced. In case, there was no
125  * header and no footer yet, the new header or footer will just be added.
126  *
127  * \note If you want to re-use the old header or footer, call takeHeaderFooter and
128  * addHeaderFooter, instead of using replaceHeaderFooter.
129  *
130  * \sa addHeaderFooter, takeHeaderFooter
131  */
132  void replaceHeaderFooter( HeaderFooter* header,
133  HeaderFooter* oldHeader = nullptr );
134 
135  /** Remove the header (or footer, resp.) from the widget,
136  * without deleting it.
137  * The chart no longer owns the header or footer, so it is
138  * the caller's responsibility to delete the header or footer.
139  *
140  * \sa addHeaderFooter, replaceHeaderFooter
141  */
142  void takeHeaderFooter( HeaderFooter* header );
143 
144  /** Returns the first of all legends. */
145  Legend* legend();
146  /** Returns a list with all legends. */
147  QList<Legend*> allLegends();
148 
149  /** Adds an empty legend on the given position. */
150  void addLegend( Position position );
151  /** Adds a new, already existing, legend. */
152  void addLegend (Legend* legend );
153 
154  void replaceLegend( Legend* legend, Legend* oldLegend = nullptr );
155  void takeLegend( Legend* legend );
156 
157 
158  /** Returns a pointer to the current diagram. */
159  AbstractDiagram* diagram();
160 
161  /** If the current diagram is a BarDiagram, it is returned; otherwise 0 is returned.
162  * This function provides type-safe casting.
163  */
164  BarDiagram* barDiagram();
165  /** If the current diagram is a LineDiagram, it is returned; otherwise 0 is returned.
166  * This function provides type-safe casting.
167  */
168  LineDiagram* lineDiagram();
169  /** If the current diagram is a LineDiagram, it is returned; otherwise 0 is returned.
170  * This function provides type-safe casting.
171  *
172  * \note Do not use lineDiagram for multi-dimensional diagrams, but use plotter instead
173  *
174  * \sa plotter
175  */
176  Plotter* plotter();
177  /** If the current diagram is a Plotter, it is returned; otherwise 0 is returned.
178  * This function provides type-safe casting.
179  */
180  PieDiagram* pieDiagram();
181  /** If the current diagram is a RingDiagram, it is returned; otherwise 0 is returned.
182  * This function provides type-safe casting.
183  */
184  RingDiagram* ringDiagram();
185  /** If the current diagram is a PolarDiagram, it is returned; otherwise 0 is returned.
186  * This function provides type-safe casting.
187  */
188  PolarDiagram* polarDiagram();
189 
190  /** Returns a pointer to the current coordinate plane. */
191  AbstractCoordinatePlane* coordinatePlane();
192 
193 
194  enum ChartType { NoType, Bar, Line, Plot, Pie, Ring, Polar };
195 
196  /** Returns the type of the chart. */
197  ChartType type() const;
198 
199  /** Sub type values, matching the values defines for the respective Diagram classes. */
200  enum SubType { Normal, Stacked, Percent, Rows };
201 
202  /** Returns the sub-type of the chart. */
203  SubType subType() const;
204 
205  public Q_SLOTS:
206  /** Sets the type of the chart. */
207  void setType( KChart::Widget::ChartType chartType, KChart::Widget::SubType subType=Normal );
208  /** \brief Sets the type of the chart without changing the main type.
209  *
210  * Make sure to use a sub-type that matches the main type,
211  * so e.g. setting sub-type Rows makes sense for Bar charts only,
212  * and it will be ignored for all other chart types.
213  *
214  * \sa KChart::BarDiagram::BarType, KChart::LineDiagram::LineType
215  * \sa KChart::PieDiagram::PieType, KChart::RingDiagram::RingType
216  * \sa KChart::PolarDiagram::PolarType
217  */
218  void setSubType( KChart::Widget::SubType subType );
219 
220  private:
221  /** Justifies the model, so that the given rows and columns fit into it. */
222  void justifyModelSize( int rows, int columns );
223  /** Checks whether the given width matches with the one used until now. */
224  bool checkDatasetWidth( int width );
225  };
226 }
227 
228 #endif // KChartWidget_H
Class only listed here to document inheritance of some KChart classes.
PieDiagram defines a common pie diagram.
Legend defines the interface for the legend drawing class.
Definition: KChartLegend.h:41
AbstractDiagram defines the interface for diagram classes.
Plotter defines a diagram type plotting two-dimensional data.
Definition: KChartPlotter.h:24
The KChart widget for usage without Interwiev.
Definition: KChartWidget.h:46
Defines a position, using compass terminology.
Contains KChart macros.
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
RingDiagram defines a common ring diagram.
SubType
Sub type values, matching the values defines for the respective Diagram classes.
Definition: KChartWidget.h:200
Definition of global enums.
BarDiagram defines a common bar diagram.
A header or footer displaying text above or below charts.
LineDiagram defines a common line diagram.
Global namespace.
PolarDiagram defines a common polar diagram.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Sep 26 2021 22:37:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.