qchart.cpp
204 lines
| 4.3 KiB
| text/x-c
|
CppLexer
/ src / qchart.cpp
Michal Klocek
|
r12 | #include "qchart.h" | ||
Tero Ahola
|
r42 | #include "qscatterseries.h" | ||
#include "qscatterseries_p.h" | ||||
Tero Ahola
|
r51 | #include "qpieseries.h" | ||
Michal Klocek
|
r85 | #include "qchartaxis.h" | ||
Michal Klocek
|
r131 | #include "chartpresenter_p.h" | ||
#include "chartdataset_p.h" | ||||
Michal Klocek
|
r139 | |||
//series | ||||
#include "barchartseries.h" | ||||
#include "stackedbarchartseries.h" | ||||
#include "percentbarchartseries.h" | ||||
Michal Klocek
|
r145 | #include "qlinechartseries.h" | ||
Michal Klocek
|
r139 | |||
Tero Ahola
|
r42 | #include <QGraphicsScene> | ||
Michal Klocek
|
r115 | #include <QGraphicsSceneResizeEvent> | ||
Michal Klocek
|
r21 | #include <QDebug> | ||
Michal Klocek
|
r12 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Michal Klocek
|
r12 | |||
Michal Klocek
|
r115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | ||
Michal Klocek
|
r143 | m_backgroundItem(0), | ||
m_titleItem(0), | ||||
m_dataset(new ChartDataSet(this)), | ||||
m_presenter(new ChartPresenter(this,m_dataset)) | ||||
Michal Klocek
|
r12 | { | ||
} | ||||
Michal Klocek
|
r143 | QChart::~QChart() {} | ||
Michal Klocek
|
r12 | |||
Michal Klocek
|
r21 | void QChart::addSeries(QChartSeries* series) | ||
Michal Klocek
|
r12 | { | ||
Michal Klocek
|
r143 | m_dataset->addSeries(series); | ||
Tero Ahola
|
r65 | } | ||
Michal Klocek
|
r143 | //TODO on review, is it really needed ?? | ||
Tero Ahola
|
r65 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | ||
{ | ||||
QChartSeries *series(0); | ||||
switch (type) { | ||||
Michal Klocek
|
r143 | case QChartSeries::SeriesTypeLine: { | ||
Michal Klocek
|
r156 | series = new QLineChartSeries(this); | ||
Michal Klocek
|
r143 | break; | ||
} | ||||
case QChartSeries::SeriesTypeBar: { | ||||
sauimone
|
r169 | //series = new BarChartSeries(this); | ||
Michal Klocek
|
r143 | break; | ||
} | ||||
case QChartSeries::SeriesTypeStackedBar: { | ||||
sauimone
|
r169 | //series = new StackedBarChartSeries(this); | ||
Michal Klocek
|
r143 | break; | ||
} | ||||
case QChartSeries::SeriesTypePercentBar: { | ||||
sauimone
|
r169 | //series = new PercentBarChartSeries(this); | ||
Michal Klocek
|
r143 | break; | ||
} | ||||
case QChartSeries::SeriesTypeScatter: { | ||||
series = new QScatterSeries(this); | ||||
break; | ||||
} | ||||
case QChartSeries::SeriesTypePie: { | ||||
series = new QPieSeries(this); | ||||
break; | ||||
} | ||||
default: | ||||
Tero Ahola
|
r61 | Q_ASSERT(false); | ||
Tero Ahola
|
r42 | break; | ||
} | ||||
Tero Ahola
|
r65 | addSeries(series); | ||
return series; | ||||
Tero Ahola
|
r42 | } | ||
Tero Ahola
|
r48 | |||
Michal Klocek
|
r122 | void QChart::setChartBackgroundBrush(const QBrush& brush) | ||
{ | ||||
Michal Klocek
|
r143 | if(!m_backgroundItem) { | ||
Michal Klocek
|
r122 | m_backgroundItem = new QGraphicsRectItem(this); | ||
m_backgroundItem->setZValue(-1); | ||||
} | ||||
m_backgroundItem->setBrush(brush); | ||||
m_backgroundItem->update(); | ||||
} | ||||
void QChart::setChartBackgroundPen(const QPen& pen) | ||||
{ | ||||
Michal Klocek
|
r143 | if(!m_backgroundItem) { | ||
Michal Klocek
|
r122 | m_backgroundItem = new QGraphicsRectItem(this); | ||
m_backgroundItem->setZValue(-1); | ||||
} | ||||
m_backgroundItem->setPen(pen); | ||||
m_backgroundItem->update(); | ||||
} | ||||
Michal Klocek
|
r87 | void QChart::setTitle(const QString& title,const QFont& font) | ||
Michal Klocek
|
r69 | { | ||
Michal Klocek
|
r87 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | ||
m_titleItem->setPlainText(title); | ||||
m_titleItem->setFont(font); | ||||
Michal Klocek
|
r69 | } | ||
Michal Klocek
|
r28 | int QChart::margin() const | ||
{ | ||||
Jani Honkonen
|
r142 | return m_presenter->margin(); | ||
Michal Klocek
|
r28 | } | ||
Michal Klocek
|
r12 | void QChart::setMargin(int margin) | ||
{ | ||||
Michal Klocek
|
r143 | m_presenter->setMargin(margin); | ||
Michal Klocek
|
r12 | } | ||
Michal Klocek
|
r153 | void QChart::setChartTheme(QChart::ChartTheme theme) | ||
Tero Ahola
|
r64 | { | ||
Michal Klocek
|
r153 | m_presenter->setChartTheme(theme); | ||
Tero Ahola
|
r64 | } | ||
Michal Klocek
|
r153 | QChart::ChartTheme QChart::chartTheme() const | ||
Tero Ahola
|
r120 | { | ||
Michal Klocek
|
r153 | return m_presenter->chartTheme(); | ||
Tero Ahola
|
r120 | } | ||
Michal Klocek
|
r115 | void QChart::zoomInToRect(const QRectF& rectangle) | ||
Michal Klocek
|
r67 | { | ||
Michal Klocek
|
r139 | m_presenter->zoomInToRect(rectangle); | ||
Michal Klocek
|
r67 | } | ||
void QChart::zoomIn() | ||||
{ | ||||
Michal Klocek
|
r139 | m_presenter->zoomIn(); | ||
Michal Klocek
|
r67 | } | ||
void QChart::zoomOut() | ||||
{ | ||||
Michal Klocek
|
r139 | m_presenter->zoomOut(); | ||
Michal Klocek
|
r67 | } | ||
Tero Ahola
|
r93 | void QChart::zoomReset() | ||
{ | ||||
Michal Klocek
|
r139 | m_presenter->zoomReset(); | ||
Tero Ahola
|
r93 | } | ||
Michal Klocek
|
r176 | void QChart::setDefaultAxisX(const QChartAxis& axis) | ||
Michal Klocek
|
r85 | { | ||
Michal Klocek
|
r176 | m_presenter->setDefaultAxisX(axis); | ||
Michal Klocek
|
r85 | } | ||
Michal Klocek
|
r155 | |||
Michal Klocek
|
r176 | void QChart::setDefaultAxisY(const QChartAxis& axis) | ||
Michal Klocek
|
r155 | { | ||
Michal Klocek
|
r176 | m_presenter->setDefaultAxisY(axis); | ||
Michal Klocek
|
r155 | } | ||
Michal Klocek
|
r176 | QChartAxis QChart::defaultAxisX() const | ||
Michal Klocek
|
r155 | { | ||
Michal Klocek
|
r176 | return m_presenter->defaultAxisX(); | ||
Michal Klocek
|
r155 | } | ||
Michal Klocek
|
r176 | QChartAxis QChart::defaultAxisY() const | ||
Michal Klocek
|
r155 | { | ||
Michal Klocek
|
r176 | return m_presenter->defaultAxisY(); | ||
Michal Klocek
|
r155 | } | ||
Michal Klocek
|
r176 | int QChart::addAxisY(const QChartAxis& axis) | ||
Michal Klocek
|
r85 | { | ||
Michal Klocek
|
r176 | return m_presenter->addAxisY(axis); | ||
} | ||||
QChartAxis QChart::axisY(int id) const | ||||
{ | ||||
return m_presenter->axisY(id); | ||||
} | ||||
void QChart::removeAxisY(int id) | ||||
{ | ||||
m_presenter->removeAxisY(id); | ||||
Michal Klocek
|
r85 | } | ||
Michal Klocek
|
r115 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | ||
{ | ||||
m_rect = QRectF(QPoint(0,0),event->newSize()); | ||||
QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | ||||
// recalculate title position | ||||
if (m_titleItem) { | ||||
QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | ||||
m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | ||||
} | ||||
//recalculate background gradient | ||||
if (m_backgroundItem) { | ||||
m_backgroundItem->setRect(rect); | ||||
} | ||||
Michal Klocek
|
r117 | QGraphicsWidget::resizeEvent(event); | ||
Michal Klocek
|
r115 | update(); | ||
} | ||||
Tero Ahola
|
r64 | #include "moc_qchart.cpp" | ||
Tero Ahola
|
r48 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||