diff --git a/src/barchart/qbarmodelmapper.cpp b/src/barchart/qbarmodelmapper.cpp index 5982617..e0023af 100644 --- a/src/barchart/qbarmodelmapper.cpp +++ b/src/barchart/qbarmodelmapper.cpp @@ -193,6 +193,7 @@ void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : + QObject(q), m_series(0), m_model(0), m_first(0), diff --git a/src/piechart/piechart.pri b/src/piechart/piechart.pri index acb7061..7bce39a 100644 --- a/src/piechart/piechart.pri +++ b/src/piechart/piechart.pri @@ -8,7 +8,8 @@ SOURCES += \ $$PWD/qpieslice.cpp \ $$PWD/qpiemodelmapper.cpp \ $$PWD/qvpiemodelmapper.cpp \ - $$PWD/qhpiemodelmapper.cpp + $$PWD/qhpiemodelmapper.cpp \ + piechart/qdonutgroup.cpp PRIVATE_HEADERS += \ $$PWD/pieslicedata_p.h \ @@ -16,12 +17,13 @@ PRIVATE_HEADERS += \ $$PWD/piesliceitem_p.h \ $$PWD/qpieslice_p.h \ $$PWD/qpieseries_p.h \ - $$PWD/qpiemodelmapper_p.h + $$PWD/qpiemodelmapper_p.h \ + $$PWD/qdonutgroup_p.h PUBLIC_HEADERS += \ $$PWD/qpieseries.h \ $$PWD/qpieslice.h \ $$PWD/qpiemodelmapper.h \ $$PWD/qvpiemodelmapper.h \ - $$PWD/qhpiemodelmapper.h - + $$PWD/qhpiemodelmapper.h \ + $$PWD/qdonutgroup.h diff --git a/src/piechart/piechartitem.cpp b/src/piechart/piechartitem.cpp index 90bb5a1..f324a13 100644 --- a/src/piechart/piechartitem.cpp +++ b/src/piechart/piechartitem.cpp @@ -106,8 +106,10 @@ void PieChartItem::updateLayout() if (m_rect.width() < m_rect.height()) m_pieRadius = m_rect.width() / 2; + m_donutInnerRadius = m_pieRadius; // apply size factor m_pieRadius *= m_series->pieSize(); + m_donutInnerRadius *= m_series->donutInnerSize(); // set layouts for existing slice items foreach (QPieSlice* slice, m_series->slices()) { @@ -215,6 +217,7 @@ PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); sliceData.m_radius = m_pieRadius; sliceData.m_donut = m_series->donut(); + sliceData.m_innerRadius = m_donutInnerRadius; return sliceData; } diff --git a/src/piechart/piechartitem_p.h b/src/piechart/piechartitem_p.h index 2e6f88b..3552f38 100644 --- a/src/piechart/piechartitem_p.h +++ b/src/piechart/piechartitem_p.h @@ -73,6 +73,7 @@ private: QRectF m_rect; QPointF m_pieCenter; qreal m_pieRadius; + qreal m_donutInnerRadius; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/pieslicedata_p.h b/src/piechart/pieslicedata_p.h index 276b5dd..45ecefa 100644 --- a/src/piechart/pieslicedata_p.h +++ b/src/piechart/pieslicedata_p.h @@ -82,7 +82,9 @@ public: m_radius = 0; m_startAngle = 0; m_angleSpan = 0; + m_donut = false; + m_innerRadius = 0; } bool operator!=(const PieSliceData &other) const @@ -136,7 +138,9 @@ public: qreal m_radius; qreal m_startAngle; qreal m_angleSpan; + bool m_donut; + qreal m_innerRadius; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/piesliceitem.cpp b/src/piechart/piesliceitem.cpp index b77d392..ff6a50a 100644 --- a/src/piechart/piesliceitem.cpp +++ b/src/piechart/piesliceitem.cpp @@ -176,8 +176,7 @@ QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAn // slice path QPainterPath path; if (m_data.m_donut) { - qreal donutFraction = 5.0; - QRectF insideRect = rect.adjusted(rect.width() / donutFraction, rect.height() / donutFraction, -rect.width() / donutFraction, -rect.height() / donutFraction); + QRectF insideRect(center.x() - m_data.m_innerRadius, center.y()-m_data.m_innerRadius, m_data.m_innerRadius*2, m_data.m_innerRadius*2); path.arcMoveTo(rect, -startAngle + 90); path.arcTo(rect, -startAngle + 90, -angleSpan); path.arcTo(insideRect, -startAngle + 90 - angleSpan, angleSpan); diff --git a/src/piechart/qdonutgroup.cpp b/src/piechart/qdonutgroup.cpp new file mode 100644 index 0000000..e930a3d --- /dev/null +++ b/src/piechart/qdonutgroup.cpp @@ -0,0 +1,39 @@ +#include "qdonutgroup.h" +#include "qdonutgroup_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QDonutGroup::QDonutGroup(QObject *parent) : + QObject(parent), + d_ptr(new QDonutGroupPrivate(this)) +{ +} + +void QDonutGroup::append(QPieSeries *donut) +{ + if (donut == 0) + return; + + donut->setDonut(); + Q_D(QDonutGroup); + d->m_donuts.append(donut); + qreal donutFraction = 1.0 / (d->m_donuts.count() + 1); + for(int i = 0; i < d->m_donuts.count(); i++) { + d->m_donuts[i]->setPieSize( (i + 2) * donutFraction); + d->m_donuts[i]->setDonutInnerSize( (i + 1) * donutFraction); + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QDonutGroupPrivate::QDonutGroupPrivate(QDonutGroup *q): + QObject(q), + q_ptr(q) +{ + // +} + +#include "moc_qdonutgroup.cpp" +#include "moc_qdonutgroup_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qdonutgroup.h b/src/piechart/qdonutgroup.h new file mode 100644 index 0000000..e25abb0 --- /dev/null +++ b/src/piechart/qdonutgroup.h @@ -0,0 +1,27 @@ +#ifndef QDONUTGROUP_H +#define QDONUTGROUP_H + +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +//class QPieSeries; +class QDonutGroupPrivate; + +class QTCOMMERCIALCHART_EXPORT QDonutGroup : public QObject +{ + Q_OBJECT +public: + explicit QDonutGroup(QObject *parent = 0); + + void append(QPieSeries *donut); + +protected: + QDonutGroupPrivate * const d_ptr; + Q_DECLARE_PRIVATE(QDonutGroup) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QDONUTGROUP_H diff --git a/src/piechart/qdonutgroup_p.h b/src/piechart/qdonutgroup_p.h new file mode 100644 index 0000000..deb3f20 --- /dev/null +++ b/src/piechart/qdonutgroup_p.h @@ -0,0 +1,29 @@ +#ifndef QDONUTGROUP_P_H +#define QDONUTGROUP_P_H + +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QPieSeries; + +class QDonutGroupPrivate : public QObject +{ + Q_OBJECT +public: + explicit QDonutGroupPrivate(QDonutGroup *q); + + void append(QPieSeries *donut); + +private: + QList m_donuts; + +private: + QDonutGroup *q_ptr; + Q_DECLARE_PUBLIC(QDonutGroup) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QDONUTGROUP_P_H diff --git a/src/piechart/qpiemodelmapper.cpp b/src/piechart/qpiemodelmapper.cpp index 14e62fc..e3224bb 100644 --- a/src/piechart/qpiemodelmapper.cpp +++ b/src/piechart/qpiemodelmapper.cpp @@ -191,6 +191,7 @@ void QPieModelMapper::setLabelsSection(int labelsSection) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : + QObject(q), m_series(0), m_model(0), m_first(0), diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index 6a7e6a5..e5b55a4 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -536,6 +536,26 @@ bool QPieSeries::donut() const return d->m_donutChart; } +void QPieSeries::setDonutInnerSize(qreal innerSize) +{ + Q_D(QPieSeries); + + if (innerSize < 0.0) + innerSize = 0.0; + if (innerSize > 1.0) + innerSize = 1.0; + + d->m_donutRelativeInnerSize = innerSize; + d->updateDerivativeData(); + emit d->pieSizeChanged(); +} + +qreal QPieSeries::donutInnerSize() const +{ + Q_D(const QPieSeries); + return d->m_donutRelativeInnerSize; +} + void QPieSeries::setHorizontalPosition(qreal relativePosition) { Q_D(QPieSeries); @@ -674,7 +694,8 @@ QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : m_pieStartAngle(0), m_pieEndAngle(360), m_sum(0), - m_donutChart(false) + m_donutChart(false), + m_donutRelativeInnerSize(0.5) { } @@ -707,7 +728,6 @@ void QPieSeriesPrivate::updateDerivativeData() d->setPercentage(s->value() / m_sum); d->setStartAngle(sliceAngle); d->setAngleSpan(pieSpan * s->percentage()); - d->m_data.m_donut = m_donutChart; sliceAngle += s->angleSpan(); } diff --git a/src/piechart/qpieseries.h b/src/piechart/qpieseries.h index 70366a3..25db8c7 100644 --- a/src/piechart/qpieseries.h +++ b/src/piechart/qpieseries.h @@ -64,6 +64,9 @@ public: void setDonut(bool donut = true); bool donut() const; + void setDonutInnerSize(qreal innerSize); + qreal donutInnerSize() const; + void setHorizontalPosition(qreal relativePosition); qreal horizontalPosition() const; diff --git a/src/piechart/qpieseries_p.h b/src/piechart/qpieseries_p.h index dbb87e8..ccab671 100644 --- a/src/piechart/qpieseries_p.h +++ b/src/piechart/qpieseries_p.h @@ -78,6 +78,7 @@ private: qreal m_pieEndAngle; qreal m_sum; bool m_donutChart; + qreal m_donutRelativeInnerSize; private: friend class QLegendPrivate; diff --git a/src/xychart/qxymodelmapper.cpp b/src/xychart/qxymodelmapper.cpp index 5ca618f..70922ae 100644 --- a/src/xychart/qxymodelmapper.cpp +++ b/src/xychart/qxymodelmapper.cpp @@ -202,6 +202,7 @@ void QXYModelMapper::setYSection(int ySection) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) : + QObject(q), m_series(0), m_model(0), m_first(0),