diff --git a/demos/chartthemes/themewidget.cpp b/demos/chartthemes/themewidget.cpp index ea8c405..702bfe1 100644 --- a/demos/chartthemes/themewidget.cpp +++ b/demos/chartthemes/themewidget.cpp @@ -180,9 +180,14 @@ QChart* ThemeWidget::createAreaChart() const QChart *chart = new QChart(); chart->setTitle("Area chart"); { + QString name("Series "); + int nameIndex = 0; for (int i(0); i < m_dataTable.count(); i++) { QLineSeries *series1 = new QLineSeries(chart); QLineSeries *series2 = new QLineSeries(chart); + series1->setName(name + QString::number(nameIndex) + QString(" lo")); + series2->setName(name + QString::number(nameIndex) + QString(" hi")); + nameIndex++; foreach (Data data, m_dataTable[i]) { series1->add(data.first); series2->add(QPointF(data.first.x(), 0.0)); @@ -223,10 +228,14 @@ QChart* ThemeWidget::createLineChart() const // line chart QChart* chart = new QChart(); chart->setTitle("Line chart"); + QString name("Series "); + int nameIndex = 0; foreach (DataList list, m_dataTable) { QLineSeries *series = new QLineSeries(chart); foreach (Data data, list) series->add(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; chart->addSeries(series); } return chart; @@ -260,10 +269,14 @@ QChart* ThemeWidget::createSplineChart() const { // spine chart QChart* chart = new QChart(); chart->setTitle("Spline chart"); + QString name("Series "); + int nameIndex = 0; foreach (DataList list, m_dataTable) { QSplineSeries *series = new QSplineSeries(chart); foreach (Data data, list) series->add(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; chart->addSeries(series); } return chart; @@ -273,10 +286,14 @@ QChart* ThemeWidget::createScatterChart() const { // scatter chart QChart* chart = new QChart(); chart->setTitle("Scatter chart"); + QString name("Series "); + int nameIndex = 0; foreach (DataList list, m_dataTable) { QScatterSeries *series = new QScatterSeries(chart); foreach (Data data, list) series->add(data.first); + series->setName(name + QString::number(nameIndex)); + nameIndex++; chart->addSeries(series); } return chart; diff --git a/src/legendmarker.cpp b/src/legendmarker.cpp index 30189e8..c80d696 100644 --- a/src/legendmarker.cpp +++ b/src/legendmarker.cpp @@ -151,11 +151,13 @@ void LegendMarker::changed() { case LegendMarkerTypeSeries: { QXYSeries* s = static_cast (m_series); + setPen(s->pen()); setBrush(s->brush()); setName(s->name()); break; } case LegendMarkerTypeBarset: { + setPen(m_barset->pen()); setBrush(m_barset->brush()); setName(m_barset->name()); break; diff --git a/src/qlegend.cpp b/src/qlegend.cpp index 29ec869..dcdbe1c 100644 --- a/src/qlegend.cpp +++ b/src/qlegend.cpp @@ -428,14 +428,14 @@ void QLegend::appendMarkers(QXYSeries* series) */ void QLegend::appendMarkers(QBarSeries *series) { - foreach(QBarSet* s, series->barSets()) { - LegendMarker* marker = new LegendMarker(series, s, this); - marker->setName(s->name()); - marker->setPen(s->pen()); - marker->setBrush(s->brush()); + foreach(QBarSet* set, series->barSets()) { + LegendMarker* marker = new LegendMarker(series, set, this); + marker->setName(set->name()); + marker->setPen(set->pen()); + marker->setBrush(set->brush()); connect(marker, SIGNAL(clicked(QBarSet *, Qt::MouseButton)), this, SIGNAL(clicked(QBarSet *, Qt::MouseButton))); - connect(s, SIGNAL(valueChanged()), marker, SLOT(changed())); + connect(set, SIGNAL(valueChanged()), marker, SLOT(changed())); connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); m_markers.append(marker); childItems().append(marker); @@ -447,15 +447,15 @@ void QLegend::appendMarkers(QBarSeries *series) */ void QLegend::appendMarkers(QPieSeries *series) { - foreach(QPieSlice* s, series->slices()) { - LegendMarker* marker = new LegendMarker(series, s, this); - marker->setName(s->label()); - marker->setPen(s->pen()); - marker->setBrush(s->brush()); + foreach(QPieSlice* slice, series->slices()) { + LegendMarker* marker = new LegendMarker(series, slice, this); + marker->setName(slice->label()); + marker->setPen(slice->pen()); + marker->setBrush(slice->brush()); connect(marker, SIGNAL(clicked(QPieSlice *, Qt::MouseButton)), this, SIGNAL(clicked(QPieSlice *, Qt::MouseButton))); - connect(s, SIGNAL(changed()), marker, SLOT(changed())); - connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); + connect(slice, SIGNAL(changed()), marker, SLOT(changed())); + connect(slice, SIGNAL(destroyed()), marker, SLOT(deleteLater())); connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); m_markers.append(marker); childItems().append(marker);