##// END OF EJS Templates
Adds trivial legend handling for slices when removed or added
Michal Klocek -
r956:e1337e5f8780
parent child
Show More
@@ -156,7 +156,6 m_pieslice(pieslice)
156 {
156 {
157 QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(selected()));
157 QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(selected()));
158 QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
158 QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
159 QObject::connect(pieslice, SIGNAL(destroyed()), this, SLOT(deleteLater())); //TODO:checkthis
160 updated();
159 updated();
161 }
160 }
162
161
@@ -73,10 +73,7 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
74 d_ptr->createConnections();
74 d_ptr->createConnections();
75 d_ptr->m_legend = new LegendScroller(this);
75 d_ptr->m_legend = new LegendScroller(this);
76 // d_ptr->m_legend->setVisible(false);
77 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
76 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
78
79 //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3);
80 }
77 }
81
78
82 /*!
79 /*!
@@ -90,7 +90,7 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,this))
90 setZValue(ChartPresenter::LegendZValue);
90 setZValue(ChartPresenter::LegendZValue);
91 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
91 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
92 setEnabled(false); // By default legend is disabled
92 setEnabled(false); // By default legend is disabled
93
93 setVisible(false);
94 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QSeries*,Domain*)));
94 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QSeries*,Domain*)));
95 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QSeries*)));
95 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QSeries*)));
96 }
96 }
@@ -404,6 +404,13 void QLegendPrivate::handleSeriesAdded(QSeries *series, Domain *domain)
404 foreach(LegendMarker* marker , markers)
404 foreach(LegendMarker* marker , markers)
405 m_markers->addToGroup(marker);
405 m_markers->addToGroup(marker);
406
406
407 if(series->type()==QSeries::SeriesTypePie)
408 {
409 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
410 QObject::connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
411 QObject::connect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
412 }
413
407 updateLayout();
414 updateLayout();
408 }
415 }
409
416
@@ -412,16 +419,32 void QLegendPrivate::handleSeriesRemoved(QSeries *series)
412
419
413 QList<QGraphicsItem *> items = m_markers->childItems();
420 QList<QGraphicsItem *> items = m_markers->childItems();
414
421
415 foreach (QGraphicsItem *markers, items) {
422 foreach (QGraphicsItem *markers, items) {
416 LegendMarker *marker = static_cast<LegendMarker*>(markers);
423 LegendMarker *marker = static_cast<LegendMarker*>(markers);
417 if (marker->series() == series) {
424 if (marker->series() == series) {
418 delete marker;
425 delete marker;
419 }
426 }
420 }
427 }
428
429 if(series->type()==QSeries::SeriesTypePie)
430 {
431 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
432 QObject::disconnect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
433 QObject::disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
434 }
421
435
422 updateLayout();
436 updateLayout();
423 }
437 }
424
438
439 void QLegendPrivate::handleUpdateSeries()
440 {
441 //TODO: reimplement to be optimal
442 QSeries* series = qobject_cast<QSeries *> (sender());
443 Q_ASSERT(series);
444 handleSeriesRemoved(series);
445 handleSeriesAdded(series,0);
446 }
447
425 #include "moc_qlegend.cpp"
448 #include "moc_qlegend.cpp"
426 #include "moc_qlegend_p.cpp"
449 #include "moc_qlegend_p.cpp"
427
450
@@ -49,6 +49,7 public:
49 public Q_SLOTS:
49 public Q_SLOTS:
50 void handleSeriesAdded(QSeries *series, Domain *domain);
50 void handleSeriesAdded(QSeries *series, Domain *domain);
51 void handleSeriesRemoved(QSeries *series);
51 void handleSeriesRemoved(QSeries *series);
52 void handleUpdateSeries(); //TODO remove this function
52
53
53 private:
54 private:
54 QLegend *q_ptr;
55 QLegend *q_ptr;
General Comments 0
You need to be logged in to leave comments. Login now