From 32248fc3cb26602da498074ac9f023361eb455ac 2012-03-29 13:31:10 From: sauimone Date: 2012-03-29 13:31:10 Subject: [PATCH] solid brush for all legend markers --- diff --git a/src/legendmarker.cpp b/src/legendmarker.cpp index 9ea5d18..82da551 100644 --- a/src/legendmarker.cpp +++ b/src/legendmarker.cpp @@ -169,27 +169,30 @@ void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) void LegendMarker::changed() { + setPen(Qt::NoPen); switch (m_series->type()) { case QSeries::SeriesTypeArea: { QAreaSeries* s = static_cast (m_series); - setPen(s->pen()); setBrush(s->brush()); setName(s->name()); break; } case QSeries::SeriesTypeLine: - case QSeries::SeriesTypeScatter: case QSeries::SeriesTypeSpline: { QXYSeries* s = static_cast (m_series); - setPen(s->pen()); - setBrush(s->brush()); + setBrush(QBrush(s->pen().color(),Qt::SolidPattern)); setName(s->name()); break; } + case QSeries::SeriesTypeScatter: { + QXYSeries* s = static_cast (m_series); + setBrush(s->brush()); + setName(s->name()); + break; + } case QSeries::SeriesTypeBar: case QSeries::SeriesTypeStackedBar: case QSeries::SeriesTypePercentBar: { - setPen(m_barset->pen()); setBrush(m_barset->brush()); setName(m_barset->name()); break; @@ -200,6 +203,7 @@ void LegendMarker::changed() break; } default: { + setBrush(Qt::NoBrush); break; } } diff --git a/src/qchart.cpp b/src/qchart.cpp index 90daf8e..13f719a 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -372,7 +372,7 @@ void QChartPrivate::updateLegendLayout() switch (m_legend->alignment()) { case QLegend::AlignmentTop: { - legendRect = m_rect.adjusted(0,0,0,-padding - plotRect.height()); + legendRect = m_rect.adjusted(0,padding,0,-padding - plotRect.height()); break; } case QLegend::AlignmentBottom: { diff --git a/src/qlegend.cpp b/src/qlegend.cpp index 20eade9..1e8f9c1 100644 --- a/src/qlegend.cpp +++ b/src/qlegend.cpp @@ -93,7 +93,7 @@ QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), m_maximumSize(150,100), m_size(m_minimumSize), m_brush(Qt::darkGray), // TODO: default should come from theme - m_alignment(QLegend::AlignmentRight), + m_alignment(QLegend::AlignmentTop), mFirstMarker(0), m_attachedToChart(true) { @@ -419,12 +419,10 @@ bool QLegend::attachedToChart() void QLegend::appendMarkers(QAreaSeries* series) { LegendMarker* marker = new LegendMarker(series,this); - marker->setName(series->name()); - marker->setPen(series->pen()); - marker->setBrush(series->brush()); connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); connect(series,SIGNAL(updated()),marker,SLOT(changed())); + marker->changed(); m_markers.append(marker); childItems().append(marker); } @@ -435,12 +433,10 @@ void QLegend::appendMarkers(QAreaSeries* series) void QLegend::appendMarkers(QXYSeries* series) { LegendMarker* marker = new LegendMarker(series,this); - marker->setName(series->name()); - marker->setPen(series->pen()); - marker->setBrush(series->brush()); connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); connect(series,SIGNAL(updated()),marker,SLOT(changed())); + marker->changed(); m_markers.append(marker); childItems().append(marker); } @@ -452,13 +448,11 @@ void QLegend::appendMarkers(QBarSeries *series) { 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(set, SIGNAL(valueChanged()), marker, SLOT(changed())); connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); + marker->changed(); m_markers.append(marker); childItems().append(marker); } @@ -471,14 +465,12 @@ void QLegend::appendMarkers(QPieSeries *series) { 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(slice, SIGNAL(changed()), marker, SLOT(changed())); connect(slice, SIGNAL(destroyed()), marker, SLOT(deleteLater())); connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); + marker->changed(); m_markers.append(marker); childItems().append(marker); }