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

KDE's Doxygen guidelines are available online.