diff --git a/src/xychart/qxymodelmapper.cpp b/src/xychart/qxymodelmapper.cpp index 8fed754..030231e 100644 --- a/src/xychart/qxymodelmapper.cpp +++ b/src/xychart/qxymodelmapper.cpp @@ -58,7 +58,7 @@ void QXYModelMapper::setSeries(QXYSeries *series) // connect the signals from the series connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); - connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(pointReplaced(int))); + connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); } int QXYModelMapper::first() const @@ -187,17 +187,48 @@ QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos) void QXYModelMapperPrivate::handlePointAdded(int pointPos) { - Q_UNUSED(pointPos) + if (m_seriesSignalsBlock) + return; + + if (m_count != -1) + m_count += 1; + + blockModelSignals(); + if (m_orientation == Qt::Vertical) + m_model->insertRows(pointPos + m_first, 1); + else + m_model->insertColumns(pointPos + m_first, 1); + + m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); + m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); + blockModelSignals(false); } void QXYModelMapperPrivate::handlePointRemoved(int pointPos) { - Q_UNUSED(pointPos) + if (m_seriesSignalsBlock) + return; + + if (m_count != -1) + m_count -= 1; + + blockModelSignals(); + if (m_orientation == Qt::Vertical) + m_model->removeRow(pointPos + m_first); + else + m_model->removeColumn(pointPos + m_first); + blockModelSignals(false); } void QXYModelMapperPrivate::handlePointReplaced(int pointPos) { - Q_UNUSED(pointPos) + if (m_seriesSignalsBlock) + return; + + blockModelSignals(); + m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); + m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); + blockModelSignals(false); } void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index d1b7fec..10722ee 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -102,7 +102,8 @@ void QXYSeries::append(const QPointF &point) { Q_D(QXYSeries); d->m_points<pointAdded(d->m_points.count()-1); +// emit d->pointAdded(d->m_points.count()-1); + emit pointAdded(d->m_points.count()-1); } /*! @@ -128,7 +129,8 @@ void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) int index = d->m_points.indexOf(oldPoint); if(index==-1) return; d->m_points[index] = newPoint; - emit d->pointReplaced(index); +// emit d->pointReplaced(index); + emit pointReplaced(index); } /*! @@ -148,7 +150,8 @@ void QXYSeries::remove(const QPointF &point) int index = d->m_points.indexOf(point); if(index==-1) return; d->m_points.remove(index); - emit d->pointRemoved(index); +// emit d->pointRemoved(index); + emit pointRemoved(index); } /*! @@ -166,7 +169,8 @@ void QXYSeries::insert(int index, const QPointF &point) { Q_D(QXYSeries); d->m_points.insert(index, point); - emit d->pointAdded(index); +// emit d->pointAdded(index); + emit pointAdded(index); } void QXYSeries::clear() diff --git a/src/xychart/qxyseries.h b/src/xychart/qxyseries.h index 9cff389..5e8844b 100644 --- a/src/xychart/qxyseries.h +++ b/src/xychart/qxyseries.h @@ -70,6 +70,9 @@ public: Q_SIGNALS: void clicked(const QPointF &point); + void pointReplaced(int index); + void pointRemoved(int index); + void pointAdded(int index); private: Q_DECLARE_PRIVATE(QXYSeries) diff --git a/src/xychart/qxyseries_p.h b/src/xychart/qxyseries_p.h index f9da140..54c63c0 100644 --- a/src/xychart/qxyseries_p.h +++ b/src/xychart/qxyseries_p.h @@ -48,9 +48,9 @@ public: Q_SIGNALS: void updated(); - void pointReplaced(int index); - void pointRemoved(int index); - void pointAdded(int index); +// void pointReplaced(int index); +// void pointRemoved(int index); +// void pointAdded(int index); protected: QVector m_points; diff --git a/src/xychart/xychart.cpp b/src/xychart/xychart.cpp index 1e7da5b..1cd7a52 100644 --- a/src/xychart/xychart.cpp +++ b/src/xychart/xychart.cpp @@ -41,10 +41,13 @@ m_series(series), m_animation(0), m_dirty(true) { - QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); - QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); - QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); - QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF))); +// QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); +// QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); +// QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); + QObject::connect(series, SIGNAL(pointReplaced(int)), this,SLOT(handlePointReplaced(int))); + QObject::connect(series, SIGNAL(pointAdded(int)), this,SLOT(handlePointAdded(int))); + QObject::connect(series, SIGNAL(pointRemoved(int)), this,SLOT(handlePointRemoved(int))); + QObject::connect(this, SIGNAL(clicked(QPointF)), series,SIGNAL(clicked(QPointF))); } void XYChart::setGeometryPoints(const QVector& points) diff --git a/tests/tablemodelchart/tablewidget.cpp b/tests/tablemodelchart/tablewidget.cpp index 31fe02c..7e525cc 100644 --- a/tests/tablemodelchart/tablewidget.cpp +++ b/tests/tablemodelchart/tablewidget.cpp @@ -90,6 +90,9 @@ TableWidget::TableWidget(QWidget *parent) QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API"); connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); + QPushButton* xyTestButton = new QPushButton("Append XY point"); + connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY())); + QLabel *spinBoxLabel = new QLabel("Rows affected:"); @@ -110,6 +113,7 @@ TableWidget::TableWidget(QWidget *parent) buttonsLayout->addWidget(specialPieButton); buttonsLayout->addWidget(specialPieButton2); buttonsLayout->addWidget(specialPieButton3); + buttonsLayout->addWidget(xyTestButton); buttonsLayout->addStretch(); // chart type radio buttons @@ -206,7 +210,7 @@ void TableWidget::updateChartType(bool toggle) if (m_lineRadioButton->isChecked()) { - // m_chart->setAnimationOptions(QChart::NoAnimation); + m_chart->setAnimationOptions(QChart::NoAnimation); // series 1 m_series = new QLineSeries(this); @@ -217,7 +221,7 @@ void TableWidget::updateChartType(bool toggle) mapper->setXColumn(0); mapper->setYColumn(1); mapper->setFirst(3); - // mapper->setCount(4); + mapper->setCount(4); // m_series->setModelMapping(0,1, Qt::Vertical); // m_series->setModelMappingRange(3, 4); @@ -355,7 +359,7 @@ void TableWidget::updateChartType(bool toggle) m_pieMapper->setLabelsColumn(7); m_pieMapper->setSeries(m_pieSeries); m_pieMapper->setModel(m_model); -// m_pieMapper->setFirst(2); + m_pieMapper->setFirst(2); // m_pieMapper->setCount(5); // pieSeries->setModelMapper(mapper); @@ -380,7 +384,7 @@ void TableWidget::updateChartType(bool toggle) m_pieMapper->setLabelsColumn(7); m_pieMapper->setModel(m_model); m_pieMapper->setSeries(m_pieSeries2); -// m_pieMapper->setFirst(2); + m_pieMapper->setFirst(2); m_pieSeries2->setLabelsVisible(true); m_pieSeries2->setPieSize(0.35); @@ -518,6 +522,17 @@ void TableWidget::testPie3() } } +void TableWidget::testXY() +{ +// if (m_series->type() != QAbstractSeries::SeriesTypeLine) { +// m_series->append(QPointF(150, 75)); +// } + + if (m_series->count() > 0) { + m_series->remove(m_series->points().last()); + } +} + TableWidget::~TableWidget() { diff --git a/tests/tablemodelchart/tablewidget.h b/tests/tablemodelchart/tablewidget.h index 4329cea..831a38e 100644 --- a/tests/tablemodelchart/tablewidget.h +++ b/tests/tablemodelchart/tablewidget.h @@ -55,6 +55,8 @@ public: void testPie2(); void testPie3(); + void testXY(); + private: QChartView* m_chartView; QChart* m_chart;