KChart

KChartAbstractPieDiagram.cpp
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "KChartAbstractPieDiagram.h"
21 #include "KChartAbstractPieDiagram_p.h"
22 
23 #include "KChartAttributesModel.h"
24 #include "KChartPieAttributes.h"
25 #include "KChartThreeDPieAttributes.h"
26 #include "KChartMath_p.h"
27 
28 #include <QMap>
29 
30 
31 using namespace KChart;
32 
33 AbstractPieDiagram::Private::Private()
34  : granularity( 1.0 )
35  , autoRotateLabels( false )
36 {
37 }
38 
39 AbstractPieDiagram::Private::~Private() {}
40 
41 AbstractPieDiagram::AbstractPieDiagram( QWidget* parent, PolarCoordinatePlane *plane ) :
42  AbstractPolarDiagram( new Private(), parent, plane )
43 {
44  init();
45 }
46 
47 AbstractPieDiagram::~AbstractPieDiagram()
48 {
49 }
50 
51 
52 void AbstractPieDiagram::init()
53 {
54 }
55 
56 
58 {
59  if ( other == this ) return true;
60  if ( ! other ) {
61  //qDebug() << "AbstractPieDiagram::compare() cannot compare to Null pointer";
62  return false;
63  }
64  /*
65  qDebug() << "\n AbstractPieDiagram::compare():";
66  // compare own properties
67  qDebug() <<
68  (granularity() == other->granularity()) &&
69  (startPosition() == other->startPosition());
70  */
71  return // compare the base class
72  ( static_cast<const AbstractPolarDiagram*>(this)->compare( other ) ) &&
73  // compare own properties
74  (granularity() == other->granularity()) &&
75  (startPosition() == other->startPosition());
76 }
77 
78 
79 #define d d_func()
80 
82 {
83  d->granularity = value;
84 }
85 
87 {
88  return (d->granularity < 0.05 || d->granularity > 36.0)
89  ? 1.0
90  : d->granularity;
91 }
92 
93 
95 {
96  Q_UNUSED( degrees );
97  qWarning() << "Deprecated AbstractPieDiagram::setStartPosition() called, setting ignored.";
98 }
99 
101 {
102  qWarning() << "Deprecated AbstractPieDiagram::startPosition() called.";
103  return 0;
104 }
105 
107 {
108  d->autoRotateLabels = autoRotate;
109 }
110 
112 {
113  return d->autoRotateLabels;
114 }
115 
116 void AbstractPieDiagram::setPieAttributes( const PieAttributes & attrs )
117 {
118  d->attributesModel->setModelData( QVariant::fromValue( attrs ), PieAttributesRole );
119  emit layoutChanged( this );
120 }
121 
122 void AbstractPieDiagram::setPieAttributes( int column, const PieAttributes & attrs )
123 {
124  d->setDatasetAttrs( column, QVariant::fromValue( attrs ), PieAttributesRole );
125  emit layoutChanged( this );
126 }
127 
128 void AbstractPieDiagram::setPieAttributes( const QModelIndex & index, const PieAttributes & attrs )
129 {
130  d->attributesModel->setData( index, QVariant::fromValue( attrs), PieAttributesRole );
131  emit layoutChanged( this );
132 }
133 
134 PieAttributes AbstractPieDiagram::pieAttributes() const
135 {
136  return d->attributesModel->data( PieAttributesRole ).value<PieAttributes>();
137 }
138 
139 PieAttributes AbstractPieDiagram::pieAttributes( int column ) const
140 {
141  const QVariant attrs( d->datasetAttrs( column, PieAttributesRole ) );
142  if ( attrs.isValid() )
143  return attrs.value< PieAttributes >();
144  return pieAttributes();
145 }
146 
147 PieAttributes AbstractPieDiagram::pieAttributes( const QModelIndex & index ) const
148 {
149  return d->attributesModel->data(
150  d->attributesModel->mapFromSource( index ),
151  PieAttributesRole ).value<PieAttributes>();
152 }
153 
154 
155 void AbstractPieDiagram::setThreeDPieAttributes( const ThreeDPieAttributes & tda )
156 {
157  d->attributesModel->setModelData( QVariant::fromValue( tda ), ThreeDPieAttributesRole );
158  emit layoutChanged( this );
159 }
160 
161 void AbstractPieDiagram::setThreeDPieAttributes( int column, const ThreeDPieAttributes & tda )
162 {
163  d->setDatasetAttrs( column, QVariant::fromValue( tda ), ThreeDPieAttributesRole );
164  emit layoutChanged( this );
165 }
166 
167 void AbstractPieDiagram::setThreeDPieAttributes( const QModelIndex & index, const ThreeDPieAttributes & tda )
168 {
169  model()->setData( index, QVariant::fromValue( tda ), ThreeDPieAttributesRole );
170  emit layoutChanged( this );
171 }
172 
173 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes() const
174 {
175  return d->attributesModel->data( ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
176 }
177 
178 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes( int column ) const
179 {
180  const QVariant attrs( d->datasetAttrs( column, ThreeDPieAttributesRole ) );
181  if ( attrs.isValid() )
182  return attrs.value< ThreeDPieAttributes >();
183  return threeDPieAttributes();
184 }
185 
186 ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes( const QModelIndex & index ) const
187 {
188  return d->attributesModel->data(
189  d->attributesModel->mapFromSource( index ),
190  ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
191 }
192 
Class only listed here to document inheritance of some KChart classes.
void setGranularity(qreal value)
Set the granularity: the smaller the granularity the more your diagram segments will show facettes in...
void setAutoRotateLabels(bool autoRotate)
If this property is set, and if a pie&#39;s TextAttributes have no rotation set, its labels will automati...
bool compare(const AbstractPieDiagram *other) const
Returns true if both diagrams have the same settings.
A set of attributes controlling the appearance of pie charts.
QVariant fromValue(const T &value)
QCA_EXPORT void init()
A set of 3D pie attributes.
Base class for any diagram type.
Base class for diagrams based on a polar coordinate system.
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:36:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.