KChart

KChartBarDiagram.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 KCHARTBARDIAGRAM_H
10#define KCHARTBARDIAGRAM_H
11
12#include "KChartAbstractCartesianDiagram.h"
13#include "KChartBarAttributes.h"
14
15QT_BEGIN_NAMESPACE
16class QPainter;
17QT_END_NAMESPACE
18
19namespace KChart {
20
21 class ThreeDBarAttributes;
22
23/**
24 * @brief BarDiagram defines a common bar diagram.
25 *
26 * It provides different subtypes which are set using \a setType.
27 */
28class KCHART_EXPORT BarDiagram : public AbstractCartesianDiagram
29{
30 Q_OBJECT
31
32 Q_DISABLE_COPY( BarDiagram )
33
34 KCHART_DECLARE_DERIVED_DIAGRAM( BarDiagram, CartesianCoordinatePlane )
35
36public:
37 class BarDiagramType;
38 friend class BarDiagramType;
39
40 explicit BarDiagram(
41 QWidget* parent = nullptr, CartesianCoordinatePlane* plane = nullptr );
42 ~BarDiagram() override;
43
44
45 /**
46 * Creates an exact copy of this diagram.
47 */
48 virtual BarDiagram * clone() const;
49 /**
50 * Returns true if both diagrams have the same settings.
51 */
52 bool compare( const BarDiagram* other ) const;
53
54 enum BarType { Normal,
55 Stacked,
56 Percent,
57 Rows ///< @deprecated Use BarDiagram::setOrientation() instead
58 };
59
60
61 /**
62 * Sets the bar diagram's type to \a type
63 * \sa BarDiagram::BarType
64 */
65 void setType( const BarType type );
66
67 /**
68 * @return the type of the bar diagram
69 */
70 BarType type() const;
71
72
73 /**
74 * Sets the orientation of the bar diagram
75 */
76 void setOrientation( Qt::Orientation orientation );
77
78 /**
79 * @return the orientation of the bar diagram
80 */
81 Qt::Orientation orientation() const;
82
83
84 /**
85 * Sets the global bar attributes to \a ba
86 */
87 void setBarAttributes( const BarAttributes & a );
88
89 /**
90 * Sets the bar attributes of data set \a column to \a ba
91 */
92 void setBarAttributes( int column, const BarAttributes & a );
93
94 /**
95 * Sets the line attributes for the model index \a index to \a ba
96 */
97 void setBarAttributes( const QModelIndex & index, const BarAttributes & a );
98
99 /**
100 * @return the global bar attribute set
101 */
102 BarAttributes barAttributes() const;
103
104 /**
105 * @return the bar attribute set of data set \a column
106 */
107 BarAttributes barAttributes( int column ) const;
108
109 /**
110 * @return the bar attribute set of the model index \a index
111 */
112 BarAttributes barAttributes( const QModelIndex & index ) const;
113
114
115 /**
116 * Sets the global 3D bar attributes to \a threeDAttrs
117 */
118 void setThreeDBarAttributes( const ThreeDBarAttributes & a );
119
120 /**
121 * Sets the 3D bar attributes of dataset \a column to \a threeDAttrs
122 */
123 void setThreeDBarAttributes( int column, const ThreeDBarAttributes & a );
124
125 /**
126 * Sets the 3D line attributes of model index \a index to \a threeDAttrs
127 */
128 void setThreeDBarAttributes( const QModelIndex & index,
129 const ThreeDBarAttributes & a );
130
131 /**
132 * @return the global 3D bar attributes
133 */
134 ThreeDBarAttributes threeDBarAttributes() const;
135
136 /**
137 * @return the 3D bar attributes of data set \a column
138 */
139 ThreeDBarAttributes threeDBarAttributes( int column ) const;
140
141 /**
142 * @return the 3D bar attributes of the model index \a index
143 */
144 ThreeDBarAttributes threeDBarAttributes( const QModelIndex & index ) const;
145
146#if defined(Q_COMPILER_MANGLES_RETURN_TYPE)
147 // implement AbstractCartesianDiagram
148 /** \reimpl */
149 const int numberOfAbscissaSegments () const;
150 /** \reimpl */
151 const int numberOfOrdinateSegments () const;
152#else
153 // implement AbstractCartesianDiagram
154 /** \reimpl */
155 int numberOfAbscissaSegments () const override;
156 /** \reimpl */
157 int numberOfOrdinateSegments () const override;
158#endif
159
160protected:
161 void paint ( PaintContext* paintContext ) override;
162
163public:
164 void resize ( const QSizeF& area ) override;
165
166protected:
167 qreal threeDItemDepth( const QModelIndex & index ) const override;
168 qreal threeDItemDepth( int column ) const override;
169 /** \reimpl */
170 const QPair<QPointF, QPointF> calculateDataBoundaries() const override;
171 void paintEvent ( QPaintEvent* ) override;
172 void resizeEvent ( QResizeEvent* ) override;
173private:
174
175 void calculateValueAndGapWidths( int rowCount, int colCount,
176 qreal groupWidth,
177 qreal& barWidth,
178 qreal& spaceBetweenBars,
179 qreal& spaceBetweenGroups );
180}; // End of class BarDiagram
181
182}
183
184#endif // KCHARTBARDIAGRAM_H
Base class for diagrams based on a cartesian coordianate system.
Set of attributes for changing the appearance of bar charts.
BarDiagram defines a common bar diagram.
Stores information about painting diagrams.
A set of 3D bar attributes.
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:52:19 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.