##// END OF EJS Templates
XYModelMapper slots for series signals implemented
Marek Rosa -
r1262:61ed30bfe89b
parent child
Show More
@@ -58,7 +58,7 void QXYModelMapper::setSeries(QXYSeries *series)
58 // connect the signals from the series
58 // connect the signals from the series
59 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
59 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
60 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
60 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
61 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(pointReplaced(int)));
61 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
62 }
62 }
63
63
64 int QXYModelMapper::first() const
64 int QXYModelMapper::first() const
@@ -187,17 +187,48 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
187
187
188 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
188 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
189 {
189 {
190 Q_UNUSED(pointPos)
190 if (m_seriesSignalsBlock)
191 return;
192
193 if (m_count != -1)
194 m_count += 1;
195
196 blockModelSignals();
197 if (m_orientation == Qt::Vertical)
198 m_model->insertRows(pointPos + m_first, 1);
199 else
200 m_model->insertColumns(pointPos + m_first, 1);
201
202 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
203 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
204 blockModelSignals(false);
191 }
205 }
192
206
193 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
207 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
194 {
208 {
195 Q_UNUSED(pointPos)
209 if (m_seriesSignalsBlock)
210 return;
211
212 if (m_count != -1)
213 m_count -= 1;
214
215 blockModelSignals();
216 if (m_orientation == Qt::Vertical)
217 m_model->removeRow(pointPos + m_first);
218 else
219 m_model->removeColumn(pointPos + m_first);
220 blockModelSignals(false);
196 }
221 }
197
222
198 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
223 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
199 {
224 {
200 Q_UNUSED(pointPos)
225 if (m_seriesSignalsBlock)
226 return;
227
228 blockModelSignals();
229 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
230 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
231 blockModelSignals(false);
201 }
232 }
202
233
203 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
234 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
@@ -102,7 +102,8 void QXYSeries::append(const QPointF &point)
102 {
102 {
103 Q_D(QXYSeries);
103 Q_D(QXYSeries);
104 d->m_points<<point;
104 d->m_points<<point;
105 emit d->pointAdded(d->m_points.count()-1);
105 // emit d->pointAdded(d->m_points.count()-1);
106 emit pointAdded(d->m_points.count()-1);
106 }
107 }
107
108
108 /*!
109 /*!
@@ -128,7 +129,8 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
128 int index = d->m_points.indexOf(oldPoint);
129 int index = d->m_points.indexOf(oldPoint);
129 if(index==-1) return;
130 if(index==-1) return;
130 d->m_points[index] = newPoint;
131 d->m_points[index] = newPoint;
131 emit d->pointReplaced(index);
132 // emit d->pointReplaced(index);
133 emit pointReplaced(index);
132 }
134 }
133
135
134 /*!
136 /*!
@@ -148,7 +150,8 void QXYSeries::remove(const QPointF &point)
148 int index = d->m_points.indexOf(point);
150 int index = d->m_points.indexOf(point);
149 if(index==-1) return;
151 if(index==-1) return;
150 d->m_points.remove(index);
152 d->m_points.remove(index);
151 emit d->pointRemoved(index);
153 // emit d->pointRemoved(index);
154 emit pointRemoved(index);
152 }
155 }
153
156
154 /*!
157 /*!
@@ -166,7 +169,8 void QXYSeries::insert(int index, const QPointF &point)
166 {
169 {
167 Q_D(QXYSeries);
170 Q_D(QXYSeries);
168 d->m_points.insert(index, point);
171 d->m_points.insert(index, point);
169 emit d->pointAdded(index);
172 // emit d->pointAdded(index);
173 emit pointAdded(index);
170 }
174 }
171
175
172 void QXYSeries::clear()
176 void QXYSeries::clear()
@@ -70,6 +70,9 public:
70
70
71 Q_SIGNALS:
71 Q_SIGNALS:
72 void clicked(const QPointF &point);
72 void clicked(const QPointF &point);
73 void pointReplaced(int index);
74 void pointRemoved(int index);
75 void pointAdded(int index);
73
76
74 private:
77 private:
75 Q_DECLARE_PRIVATE(QXYSeries)
78 Q_DECLARE_PRIVATE(QXYSeries)
@@ -48,9 +48,9 public:
48
48
49 Q_SIGNALS:
49 Q_SIGNALS:
50 void updated();
50 void updated();
51 void pointReplaced(int index);
51 // void pointReplaced(int index);
52 void pointRemoved(int index);
52 // void pointRemoved(int index);
53 void pointAdded(int index);
53 // void pointAdded(int index);
54
54
55 protected:
55 protected:
56 QVector<QPointF> m_points;
56 QVector<QPointF> m_points;
@@ -41,9 +41,12 m_series(series),
41 m_animation(0),
41 m_animation(0),
42 m_dirty(true)
42 m_dirty(true)
43 {
43 {
44 QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
44 // QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
45 QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
45 // QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
46 QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
46 // QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
47 QObject::connect(series, SIGNAL(pointReplaced(int)), this,SLOT(handlePointReplaced(int)));
48 QObject::connect(series, SIGNAL(pointAdded(int)), this,SLOT(handlePointAdded(int)));
49 QObject::connect(series, SIGNAL(pointRemoved(int)), this,SLOT(handlePointRemoved(int)));
47 QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF)));
50 QObject::connect(this, SIGNAL(clicked(QPointF)), series,SIGNAL(clicked(QPointF)));
48 }
51 }
49
52
@@ -90,6 +90,9 TableWidget::TableWidget(QWidget *parent)
90 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
90 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
91 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
91 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
92
92
93 QPushButton* xyTestButton = new QPushButton("Append XY point");
94 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
95
93
96
94 QLabel *spinBoxLabel = new QLabel("Rows affected:");
97 QLabel *spinBoxLabel = new QLabel("Rows affected:");
95
98
@@ -110,6 +113,7 TableWidget::TableWidget(QWidget *parent)
110 buttonsLayout->addWidget(specialPieButton);
113 buttonsLayout->addWidget(specialPieButton);
111 buttonsLayout->addWidget(specialPieButton2);
114 buttonsLayout->addWidget(specialPieButton2);
112 buttonsLayout->addWidget(specialPieButton3);
115 buttonsLayout->addWidget(specialPieButton3);
116 buttonsLayout->addWidget(xyTestButton);
113 buttonsLayout->addStretch();
117 buttonsLayout->addStretch();
114
118
115 // chart type radio buttons
119 // chart type radio buttons
@@ -206,7 +210,7 void TableWidget::updateChartType(bool toggle)
206
210
207 if (m_lineRadioButton->isChecked())
211 if (m_lineRadioButton->isChecked())
208 {
212 {
209 // m_chart->setAnimationOptions(QChart::NoAnimation);
213 m_chart->setAnimationOptions(QChart::NoAnimation);
210
214
211 // series 1
215 // series 1
212 m_series = new QLineSeries(this);
216 m_series = new QLineSeries(this);
@@ -217,7 +221,7 void TableWidget::updateChartType(bool toggle)
217 mapper->setXColumn(0);
221 mapper->setXColumn(0);
218 mapper->setYColumn(1);
222 mapper->setYColumn(1);
219 mapper->setFirst(3);
223 mapper->setFirst(3);
220 // mapper->setCount(4);
224 mapper->setCount(4);
221
225
222 // m_series->setModelMapping(0,1, Qt::Vertical);
226 // m_series->setModelMapping(0,1, Qt::Vertical);
223 // m_series->setModelMappingRange(3, 4);
227 // m_series->setModelMappingRange(3, 4);
@@ -355,7 +359,7 void TableWidget::updateChartType(bool toggle)
355 m_pieMapper->setLabelsColumn(7);
359 m_pieMapper->setLabelsColumn(7);
356 m_pieMapper->setSeries(m_pieSeries);
360 m_pieMapper->setSeries(m_pieSeries);
357 m_pieMapper->setModel(m_model);
361 m_pieMapper->setModel(m_model);
358 // m_pieMapper->setFirst(2);
362 m_pieMapper->setFirst(2);
359 // m_pieMapper->setCount(5);
363 // m_pieMapper->setCount(5);
360 // pieSeries->setModelMapper(mapper);
364 // pieSeries->setModelMapper(mapper);
361
365
@@ -380,7 +384,7 void TableWidget::updateChartType(bool toggle)
380 m_pieMapper->setLabelsColumn(7);
384 m_pieMapper->setLabelsColumn(7);
381 m_pieMapper->setModel(m_model);
385 m_pieMapper->setModel(m_model);
382 m_pieMapper->setSeries(m_pieSeries2);
386 m_pieMapper->setSeries(m_pieSeries2);
383 // m_pieMapper->setFirst(2);
387 m_pieMapper->setFirst(2);
384
388
385 m_pieSeries2->setLabelsVisible(true);
389 m_pieSeries2->setLabelsVisible(true);
386 m_pieSeries2->setPieSize(0.35);
390 m_pieSeries2->setPieSize(0.35);
@@ -518,6 +522,17 void TableWidget::testPie3()
518 }
522 }
519 }
523 }
520
524
525 void TableWidget::testXY()
526 {
527 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
528 // m_series->append(QPointF(150, 75));
529 // }
530
531 if (m_series->count() > 0) {
532 m_series->remove(m_series->points().last());
533 }
534 }
535
521 TableWidget::~TableWidget()
536 TableWidget::~TableWidget()
522 {
537 {
523
538
@@ -55,6 +55,8 public:
55 void testPie2();
55 void testPie2();
56 void testPie3();
56 void testPie3();
57
57
58 void testXY();
59
58 private:
60 private:
59 QChartView* m_chartView;
61 QChartView* m_chartView;
60 QChart* m_chart;
62 QChart* m_chart;
General Comments 0
You need to be logged in to leave comments. Login now