diff --git a/src/qchart.cpp b/src/qchart.cpp index 9efd131..e70fe95 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -86,8 +86,8 @@ QChartSeries* QChart::createSeries(QList x, QList y, QChartSeries: switch (type) { case QChartSeries::SeriesTypeScatter: { QScatterSeries *scatterSeries = new QScatterSeries(x, y, this); - connect(this, SIGNAL(sizeChanged(QRectF, qreal, qreal)), - scatterSeries, SLOT(chartSizeChanged(QRectF, qreal, qreal))); + connect(this, SIGNAL(sizeChanged(QRectF)), + scatterSeries, SLOT(chartSizeChanged(QRectF))); scatterSeries->d->setParentItem(this); return scatterSeries; } @@ -95,8 +95,8 @@ QChartSeries* QChart::createSeries(QList x, QList y, QChartSeries: // TODO: we now have also a list of y values as a parameter, it is ignored // we should use a generic data class instead of list of x and y values QPieSeries *pieSeries = new QPieSeries(x, this); - connect(this, SIGNAL(sizeChanged(QRectF, qreal, qreal)), - pieSeries, SLOT(chartSizeChanged(QRectF, qreal, qreal))); + connect(this, SIGNAL(sizeChanged(QRectF)), + pieSeries, SLOT(chartSizeChanged(QRectF))); return pieSeries; } default: @@ -113,12 +113,11 @@ void QChart::setSize(const QSizeF& size) m_grid->setPos(m_rect.topLeft()); m_grid->setSize(m_rect.size()); - // TODO: calculate the scale + // TODO: TTD for setting scale + //emit scaleChanged(100, 100); // TODO: calculate the origo // TODO: not sure if emitting a signal here is the best from performance point of view - const qreal xscale = size.width() / 100; - const qreal yscale = size.height() / 100; - emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale); + emit sizeChanged(QRectF(0, 0, size.width(), size.height())); for (int i(0); i < m_plotDomainList.size(); i++) m_plotDomainList[i].m_viewportRect = m_rect; diff --git a/src/qchart.h b/src/qchart.h index 0d6d98d..cea8f0d 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -42,7 +42,8 @@ public: int margin() const; signals: - void sizeChanged(QRectF rect, qreal xscale, qreal yscale); + void sizeChanged(QRectF rect); + void scaleChanged(qreal xscale, qreal yscale); private: Q_DISABLE_COPY(QChart) diff --git a/src/qpieseries.cpp b/src/qpieseries.cpp index 35907fa..d80cf37 100644 --- a/src/qpieseries.cpp +++ b/src/qpieseries.cpp @@ -9,24 +9,16 @@ QPieSeries::QPieSeries(QList x, QGraphicsObject *parent) : QChartSeries(parent), m_x(x) { -} - -QPieSeries::~QPieSeries() -{ -} - -void QPieSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) -{ + // Create slices qreal fullPie = 360; qreal total = 0; foreach (qreal value, m_x) total += value; - // We must have a parent for the graphics items we create - // TODO: maybe QChartSeries needs to be a QGraphicsObject to make this clear for the users? - QGraphicsItem *parentItem = qobject_cast(parent()); + QGraphicsItem *parentItem = qobject_cast(parent); Q_ASSERT(parentItem); 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_x) { qreal span = value / total * fullPie; PieSlice *slice = new PieSlice(randomColor(), angle, span); @@ -36,6 +28,14 @@ void QPieSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) } } +QPieSeries::~QPieSeries() +{ +} + +void QPieSeries::chartSizeChanged(QRectF /*rect*/) +{ +} + QColor QPieSeries::randomColor() { QColor c; diff --git a/src/qpieseries.h b/src/qpieseries.h index 4d48bd7..ee9518f 100644 --- a/src/qpieseries.h +++ b/src/qpieseries.h @@ -24,7 +24,7 @@ public: // from QChartSeries QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } public Q_SLOTS: - void chartSizeChanged(QRectF rect, qreal xscale, qreal yscale); + void chartSizeChanged(QRectF rect); private: //Q_DECLARE_PRIVATE(QPieSeries) diff --git a/src/qscatterseries.cpp b/src/qscatterseries.cpp index 7033e31..824b695 100644 --- a/src/qscatterseries.cpp +++ b/src/qscatterseries.cpp @@ -12,22 +12,28 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QScatterSeriesPrivate::QScatterSeriesPrivate(QList x, QList y, QGraphicsItem *parent) : QGraphicsItem(parent), m_x(x), - m_y(y) + m_y(y), + m_scalex(100), // TODO: let the use define the scale (or autoscaled) + m_scaley(100) { + resize(parent->boundingRect()); } -void QScatterSeriesPrivate::resize(QRectF rect, qreal xscale, qreal yscale) +void QScatterSeriesPrivate::resize(QRectF rect) { m_scenex.clear(); m_sceney.clear(); foreach(qreal x, m_x) - m_scenex.append(rect.left() + x * xscale); + m_scenex.append(rect.left() + x * (rect.width() / m_scalex)); foreach(qreal y, m_y) - m_sceney.append(rect.bottom() - y * yscale); + m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley)); } +// TODO: +//void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale) + QRectF QScatterSeriesPrivate::boundingRect() const { return QRectF(0, 0, 55, 100); @@ -38,7 +44,7 @@ void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsI QPen pen = painter->pen(); QBrush brush = pen.brush(); // TODO: The opacity should be user definable... - brush.setColor(QColor(255, 82, 0, 50)); + brush.setColor(QColor(255, 82, 0, 100)); pen.setBrush(brush); pen.setWidth(4); painter->setPen(pen); @@ -58,14 +64,20 @@ QScatterSeries::QScatterSeries(QList x, QList y, QObject *parent) { } -void QScatterSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) +void QScatterSeries::chartSizeChanged(QRectF rect) { // Recalculate scatter data point locations on the scene // d->transform().reset(); // d->transform().translate(); - d->resize(rect, xscale, yscale); + d->resize(rect); } +// TODO: +//void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) +//{ +// d->rescale(xscale, yscale); +//} + QScatterSeries::~QScatterSeries() { delete d; diff --git a/src/qscatterseries.h b/src/qscatterseries.h index 8c5197c..15c1320 100644 --- a/src/qscatterseries.h +++ b/src/qscatterseries.h @@ -19,7 +19,8 @@ public: // from QChartSeries QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } public Q_SLOTS: - void chartSizeChanged(QRectF rect, qreal xscale, qreal yscale); + void chartSizeChanged(QRectF rect); + //void chartScaleChanged(qreal xscale, qreal yscale); private: Q_DECLARE_PRIVATE(QScatterSeries) diff --git a/src/qscatterseries_p.h b/src/qscatterseries_p.h index d818c27..e68d2d8 100644 --- a/src/qscatterseries_p.h +++ b/src/qscatterseries_p.h @@ -15,13 +15,15 @@ public: QScatterSeriesPrivate(QList x, QList y, QGraphicsItem *parent); public: // from QGraphicsItem - void resize(QRectF rect, qreal xscale, qreal yscale); + void resize(QRectF rect); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); // TODO: use the chart data class instead of list of x and y values? QList m_x; QList m_y; + qreal m_scalex; + qreal m_scaley; QList m_scenex; QList m_sceney; };