KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
KDChartAbstractPieDiagram.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
24 #include "KDChartAbstractPieDiagram_p.h"
25 
26 #include "KDChartAttributesModel.h"
27 #include "KDChartPieAttributes.h"
29 
30 #include <QMap>
31 
32 #include <KDABLibFakes>
33 
34 
35 using namespace KDChart;
36 
37 AbstractPieDiagram::Private::Private()
38  : granularity( 1.0 )
39  , autoRotateLabels( false )
40 {
41 }
42 
43 AbstractPieDiagram::Private::~Private() {}
44 
46  AbstractPolarDiagram( new Private(), parent, plane )
47 {
48  init();
49 }
50 
52 {
53 }
54 
55 
56 void AbstractPieDiagram::init()
57 {
58 }
59 
60 
62 {
63  if ( other == this ) return true;
64  if ( ! other ) {
65  //qDebug() << "AbstractPieDiagram::compare() cannot compare to Null pointer";
66  return false;
67  }
68  /*
69  qDebug() << "\n AbstractPieDiagram::compare():";
70  // compare own properties
71  qDebug() <<
72  (granularity() == other->granularity()) &&
73  (startPosition() == other->startPosition());
74  */
75  return // compare the base class
76  ( static_cast<const AbstractPolarDiagram*>(this)->compare( other ) ) &&
77  // compare own properties
78  (granularity() == other->granularity()) &&
79  (startPosition() == other->startPosition());
80 }
81 
82 
83 #define d d_func()
84 
86 {
87  d->granularity = value;
88 }
89 
91 {
92  return (d->granularity < 0.05 || d->granularity > 36.0)
93  ? 1.0
94  : d->granularity;
95 }
96 
97 
99 {
100  Q_UNUSED( degrees );
101  qWarning() << "Deprecated AbstractPieDiagram::setStartPosition() called, setting ignored.";
102 }
103 
105 {
106  qWarning() << "Deprecated AbstractPieDiagram::startPosition() called.";
107  return 0;
108 }
109 
111 {
112  d->autoRotateLabels = autoRotate;
113 }
114 
116 {
117  return d->autoRotateLabels;
118 }
119 
121 {
122  d->attributesModel->setModelData( qVariantFromValue( attrs ), PieAttributesRole );
123  emit layoutChanged( this );
124 }
125 
126 void AbstractPieDiagram::setPieAttributes( int column, const PieAttributes & attrs )
127 {
128  d->setDatasetAttrs( column, qVariantFromValue( attrs ), PieAttributesRole );
129  emit layoutChanged( this );
130 }
131 
132 void AbstractPieDiagram::setPieAttributes( const QModelIndex & index, const PieAttributes & attrs )
133 {
134  d->attributesModel->setData( index, qVariantFromValue( attrs), PieAttributesRole );
135  emit layoutChanged( this );
136 }
137 
138 // Note: Our users NEED this method - even if
139 // we do not need it at drawing time!
140 // (khz, 2006-07-28)
142 {
143  return d->attributesModel->data( PieAttributesRole ).value<PieAttributes>();
144 }
145 
146 // Note: Our users NEED this method - even if
147 // we do not need it at drawing time!
148 // (khz, 2006-07-28)
150 {
151  const QVariant attrs( d->datasetAttrs( column, PieAttributesRole ) );
152  if ( attrs.isValid() )
153  return attrs.value< PieAttributes >();
154  return pieAttributes();
155 }
156 
157 PieAttributes AbstractPieDiagram::pieAttributes( const QModelIndex & index ) const
158 {
159  return d->attributesModel->data(
160  d->attributesModel->mapFromSource( index ),
161  PieAttributesRole ).value<PieAttributes>();
162 }
163 
164 
166 {
167  d->attributesModel->setModelData( qVariantFromValue( tda ), ThreeDPieAttributesRole );
168  emit layoutChanged( this );
169 }
170 
172 {
173  d->setDatasetAttrs( column, qVariantFromValue( tda ), ThreeDPieAttributesRole );
174  emit layoutChanged( this );
175 }
176 
177 void AbstractPieDiagram::setThreeDPieAttributes( const QModelIndex & index, const ThreeDPieAttributes & tda )
178 {
179  model()->setData( index, qVariantFromValue( tda ), ThreeDPieAttributesRole );
180  emit layoutChanged( this );
181 }
182 
183 // Note: Our users NEED this method - even if
184 // we do not need it at drawing time!
185 // (khz, 2006-07-28)
187 {
188  return d->attributesModel->data( ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
189 }
190 
191 // Note: Our users NEED this method - even if
192 // we do not need it at drawing time!
193 // (khz, 2006-07-28)
195 {
196  const QVariant attrs( d->datasetAttrs( column, ThreeDPieAttributesRole ) );
197  if ( attrs.isValid() )
198  return attrs.value< ThreeDPieAttributes >();
199  return threeDPieAttributes();
200 }
201 
203 {
204  return d->attributesModel->data(
205  d->attributesModel->mapFromSource( index ),
206  ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
207 }
208 

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/