From 2661cb767b8bb76a18394b1a16330af8ba96ded4 2012-05-29 11:42:37 From: Tero Ahola Date: 2012-05-29 11:42:37 Subject: [PATCH] Scatter customization to QML api --- diff --git a/demos/qmlcustomizations/qml/qmlcustomizations/main.qml b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml index 375dcaf..622b965 100644 --- a/demos/qmlcustomizations/qml/qmlcustomizations/main.qml +++ b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml @@ -80,6 +80,7 @@ Rectangle { interval = splineSeries.at(__activeIndex).y; scatterSeries.append(__activeIndex, interval); scatterSeries.color = Qt.tint(scatterSeries.color, "#05FF0000"); + scatterSeries.markerSize += 0.5; } else { // Switch the colors of the slice and the border wheelOfFortune.at(index).borderWidth = 2; diff --git a/demos/qmlcustommodel/customtablemodel.h b/demos/qmlcustommodel/customtablemodel.h index 5d6e0f7..f472b19 100644 --- a/demos/qmlcustommodel/customtablemodel.h +++ b/demos/qmlcustommodel/customtablemodel.h @@ -40,7 +40,6 @@ public: Qt::ItemFlags flags ( const QModelIndex & index ) const; void insertColumn(int column, const QModelIndex &parent = QModelIndex()); void insertRow(int row, const QModelIndex &parent = QModelIndex()); - /*Q_INVOKABLE*/ //bool removeRow(int row, const QModelIndex &parent = QModelIndex()); Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); Q_INVOKABLE bool removeRow (int row, const QModelIndex &parent = QModelIndex()); diff --git a/examples/scatterchart/chartview.cpp b/examples/scatterchart/chartview.cpp index d3e2ca0..4adfe0d 100644 --- a/examples/scatterchart/chartview.cpp +++ b/examples/scatterchart/chartview.cpp @@ -7,13 +7,13 @@ ChartView::ChartView(QWidget *parent) : //![1] QScatterSeries *series0 = new QScatterSeries(); series0->setName("scatter1"); - series0->setShape(QScatterSeries::MarkerShapeCircle); - series0->setSize(15.0); + series0->setMarkerShape(QScatterSeries::MarkerShapeCircle); + series0->setMarkerSize(15.0); QScatterSeries *series1 = new QScatterSeries(); series1->setName("scatter2"); - series1->setShape(QScatterSeries::MarkerShapeCircle); - series1->setSize(20.0); + series1->setMarkerShape(QScatterSeries::MarkerShapeCircle); + series1->setMarkerSize(20.0); //![1] //![2] diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index d585af3..6dfb54e 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -56,6 +56,9 @@ public: qmlRegisterType(uri, 1, 0, "PieSlice"); qmlRegisterType(uri, 1, 0, "BarSet"); + + qmlRegisterUncreatableType(uri, 1, 0, "QScatterSeries", + QLatin1String("Trying to create uncreatable: QScatterSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "QPieSeries", QLatin1String("Trying to create uncreatable: QPieSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractItemModel", diff --git a/src/linechart/qlineseries.cpp b/src/linechart/qlineseries.cpp index 3954496..15d9720 100644 --- a/src/linechart/qlineseries.cpp +++ b/src/linechart/qlineseries.cpp @@ -118,4 +118,6 @@ Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter) return line; } +#include "moc_qlineseries.cpp" + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/linechart/qlineseries.h b/src/linechart/qlineseries.h index ac8b411..f817cf2 100644 --- a/src/linechart/qlineseries.h +++ b/src/linechart/qlineseries.h @@ -31,10 +31,11 @@ class QLineSeriesPrivate; class QTCOMMERCIALCHART_EXPORT QLineSeries : public QXYSeries { + Q_OBJECT + public: explicit QLineSeries(QObject *parent = 0); ~QLineSeries(); - QAbstractSeries::SeriesType type() const; protected: @@ -44,7 +45,6 @@ private: Q_DECLARE_PRIVATE(QLineSeries) Q_DISABLE_COPY(QLineSeries) friend class LineChartItem; - }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/scatterchart/qscatterseries.cpp b/src/scatterchart/qscatterseries.cpp index 65f4631..6939fb7 100644 --- a/src/scatterchart/qscatterseries.cpp +++ b/src/scatterchart/qscatterseries.cpp @@ -89,7 +89,7 @@ QAbstractSeries::SeriesType QScatterSeries::type() const /*! Returns the shape used for drawing markers. */ -QScatterSeries::MarkerShape QScatterSeries::shape() const +QScatterSeries::MarkerShape QScatterSeries::markerShape() const { Q_D(const QScatterSeries); return d->m_shape; @@ -99,7 +99,7 @@ QScatterSeries::MarkerShape QScatterSeries::shape() const Overrides the default shape of the marker items with a user defined \a shape. The default shape is defined by chart theme setting. */ -void QScatterSeries::setShape(MarkerShape shape) +void QScatterSeries::setMarkerShape(MarkerShape shape) { Q_D(QScatterSeries); if (d->m_shape != shape) { @@ -111,7 +111,7 @@ void QScatterSeries::setShape(MarkerShape shape) /*! Returns the size of the marker items. */ -qreal QScatterSeries::size() const +qreal QScatterSeries::markerSize() const { Q_D(const QScatterSeries); return d->m_size; @@ -120,7 +120,7 @@ qreal QScatterSeries::size() const /*! Set the \a size of the marker items. The default size is 15. */ -void QScatterSeries::setSize(qreal size) +void QScatterSeries::setMarkerSize(qreal size) { Q_D(QScatterSeries); @@ -151,5 +151,6 @@ Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) return scatter; } +#include "moc_qscatterseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/scatterchart/qscatterseries.h b/src/scatterchart/qscatterseries.h index 82e1b9b..4f319c1 100644 --- a/src/scatterchart/qscatterseries.h +++ b/src/scatterchart/qscatterseries.h @@ -30,6 +30,10 @@ class QScatterSeriesPrivate; class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries { + Q_OBJECT + Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape) + Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize) + Q_ENUMS(MarkerShape) public: enum MarkerShape { @@ -40,13 +44,11 @@ public: public: explicit QScatterSeries(QObject *parent = 0); ~QScatterSeries(); - QAbstractSeries::SeriesType type() const; - - MarkerShape shape() const; - void setShape(MarkerShape shape); - qreal size() const; - void setSize(qreal size); + MarkerShape markerShape() const; + void setMarkerShape(MarkerShape shape); + qreal markerSize() const; + void setMarkerSize(qreal size); private: Q_DECLARE_PRIVATE(QScatterSeries) diff --git a/src/scatterchart/scatterchartitem.cpp b/src/scatterchart/scatterchartitem.cpp index 59721c4..53e2fbd 100644 --- a/src/scatterchart/scatterchartitem.cpp +++ b/src/scatterchart/scatterchartitem.cpp @@ -167,21 +167,22 @@ void ScatterChartItem::setBrush(const QBrush& brush) void ScatterChartItem::handleUpdated() { - int count = m_items.childItems().count(); if(count==0) return; - bool recreate = m_size != m_series->size() || m_shape != m_series->shape(); - - //TODO: only rewrite on size change + bool recreate = m_size != m_series->markerSize() || m_shape != m_series->markerShape(); - m_size = m_series->size(); - m_shape = m_series->shape(); + m_size = m_series->markerSize(); + m_shape = m_series->markerShape(); if(recreate) { + // TODO: optimize handleUpdate to recreate points only in case shape changed deletePoints(count); createPoints(count); + + // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points + updateGeometry(); } setPen(m_series->pen()); diff --git a/src/splinechart/qsplineseries.h b/src/splinechart/qsplineseries.h index fb6dce7..0d63dbb 100644 --- a/src/splinechart/qsplineseries.h +++ b/src/splinechart/qsplineseries.h @@ -34,8 +34,8 @@ class QSplineSeriesPrivate; class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QLineSeries { Q_OBJECT -public: +public: explicit QSplineSeries(QObject *parent = 0); ~QSplineSeries(); QAbstractSeries::SeriesType type() const; diff --git a/tests/chartwidgettest/dataseriedialog.cpp b/tests/chartwidgettest/dataseriedialog.cpp index 7f1784e..6892e05 100644 --- a/tests/chartwidgettest/dataseriedialog.cpp +++ b/tests/chartwidgettest/dataseriedialog.cpp @@ -111,6 +111,7 @@ QGroupBox *DataSerieDialog::rowCountSelector() layout->addWidget(radio); layout->addWidget(new QRadioButton("50")); layout->addWidget(new QRadioButton("100")); + layout->addWidget(new QRadioButton("1000")); layout->addWidget(new QRadioButton("10000")); layout->addWidget(new QRadioButton("100000")); layout->addWidget(new QRadioButton("1000000"));