From d6b5513f55834c8fa17fb0612227df95e7e0294e 2012-02-09 08:30:33 From: Jani Honkonen Date: 2012-02-09 08:30:33 Subject: [PATCH] Pie chart refactoring --- diff --git a/example/piechart/main.cpp b/example/piechart/main.cpp index 3a70ac3..9695b70 100644 --- a/example/piechart/main.cpp +++ b/example/piechart/main.cpp @@ -17,12 +17,11 @@ int main(int argc, char *argv[]) Q_ASSERT(series); // Add test data to the series - QList x; - for (qreal i(0.0); i < 20; i += 0.5) { - // Linear data with random component - x.append(i + ((qreal)(rand() % 100)) / 100 ); - } - series->setData(x); + series->add(QPieSlice(1, "test1", Qt::red)); + series->add(QPieSlice(2, "test2", Qt::green)); + series->add(QPieSlice(3, "test3", Qt::blue)); + series->add(QPieSlice(4, "test4", Qt::darkRed)); + series->add(QPieSlice(5, "test5", Qt::darkGreen)); // Use the chart widget as the central widget QMainWindow w; diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 2ef0947..d41550f 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -4,6 +4,8 @@ #include "barchartseries.h" #include "stackedbarchartseries.h" #include "percentbarchartseries.h" +#include "piechart/qpieseries.h" +#include "piechart/piepresentation.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -82,6 +84,12 @@ void ChartDataSet::addSeries(QChartSeries* series) } break; + case QChartSeries::SeriesTypePie: { + QPieSeries *pieSeries = static_cast(series); + // TODO: domain stuff + break; + } + default: { qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; return; diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 25a2140..542d35b 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -7,6 +7,7 @@ #include "stackedbarchartseries.h" #include "percentbarchartseries.h" #include "qxychartseries.h" +#include "qpieseries.h" //items #include "axisitem_p.h" #include "bargroup.h" @@ -14,6 +15,7 @@ #include "xylinechartitem_p.h" #include "percentbargroup.h" #include "linechartanimationitem_p.h" +#include "piepresentation.h" #include #include @@ -162,19 +164,18 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) break; } - case QChartSeries::SeriesTypePie: { - QPieSeries *pieSeries = qobject_cast(series); - pieSeries->d->setParentItem(this); - m_chartItems << pieSeries->d; - pieSeries->d->m_chartTheme = m_chartTheme; - m_chartTheme->addObserver(pieSeries->d); - break; - } - default: - break; - } */ + case QChartSeries::SeriesTypePie: { + QPieSeries *pieSeries = qobject_cast(series); + PiePresentation* pieChart = new PiePresentation(m_chart, pieSeries); + pieSeries->m_piePresentation = pieChart; // TODO: remove this pointer passing use signals&slots + QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pieChart, SLOT(handleGeometryChanged(const QRectF&))); + QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pieChart, SLOT(handleDomainChanged(const Domain&))); + m_chartItems.insert(series, pieChart); + break; + } + default: { qDebug()<< "Series type" << series->type() << "not implemented."; break; diff --git a/src/piechart/piepresentation.cpp b/src/piechart/piepresentation.cpp new file mode 100644 index 0000000..050a80e --- /dev/null +++ b/src/piechart/piepresentation.cpp @@ -0,0 +1,122 @@ + +#include "piepresentation.h" +#include "pieslice.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +PiePresentation::PiePresentation(QGraphicsItem *parent, QPieSeries *series) : + ChartItem(parent), + m_pieSeries(series) +{ + Q_ASSERT(parent); + Q_ASSERT(series); + m_rect = parentItem()->boundingRect(); + setAcceptHoverEvents(true); +} + +PiePresentation::~PiePresentation() +{ + while (m_slices.count()) + delete m_slices.takeLast(); +} + +void PiePresentation::seriesChanged() +{ + const qreal fullPie = 360; + qreal total = 0; + + // calculate total + foreach (QPieSlice sliceData, m_pieSeries->slices()) + total += sliceData.m_value; + + // TODO: no need to create new slices in case size changed; we should re-use the existing ones + while (m_slices.count()) + delete m_slices.takeLast(); + + // create slices + qreal angle = 0; + for (int i=0; icount(); i++) { + QPieSlice sliceData = m_pieSeries->slice(i); + qreal span = sliceData.m_value / total * fullPie; + PieSlice *slice = new PieSlice(this, i, angle, span); + m_slices.append(slice); + angle += span; + } + + resize(); +} + +void PiePresentation::setSize(const QSizeF &size) +{ + // TODO: allow user setting the size? + // TODO: allow user defining the margins? + m_rect.setSize(size); + resize(); +} + +void PiePresentation::setPlotDomain(const PlotDomain& plotDomain) +{ + // TODO +} + +void PiePresentation::resize() +{ + m_pieRect = m_rect; + + if (m_pieRect.width() < m_pieRect.height()) { + m_pieRect.setWidth(m_pieRect.width() * m_pieSeries->m_sizeFactor); + m_pieRect.setHeight(m_pieRect.width()); + m_pieRect.moveCenter(m_rect.center()); + } else { + m_pieRect.setHeight(m_pieRect.height() * m_pieSeries->m_sizeFactor); + m_pieRect.setWidth(m_pieRect.height()); + m_pieRect.moveCenter(m_rect.center()); + } + + switch (m_pieSeries->m_position) { + case QPieSeries::PiePositionTopLeft: { + m_pieRect.setHeight(m_pieRect.height() / 2); + m_pieRect.setWidth(m_pieRect.height()); + m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2)); + break; + } + case QPieSeries::PiePositionTopRight: { + m_pieRect.setHeight(m_pieRect.height() / 2); + m_pieRect.setWidth(m_pieRect.height()); + m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2)); + break; + } + case QPieSeries::PiePositionBottomLeft: { + m_pieRect.setHeight(m_pieRect.height() / 2); + m_pieRect.setWidth(m_pieRect.height()); + m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3)); + break; + } + case QPieSeries::PiePositionBottomRight: { + m_pieRect.setHeight(m_pieRect.height() / 2); + m_pieRect.setWidth(m_pieRect.height()); + m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3)); + break; + } + default: + break; + } + + qDebug() << "presentation rect:" << m_rect; + qDebug() << "pie rect:" << m_pieRect; +} + +void PiePresentation::handleDomainChanged(const Domain& domain) +{ + // TODO +} + +void PiePresentation::handleGeometryChanged(const QRectF& rect) +{ + setSize(rect.size()); +} + +#include "moc_piepresentation.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/piepresentation.h b/src/piechart/piepresentation.h new file mode 100644 index 0000000..70d718c --- /dev/null +++ b/src/piechart/piepresentation.h @@ -0,0 +1,45 @@ +#ifndef PIEPRESENTATION_H +#define PIEPRESENTATION_H + +#include "chartitem_p.h" +#include "qpieseries.h" + +class QGraphicsItem; +QTCOMMERCIALCHART_BEGIN_NAMESPACE +class PieSlice; + +class PiePresentation : public QObject, public ChartItem +{ + Q_OBJECT + +public: + // TODO: use a generic data class instead of x and y + PiePresentation(QGraphicsItem *parent, QPieSeries *series); + ~PiePresentation(); + +public: // from ChartItem + void setSize(const QSizeF &size); + void setPlotDomain(const PlotDomain& data); + QRectF boundingRect() const { return m_rect; } + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} + +public: + void seriesChanged(); + void resize(); + QRectF pieRect() const { return m_pieRect; } + +public Q_SLOTS: + void handleDomainChanged(const Domain& domain); + void handleGeometryChanged(const QRectF& rect); + +private: + friend class PieSlice; + QList m_slices; + QPieSeries *m_pieSeries; + QRectF m_rect; + QRectF m_pieRect; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // PIEPRESENTATION_H diff --git a/src/pieslice.cpp b/src/piechart/pieslice.cpp similarity index 73% rename from src/pieslice.cpp rename to src/piechart/pieslice.cpp index 36b0dba..80e916f 100644 --- a/src/pieslice.cpp +++ b/src/piechart/pieslice.cpp @@ -1,16 +1,19 @@ #include "pieslice.h" +#include "piepresentation.h" #include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE -PieSlice::PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect) - : m_color(color), +PieSlice::PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span) + :QGraphicsItem(piePresentation), + m_seriesIndex(seriesIndex), m_startAngle(startAngle), - m_span(span), - m_rect(rect) + m_span(span) { + Q_ASSERT(piePresentation); setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::LeftButton); } PieSlice::~PieSlice() @@ -19,17 +22,18 @@ PieSlice::~PieSlice() QRectF PieSlice::boundingRect() const { - return m_rect; + return shape().boundingRect(); } QPainterPath PieSlice::shape() const { + QRectF rect = (static_cast(parentItem()))->pieRect(); qreal angle = (-m_startAngle) + (90); qreal span = -m_span; QPainterPath path; - path.moveTo(boundingRect().center()); - path.arcTo(boundingRect(), angle, span); + path.moveTo(rect.center()); + path.arcTo(rect, angle, span); // TODO: draw the shape so that it might have a hole in the center // - Sin & Cos will be needed to find inner/outer arc endpoints @@ -44,13 +48,17 @@ QPainterPath PieSlice::shape() const return path; } -void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) +void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) { painter->setRenderHint(QPainter::Antialiasing); // TODO: how to map theme settings to a pie slice? Now we //painter->setPen(m_theme.linePen); // TODO: - painter->setBrush(m_theme.linePen.color()); + + QPieSlice data = (static_cast(parentItem()))->m_pieSeries->slice(m_seriesIndex); + painter->setBrush(data.m_color); + + //painter->setBrush(m_theme.linePen.color()); // From Qt docs: // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). @@ -63,12 +71,20 @@ void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option //painter->drawPie(boundingRect(), angle, span); painter->drawPath(shape()); + + // Draw the label + // TODO: do this better + painter->drawText(boundingRect().center(), data.m_label); } void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) { QGraphicsItem::hoverEnterEvent(event); - qDebug() << "hover" << m_color << m_startAngle << m_span; + qDebug() << "hover" << m_seriesIndex << m_startAngle << m_span; } +void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + QGraphicsItem::mousePressEvent(event); +} QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/pieslice.h b/src/piechart/pieslice.h similarity index 75% rename from src/pieslice.h rename to src/piechart/pieslice.h index 67fdcdf..c22641f 100644 --- a/src/pieslice.h +++ b/src/piechart/pieslice.h @@ -8,25 +8,26 @@ #include QTCOMMERCIALCHART_BEGIN_NAMESPACE +class PiePresentation; class PieSlice : public QGraphicsItem { public: - PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect); + PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span); ~PieSlice(); public: // from QGraphicsItem QRectF boundingRect() const; QPainterPath shape() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void hoverEnterEvent(QGraphicsSceneHoverEvent * event); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); -public: - QColor m_color; +private: + int m_seriesIndex; qreal m_startAngle; qreal m_span; - QRectF m_rect; - SeriesTheme m_theme; + //SeriesTheme m_theme; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp new file mode 100644 index 0000000..bcfe928 --- /dev/null +++ b/src/piechart/qpieseries.cpp @@ -0,0 +1,93 @@ +#include "qpieseries.h" +#include "piepresentation.h" +#include "pieslice.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QPieSeries::QPieSeries(QObject *parent) : + QChartSeries(parent), + m_piePresentation(0), + m_sizeFactor(1.0), + m_position(PiePositionMaximized) +{ +} + +QPieSeries::~QPieSeries() +{ + +} + +void QPieSeries::set(QList slices) +{ + m_slices = slices; + if (m_piePresentation) { + m_piePresentation->seriesChanged(); + m_piePresentation->update(); + } +} + +void QPieSeries::add(QList slices) +{ + m_slices += slices; + if (m_piePresentation) { + m_piePresentation->seriesChanged(); + // TODO: m_piePresentation->seriesAppended()?? + m_piePresentation->update(); + } +} + +void QPieSeries::add(QPieSlice slice) +{ + add(QList() << slice); +} + +QPieSlice QPieSeries::slice(int index) const +{ + if ((index >= 0) && (index < m_slices.count())) + return m_slices.at(index); + return QPieSlice(); +} + +bool QPieSeries::update(int index, QPieSlice slice) +{ + if ((index >= 0) && (index < m_slices.count())) { + m_slices[index] = slice; + if (m_piePresentation) { + m_piePresentation->seriesChanged(); + // TODO: for a nice animation we need something like + // m_piePresentation->sliceChanged(index, oldslice, newslice) + m_piePresentation->update(); + } + return true; + } + return false; +} + +void QPieSeries::setSizeFactor(qreal factor) +{ + if (factor > 0.0) + m_sizeFactor = factor; + + if (m_piePresentation) { + m_piePresentation->resize(); + m_piePresentation->update(); + // TODO: do we have to update the parent item also? + // - potential issue: what if this function is called from the parent context? + } +} + +void QPieSeries::setPosition(PiePosition position) +{ + m_position = position; + if (m_piePresentation) { + m_piePresentation->resize(); + m_piePresentation->update(); + // TODO: do we have to update the parent item also? + // - potential issue: what if this function is called from the parent context? + } +} + +#include "moc_qpieseries.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qpieseries.h b/src/piechart/qpieseries.h similarity index 57% rename from src/qpieseries.h rename to src/piechart/qpieseries.h index 01ad966..4aeff9d 100644 --- a/src/qpieseries.h +++ b/src/piechart/qpieseries.h @@ -8,9 +8,24 @@ class QGraphicsObject; QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QPieSeriesPrivate; +class PiePresentation; class PieSlice; +class QPieSlice +{ +public: + QPieSlice() + :m_value(0), m_label(""), m_color(Qt::white), m_isExploded(false) {} + + QPieSlice(qreal value, QString label, QColor color, bool exploded = false) + :m_value(value), m_label(label), m_color(color), m_isExploded(exploded) {} +public: + qreal m_value; + QString m_label; + QColor m_color; + bool m_isExploded; +}; + class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries { Q_OBJECT @@ -25,27 +40,45 @@ public: }; public: - // TODO: use a generic data class instead of x and y - QPieSeries(QGraphicsObject *parent = 0); + QPieSeries(QObject *parent = 0); ~QPieSeries(); public: // from QChartSeries QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } - bool setData(QList data); public: - void setSliceColor(int index, QColor color); - QColor sliceColor(int index); - int sliceCount(); + void set(QList slices); + void add(QList slices); + void add(QPieSlice slice); + + int count() const { return m_slices.count(); } + + QList slices() const { return m_slices; } + QPieSlice slice(int index) const; + bool update(int index, QPieSlice slice); + + // TODO: convenience functions + //void updateValue(int sliceIndex, qreal value); + //void updateLabel(int sliceIndex, QString label); + //void updateColor(int sliceIndex, QColor color); + //void updateExploded(int slizeIndex, bool exploded); + void setSizeFactor(qreal sizeFactor); - qreal sizeFactor(); + qreal sizeFactor() const { return m_sizeFactor; } + void setPosition(PiePosition position); + PiePosition position() const { return m_position; } private: - Q_DECLARE_PRIVATE(QPieSeries) Q_DISABLE_COPY(QPieSeries) - friend class QChart; - QPieSeriesPrivate *const d; + // TODO: use PIML + friend class ChartPresenter; + friend class ChartDataSet; + friend class PiePresentation; + PiePresentation *m_piePresentation; + QList m_slices; + qreal m_sizeFactor; + PiePosition m_position; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchart.cpp b/src/qchart.cpp index c7eef49..1f481ef 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -3,7 +3,6 @@ #include "qscatterseries.h" #include "qscatterseries_p.h" #include "qpieseries.h" -#include "qpieseries_p.h" #include "qchartaxis.h" #include "charttheme_p.h" #include "chartitem_p.h" @@ -121,7 +120,7 @@ void QChart::setTitle(const QString& title,const QFont& font) int QChart::margin() const { - m_presenter->margin(); + return m_presenter->margin(); } void QChart::setMargin(int margin) diff --git a/src/qpieseries.cpp b/src/qpieseries.cpp deleted file mode 100644 index 357ea6f..0000000 --- a/src/qpieseries.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include "qpieseries_p.h" -#include "qpieseries.h" -#include -#include "pieslice.h" -#include - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -QPieSeriesPrivate::QPieSeriesPrivate(QGraphicsItem *parent) : - ChartItem(parent), - m_sizeFactor(1.0), - m_position(QPieSeries::PiePositionMaximized), - m_chartTheme(0) -{ -} - -QPieSeriesPrivate::~QPieSeriesPrivate() -{ - while (m_slices.count()) - delete m_slices.takeLast(); -} - -bool QPieSeriesPrivate::setData(QList data) -{ - m_data = data; - - if (parentItem()) { - // Create slices - qreal fullPie = 360; - qreal total = 0; - foreach (qreal value, m_data) - total += value; - - m_chartSize = parentItem()->boundingRect(); - qreal angle = 0; - // TODO: no need to create new slices in case size changed; we should re-use the existing ones - foreach (qreal value, m_data) { - qreal span = value / total * fullPie; - PieSlice *slice = new PieSlice(QColor(), angle, span, parentItem()->boundingRect()); - slice->setParentItem(parentItem()); - m_slices.append(slice); - angle += span; - } - - themeChanged(m_chartTheme); - resizeSlices(m_chartSize); - } - - return true; -} - -void QPieSeriesPrivate::setSize(const QSizeF &size) -{ - // TODO: allow user setting the size? - // TODO: allow user defining the margins? - m_chartSize = QRect(0, 0, size.width(), size.height()); - resizeSlices(m_chartSize); -} - -void QPieSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) -{ - // TODO -} - -void QPieSeriesPrivate::themeChanged(ChartTheme *theme) -{ - if (theme) { - m_chartTheme = theme; - for (int i(0); i < m_slices.count(); i++) - m_slices.at(i)->m_theme = theme->themeForSeries(); - } -} - -void QPieSeriesPrivate::resizeSlices(QRectF rect) -{ - QRectF tempRect = rect; - if (tempRect.width() < tempRect.height()) { - tempRect.setWidth(tempRect.width() * m_sizeFactor); - tempRect.setHeight(tempRect.width()); - tempRect.moveCenter(rect.center()); - } else { - tempRect.setHeight(tempRect.height() * m_sizeFactor); - tempRect.setWidth(tempRect.height()); - tempRect.moveCenter(rect.center()); - } - - switch (m_position) { - case QPieSeries::PiePositionTopLeft: { - tempRect.setHeight(tempRect.height() / 2); - tempRect.setWidth(tempRect.height()); - tempRect.moveCenter(QPointF(rect.center().x() / 2, rect.center().y() / 2)); - break; - } - case QPieSeries::PiePositionTopRight: { - tempRect.setHeight(tempRect.height() / 2); - tempRect.setWidth(tempRect.height()); - tempRect.moveCenter(QPointF((rect.center().x() / 2) * 3, rect.center().y() / 2)); - break; - } - case QPieSeries::PiePositionBottomLeft: { - tempRect.setHeight(tempRect.height() / 2); - tempRect.setWidth(tempRect.height()); - tempRect.moveCenter(QPointF(rect.center().x() / 2, (rect.center().y() / 2) * 3)); - break; - } - case QPieSeries::PiePositionBottomRight: { - tempRect.setHeight(tempRect.height() / 2); - tempRect.setWidth(tempRect.height()); - tempRect.moveCenter(QPointF((rect.center().x() / 2) * 3, (rect.center().y() / 2) * 3)); - break; - } - default: - break; - } - - foreach (PieSlice *slice, m_slices) - slice->m_rect = tempRect; -} - -QPieSeries::QPieSeries(QGraphicsObject *parent) : - QChartSeries(parent), - d(new QPieSeriesPrivate(parent)) -{ -} - -QPieSeries::~QPieSeries() -{ - delete d; -} - -bool QPieSeries::setData(QList data) -{ - return d->setData(data); -} - -void QPieSeries::setSliceColor(int index, QColor color) -{ - if (index >= 0 && index < d->m_slices.count()) - d->m_slices.at(index)->m_color = color; -} - -QColor QPieSeries::sliceColor(int index) -{ - if (index >= 0 && index < d->m_slices.count()) - return d->m_slices.at(index)->m_color; - else - return QColor(); -} - -int QPieSeries::sliceCount() -{ - return d->m_slices.count(); -} - -void QPieSeries::setSizeFactor(qreal factor) -{ - if (factor > 0.0) - d->m_sizeFactor = factor; - d->resizeSlices(d->m_chartSize); - - // Initiate update via the parent graphics item - // TODO: potential issue: what if this function is called from the parent context? - if (d->parentItem()) - d->parentItem()->update(); -} - -qreal QPieSeries::sizeFactor() -{ - return d->m_sizeFactor; -} - -void QPieSeries::setPosition(PiePosition position) -{ - d->m_position = position; - d->resizeSlices(d->m_chartSize); - - // Initiate update via the parent graphics item - // TODO: potential issue: what if this function is called from the parent context? - QGraphicsItem *parentItem = qobject_cast(parent()); - Q_ASSERT(parentItem); - parentItem->update(); -} - -#include "moc_qpieseries.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qpieseries_p.h b/src/qpieseries_p.h deleted file mode 100644 index 4cdd5f1..0000000 --- a/src/qpieseries_p.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef PIESERIESPRIVATE_H -#define PIESERIESPRIVATE_H - -#include "chartitem_p.h" -#include "charttheme_p.h" -#include "qpieseries.h" -#include -#include - -class QGraphicsItem; -QTCOMMERCIALCHART_BEGIN_NAMESPACE -class PieSlice; - -class QPieSeriesPrivate : public ChartItem, public ChartThemeObserver -{ -public: - // TODO: use a generic data class instead of x and y - QPieSeriesPrivate(QGraphicsItem *parent); - ~QPieSeriesPrivate(); - -public: // from ChartItem - void setSize(const QSizeF &size); - void setPlotDomain(const PlotDomain& data); - // This is a dummy QGraphicsItem; dummy implementation - QRectF boundingRect() const { return parentItem()->boundingRect(); } - // This is a dummy QGraphicsItem; no implementation - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} - -public: // from ChartThemeObserver - void themeChanged(ChartTheme *theme); - -public: - bool setData(QList data); - void resizeSlices(QRectF rect); - QList m_data; - QList m_slices; - QRectF m_chartSize; - qreal m_sizeFactor; - QPieSeries::PiePosition m_position; - ChartTheme *m_chartTheme; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // PIESERIESPRIVATE_H diff --git a/src/src.pro b/src/src.pro index 735187b..f94116e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -23,12 +23,13 @@ SOURCES += \ xylinechart/qxychartseries.cpp \ xylinechart/xylinechartitem.cpp \ xylinechart/linechartanimationitem.cpp \ + piechart/qpieseries.cpp \ + piechart/pieslice.cpp \ + piechart/piepresentation.cpp \ plotdomain.cpp \ qscatterseries.cpp \ - qpieseries.cpp \ qchart.cpp \ axisitem.cpp \ - pieslice.cpp \ qchartview.cpp \ qchartseries.cpp \ qchartaxis.cpp \ @@ -40,16 +41,18 @@ SOURCES += \ chartpresenter.cpp \ domain.cpp + + PRIVATE_HEADERS += \ xylinechart/xylinechartitem_p.h \ xylinechart/linechartanimationitem_p.h \ barchart/barlabel_p.h \ barchart/bar_p.h \ barchart/separator_p.h \ + piechart/piepresentation.h \ + piechart/pieslice.h \ plotdomain_p.h \ qscatterseries_p.h \ - qpieseries_p.h \ - pieslice.h \ axisitem_p.h \ chartitem_p.h \ charttheme_p.h \ @@ -60,7 +63,6 @@ PRIVATE_HEADERS += \ PUBLIC_HEADERS += \ qchartseries.h \ qscatterseries.h \ - qpieseries.h \ qchart.h \ qchartglobal.h \ xylinechart/qxychartseries.h \ @@ -72,6 +74,7 @@ PUBLIC_HEADERS += \ barchart/percentbargroup.h \ barchart/barchartseriesbase.h \ barchart/bargroupbase.h \ + piechart/qpieseries.h \ qchartview.h \ qchartaxis.h @@ -80,6 +83,7 @@ HEADERS += $$PRIVATE_HEADERS INCLUDEPATH += xylinechart \ barchart \ + piechart \ . OBJECTS_DIR = $$CHART_BUILD_DIR/lib