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

KDE's Doxygen guidelines are available online.