From 6c3759bde1fdda933d6d147663a7b5fdede93ed3 2012-02-09 10:52:42 From: Jani Honkonen Date: 2012-02-09 10:52:42 Subject: [PATCH] Moved pie stuff to own .pri file and rename stuff --- diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 1d051ad..9544a0c 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -4,8 +4,7 @@ #include "barchartseries.h" #include "stackedbarchartseries.h" #include "percentbarchartseries.h" -#include "piechart/qpieseries.h" -#include "piechart/piepresentation.h" +#include "qpieseries.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 1bb6320..564a0d0 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -16,7 +16,7 @@ #include "linechartitem_p.h" #include "percentbargroup.h" #include "linechartanimationitem_p.h" -#include "piepresentation.h" +#include "piepresenter.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -149,11 +149,11 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) 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); + PiePresenter* pie = new PiePresenter(m_chart, pieSeries); + pieSeries->m_piePresenter = pie; // TODO: remove this pointer passing use signals&slots + QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); + QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); + m_chartItems.insert(series, pie); break; } diff --git a/src/piechart/piechart.pri b/src/piechart/piechart.pri new file mode 100644 index 0000000..26dbcd0 --- /dev/null +++ b/src/piechart/piechart.pri @@ -0,0 +1,14 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +SOURCES += \ + $$PWD/qpieseries.cpp \ + $$PWD/pieslice.cpp \ + $$PWD/piepresenter.cpp + +PRIVATE_HEADERS += \ + $$PWD/piepresenter.h \ + $$PWD/pieslice.h + +PUBLIC_HEADERS += \ + $$PWD/qpieseries.h diff --git a/src/piechart/piepresentation.cpp b/src/piechart/piepresenter.cpp similarity index 90% rename from src/piechart/piepresentation.cpp rename to src/piechart/piepresenter.cpp index 050a80e..3472bc0 100644 --- a/src/piechart/piepresentation.cpp +++ b/src/piechart/piepresenter.cpp @@ -1,11 +1,11 @@ -#include "piepresentation.h" +#include "piepresenter.h" #include "pieslice.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE -PiePresentation::PiePresentation(QGraphicsItem *parent, QPieSeries *series) : +PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series) : ChartItem(parent), m_pieSeries(series) { @@ -15,13 +15,13 @@ PiePresentation::PiePresentation(QGraphicsItem *parent, QPieSeries *series) : setAcceptHoverEvents(true); } -PiePresentation::~PiePresentation() +PiePresenter::~PiePresenter() { while (m_slices.count()) delete m_slices.takeLast(); } -void PiePresentation::seriesChanged() +void PiePresenter::seriesChanged() { const qreal fullPie = 360; qreal total = 0; @@ -47,7 +47,7 @@ void PiePresentation::seriesChanged() resize(); } -void PiePresentation::setSize(const QSizeF &size) +void PiePresenter::setSize(const QSizeF &size) { // TODO: allow user setting the size? // TODO: allow user defining the margins? @@ -55,12 +55,12 @@ void PiePresentation::setSize(const QSizeF &size) resize(); } -void PiePresentation::setPlotDomain(const PlotDomain& plotDomain) +void PiePresenter::setPlotDomain(const PlotDomain& plotDomain) { // TODO } -void PiePresentation::resize() +void PiePresenter::resize() { m_pieRect = m_rect; @@ -107,16 +107,16 @@ void PiePresentation::resize() qDebug() << "pie rect:" << m_pieRect; } -void PiePresentation::handleDomainChanged(const Domain& domain) +void PiePresenter::handleDomainChanged(const Domain& domain) { // TODO } -void PiePresentation::handleGeometryChanged(const QRectF& rect) +void PiePresenter::handleGeometryChanged(const QRectF& rect) { setSize(rect.size()); } -#include "moc_piepresentation.cpp" +#include "moc_piepresenter.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/piepresentation.h b/src/piechart/piepresenter.h similarity index 82% rename from src/piechart/piepresentation.h rename to src/piechart/piepresenter.h index 70d718c..3e88645 100644 --- a/src/piechart/piepresentation.h +++ b/src/piechart/piepresenter.h @@ -1,5 +1,5 @@ -#ifndef PIEPRESENTATION_H -#define PIEPRESENTATION_H +#ifndef PIEPRESENTER_H +#define PIEPRESENTER_H #include "chartitem_p.h" #include "qpieseries.h" @@ -8,14 +8,14 @@ class QGraphicsItem; QTCOMMERCIALCHART_BEGIN_NAMESPACE class PieSlice; -class PiePresentation : public QObject, public ChartItem +class PiePresenter : public QObject, public ChartItem { Q_OBJECT public: // TODO: use a generic data class instead of x and y - PiePresentation(QGraphicsItem *parent, QPieSeries *series); - ~PiePresentation(); + PiePresenter(QGraphicsItem *parent, QPieSeries *series); + ~PiePresenter(); public: // from ChartItem void setSize(const QSizeF &size); @@ -42,4 +42,4 @@ private: QTCOMMERCIALCHART_END_NAMESPACE -#endif // PIEPRESENTATION_H +#endif // PIEPRESENTER_H diff --git a/src/piechart/pieslice.cpp b/src/piechart/pieslice.cpp index fda691c..468185f 100644 --- a/src/piechart/pieslice.cpp +++ b/src/piechart/pieslice.cpp @@ -1,11 +1,11 @@ #include "pieslice.h" -#include "piepresentation.h" +#include "piepresenter.h" #include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE -PieSlice::PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span) +PieSlice::PieSlice(PiePresenter *piePresentation, int seriesIndex, qreal startAngle, qreal span) :QGraphicsItem(piePresentation), m_seriesIndex(seriesIndex), m_startAngle(startAngle), @@ -27,7 +27,7 @@ QRectF PieSlice::boundingRect() const QPainterPath PieSlice::shape() const { - QRectF rect = (static_cast(parentItem()))->pieRect(); + QRectF rect = (static_cast(parentItem()))->pieRect(); qreal angle = (-m_startAngle) + (90); qreal span = -m_span; @@ -55,7 +55,7 @@ void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option //painter->setPen(m_theme.linePen); // TODO: - QPieSlice data = (static_cast(parentItem()))->m_pieSeries->slice(m_seriesIndex); + QPieSlice data = (static_cast(parentItem()))->m_pieSeries->slice(m_seriesIndex); painter->setBrush(data.m_color); diff --git a/src/piechart/pieslice.h b/src/piechart/pieslice.h index 444990b..09a9e32 100644 --- a/src/piechart/pieslice.h +++ b/src/piechart/pieslice.h @@ -8,12 +8,12 @@ #include QTCOMMERCIALCHART_BEGIN_NAMESPACE -class PiePresentation; +class PiePresenter; class PieSlice : public QGraphicsItem { public: - PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span); + PieSlice(PiePresenter *piePresentation, int seriesIndex, qreal startAngle, qreal span); ~PieSlice(); public: // from QGraphicsItem diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index bcfe928..e46f90a 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -1,5 +1,5 @@ #include "qpieseries.h" -#include "piepresentation.h" +#include "piepresenter.h" #include "pieslice.h" #include @@ -7,7 +7,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QPieSeries::QPieSeries(QObject *parent) : QChartSeries(parent), - m_piePresentation(0), + m_piePresenter(0), m_sizeFactor(1.0), m_position(PiePositionMaximized) { @@ -21,19 +21,19 @@ QPieSeries::~QPieSeries() void QPieSeries::set(QList slices) { m_slices = slices; - if (m_piePresentation) { - m_piePresentation->seriesChanged(); - m_piePresentation->update(); + if (m_piePresenter) { + m_piePresenter->seriesChanged(); + m_piePresenter->update(); } } void QPieSeries::add(QList slices) { m_slices += slices; - if (m_piePresentation) { - m_piePresentation->seriesChanged(); - // TODO: m_piePresentation->seriesAppended()?? - m_piePresentation->update(); + if (m_piePresenter) { + m_piePresenter->seriesChanged(); + // TODO: m_piePresenter->seriesAppended()?? + m_piePresenter->update(); } } @@ -53,11 +53,11 @@ bool QPieSeries::update(int index, QPieSlice slice) { if ((index >= 0) && (index < m_slices.count())) { m_slices[index] = slice; - if (m_piePresentation) { - m_piePresentation->seriesChanged(); + if (m_piePresenter) { + m_piePresenter->seriesChanged(); // TODO: for a nice animation we need something like - // m_piePresentation->sliceChanged(index, oldslice, newslice) - m_piePresentation->update(); + // m_piePresenter->sliceChanged(index, oldslice, newslice) + m_piePresenter->update(); } return true; } @@ -69,9 +69,9 @@ void QPieSeries::setSizeFactor(qreal factor) if (factor > 0.0) m_sizeFactor = factor; - if (m_piePresentation) { - m_piePresentation->resize(); - m_piePresentation->update(); + if (m_piePresenter) { + m_piePresenter->resize(); + m_piePresenter->update(); // TODO: do we have to update the parent item also? // - potential issue: what if this function is called from the parent context? } @@ -80,9 +80,9 @@ void QPieSeries::setSizeFactor(qreal factor) void QPieSeries::setPosition(PiePosition position) { m_position = position; - if (m_piePresentation) { - m_piePresentation->resize(); - m_piePresentation->update(); + if (m_piePresenter) { + m_piePresenter->resize(); + m_piePresenter->update(); // TODO: do we have to update the parent item also? // - potential issue: what if this function is called from the parent context? } diff --git a/src/piechart/qpieseries.h b/src/piechart/qpieseries.h index 4aeff9d..f0a916d 100644 --- a/src/piechart/qpieseries.h +++ b/src/piechart/qpieseries.h @@ -8,7 +8,7 @@ class QGraphicsObject; QTCOMMERCIALCHART_BEGIN_NAMESPACE -class PiePresentation; +class PiePresenter; class PieSlice; class QPieSlice @@ -74,8 +74,8 @@ private: // TODO: use PIML friend class ChartPresenter; friend class ChartDataSet; - friend class PiePresentation; - PiePresentation *m_piePresentation; + friend class PiePresenter; + PiePresenter *m_piePresenter; QList m_slices; qreal m_sizeFactor; PiePosition m_position; diff --git a/src/src.pro b/src/src.pro index 864283a..02b7382 100644 --- a/src/src.pro +++ b/src/src.pro @@ -17,9 +17,6 @@ SOURCES += barchart/barchartseries.cpp \ linechart/linechartanimationitem.cpp \ linechart/linechartitem.cpp \ linechart/qlinechartseries.cpp \ - piechart/qpieseries.cpp \ - piechart/pieslice.cpp \ - piechart/piepresentation.cpp \ barchart/separator.cpp \ barchart/bargroupbase.cpp \ barchart/barchartseriesbase.cpp \ @@ -39,8 +36,6 @@ PRIVATE_HEADERS += linechart/linechartitem_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 \ axisitem_p.h \ @@ -58,13 +53,15 @@ PUBLIC_HEADERS += linechart/qlinechartseries.h \ barchart/percentbargroup.h \ barchart/barchartseriesbase.h \ barchart/bargroupbase.h \ - piechart/qpieseries.h \ qchartseries.h \ qscatterseries.h \ qchart.h \ qchartglobal.h \ qchartview.h \ qchartaxis.h + +include(piechart/piechart.pri) + THEMES += themes/chartthemeicy_p.h \ themes/chartthemegrayscale_p.h \ themes/chartthemescientific_p.h \ @@ -74,7 +71,6 @@ HEADERS += $$PRIVATE_HEADERS HEADERS += $$THEMES INCLUDEPATH += linechart \ barchart \ - piechart \ themes \ . OBJECTS_DIR = $$CHART_BUILD_DIR/lib