chartpresenter.cpp
529 lines
| 18.7 KiB
| text/x-c
|
CppLexer
/ src / chartpresenter.cpp
|
r794 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r139 | #include "qchart.h" | ||
|
r855 | #include "qchart_p.h" | ||
|
r140 | #include "qchartaxis.h" | ||
|
r131 | #include "chartpresenter_p.h" | ||
#include "chartdataset_p.h" | ||||
|
r143 | #include "charttheme_p.h" | ||
|
r530 | #include "chartanimator_p.h" | ||
|
r139 | //series | ||
|
r338 | #include "qbarseries.h" | ||
#include "qstackedbarseries.h" | ||||
#include "qpercentbarseries.h" | ||||
|
r349 | #include "qlineseries.h" | ||
|
r421 | #include "qareaseries.h" | ||
|
r142 | #include "qpieseries.h" | ||
|
r158 | #include "qscatterseries.h" | ||
|
r295 | #include "qsplineseries.h" | ||
|
r139 | //items | ||
|
r140 | #include "axisitem_p.h" | ||
|
r421 | #include "areachartitem_p.h" | ||
|
r666 | #include "barchartitem_p.h" | ||
#include "stackedbarchartitem_p.h" | ||||
#include "percentbarchartitem_p.h" | ||||
|
r145 | #include "linechartitem_p.h" | ||
|
r568 | #include "piechartitem_p.h" | ||
|
r470 | #include "scatterchartitem_p.h" | ||
|
r460 | #include "splinechartitem_p.h" | ||
|
r131 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | ||||
|
r401 | m_chart(chart), | ||
|
r530 | m_animator(0), | ||
|
r401 | m_dataset(dataset), | ||
m_chartTheme(0), | ||||
|
r855 | m_chartRect(QRectF(QPoint(0,0),m_chart->size())), | ||
|
r645 | m_options(QChart::NoAnimation), | ||
|
r742 | m_themeForce(false), | ||
|
r855 | m_minLeftMargin(0), | ||
m_minBottomMargin(0), | ||||
m_backgroundItem(0), | ||||
m_titleItem(0), | ||||
m_marginBig(60), | ||||
m_marginSmall(20), | ||||
m_marginTiny(10), | ||||
m_chartMargins(QRect(m_marginBig,m_marginBig,0,0)) | ||||
|
r131 | { | ||
} | ||||
ChartPresenter::~ChartPresenter() | ||||
{ | ||||
|
r531 | delete m_chartTheme; | ||
|
r131 | } | ||
|
r855 | void ChartPresenter::setGeometry(const QRectF& rect) | ||
|
r131 | { | ||
|
r439 | m_rect = rect; | ||
|
r147 | Q_ASSERT(m_rect.isValid()); | ||
|
r855 | updateLayout(); | ||
} | ||||
void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width) | ||||
{ | ||||
switch(axis->axisType()){ | ||||
case Axis::X_AXIS: | ||||
{ | ||||
if(width>m_chartRect.width()+ m_chartMargins.left()) { | ||||
m_minLeftMargin= width - m_chartRect.width(); | ||||
updateLayout(); | ||||
} | ||||
break; | ||||
} | ||||
case Axis::Y_AXIS: | ||||
{ | ||||
if(m_minLeftMargin!=width){ | ||||
m_minLeftMargin= width; | ||||
updateLayout(); | ||||
} | ||||
break; | ||||
} | ||||
} | ||||
} | ||||
void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height) | ||||
{ | ||||
switch(axis->axisType()){ | ||||
case Axis::X_AXIS: | ||||
{ | ||||
if(m_minBottomMargin!=height) { | ||||
m_minBottomMargin= height; | ||||
updateLayout(); | ||||
} | ||||
break; | ||||
} | ||||
case Axis::Y_AXIS: | ||||
{ | ||||
if(height>m_chartMargins.bottom()+m_chartRect.height()){ | ||||
m_minBottomMargin= height - m_chartRect.height(); | ||||
updateLayout(); | ||||
} | ||||
break; | ||||
} | ||||
} | ||||
|
r139 | } | ||
|
r131 | |||
|
r439 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | ||
|
r223 | { | ||
|
r677 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); | ||
|
r298 | |||
|
r530 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | ||
m_animator->addAnimation(item); | ||||
|
r439 | } | ||
|
r530 | |||
|
r439 | if(axis==m_dataset->axisX()){ | ||
|
r645 | m_chartTheme->decorate(axis,true,m_themeForce); | ||
|
r531 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | ||
|
r439 | //initialize | ||
|
r531 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | ||
|
r562 | |||
|
r439 | } | ||
else{ | ||||
|
r645 | m_chartTheme->decorate(axis,false,m_themeForce); | ||
|
r531 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | ||
|
r439 | //initialize | ||
|
r531 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | ||
|
r223 | } | ||
|
r298 | |||
|
r223 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | ||
|
r439 | //initialize | ||
|
r855 | item->handleGeometryChanged(m_chartRect); | ||
|
r561 | m_axisItems.insert(axis, item); | ||
|
r223 | } | ||
void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | ||||
{ | ||||
|
r677 | Axis* item = m_axisItems.take(axis); | ||
|
r223 | Q_ASSERT(item); | ||
|
r530 | if(m_animator) m_animator->removeAnimation(item); | ||
|
r223 | delete item; | ||
} | ||||
|
r439 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | ||
|
r131 | { | ||
|
r677 | Chart *item = 0 ; | ||
|
r531 | |||
|
r131 | switch(series->type()) | ||
{ | ||||
|
r418 | case QSeries::SeriesTypeLine: { | ||
|
r426 | |||
|
r418 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | ||
|
r677 | LineChartItem* line = new LineChartItem(lineSeries,this); | ||
|
r531 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
m_animator->addAnimation(line); | ||||
|
r139 | } | ||
|
r645 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); | ||
|
r531 | 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; | ||||
|
r426 | break; | ||
} | ||||
|
r421 | |||
|
r426 | case QSeries::SeriesTypeArea: { | ||
|
r139 | |||
|
r426 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | ||
|
r677 | AreaChartItem* area = new AreaChartItem(areaSeries,this); | ||
|
r426 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
|
r648 | m_animator->addAnimation(area->upperLineItem()); | ||
if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | ||||
|
r131 | } | ||
|
r645 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); | ||
|
r531 | 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; | ||||
|
r401 | break; | ||
} | ||||
|
r139 | |||
|
r418 | case QSeries::SeriesTypeBar: { | ||
QBarSeries* barSeries = static_cast<QBarSeries*>(series); | ||||
|
r677 | BarChartItem* bar = new BarChartItem(barSeries,this); | ||
|
r531 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
|
r671 | m_animator->addAnimation(bar); | ||
|
r531 | } | ||
|
r645 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); | ||
|
r531 | 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; | ||||
|
r401 | break; | ||
} | ||||
|
r131 | |||
|
r418 | case QSeries::SeriesTypeStackedBar: { | ||
QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | ||||
|
r677 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this); | ||
|
r531 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
|
r671 | m_animator->addAnimation(bar); | ||
|
r531 | } | ||
|
r645 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); | ||
|
r531 | 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; | ||||
|
r401 | break; | ||
} | ||||
|
r139 | |||
|
r418 | case QSeries::SeriesTypePercentBar: { | ||
QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | ||||
|
r677 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this); | ||
|
r531 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
|
r671 | m_animator->addAnimation(bar); | ||
|
r531 | } | ||
|
r645 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); | ||
|
r531 | 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; | ||||
|
r401 | break; | ||
} | ||||
|
r476 | |||
|
r531 | case QSeries::SeriesTypeScatter: { | ||
|
r869 | |||
|
r531 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | ||
|
r677 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this); | ||
|
r538 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
m_animator->addAnimation(scatter); | ||||
} | ||||
|
r645 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); | ||
|
r538 | 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; | ||||
break; | ||||
|
r531 | } | ||
|
r418 | |||
|
r531 | case QSeries::SeriesTypePie: { | ||
QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | ||||
|
r677 | PieChartItem* pie = new PieChartItem(pieSeries, this); | ||
|
r531 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
|
r618 | m_animator->addAnimation(pie); | ||
|
r531 | } | ||
|
r645 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); | ||
|
r531 | 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))); | ||||
|
r418 | // Hide all from background when there is only piechart | ||
// TODO: refactor this ugly code... should be one setting for this | ||||
if (m_chartItems.count() == 0) { | ||||
|
r534 | m_chart->axisX()->hide(); | ||
m_chart->axisY()->hide(); | ||||
|
r131 | } | ||
|
r531 | item=pie; | ||
|
r401 | break; | ||
} | ||||
|
r427 | |||
|
r419 | case QSeries::SeriesTypeSpline: { | ||
|
r538 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | ||
|
r677 | SplineChartItem* spline = new SplineChartItem(splineSeries, this); | ||
|
r538 | if(m_options.testFlag(QChart::SeriesAnimations)) { | ||
m_animator->addAnimation(spline); | ||||
} | ||||
|
r645 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); | ||
|
r538 | 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; | ||||
break; | ||||
} | ||||
|
r401 | default: { | ||
qDebug()<< "Series type" << series->type() << "not implemented."; | ||||
|
r295 | break; | ||
} | ||||
|
r131 | } | ||
|
r439 | |||
|
r531 | //initialize | ||
item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | ||||
|
r855 | if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect); | ||
|
r531 | m_chartItems.insert(series,item); | ||
|
r131 | } | ||
|
r360 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | ||
|
r139 | { | ||
|
r677 | Chart* item = m_chartItems.take(series); | ||
|
r530 | Q_ASSERT(item); | ||
|
r560 | if(m_animator) { | ||
//small hack to handle area animations | ||||
if(series->type()==QSeries::SeriesTypeArea){ | ||||
QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | ||||
AreaChartItem* area = static_cast<AreaChartItem*>(item); | ||||
m_animator->removeAnimation(area->upperLineItem()); | ||||
|
r648 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | ||
|
r560 | }else | ||
m_animator->removeAnimation(item); | ||||
} | ||||
|
r401 | delete item; | ||
|
r139 | } | ||
|
r131 | |||
|
r740 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | ||
|
r143 | { | ||
|
r531 | if(m_chartTheme && m_chartTheme->id() == theme) return; | ||
|
r143 | delete m_chartTheme; | ||
|
r645 | m_themeForce = force; | ||
|
r143 | m_chartTheme = ChartTheme::createTheme(theme); | ||
|
r645 | m_chartTheme->decorate(m_chart,m_themeForce); | ||
|
r783 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); | ||
|
r531 | resetAllElements(); | ||
|
r176 | } | ||
|
r740 | QChart::ChartTheme ChartPresenter::theme() | ||
|
r143 | { | ||
|
r153 | return m_chartTheme->id(); | ||
} | ||||
|
r298 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | ||
{ | ||||
if(m_options!=options) { | ||||
m_options=options; | ||||
|
r530 | if(m_options!=QChart::NoAnimation && !m_animator) { | ||
m_animator= new ChartAnimator(this); | ||||
|
r298 | } | ||
|
r531 | resetAllElements(); | ||
|
r298 | } | ||
|
r530 | |||
|
r298 | } | ||
|
r531 | void ChartPresenter::resetAllElements() | ||
{ | ||||
QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | ||||
QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | ||||
foreach(QChartAxis* axis, axisList) { | ||||
handleAxisRemoved(axis); | ||||
handleAxisAdded(axis,m_dataset->domain(axis)); | ||||
} | ||||
foreach(QSeries* series, seriesList) { | ||||
handleSeriesRemoved(series); | ||||
handleSeriesAdded(series,m_dataset->domain(series)); | ||||
} | ||||
} | ||||
|
r439 | void ChartPresenter::zoomIn() | ||
{ | ||||
|
r855 | QRectF rect = chartGeometry(); | ||
|
r439 | rect.setWidth(rect.width()/2); | ||
rect.setHeight(rect.height()/2); | ||||
|
r855 | rect.moveCenter(chartGeometry().center()); | ||
|
r439 | zoomIn(rect); | ||
} | ||||
void ChartPresenter::zoomIn(const QRectF& rect) | ||||
{ | ||||
QRectF r = rect.normalized(); | ||||
|
r855 | r.translate(-m_chartMargins.topLeft()); | ||
|
r531 | if(m_animator) { | ||
|
r855 | QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); | ||
|
r531 | m_animator->setState(ChartAnimator::ZoomInState,point); | ||
} | ||||
|
r855 | m_dataset->zoomInDomain(r,chartGeometry().size()); | ||
|
r531 | if(m_animator) { | ||
m_animator->setState(ChartAnimator::ShowState); | ||||
} | ||||
|
r439 | } | ||
void ChartPresenter::zoomOut() | ||||
{ | ||||
|
r531 | if(m_animator) | ||
{ | ||||
m_animator->setState(ChartAnimator::ZoomOutState); | ||||
} | ||||
|
r678 | |||
|
r855 | QSizeF size = chartGeometry().size(); | ||
QRectF rect = chartGeometry(); | ||||
rect.translate(-m_chartMargins.topLeft()); | ||||
|
r803 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); | ||
|
r678 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | ||
|
r531 | if(m_animator){ | ||
m_animator->setState(ChartAnimator::ShowState); | ||||
} | ||||
|
r439 | } | ||
|
r531 | void ChartPresenter::scroll(int dx,int dy) | ||
{ | ||||
if(m_animator){ | ||||
if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | ||||
if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | ||||
if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | ||||
if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | ||||
} | ||||
|
r855 | m_dataset->scrollDomain(dx,dy,chartGeometry().size()); | ||
|
r531 | |||
|
r547 | if(m_animator){ | ||
|
r531 | m_animator->setState(ChartAnimator::ShowState); | ||
} | ||||
} | ||||
|
r298 | QChart::AnimationOptions ChartPresenter::animationOptions() const | ||
{ | ||||
return m_options; | ||||
} | ||||
|
r855 | void ChartPresenter::updateLayout() | ||
{ | ||||
if (!m_rect.isValid()) return; | ||||
// recalculate title size | ||||
QSize titleSize; | ||||
int titlePadding=0; | ||||
if (m_titleItem) { | ||||
titleSize= m_titleItem->boundingRect().size().toSize(); | ||||
} | ||||
//defaults | ||||
m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig)); | ||||
titlePadding = m_chartMargins.top()/2; | ||||
QLegend* legend = m_chart->d_ptr->m_legend; | ||||
// recalculate legend position | ||||
if (legend->isAttachedToChart() && legend->isEnabled()) { | ||||
QRect legendRect; | ||||
// Reserve some space for legend | ||||
switch (legend->alignment()) { | ||||
case QLegend::AlignmentTop: { | ||||
int ledgendSize = legend->minHeight(); | ||||
int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; | ||||
m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | ||||
m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny)); | ||||
titlePadding = m_marginTiny + m_marginTiny; | ||||
break; | ||||
} | ||||
case QLegend::AlignmentBottom: { | ||||
int ledgendSize = legend->minHeight(); | ||||
int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; | ||||
m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); | ||||
m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall)); | ||||
titlePadding = m_chartMargins.top()/2; | ||||
break; | ||||
} | ||||
case QLegend::AlignmentLeft: { | ||||
|
r888 | int ledgendSize = legend->minWidth(); | ||
|
r855 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; | ||
m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | ||||
m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom())); | ||||
titlePadding = m_chartMargins.top()/2; | ||||
break; | ||||
} | ||||
case QLegend::AlignmentRight: { | ||||
|
r888 | int ledgendSize = legend->minWidth(); | ||
|
r855 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; | ||
m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); | ||||
m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom())); | ||||
titlePadding = m_chartMargins.top()/2; | ||||
break; | ||||
} | ||||
default: { | ||||
break; | ||||
} | ||||
} | ||||
} | ||||
// recalculate title position | ||||
if (m_titleItem) { | ||||
QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | ||||
m_titleItem->setPos(center.x(),titlePadding); | ||||
} | ||||
//recalculate background gradient | ||||
if (m_backgroundItem) { | ||||
m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny)); | ||||
} | ||||
|
r869 | QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom()); | ||
|
r871 | legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); | ||
|
r869 | if(m_chartRect!=chartRect){ | ||
m_chartRect=chartRect; | ||||
emit geometryChanged(m_chartRect); | ||||
} | ||||
|
r855 | |||
|
r871 | |||
|
r855 | } | ||
void ChartPresenter::createChartBackgroundItem() | ||||
{ | ||||
if (!m_backgroundItem) { | ||||
m_backgroundItem = new ChartBackground(rootItem()); | ||||
m_backgroundItem->setPen(Qt::NoPen); | ||||
m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | ||||
} | ||||
} | ||||
void ChartPresenter::createChartTitleItem() | ||||
{ | ||||
if (!m_titleItem) { | ||||
m_titleItem = new QGraphicsSimpleTextItem(rootItem()); | ||||
m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | ||||
} | ||||
} | ||||
|
r143 | |||
|
r131 | #include "moc_chartpresenter_p.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||