KChart

KChartAbstractPieDiagram.cpp
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 #include "KChartAbstractPieDiagram.h"
10 #include "KChartAbstractPieDiagram_p.h"
11 
12 #include "KChartAttributesModel.h"
13 #include "KChartPieAttributes.h"
14 #include "KChartThreeDPieAttributes.h"
15 #include "KChartMath_p.h"
16 
17 #include <QMap>
18 
19 
20 using namespace KChart;
21 
22 AbstractPieDiagram::Private::Private()
23  : granularity( 1.0 )
24  , autoRotateLabels( false )
25 {
26 }
27 
28 AbstractPieDiagram::Private::~Private() {}
29 
30 AbstractPieDiagram::AbstractPieDiagram( QWidget* parent, PolarCoordinatePlane *plane ) :
31  AbstractPolarDiagram( new Private(), parent, plane )
32 {
33  init();
34 }
35 
36 AbstractPieDiagram::~AbstractPieDiagram()
37 {
38 }
39 
40 
41 void AbstractPieDiagram::init()
42 {
43 }
44 
45 
47 {
48  if ( other == this ) return true;
49  if ( ! other ) {
50  //qDebug() << "AbstractPieDiagram::compare() cannot compare to Null pointer";
51  return false;
52  }
53  /*
54  qDebug() << "\n AbstractPieDiagram::compare():";
55  // compare own properties
56  qDebug() <<
57  (granularity() == other->granularity()) &&
58  (startPosition() == other->startPosition());
59  */
60  return // compare the base class
61  ( static_cast<const AbstractPolarDiagram*>(this)->compare( other ) ) &&
62  // compare own properties
63  (granularity() == other->granularity()) &&
64  (startPosition() == other->startPosition());
65 }
66 
67 
68 #define d d_func()
69 
71 {
72  d->granularity = value;
73 }
74 
76 {
77  return (d->granularity < 0.05 || d->granularity > 36.0)
78  ? 1.0
79  : d->granularity;
80 }
81 
82 
84 {
85  Q_UNUSED( degrees );
86  qWarning() << "Deprecated AbstractPieDiagram::setStartPosition() called, setting ignored.";
87 }
88 
90 {
91  qWarning() << "Deprecated AbstractPieDiagram::startPosition() called.";
92  return 0;
93 }
94 
96 {
97  d->autoRotateLabels = autoRotate;
98 }
99 
101 {
102  return d->autoRotateLabels;
103 }
104 
105 void AbstractPieDiagram::setPieAttributes( const PieAttributes & attrs )
106 {
107  d->attributesModel->setModelData( QVariant::fromValue( attrs ), PieAttributesRole );
108  Q_EMIT layoutChanged( this );
109 }
110 
111 void AbstractPieDiagram::setPieAttributes( int column, const PieAttributes & attrs )
112 {
113  d->setDatasetAttrs( column, QVariant::fromValue( attrs ), PieAttributesRole );
114  Q_EMIT layoutChanged( this );
115 }
116 
117 void AbstractPieDiagram::setPieAttributes( const QModelIndex & index, const PieAttributes & attrs )
118 {
119  d->attributesModel->setData( index, QVariant::fromValue( attrs), PieAttributesRole );
120  Q_EMIT layoutChanged( this );
121 }
122 
123 PieAttributes AbstractPieDiagram::pieAttributes() const
124 {
125  return d->attributesModel->data( PieAttributesRole ).value<PieAttributes>();
126 }
127 
128 PieAttributes AbstractPieDiagram::pieAttributes( int column ) const
129 {
130  const QVariant attrs( d->datasetAttrs( column, PieAttributesRole ) );
131  if ( attrs.isValid() )
132  return attrs.value< PieAttributes >();
133  return pieAttributes();
134 }
135 
136 PieAttributes AbstractPieDiagram::pieAttributes( const QModelIndex & index ) const
137 {
138  return d->attributesModel->data(
139  d->attributesModel->mapFromSource( index ),
140  PieAttributesRole ).value<PieAttributes>();
141 }
142 
143 
144 void AbstractPieDiagram::setThreeDPieAttributes( const ThreeDPieAttributes & tda )
145 {
146  d->attributesModel->setModelData( QVariant::fromValue( tda ), ThreeDPieAttributesRole );
147  Q_EMIT layoutChanged( this );
148 }
149 
150 void AbstractPieDiagram::setThreeDPieAttributes( int column, const ThreeDPieAttributes & tda )
151 {
152  d->setDatasetAttrs( column, QVariant::fromValue( tda ), ThreeDPieAttributesRole );
153  Q_EMIT layoutChanged( this );
154 }
155 
156 void AbstractPieDiagram::setThreeDPieAttributes( const QModelIndex & index, const ThreeDPieAttributes & tda )
157 {
158  model()->setData( index, QVariant::fromValue( tda ), ThreeDPieAttributesRole );
159  Q_EMIT layoutChanged( this );
160 }
161 
162 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes() const
163 {
164  return d->attributesModel->data( ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
165 }
166 
167 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes( int column ) const
168 {
169  const QVariant attrs( d->datasetAttrs( column, ThreeDPieAttributesRole ) );
170  if ( attrs.isValid() )
171  return attrs.value< ThreeDPieAttributes >();
172  return threeDPieAttributes();
173 }
174 
175 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes( const QModelIndex & index ) const
176 {
177  return d->attributesModel->data(
178  d->attributesModel->mapFromSource( index ),
179  ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
180 }
181 
A set of 3D pie attributes.
void setAutoRotateLabels(bool autoRotate)
If this property is set, and if a pie's TextAttributes have no rotation set, its labels will automati...
QVariant fromValue(const T &value)
Q_EMITQ_EMIT
A set of attributes controlling the appearance of pie charts.
Base class for diagrams based on a polar coordinate system.
QAbstractItemModel * model() const const
QCA_EXPORT void init()
Class only listed here to document inheritance of some KChart classes.
Base class for any diagram type.
bool compare(const AbstractPieDiagram *other) const
Returns true if both diagrams have the same settings.
void setGranularity(qreal value)
Set the granularity: the smaller the granularity the more your diagram segments will show facettes in...
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
void layoutChanged(KChart::AbstractDiagram *)
Diagrams are supposed to emit this signal, when the layout of one of their element changes.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Dec 4 2022 04:03:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.