From 543ce926fdb732b998dc362638d17a99fbc74179 2012-02-27 15:11:55 From: Tero Ahola Date: 2012-02-27 15:11:55 Subject: [PATCH] Fixing review findings in QScatterSeries --- diff --git a/doc/src/index.qdoc b/doc/src/index.qdoc index efe0e0a..aaee5f8 100644 --- a/doc/src/index.qdoc +++ b/doc/src/index.qdoc @@ -7,10 +7,13 @@ qtcommercial

- QCharts is a part of Qt Commercial addons package. It provides a set of simple chart components which are available for Qt Commercial customers. - It uses Qt Graphics View Framework, therefore charts can be easily integrated 2D modern user interfaces. QCharts can be used as QWidgets, QGraphicsWidget or QML elements. - Users can easily create impressive graphs by selecting one of the charts themes. + QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart + components which are available for Qt Commercial customers. It uses Qt Graphics View + Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can + be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive + graphs by selecting one of the charts themes.

+ diff --git a/example/scatter/main.cpp b/example/scatter/main.cpp index 59c0446..bd612f4 100644 --- a/example/scatter/main.cpp +++ b/example/scatter/main.cpp @@ -27,14 +27,9 @@ int main(int argc, char *argv[]) chartView->addSeries(scatter); //! [1] - // Add some more data - //! [2] - scatter->addData(QPointF(2.0, 5.5)); - //! [2] - // And more //! [3] - *scatter << QPointF(2.0, 5.5); + *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4); //! [3] // Add another scatter series (re-use the previous pointer) @@ -46,14 +41,14 @@ int main(int argc, char *argv[]) } //! [4] QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); - scatter->setMarkerBrush(brush); + scatter->setBrush(brush); //! [4] //! [5] QPen pen(QColor(0, 255, 0, 80), 3); - scatter->setMarkerPen(pen); + scatter->setPen(pen); //! [5] //! [6] - scatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle); + scatter->setShape(QScatterSeries::MarkerShapeRectangle); //! [6] chartView->addSeries(scatter); diff --git a/qmlplugin/declarativescatterseries.cpp b/qmlplugin/declarativescatterseries.cpp index 6100df3..5780cca 100644 --- a/qmlplugin/declarativescatterseries.cpp +++ b/qmlplugin/declarativescatterseries.cpp @@ -59,7 +59,7 @@ void DeclarativeScatterSeries::appendData(QDeclarativeListPropertym_data.append(element); if (series->m_series) - series->m_series->addData(QPointF(element->x(), element->y())); + series->m_series->add(element->x(), element->y()); } } diff --git a/src/scatterseries/qscatterseries.cpp b/src/scatterseries/qscatterseries.cpp index 6b17764..969d4e5 100644 --- a/src/scatterseries/qscatterseries.cpp +++ b/src/scatterseries/qscatterseries.cpp @@ -41,16 +41,6 @@ */ /*! - \fn void QScatterSeries::hoverEnter() - \brief TODO -*/ - -/*! - \fn void QScatterSeries::hoverLeave() - \brief TODO -*/ - -/*! \fn void QScatterSeries::changed() \brief TODO */ @@ -86,11 +76,18 @@ QScatterSeries::~QScatterSeries() } /*! + Add single data point with \a x and \a y coordinates to the series. +*/ +void QScatterSeries::add(qreal x, qreal y) +{ + d->m_data.append(QPointF(x, y)); + emit changed(); +} + +/*! Add single data point with \a value to the series. - For example: - \snippet ../example/scatter/main.cpp 2 */ -void QScatterSeries::addData(QPointF value) +void QScatterSeries::add(QPointF value) { d->m_data.append(value); emit changed(); @@ -99,7 +96,7 @@ void QScatterSeries::addData(QPointF value) /*! Add list of \a points to the series. */ -void QScatterSeries::addData(QList points) +void QScatterSeries::add(QList points) { d->m_data.append(points); emit changed(); @@ -107,7 +104,7 @@ void QScatterSeries::addData(QList points) /*! Stream operator for adding a data point with \a value to the series. - \sa addData() + \sa add() For example: \snippet ../example/scatter/main.cpp 3 @@ -121,7 +118,7 @@ QScatterSeries& QScatterSeries::operator << (const QPointF &value) /*! Stream operator for adding a list of points to the series. - \sa addData() + \sa add() */ QScatterSeries& QScatterSeries::operator << (QList value) { @@ -158,10 +155,10 @@ QList QScatterSeries::data() beatiful markers defined by the chart's theme: \image scatter_example_pen.jpg - \sa setMarkerBrush() + \sa setBrush() \sa QChart::setChartTheme() */ -void QScatterSeries::setMarkerPen(QPen pen) +void QScatterSeries::setPen(QPen pen) { d->m_markerPen = pen; } @@ -169,7 +166,7 @@ void QScatterSeries::setMarkerPen(QPen pen) /*! Returns the pen used for drawing markers. */ -QPen QScatterSeries::markerPen() +QPen QScatterSeries::pen() { return d->m_markerPen; } @@ -184,10 +181,10 @@ QPen QScatterSeries::markerPen() Would fill your scatter markers with an opaque red color: \image scatter_example_brush.jpg - \sa setMarkerPen() + \sa setPen() \sa QChart::setChartTheme() */ -void QScatterSeries::setMarkerBrush(QBrush brush) +void QScatterSeries::setBrush(QBrush brush) { d->m_markerBrush = brush; } @@ -195,7 +192,7 @@ void QScatterSeries::setMarkerBrush(QBrush brush) /*! Returns the brush used for drawing markers. */ -QBrush QScatterSeries::markerBrush() +QBrush QScatterSeries::brush() { return d->m_markerBrush; } @@ -210,7 +207,7 @@ QBrush QScatterSeries::markerBrush() Would make your scatter marker items rectangle: \image scatter_example_shape.jpg */ -void QScatterSeries::setMarkerShape(MarkerShape shape) +void QScatterSeries::setShape(MarkerShape shape) { d->m_markerShape = shape; } @@ -218,7 +215,7 @@ void QScatterSeries::setMarkerShape(MarkerShape shape) /*! Returns the shape used for drawing markers. */ -QScatterSeries::MarkerShape QScatterSeries::markerShape() +QScatterSeries::MarkerShape QScatterSeries::shape() { return (QScatterSeries::MarkerShape) d->m_markerShape; } diff --git a/src/scatterseries/qscatterseries.h b/src/scatterseries/qscatterseries.h index 640637a..20ec3ab 100644 --- a/src/scatterseries/qscatterseries.h +++ b/src/scatterseries/qscatterseries.h @@ -33,28 +33,25 @@ public: // from QChartSeries QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } public: - void addData(QPointF value); - void addData(QList points); + void add(qreal x, qreal y); + void add(QPointF value); + void add(QList points); void setData(QList points); QScatterSeries& operator << (const QPointF &value); QScatterSeries& operator << (QList points); QList data(); - //TODO: insertData? + //TODO: insert, replace, remove, clear...? - QPen markerPen(); - QBrush markerBrush(); - MarkerShape markerShape(); + QPen pen(); + void setPen(QPen pen); + QBrush brush(); + void setBrush(QBrush brush); + MarkerShape shape(); + void setShape(MarkerShape shape); // TODO: marker size? -public Q_SLOTS: - void setMarkerPen(QPen pen); - void setMarkerBrush(QBrush brush); - void setMarkerShape(MarkerShape shape); - Q_SIGNALS: void clicked(/* TODO: parameters? */); - void hoverEnter(/* TODO: parameters? */); - void hoverLeave(/* TODO: parameters? */); // TODO: move to PIMPL for simplicity or does the user ever need changed signals? // TODO: more finegrained signaling for performance reasons // (check QPieSeries implementation with change sets) diff --git a/src/scatterseries/scatterpresenter.cpp b/src/scatterseries/scatterpresenter.cpp index 21033ef..ea67f10 100644 --- a/src/scatterseries/scatterpresenter.cpp +++ b/src/scatterseries/scatterpresenter.cpp @@ -25,6 +25,7 @@ ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); dropShadow->setOffset(2.0); + dropShadow->setBlurRadius(2.0); setGraphicsEffect(dropShadow); } @@ -54,10 +55,10 @@ void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * // Paint the shape // The custom settings in series override those defined by the theme QPen pen = m_markerPen; - if (m_series->markerPen().color().isValid()) - pen = m_series->markerPen(); - if (m_series->markerBrush().color().isValid()) - painter->setBrush(m_series->markerBrush()); + if (m_series->pen().color().isValid()) + pen = m_series->pen(); + if (m_series->brush().color().isValid()) + painter->setBrush(m_series->brush()); else painter->setBrush(m_markerBrush); painter->setPen(pen); @@ -82,7 +83,7 @@ void ScatterPresenter::changeGeometry() qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); - int shape = m_series->markerShape(); + int shape = m_series->shape(); m_path = QPainterPath(); foreach (QPointF point, m_series->data()) { @@ -104,14 +105,8 @@ void ScatterPresenter::changeGeometry() m_path.addRect(x, y, 9, 9); break; case QScatterSeries::MarkerShapeTiltedRectangle: { - // TODO: -// static const QPointF points[4] = { -// QPointF(-1.0 + x, 0.0 + y), -// QPointF(0.0 + x, 1.0 + y), -// QPointF(1.0 + x, 0.0 + y), -// QPointF(0.0 + x, -1.0 + y) -// }; - //m_path.addPolygon(QPolygon(4, &points)); + // TODO: tilt the rectangle + m_path.addRect(x, y, 9, 9); break; } default:
linechart barchart