From f23c0d74d41673b09421ad12f8b9d0486f141d62 2012-03-13 15:00:28 From: Michal Klocek Date: 2012-03-13 15:00:28 Subject: [PATCH] Fix theme decoration calls on all xyseries --- diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index d193015..93d7e06 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -105,11 +105,14 @@ void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) } if(axis==m_dataset->axisX()){ + m_chartTheme->decorate(axis,true); QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); //initialize item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); + } else{ + m_chartTheme->decorate(axis,false); QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); //initialize item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); @@ -118,7 +121,6 @@ void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); //initialize item->handleGeometryChanged(m_rect); - m_chartTheme->decorate(axis, m_chart); m_axisItems.insert(axis, item); } @@ -144,7 +146,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { m_animator->addAnimation(line); } - m_chartTheme->decorate(line, lineSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series)); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); item = line; @@ -159,7 +161,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) m_animator->addAnimation(area->upperLineItem()); if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); } - m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series)); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); item=area; @@ -211,7 +213,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { m_animator->addAnimation(scatter); } - m_chartTheme->decorate(scatter, scatterSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series)); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); item = scatter; @@ -244,7 +246,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { m_animator->addAnimation(spline); } - m_chartTheme->decorate(spline, splineSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series)); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); item=spline; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 43927f9..4000688 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -71,7 +71,7 @@ void ChartTheme::decorate(QLegend* legend) legend->setBackgroundBrush(m_backgroundGradient); } -void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index) +void ChartTheme::decorate(QAreaSeries* series, int index) { QPen pen; QBrush brush; @@ -89,7 +89,7 @@ void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index) } -void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int index) +void ChartTheme::decorate(QLineSeries* series,int index) { QPen pen; if(pen == series->pen()){ @@ -159,10 +159,8 @@ void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,i } } -void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int index) +void ChartTheme::decorate(QScatterSeries* series, int index) { - Q_ASSERT(item); - Q_ASSERT(series); QPen pen; QBrush brush; @@ -191,45 +189,26 @@ void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int index) } } -void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int index) +void ChartTheme::decorate(QSplineSeries* series, int index) { - Q_ASSERT(item); - Q_ASSERT(series); - QPen pen; - if(pen != series->pen()){ - item->setLinePen(series->pen()); - }else{ + if(pen == series->pen()){ pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); - pen.setWidthF(series->pen().widthF()); - item->setLinePen(series->pen()); + pen.setWidthF(2); + series->setPen(pen); } - -// QColor color = m_seriesColors.at(index % m_seriesColors.size()); - // TODO: define alpha in the theme? or in the series? - //color.setAlpha(120); - -// QBrush brush(color, Qt::SolidPattern); -// presenter->m_markerBrush = brush; - -// QPen pen(brush, 3); -// pen.setColor(color); -// presenter->m_markerPen = pen; } -void ChartTheme::decorate(QChartAxis* axis, QChart* parent) +void ChartTheme::decorate(QChartAxis* axis,bool axisX) { - Q_ASSERT(axis); - Q_ASSERT(parent); - if (axis->isAxisVisible()) { axis->setLabelsBrush(m_axisLabelBrush); axis->setLabelsPen(m_axisLabelPen); // TODO: check the axis type (x or y) should define whether to show the shades or not if (m_backgroundShades == BackgroundShadesBoth - || (m_backgroundShades == BackgroundShadesVertical && parent->axisX() == axis) - || (m_backgroundShades == BackgroundShadesHorizontal && parent->axisY() == axis)) { + || (m_backgroundShades == BackgroundShadesVertical && axisX) + || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { axis->setShadesPen(m_backgroundShadesPen); axis->setShadesBrush(m_backgroundShadesBrush); } else { diff --git a/src/charttheme_p.h b/src/charttheme_p.h index 6500f3d..dc14627 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -48,12 +48,12 @@ public: void decorate(BarPresenter* item, QBarSeries* series, int index); void decorate(StackedBarPresenter* item, QStackedBarSeries* series, int index); void decorate(PercentBarPresenter* item, QPercentBarSeries* series, int index); - void decorate(LineChartItem* item, QLineSeries* series, int index); - void decorate(AreaChartItem* item, QAreaSeries* series, int index); - void decorate(ScatterChartItem* presenter, QScatterSeries* series, int index); + void decorate(QLineSeries* series, int index); + void decorate(QAreaSeries* series, int index); + void decorate(QScatterSeries* series, int index); void decorate(PiePresenter* item, QPieSeries* series, int index); - void decorate(SplineChartItem* presenter, QSplineSeries* series, int index); - void decorate(QChartAxis* axis, QChart* parent); + void decorate(QSplineSeries* series, int index); + void decorate(QChartAxis* axis, bool axisX); public: // utils void generateSeriesGradients(); diff --git a/src/splinechart/splinechartitem.cpp b/src/splinechart/splinechartitem.cpp index 2d565ee..9643f1e 100644 --- a/src/splinechart/splinechartitem.cpp +++ b/src/splinechart/splinechartitem.cpp @@ -53,17 +53,12 @@ void SplineChartItem::setLayout(QVector& points) XYChartItem::setLayout(points); } -void SplineChartItem::setLinePen(const QPen& pen) -{ - m_pen = pen; -} - //handlers void SplineChartItem::handleUpdated() { //m_items.setVisible(m_series->pointsVisible()); - setLinePen(m_series->pen()); + m_pen = m_series->pen(); update(); } diff --git a/src/splinechart/splinechartitem_p.h b/src/splinechart/splinechartitem_p.h index f043555..5b9f77f 100644 --- a/src/splinechart/splinechartitem_p.h +++ b/src/splinechart/splinechartitem_p.h @@ -18,7 +18,6 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QPainterPath shape() const; - void setLinePen(const QPen& pen); void setPointsVisible(bool visible); public slots: