@@ -0,0 +1,39 | |||||
|
1 | #include "qdonutgroup.h" | |||
|
2 | #include "qdonutgroup_p.h" | |||
|
3 | ||||
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
5 | ||||
|
6 | QDonutGroup::QDonutGroup(QObject *parent) : | |||
|
7 | QObject(parent), | |||
|
8 | d_ptr(new QDonutGroupPrivate(this)) | |||
|
9 | { | |||
|
10 | } | |||
|
11 | ||||
|
12 | void QDonutGroup::append(QPieSeries *donut) | |||
|
13 | { | |||
|
14 | if (donut == 0) | |||
|
15 | return; | |||
|
16 | ||||
|
17 | donut->setDonut(); | |||
|
18 | Q_D(QDonutGroup); | |||
|
19 | d->m_donuts.append(donut); | |||
|
20 | qreal donutFraction = 1.0 / (d->m_donuts.count() + 1); | |||
|
21 | for(int i = 0; i < d->m_donuts.count(); i++) { | |||
|
22 | d->m_donuts[i]->setPieSize( (i + 2) * donutFraction); | |||
|
23 | d->m_donuts[i]->setDonutInnerSize( (i + 1) * donutFraction); | |||
|
24 | } | |||
|
25 | } | |||
|
26 | ||||
|
27 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
28 | ||||
|
29 | QDonutGroupPrivate::QDonutGroupPrivate(QDonutGroup *q): | |||
|
30 | QObject(q), | |||
|
31 | q_ptr(q) | |||
|
32 | { | |||
|
33 | // | |||
|
34 | } | |||
|
35 | ||||
|
36 | #include "moc_qdonutgroup.cpp" | |||
|
37 | #include "moc_qdonutgroup_p.cpp" | |||
|
38 | ||||
|
39 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,27 | |||||
|
1 | #ifndef QDONUTGROUP_H | |||
|
2 | #define QDONUTGROUP_H | |||
|
3 | ||||
|
4 | #include <QObject> | |||
|
5 | #include <QPieSeries> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | //class QPieSeries; | |||
|
10 | class QDonutGroupPrivate; | |||
|
11 | ||||
|
12 | class QTCOMMERCIALCHART_EXPORT QDonutGroup : public QObject | |||
|
13 | { | |||
|
14 | Q_OBJECT | |||
|
15 | public: | |||
|
16 | explicit QDonutGroup(QObject *parent = 0); | |||
|
17 | ||||
|
18 | void append(QPieSeries *donut); | |||
|
19 | ||||
|
20 | protected: | |||
|
21 | QDonutGroupPrivate * const d_ptr; | |||
|
22 | Q_DECLARE_PRIVATE(QDonutGroup) | |||
|
23 | }; | |||
|
24 | ||||
|
25 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
26 | ||||
|
27 | #endif // QDONUTGROUP_H |
@@ -0,0 +1,29 | |||||
|
1 | #ifndef QDONUTGROUP_P_H | |||
|
2 | #define QDONUTGROUP_P_H | |||
|
3 | ||||
|
4 | #include <QObject> | |||
|
5 | #include <qdonutgroup.h> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | class QPieSeries; | |||
|
10 | ||||
|
11 | class QDonutGroupPrivate : public QObject | |||
|
12 | { | |||
|
13 | Q_OBJECT | |||
|
14 | public: | |||
|
15 | explicit QDonutGroupPrivate(QDonutGroup *q); | |||
|
16 | ||||
|
17 | void append(QPieSeries *donut); | |||
|
18 | ||||
|
19 | private: | |||
|
20 | QList<QPieSeries *> m_donuts; | |||
|
21 | ||||
|
22 | private: | |||
|
23 | QDonutGroup *q_ptr; | |||
|
24 | Q_DECLARE_PUBLIC(QDonutGroup) | |||
|
25 | }; | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
28 | ||||
|
29 | #endif // QDONUTGROUP_P_H |
@@ -193,6 +193,7 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |||||
193 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
193 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
194 |
|
194 | |||
195 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
195 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
|
196 | QObject(q), | |||
196 | m_series(0), |
|
197 | m_series(0), | |
197 | m_model(0), |
|
198 | m_model(0), | |
198 | m_first(0), |
|
199 | m_first(0), |
@@ -8,7 +8,8 SOURCES += \ | |||||
8 | $$PWD/qpieslice.cpp \ |
|
8 | $$PWD/qpieslice.cpp \ | |
9 | $$PWD/qpiemodelmapper.cpp \ |
|
9 | $$PWD/qpiemodelmapper.cpp \ | |
10 | $$PWD/qvpiemodelmapper.cpp \ |
|
10 | $$PWD/qvpiemodelmapper.cpp \ | |
11 | $$PWD/qhpiemodelmapper.cpp |
|
11 | $$PWD/qhpiemodelmapper.cpp \ | |
|
12 | piechart/qdonutgroup.cpp | |||
12 |
|
13 | |||
13 | PRIVATE_HEADERS += \ |
|
14 | PRIVATE_HEADERS += \ | |
14 | $$PWD/pieslicedata_p.h \ |
|
15 | $$PWD/pieslicedata_p.h \ | |
@@ -16,12 +17,13 PRIVATE_HEADERS += \ | |||||
16 | $$PWD/piesliceitem_p.h \ |
|
17 | $$PWD/piesliceitem_p.h \ | |
17 | $$PWD/qpieslice_p.h \ |
|
18 | $$PWD/qpieslice_p.h \ | |
18 | $$PWD/qpieseries_p.h \ |
|
19 | $$PWD/qpieseries_p.h \ | |
19 | $$PWD/qpiemodelmapper_p.h |
|
20 | $$PWD/qpiemodelmapper_p.h \ | |
|
21 | $$PWD/qdonutgroup_p.h | |||
20 |
|
22 | |||
21 | PUBLIC_HEADERS += \ |
|
23 | PUBLIC_HEADERS += \ | |
22 | $$PWD/qpieseries.h \ |
|
24 | $$PWD/qpieseries.h \ | |
23 | $$PWD/qpieslice.h \ |
|
25 | $$PWD/qpieslice.h \ | |
24 | $$PWD/qpiemodelmapper.h \ |
|
26 | $$PWD/qpiemodelmapper.h \ | |
25 | $$PWD/qvpiemodelmapper.h \ |
|
27 | $$PWD/qvpiemodelmapper.h \ | |
26 | $$PWD/qhpiemodelmapper.h |
|
28 | $$PWD/qhpiemodelmapper.h \ | |
27 |
|
29 | $$PWD/qdonutgroup.h |
@@ -106,8 +106,10 void PieChartItem::updateLayout() | |||||
106 | if (m_rect.width() < m_rect.height()) |
|
106 | if (m_rect.width() < m_rect.height()) | |
107 | m_pieRadius = m_rect.width() / 2; |
|
107 | m_pieRadius = m_rect.width() / 2; | |
108 |
|
108 | |||
|
109 | m_donutInnerRadius = m_pieRadius; | |||
109 | // apply size factor |
|
110 | // apply size factor | |
110 | m_pieRadius *= m_series->pieSize(); |
|
111 | m_pieRadius *= m_series->pieSize(); | |
|
112 | m_donutInnerRadius *= m_series->donutInnerSize(); | |||
111 |
|
113 | |||
112 | // set layouts for existing slice items |
|
114 | // set layouts for existing slice items | |
113 | foreach (QPieSlice* slice, m_series->slices()) { |
|
115 | foreach (QPieSlice* slice, m_series->slices()) { | |
@@ -215,6 +217,7 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) | |||||
215 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
217 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
216 | sliceData.m_radius = m_pieRadius; |
|
218 | sliceData.m_radius = m_pieRadius; | |
217 | sliceData.m_donut = m_series->donut(); |
|
219 | sliceData.m_donut = m_series->donut(); | |
|
220 | sliceData.m_innerRadius = m_donutInnerRadius; | |||
218 | return sliceData; |
|
221 | return sliceData; | |
219 | } |
|
222 | } | |
220 |
|
223 |
@@ -73,6 +73,7 private: | |||||
73 | QRectF m_rect; |
|
73 | QRectF m_rect; | |
74 | QPointF m_pieCenter; |
|
74 | QPointF m_pieCenter; | |
75 | qreal m_pieRadius; |
|
75 | qreal m_pieRadius; | |
|
76 | qreal m_donutInnerRadius; | |||
76 | }; |
|
77 | }; | |
77 |
|
78 | |||
78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -82,7 +82,9 public: | |||||
82 | m_radius = 0; |
|
82 | m_radius = 0; | |
83 | m_startAngle = 0; |
|
83 | m_startAngle = 0; | |
84 | m_angleSpan = 0; |
|
84 | m_angleSpan = 0; | |
|
85 | ||||
85 | m_donut = false; |
|
86 | m_donut = false; | |
|
87 | m_innerRadius = 0; | |||
86 | } |
|
88 | } | |
87 |
|
89 | |||
88 | bool operator!=(const PieSliceData &other) const |
|
90 | bool operator!=(const PieSliceData &other) const | |
@@ -136,7 +138,9 public: | |||||
136 | qreal m_radius; |
|
138 | qreal m_radius; | |
137 | qreal m_startAngle; |
|
139 | qreal m_startAngle; | |
138 | qreal m_angleSpan; |
|
140 | qreal m_angleSpan; | |
|
141 | ||||
139 | bool m_donut; |
|
142 | bool m_donut; | |
|
143 | qreal m_innerRadius; | |||
140 | }; |
|
144 | }; | |
141 |
|
145 | |||
142 | QTCOMMERCIALCHART_END_NAMESPACE |
|
146 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -176,8 +176,7 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAn | |||||
176 | // slice path |
|
176 | // slice path | |
177 | QPainterPath path; |
|
177 | QPainterPath path; | |
178 | if (m_data.m_donut) { |
|
178 | if (m_data.m_donut) { | |
179 | qreal donutFraction = 5.0; |
|
179 | QRectF insideRect(center.x() - m_data.m_innerRadius, center.y()-m_data.m_innerRadius, m_data.m_innerRadius*2, m_data.m_innerRadius*2); | |
180 | QRectF insideRect = rect.adjusted(rect.width() / donutFraction, rect.height() / donutFraction, -rect.width() / donutFraction, -rect.height() / donutFraction); |
|
|||
181 | path.arcMoveTo(rect, -startAngle + 90); |
|
180 | path.arcMoveTo(rect, -startAngle + 90); | |
182 | path.arcTo(rect, -startAngle + 90, -angleSpan); |
|
181 | path.arcTo(rect, -startAngle + 90, -angleSpan); | |
183 | path.arcTo(insideRect, -startAngle + 90 - angleSpan, angleSpan); |
|
182 | path.arcTo(insideRect, -startAngle + 90 - angleSpan, angleSpan); |
@@ -191,6 +191,7 void QPieModelMapper::setLabelsSection(int labelsSection) | |||||
191 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
192 |
|
192 | |||
193 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
193 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : | |
|
194 | QObject(q), | |||
194 | m_series(0), |
|
195 | m_series(0), | |
195 | m_model(0), |
|
196 | m_model(0), | |
196 | m_first(0), |
|
197 | m_first(0), |
@@ -536,6 +536,26 bool QPieSeries::donut() const | |||||
536 | return d->m_donutChart; |
|
536 | return d->m_donutChart; | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
|
539 | void QPieSeries::setDonutInnerSize(qreal innerSize) | |||
|
540 | { | |||
|
541 | Q_D(QPieSeries); | |||
|
542 | ||||
|
543 | if (innerSize < 0.0) | |||
|
544 | innerSize = 0.0; | |||
|
545 | if (innerSize > 1.0) | |||
|
546 | innerSize = 1.0; | |||
|
547 | ||||
|
548 | d->m_donutRelativeInnerSize = innerSize; | |||
|
549 | d->updateDerivativeData(); | |||
|
550 | emit d->pieSizeChanged(); | |||
|
551 | } | |||
|
552 | ||||
|
553 | qreal QPieSeries::donutInnerSize() const | |||
|
554 | { | |||
|
555 | Q_D(const QPieSeries); | |||
|
556 | return d->m_donutRelativeInnerSize; | |||
|
557 | } | |||
|
558 | ||||
539 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
559 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
540 | { |
|
560 | { | |
541 | Q_D(QPieSeries); |
|
561 | Q_D(QPieSeries); | |
@@ -674,7 +694,8 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |||||
674 | m_pieStartAngle(0), |
|
694 | m_pieStartAngle(0), | |
675 | m_pieEndAngle(360), |
|
695 | m_pieEndAngle(360), | |
676 | m_sum(0), |
|
696 | m_sum(0), | |
677 | m_donutChart(false) |
|
697 | m_donutChart(false), | |
|
698 | m_donutRelativeInnerSize(0.5) | |||
678 | { |
|
699 | { | |
679 | } |
|
700 | } | |
680 |
|
701 | |||
@@ -707,7 +728,6 void QPieSeriesPrivate::updateDerivativeData() | |||||
707 | d->setPercentage(s->value() / m_sum); |
|
728 | d->setPercentage(s->value() / m_sum); | |
708 | d->setStartAngle(sliceAngle); |
|
729 | d->setStartAngle(sliceAngle); | |
709 | d->setAngleSpan(pieSpan * s->percentage()); |
|
730 | d->setAngleSpan(pieSpan * s->percentage()); | |
710 | d->m_data.m_donut = m_donutChart; |
|
|||
711 | sliceAngle += s->angleSpan(); |
|
731 | sliceAngle += s->angleSpan(); | |
712 | } |
|
732 | } | |
713 |
|
733 |
@@ -64,6 +64,9 public: | |||||
64 | void setDonut(bool donut = true); |
|
64 | void setDonut(bool donut = true); | |
65 | bool donut() const; |
|
65 | bool donut() const; | |
66 |
|
66 | |||
|
67 | void setDonutInnerSize(qreal innerSize); | |||
|
68 | qreal donutInnerSize() const; | |||
|
69 | ||||
67 | void setHorizontalPosition(qreal relativePosition); |
|
70 | void setHorizontalPosition(qreal relativePosition); | |
68 | qreal horizontalPosition() const; |
|
71 | qreal horizontalPosition() const; | |
69 |
|
72 |
@@ -78,6 +78,7 private: | |||||
78 | qreal m_pieEndAngle; |
|
78 | qreal m_pieEndAngle; | |
79 | qreal m_sum; |
|
79 | qreal m_sum; | |
80 | bool m_donutChart; |
|
80 | bool m_donutChart; | |
|
81 | qreal m_donutRelativeInnerSize; | |||
81 |
|
82 | |||
82 | private: |
|
83 | private: | |
83 | friend class QLegendPrivate; |
|
84 | friend class QLegendPrivate; |
@@ -202,6 +202,7 void QXYModelMapper::setYSection(int ySection) | |||||
202 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
202 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
203 |
|
203 | |||
204 | QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) : |
|
204 | QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) : | |
|
205 | QObject(q), | |||
205 | m_series(0), |
|
206 | m_series(0), | |
206 | m_model(0), |
|
207 | m_model(0), | |
207 | m_first(0), |
|
208 | m_first(0), |
General Comments 0
You need to be logged in to leave comments.
Login now