KD Chart 2  [rev.2.7]
KDChartAbstractPieDiagram.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 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 
139 {
140  return d->attributesModel->data( PieAttributesRole ).value<PieAttributes>();
141 }
142 
144 {
145  const QVariant attrs( d->datasetAttrs( column, PieAttributesRole ) );
146  if ( attrs.isValid() )
147  return attrs.value< PieAttributes >();
148  return pieAttributes();
149 }
150 
151 PieAttributes AbstractPieDiagram::pieAttributes( const QModelIndex & index ) const
152 {
153  return d->attributesModel->data(
154  d->attributesModel->mapFromSource( index ),
155  PieAttributesRole ).value<PieAttributes>();
156 }
157 
158 
160 {
161  d->attributesModel->setModelData( qVariantFromValue( tda ), ThreeDPieAttributesRole );
162  emit layoutChanged( this );
163 }
164 
166 {
167  d->setDatasetAttrs( column, qVariantFromValue( tda ), ThreeDPieAttributesRole );
168  emit layoutChanged( this );
169 }
170 
171 void AbstractPieDiagram::setThreeDPieAttributes( const QModelIndex & index, const ThreeDPieAttributes & tda )
172 {
173  model()->setData( index, qVariantFromValue( tda ), ThreeDPieAttributesRole );
174  emit layoutChanged( this );
175 }
176 
178 {
179  return d->attributesModel->data( ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
180 }
181 
183 {
184  const QVariant attrs( d->datasetAttrs( column, ThreeDPieAttributesRole ) );
185  if ( attrs.isValid() )
186  return attrs.value< ThreeDPieAttributes >();
187  return threeDPieAttributes();
188 }
189 
191 {
192  return d->attributesModel->data(
193  d->attributesModel->mapFromSource( index ),
194  ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
195 }
196 
AbstractPieDiagram(QWidget *parent=0, PolarCoordinatePlane *plane=0)
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...
void setAutoRotateLabels(bool autoRotate)
If this property is set, and if a pie&#39;s TextAttributes have no rotation set, its labels will automati...
Base class for diagrams based on a polar coordinate system.
void setThreeDPieAttributes(const ThreeDPieAttributes &a)
QModelIndex parent(const QModelIndex &index) const override
A set of attributes controlling the appearance of pie charts.
void setPieAttributes(const PieAttributes &a)
A set of 3D pie attributes.
Base class for any diagram type.
ThreeDPieAttributes threeDPieAttributes() const
void layoutChanged(AbstractDiagram *)
Diagrams are supposed to emit this signal, when the layout of one of their element changes...
Class only listed here to document inheritance of some KDChart classes.

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/