From 9b55fd85f9c4b1ff735fd4f8d05c6287a94acea9 2012-03-19 10:28:15 From: Michal Klocek Date: 2012-03-19 10:28:15 Subject: [PATCH] Adds force option to chartTheme * adds missing pen to QLegend * adds missing getters pen,brush from qcharts * renames set getters for titile and background in qchart --- diff --git a/examples/axischart/main.cpp b/examples/axischart/main.cpp index 86c3d56..33a5702 100644 --- a/examples/axischart/main.cpp +++ b/examples/axischart/main.cpp @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) QChartAxis* axisY = chartView->axisY(); axisY->setLabelsAngle(45); axisY->setShadesBrush(Qt::yellow); + axisY->setShadesVisible(true); axisY->setGridLineVisible(false); QChartAxisCategories* categoriesY = axisY->categories(); diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 223bf84..4f69687 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -33,10 +33,11 @@ ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char m_chartTheme(0), m_zoomIndex(0), m_rect(QRectF(QPoint(0,0),m_chart->size())), - m_options(QChart::NoAnimation) + m_options(QChart::NoAnimation), + m_themeForce(false) { createConnections(); - setChartTheme(QChart::ChartThemeDefault); + setChartTheme(QChart::ChartThemeDefault,false); } ChartPresenter::~ChartPresenter() @@ -94,14 +95,14 @@ void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) } if(axis==m_dataset->axisX()){ - m_chartTheme->decorate(axis,true); + m_chartTheme->decorate(axis,true,m_themeForce); 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); + m_chartTheme->decorate(axis,false,m_themeForce); QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); //initialize item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); @@ -135,7 +136,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { m_animator->addAnimation(line); } - m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); 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; @@ -150,7 +151,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) m_animator->addAnimation(area->upperLineItem()); if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); } - m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); 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; @@ -163,7 +164,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { // m_animator->addAnimation(bar); } - m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries)); + m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); item=bar; @@ -176,7 +177,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { // m_animator->addAnimation(bar); } - m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); + m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); item=bar; @@ -189,7 +190,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { // m_animator->addAnimation(bar); } - m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); + m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); item=bar; @@ -202,7 +203,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { m_animator->addAnimation(scatter); } - m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); 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; @@ -215,7 +216,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { m_animator->addAnimation(pie); } - m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); // Hide all from background when there is only piechart @@ -223,7 +224,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if (m_chartItems.count() == 0) { m_chart->axisX()->hide(); m_chart->axisY()->hide(); - m_chart->setChartBackgroundBrush(Qt::transparent); + m_chart->setBackgroundVisible(false); } item=pie; break; @@ -235,7 +236,7 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) if(m_options.testFlag(QChart::SeriesAnimations)) { m_animator->addAnimation(spline); } - m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series)); + m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); 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; @@ -271,13 +272,14 @@ void ChartPresenter::handleSeriesRemoved(QSeries* series) delete item; } -void ChartPresenter::setChartTheme(QChart::ChartTheme theme) +void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force) { if(m_chartTheme && m_chartTheme->id() == theme) return; delete m_chartTheme; + m_themeForce = force; m_chartTheme = ChartTheme::createTheme(theme); - m_chartTheme->decorate(m_chart); - m_chartTheme->decorate(m_chart->legend()); + m_chartTheme->decorate(m_chart,m_themeForce); + m_chartTheme->decorate(m_chart->legend(),m_themeForce); resetAllElements(); } diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index 0394649..f7de94e 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -41,7 +41,7 @@ public: QRectF geometry() const; ChartAnimator* animator() const {return m_animator;}; - void setChartTheme(QChart::ChartTheme theme); + void setChartTheme(QChart::ChartTheme theme,bool force = true); QChart::ChartTheme chartTheme(); void setAnimationOptions(QChart::AnimationOptions options); @@ -77,6 +77,7 @@ private: QVector m_zoomStack; QRectF m_rect; QChart::AnimationOptions m_options; + bool m_themeForce; }; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 892fb75..19511be 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -75,82 +75,110 @@ ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) } } -void ChartTheme::decorate(QChart* chart) +void ChartTheme::decorate(QChart* chart,bool force) { - if (m_backgroundShades == BackgroundShadesNone) { - chart->setChartBackgroundBrush(m_chartBackgroundGradient); - } else { - chart->setChartBackgroundBrush(Qt::NoBrush); + QPen pen; + QBrush brush; + + if(brush == chart->backgroundBrush() || force) + { + if (m_backgroundShades == BackgroundShadesNone) { + chart->setBackgroundBrush(m_chartBackgroundGradient); + } + else { + chart->setBackgroundBrush(Qt::NoBrush); + } } - chart->setChartTitleFont(m_masterFont); - chart->setChartTitleBrush(m_titleBrush); + chart->setTitleFont(m_masterFont); + chart->setTitleBrush(m_titleBrush); } -void ChartTheme::decorate(QLegend* legend) +void ChartTheme::decorate(QLegend* legend,bool force) { - legend->setBackgroundBrush(m_chartBackgroundGradient); + QPen pen; + QBrush brush; + + if (pen == legend->pen() || force){ + //TODO:: legend->setPen(); + } + + + if (brush == legend->brush() || force) { + legend->setBrush(m_chartBackgroundGradient); + } } -void ChartTheme::decorate(QAreaSeries* series, int index) +void ChartTheme::decorate(QAreaSeries* series, int index,bool force) { QPen pen; QBrush brush; - if (pen == series->pen()){ + if (pen == series->pen() || force){ pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); pen.setWidthF(2); series->setPen(pen); } - if (brush == series->brush()) { + if (brush == series->brush() || force) { QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); series->setBrush(brush); } } -void ChartTheme::decorate(QLineSeries* series,int index) +void ChartTheme::decorate(QLineSeries* series,int index,bool force) { QPen pen; - if(pen == series->pen()){ + if(pen == series->pen() || force ){ pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); pen.setWidthF(2); series->setPen(pen); } } -void ChartTheme::decorate(QBarSeries* series,int index) +void ChartTheme::decorate(QBarSeries* series,int index,bool force) { + QBrush brush; QList sets = series->barSets(); + for (int i=0; i 1) pos = (qreal) i / (qreal) (sets.count() - 1); + + if(brush == sets.at(i)->brush() || force ){ QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); sets.at(i)->setBrush(QBrush(c)); - + } // Pick label color as far as possible from bar color (within gradient). // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) // TODO: better picking of label color? + QColor c; + if (pos < 0.3) { c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); } else { c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); } sets.at(i)->setFloatingValuePen(QPen(c)); + } } -void ChartTheme::decorate(QStackedBarSeries* series,int index) +void ChartTheme::decorate(QStackedBarSeries* series,int index,bool force) { + QBrush brush; QList sets = series->barSets(); + for (int i=0; i 1) pos = (qreal) i / (qreal) (sets.count() - 1); + if(brush == sets.at(i)->brush() || force){ QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); sets.at(i)->setBrush(QBrush(c)); - + } + QColor c; if (pos < 0.3) { c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); } else { @@ -160,16 +188,21 @@ void ChartTheme::decorate(QStackedBarSeries* series,int index) } } -void ChartTheme::decorate(QPercentBarSeries* series,int index) +void ChartTheme::decorate(QPercentBarSeries* series,int index,bool force) { + QBrush brush; QList sets = series->barSets(); + for (int i=0; i 1) pos = (qreal) i / (qreal) (sets.count() - 1); + + if(brush == sets.at(i)->brush() || force){ QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); sets.at(i)->setBrush(QBrush(c)); - + } + QColor c; if (pos < 0.3) { c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); } else { @@ -179,64 +212,99 @@ void ChartTheme::decorate(QPercentBarSeries* series,int index) } } -void ChartTheme::decorate(QScatterSeries* series, int index) +void ChartTheme::decorate(QScatterSeries* series, int index,bool force) { QPen pen; QBrush brush; - if (pen == series->pen()) { + if (pen == series->pen() || force) { pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); pen.setWidthF(2); series->setPen(pen); } - if (brush == series->brush()) { + if (brush == series->brush() || force) { QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); series->setBrush(brush); } } -void ChartTheme::decorate(QPieSeries* series, int index) +void ChartTheme::decorate(QPieSeries* series, int index, bool force) { // Get color for a slice from a gradient linearly, beginning from the start of the gradient + + QPen pen; + QBrush brush; + for (int i(0); i < series->slices().count(); i++) { qreal pos = (qreal) i / (qreal) series->count(); + if( pen == series->slices().at(i)->slicePen() || force){ QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); series->slices().at(i)->setSlicePen(penColor); + } + if( brush == series->slices().at(i)->sliceBrush() || force){ QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); series->slices().at(i)->setSliceBrush(brushColor); + } } } -void ChartTheme::decorate(QSplineSeries* series, int index) +void ChartTheme::decorate(QSplineSeries* series, int index, bool force) { QPen pen; - if(pen == series->pen()){ + if(pen == series->pen() || force){ pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); pen.setWidthF(2); series->setPen(pen); } } -void ChartTheme::decorate(QChartAxis* axis,bool axisX) +void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) { + QPen pen; + QBrush brush; + QFont font; + if (axis->isAxisVisible()) { - axis->setLabelsBrush(m_axisLabelBrush); - axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons - if (m_backgroundShades == BackgroundShadesBoth - || (m_backgroundShades == BackgroundShadesVertical && axisX) - || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { - axis->setShadesPen(m_backgroundShadesPen); - axis->setShadesBrush(m_backgroundShadesBrush); - } else { - // The shades not supposed to be shown for this axis, clear possible brush and pen - axis->setShadesPen(Qt::NoPen); - axis->setShadesBrush(Qt::NoBrush); + + if(brush == axis->labelsBrush() || force){ + axis->setLabelsBrush(m_axisLabelBrush); + } + if(pen == axis->labelsPen() || force){ + axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons + } + + + if (axis->shadesVisible() || force) { + + if(brush == axis->shadesBrush() || force){ + axis->setShadesBrush(m_backgroundShadesBrush); + } + + if(pen == axis->shadesPen() || force){ + axis->setShadesPen(m_backgroundShadesPen); + } + + if(force && (m_backgroundShades == BackgroundShadesBoth + || (m_backgroundShades == BackgroundShadesVertical && axisX) + || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ + axis->setShadesVisible(true); + + } + } + + if(pen == axis->axisPen() || force){ + axis->setAxisPen(m_axisLinePen); + } + + if(pen == axis->gridLinePen() || force){ + axis->setGridLinePen(m_gridLinePen); + } + + if(font == axis->labelsFont() || force){ + axis->setLabelsFont(m_masterFont); } - axis->setAxisPen(m_axisLinePen); - axis->setGridLinePen(m_gridLinePen); - axis->setLabelsFont(m_masterFont); } } diff --git a/src/charttheme_p.h b/src/charttheme_p.h index e5f454a..ec5ac47 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -42,18 +42,18 @@ protected: public: static ChartTheme* createTheme(QChart::ChartTheme theme); QChart::ChartTheme id() const {return m_id;} - void decorate(QChart* chart); - void decorate(QLegend* legend); + void decorate(QChart* chart,bool force = true); + void decorate(QLegend* legend,bool force = true); //void decorate(ChartItem* item, QSeries* series,int index); - void decorate(QBarSeries* series, int index); - void decorate(QStackedBarSeries* series, int index); - void decorate(QPercentBarSeries* series, int index); - void decorate(QLineSeries* series, int index); - void decorate(QAreaSeries* series, int index); - void decorate(QScatterSeries* series, int index); - void decorate(QPieSeries* series, int index); - void decorate(QSplineSeries* series, int index); - void decorate(QChartAxis* axis, bool axisX); + void decorate(QBarSeries* series, int index,bool force = true); + void decorate(QStackedBarSeries* series, int index,bool force = true); + void decorate(QPercentBarSeries* series, int index,bool force = true); + void decorate(QLineSeries* series, int index,bool force = true); + void decorate(QAreaSeries* series, int index,bool force = true); + void decorate(QScatterSeries* series, int index,bool force = true); + void decorate(QPieSeries* series, int index,bool force = true); + void decorate(QSplineSeries* series, int index,bool force = true); + void decorate(QChartAxis* axis, bool axisX,bool force = true); public: // utils void generateSeriesGradients(); diff --git a/src/qchart.cpp b/src/qchart.cpp index bf69bfa..f59faaf 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -104,27 +104,39 @@ void QChart::removeAllSeries() /*! Sets the \a brush that is used for painting the background of the chart area. */ -void QChart::setChartBackgroundBrush(const QBrush& brush) +void QChart::setBackgroundBrush(const QBrush& brush) { createChartBackgroundItem(); m_backgroundItem->setBrush(brush); m_backgroundItem->update(); } +QBrush QChart::backgroundBrush() const +{ + if(!m_backgroundItem) return QBrush(); + return m_backgroundItem->brush(); +} + /*! Sets the \a pen that is used for painting the background of the chart area. */ -void QChart::setChartBackgroundPen(const QPen& pen) +void QChart::setBackgroundPen(const QPen& pen) { createChartBackgroundItem(); m_backgroundItem->setPen(pen); m_backgroundItem->update(); } +QPen QChart::backgroundPen() const +{ + if(!m_backgroundItem) return QPen(); + return m_backgroundItem->pen(); +} + /*! Sets the chart \a title. The description text that is drawn above the chart. */ -void QChart::setChartTitle(const QString& title) +void QChart::setTitle(const QString& title) { createChartTitleItem(); m_titleItem->setText(title); @@ -134,7 +146,7 @@ void QChart::setChartTitle(const QString& title) /*! Returns the chart title. The description text that is drawn above the chart. */ -QString QChart::chartTitle() const +QString QChart::title() const { if(m_titleItem) return m_titleItem->text(); @@ -145,7 +157,7 @@ QString QChart::chartTitle() const /*! Sets the \a font that is used for rendering the description text that is rendered above the chart. */ -void QChart::setChartTitleFont(const QFont& font) +void QChart::setTitleFont(const QFont& font) { createChartTitleItem(); m_titleItem->setFont(font); @@ -155,7 +167,7 @@ void QChart::setChartTitleFont(const QFont& font) /*! Sets the \a brush used for rendering the title text. */ -void QChart::setChartTitleBrush(const QBrush &brush) +void QChart::setTitleBrush(const QBrush &brush) { createChartTitleItem(); m_titleItem->setBrush(brush); @@ -165,9 +177,9 @@ void QChart::setChartTitleBrush(const QBrush &brush) /*! Returns the brush used for rendering the title text. */ -QBrush QChart::chartTitleBrush() +QBrush QChart::titleBrush() const { - createChartTitleItem(); + if(!m_titleItem) return QBrush(); return m_titleItem->brush(); } @@ -365,6 +377,19 @@ void QChart::setBackgroundDiameter(int diameter) m_backgroundItem->update(); } +void QChart::setBackgroundVisible(bool visible) +{ + createChartBackgroundItem(); + m_backgroundItem->setVisible(visible); +} + +bool QChart::isBackgroundVisible() const +{ + if(!m_backgroundItem) return false; + return m_backgroundItem->isVisible(); +} + + #include "moc_qchart.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchart.h b/src/qchart.h index f3d4f0e..ced697c 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -58,13 +58,19 @@ public: void setChartTheme(QChart::ChartTheme theme); QChart::ChartTheme chartTheme() const; - void setChartTitle(const QString& title); - QString chartTitle() const; - void setChartTitleFont(const QFont& font); - void setChartTitleBrush(const QBrush &brush); - QBrush chartTitleBrush(); - void setChartBackgroundBrush(const QBrush& brush); - void setChartBackgroundPen(const QPen& pen); + void setTitle(const QString& title); + QString title() const; + void setTitleFont(const QFont& font); + QFont titleFont() const; + void setTitleBrush(const QBrush &brush); + QBrush titleBrush() const; + void setBackgroundBrush(const QBrush& brush); + QBrush backgroundBrush() const; + void setBackgroundPen(const QPen& pen); + QPen backgroundPen() const; + + void setBackgroundVisible(bool visible); + bool isBackgroundVisible() const; void setAnimationOptions(AnimationOptions options); AnimationOptions animationOptions() const; diff --git a/src/qchartview.cpp b/src/qchartview.cpp index 25483a8..78a0d65 100644 --- a/src/qchartview.cpp +++ b/src/qchartview.cpp @@ -129,7 +129,7 @@ void QChartView::zoomOut() */ void QChartView::setChartTitle(const QString& title) { - m_chart->setChartTitle(title); + m_chart->setTitle(title); } /*! @@ -137,7 +137,7 @@ void QChartView::setChartTitle(const QString& title) */ QString QChartView::chartTitle() const { - return m_chart->chartTitle(); + return m_chart->title(); } /*! @@ -145,7 +145,7 @@ QString QChartView::chartTitle() const */ void QChartView::setChartTitleFont(const QFont& font) { - m_chart->setChartTitleFont(font); + m_chart->setTitleFont(font); } /*! @@ -153,7 +153,7 @@ void QChartView::setChartTitleFont(const QFont& font) */ void QChartView::setChartTitleBrush(const QBrush &brush) { - m_chart->setChartTitleBrush(brush); + m_chart->setTitleBrush(brush); } /*! @@ -161,7 +161,7 @@ void QChartView::setChartTitleBrush(const QBrush &brush) */ QBrush QChartView::chartTitleBrush() { - return m_chart->chartTitleBrush(); + return m_chart->titleBrush(); } /*! @@ -169,7 +169,7 @@ QBrush QChartView::chartTitleBrush() */ void QChartView::setChartBackgroundBrush(const QBrush& brush) { - m_chart->setChartBackgroundBrush(brush); + m_chart->setBackgroundBrush(brush); } /*! @@ -177,7 +177,7 @@ void QChartView::setChartBackgroundBrush(const QBrush& brush) */ void QChartView::setChartBackgroundPen(const QPen& pen) { - m_chart->setChartBackgroundPen(pen); + m_chart->setBackgroundPen(pen); } /*! diff --git a/src/qlegend.cpp b/src/qlegend.cpp index 9c968f4..585ea2d 100644 --- a/src/qlegend.cpp +++ b/src/qlegend.cpp @@ -27,7 +27,7 @@ QLegend::QLegend(QGraphicsItem *parent) ,mSize(0,0) ,mMinimumSize(50,20) // TODO: magic numbers ,mMaximumSize(150,100) - ,mBackgroundBrush(Qt::darkGray) // TODO: from theme? + ,m_brush(Qt::darkGray) // TODO: from theme? ,mPreferredLayout(QLegend::PreferredLayoutVertical) { // setVisible(false); @@ -40,7 +40,8 @@ void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q Q_UNUSED(widget) painter->setOpacity(0.5); - painter->setBrush(mBackgroundBrush); + painter->setPen(m_pen); + painter->setBrush(m_brush); painter->drawRect(boundingRect()); } @@ -49,14 +50,30 @@ QRectF QLegend::boundingRect() const return QRectF(mPos,mSize); } -void QLegend::setBackgroundBrush(const QBrush& brush) +void QLegend::setBrush(const QBrush& brush) { - mBackgroundBrush = brush; + if(m_brush!=brush){ + m_brush = brush; + update(); + } +} + +QBrush QLegend::brush() const +{ + return m_brush; +} + +void QLegend::setPen(const QPen& pen) +{ + if(m_pen!=pen){ + m_pen = pen; + update(); + } } -QBrush QLegend::backgroundBrush() const +QPen QLegend::pen() const { - return mBackgroundBrush; + return m_pen; } void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred) diff --git a/src/qlegend.h b/src/qlegend.h index 77ecef6..98c1643 100644 --- a/src/qlegend.h +++ b/src/qlegend.h @@ -30,8 +30,11 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); QRectF boundingRect() const; - void setBackgroundBrush(const QBrush& brush); - QBrush backgroundBrush() const; + void setBrush(const QBrush& brush); + QBrush brush() const; + + void setPen(const QPen& pen); + QPen pen() const; void setPreferredLayout(QLegend::PreferredLayout preferred); @@ -74,7 +77,8 @@ private: // QList mSeriesList; QList mMarkers; - QBrush mBackgroundBrush; + QBrush m_brush; + QPen m_pen; QLegend::PreferredLayout mPreferredLayout; };