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
20using namespace KChart;
21
22AbstractPieDiagram::Private::Private()
23 : granularity( 1.0 )
24 , autoRotateLabels( false )
25{
26}
27
28AbstractPieDiagram::Private::~Private() {}
29
30AbstractPieDiagram::AbstractPieDiagram( QWidget* parent, PolarCoordinatePlane *plane ) :
31 AbstractPolarDiagram( new Private(), parent, plane )
32{
33 init();
34}
35
36AbstractPieDiagram::~AbstractPieDiagram()
37{
38}
39
40
41void 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
105void AbstractPieDiagram::setPieAttributes( const PieAttributes & attrs )
106{
107 d->attributesModel->setModelData( QVariant::fromValue( attrs ), PieAttributesRole );
108 Q_EMIT layoutChanged( this );
109}
110
111void AbstractPieDiagram::setPieAttributes( int column, const PieAttributes & attrs )
112{
113 d->setDatasetAttrs( column, QVariant::fromValue( attrs ), PieAttributesRole );
114 Q_EMIT layoutChanged( this );
115}
116
117void 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
123PieAttributes AbstractPieDiagram::pieAttributes() const
124{
125 return d->attributesModel->data( PieAttributesRole ).value<PieAttributes>();
126}
127
128PieAttributes 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
136PieAttributes AbstractPieDiagram::pieAttributes( const QModelIndex & index ) const
137{
138 return d->attributesModel->data(
139 d->attributesModel->mapFromSource( index ),
140 PieAttributesRole ).value<PieAttributes>();
141}
142
143
144void AbstractPieDiagram::setThreeDPieAttributes( const ThreeDPieAttributes & tda )
145{
146 d->attributesModel->setModelData( QVariant::fromValue( tda ), ThreeDPieAttributesRole );
147 Q_EMIT layoutChanged( this );
148}
149
150void AbstractPieDiagram::setThreeDPieAttributes( int column, const ThreeDPieAttributes & tda )
151{
152 d->setDatasetAttrs( column, QVariant::fromValue( tda ), ThreeDPieAttributesRole );
153 Q_EMIT layoutChanged( this );
154}
155
156void AbstractPieDiagram::setThreeDPieAttributes( const QModelIndex & index, const ThreeDPieAttributes & tda )
157{
158 model()->setData( index, QVariant::fromValue( tda ), ThreeDPieAttributesRole );
159 Q_EMIT layoutChanged( this );
160}
161
162ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes() const
163{
164 return d->attributesModel->data( ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
165}
166
167ThreeDPieAttributes 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
175ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes( const QModelIndex & index ) const
176{
177 return d->attributesModel->data(
178 d->attributesModel->mapFromSource( index ),
179 ThreeDPieAttributesRole ).value<ThreeDPieAttributes>();
180}
181
bool compare(const AbstractDiagram *other) const
Returns true if both diagrams have the same settings.
void layoutChanged(KChart::AbstractDiagram *)
Diagrams are supposed to emit this signal, when the layout of one of their element changes.
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...
void setAutoRotateLabels(bool autoRotate)
If this property is set, and if a pie's TextAttributes have no rotation set, its labels will automati...
Base class for diagrams based on a polar coordinate system.
A set of attributes controlling the appearance of pie charts.
A set of 3D pie attributes.
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QAbstractItemModel * model() const const
Q_EMITQ_EMIT
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:04:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.