chartpresenter.cpp
319 lines
| 7.3 KiB
| text/x-c
|
CppLexer
/ src / chartpresenter.cpp
Jani Honkonen
|
r794 | /**************************************************************************** | ||
Michal Klocek
|
r969 | ** | ||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
#include "chartpresenter_p.h" | ||||
Michal Klocek
|
r139 | #include "qchart.h" | ||
Michal Klocek
|
r2273 | #include "chartitem_p.h" | ||
Michal Klocek
|
r855 | #include "qchart_p.h" | ||
Michal Klocek
|
r1541 | #include "qabstractaxis.h" | ||
Michal Klocek
|
r1556 | #include "qabstractaxis_p.h" | ||
Michal Klocek
|
r131 | #include "chartdataset_p.h" | ||
Michal Klocek
|
r1241 | #include "chartanimation_p.h" | ||
Tero Ahola
|
r988 | #include "qabstractseries_p.h" | ||
Michal Klocek
|
r421 | #include "qareaseries.h" | ||
Michal Klocek
|
r1006 | #include "chartaxis_p.h" | ||
#include "chartbackground_p.h" | ||||
Michal Klocek
|
r1534 | #include "chartlayout_p.h" | ||
Michal Klocek
|
r1965 | #include "charttitle_p.h" | ||
Michal Klocek
|
r1241 | #include <QTimer> | ||
Michal Klocek
|
r131 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Michal Klocek
|
r2273 | ChartPresenter::ChartPresenter(QChart *chart) | ||
Jani Honkonen
|
r2131 | : QObject(chart), | ||
m_chart(chart), | ||||
m_options(QChart::NoAnimation), | ||||
m_state(ShowState), | ||||
m_layout(new ChartLayout(this)), | ||||
m_background(0), | ||||
m_title(0) | ||||
Michal Klocek
|
r131 | { | ||
Michal Klocek
|
r1241 | |||
Michal Klocek
|
r131 | } | ||
ChartPresenter::~ChartPresenter() | ||||
{ | ||||
Michal Klocek
|
r2273 | |||
Michal Klocek
|
r131 | } | ||
Michal Klocek
|
r2273 | void ChartPresenter::setGeometry(const QRectF rect) | ||
Michal Klocek
|
r131 | { | ||
Michal Klocek
|
r2273 | if(m_rect != rect) { | ||
m_rect=rect; | ||||
foreach (ChartItem *chart, m_chartItems){ | ||||
chart->domain()->setSize(rect.size()); | ||||
chart->setPos(rect.topLeft()); | ||||
} | ||||
} | ||||
} | ||||
Michal Klocek
|
r1698 | |||
Michal Klocek
|
r2273 | QRectF ChartPresenter::geometry() const | ||
{ | ||||
return m_rect; | ||||
} | ||||
Michal Klocek
|
r1698 | |||
Michal Klocek
|
r2273 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) | ||
{ | ||||
qDebug()<<__FUNCTION__; | ||||
axis->d_ptr->initializeGraphics(rootItem()); | ||||
axis->d_ptr->initializeAnimations(m_options); | ||||
ChartAxis *item = axis->d_ptr->axisItem(); | ||||
item->setPresenter(this); | ||||
item->setThemeManager(m_chart->d_ptr->m_themeManager); | ||||
m_axisItems<<item; | ||||
m_axes<<axis; | ||||
Michal Klocek
|
r2105 | m_layout->invalidate(); | ||
Michal Klocek
|
r223 | } | ||
Jani Honkonen
|
r2131 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) | ||
Michal Klocek
|
r223 | { | ||
Michal Klocek
|
r2273 | qDebug()<<__FUNCTION__; | ||
ChartAxis *item = axis->d_ptr->m_item.take(); | ||||
Michal Klocek
|
r1729 | item->hide(); | ||
item->disconnect(); | ||||
sauimone
|
r1562 | item->deleteLater(); | ||
Michal Klocek
|
r2273 | m_axisItems.removeAll(item); | ||
m_axes.removeAll(axis); | ||||
Michal Klocek
|
r2154 | m_layout->invalidate(); | ||
Michal Klocek
|
r223 | } | ||
Michal Klocek
|
r2273 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) | ||
Michal Klocek
|
r131 | { | ||
Michal Klocek
|
r2273 | qDebug()<<__FUNCTION__; | ||
series->d_ptr->initializeGraphics(rootItem()); | ||||
series->d_ptr->initializeAnimations(m_options); | ||||
ChartItem *chart = series->d_ptr->chartItem(); | ||||
chart->setPresenter(this); | ||||
chart->setThemeManager(m_chart->d_ptr->m_themeManager); | ||||
chart->domain()->setSize(m_rect.size()); | ||||
chart->setPos(m_rect.topLeft()); | ||||
chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored | ||||
m_chartItems<<chart; | ||||
m_series<<series; | ||||
Michal Klocek
|
r2105 | m_layout->invalidate(); | ||
Michal Klocek
|
r131 | } | ||
Jani Honkonen
|
r2131 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | ||
Michal Klocek
|
r139 | { | ||
Michal Klocek
|
r2273 | qDebug()<<__FUNCTION__; | ||
ChartItem *chart = series->d_ptr->m_item.take(); | ||||
chart->hide(); | ||||
chart->disconnect(); | ||||
chart->deleteLater(); | ||||
m_chartItems.removeAll(chart); | ||||
m_series.removeAll(series); | ||||
m_layout->invalidate(); | ||||
Michal Klocek
|
r153 | } | ||
Michal Klocek
|
r298 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | ||
{ | ||||
Jani Honkonen
|
r2131 | if (m_options != options) { | ||
m_options = options; | ||||
Michal Klocek
|
r530 | |||
Michal Klocek
|
r2273 | foreach(QAbstractSeries* series, m_series){ | ||
series->d_ptr->initializeAnimations(m_options); | ||||
} | ||||
foreach(QAbstractAxis* axis, m_axes){ | ||||
axis->d_ptr->initializeAnimations(m_options); | ||||
} | ||||
Jani Honkonen
|
r2131 | } | ||
Michal Klocek
|
r531 | } | ||
Michal Klocek
|
r2273 | void ChartPresenter::setState(State state,QPointF point) | ||
Michal Klocek
|
r439 | { | ||
Michal Klocek
|
r2273 | m_state=state; | ||
m_statePoint=point; | ||||
Michal Klocek
|
r531 | } | ||
Michal Klocek
|
r298 | QChart::AnimationOptions ChartPresenter::animationOptions() const | ||
{ | ||||
return m_options; | ||||
} | ||||
Michal Klocek
|
r1534 | void ChartPresenter::createBackgroundItem() | ||
Michal Klocek
|
r855 | { | ||
Michal Klocek
|
r1965 | if (!m_background) { | ||
m_background = new ChartBackground(rootItem()); | ||||
m_background->setPen(Qt::NoPen); | ||||
m_background->setZValue(ChartPresenter::BackgroundZValue); | ||||
Michal Klocek
|
r1534 | } | ||
} | ||||
Michal Klocek
|
r855 | |||
Michal Klocek
|
r1534 | void ChartPresenter::createTitleItem() | ||
{ | ||||
Michal Klocek
|
r1965 | if (!m_title) { | ||
m_title = new ChartTitle(rootItem()); | ||||
m_title->setZValue(ChartPresenter::BackgroundZValue); | ||||
Michal Klocek
|
r1534 | } | ||
} | ||||
Tero Ahola
|
r1524 | |||
Michal Klocek
|
r855 | |||
Michal Klocek
|
r1534 | void ChartPresenter::handleAnimationFinished() | ||
{ | ||||
Jani Honkonen
|
r2131 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); | ||
if (m_animations.empty()) | ||||
emit animationsFinished(); | ||||
Michal Klocek
|
r1534 | } | ||
Michal Klocek
|
r855 | |||
Jani Honkonen
|
r2131 | void ChartPresenter::startAnimation(ChartAnimation *animation) | ||
Michal Klocek
|
r1534 | { | ||
Michal Klocek
|
r2105 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | ||
Jani Honkonen
|
r2131 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); | ||
if (!m_animations.isEmpty()) | ||||
Michal Klocek
|
r1534 | m_animations.append(animation); | ||
QTimer::singleShot(0, animation, SLOT(start())); | ||||
} | ||||
Michal Klocek
|
r855 | |||
Jani Honkonen
|
r2131 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) | ||
Michal Klocek
|
r1534 | { | ||
createBackgroundItem(); | ||||
Michal Klocek
|
r1965 | m_background->setBrush(brush); | ||
Michal Klocek
|
r1534 | m_layout->invalidate(); | ||
} | ||||
Michal Klocek
|
r855 | |||
Michal Klocek
|
r1534 | QBrush ChartPresenter::backgroundBrush() const | ||
{ | ||||
Jani Honkonen
|
r2131 | if (!m_background) | ||
return QBrush(); | ||||
Michal Klocek
|
r1965 | return m_background->brush(); | ||
Michal Klocek
|
r1534 | } | ||
Michal Klocek
|
r855 | |||
Jani Honkonen
|
r2131 | void ChartPresenter::setBackgroundPen(const QPen &pen) | ||
Michal Klocek
|
r1534 | { | ||
createBackgroundItem(); | ||||
Michal Klocek
|
r1965 | m_background->setPen(pen); | ||
Michal Klocek
|
r1534 | m_layout->invalidate(); | ||
} | ||||
Michal Klocek
|
r855 | |||
Michal Klocek
|
r1534 | QPen ChartPresenter::backgroundPen() const | ||
{ | ||||
Jani Honkonen
|
r2131 | if (!m_background) | ||
return QPen(); | ||||
Michal Klocek
|
r1965 | return m_background->pen(); | ||
Michal Klocek
|
r1534 | } | ||
Michal Klocek
|
r913 | |||
Jani Honkonen
|
r2131 | void ChartPresenter::setTitle(const QString &title) | ||
Michal Klocek
|
r1534 | { | ||
createTitleItem(); | ||||
Michal Klocek
|
r1965 | m_title->setText(title); | ||
Michal Klocek
|
r1534 | m_layout->invalidate(); | ||
} | ||||
Michal Klocek
|
r913 | |||
Michal Klocek
|
r1534 | QString ChartPresenter::title() const | ||
{ | ||||
Jani Honkonen
|
r2131 | if (!m_title) | ||
return QString(); | ||||
Michal Klocek
|
r1965 | return m_title->text(); | ||
Michal Klocek
|
r1534 | } | ||
Michal Klocek
|
r855 | |||
Jani Honkonen
|
r2131 | void ChartPresenter::setTitleFont(const QFont &font) | ||
Michal Klocek
|
r1534 | { | ||
createTitleItem(); | ||||
Michal Klocek
|
r1965 | m_title->setFont(font); | ||
Michal Klocek
|
r1534 | m_layout->invalidate(); | ||
} | ||||
Michal Klocek
|
r855 | |||
Michal Klocek
|
r1534 | QFont ChartPresenter::titleFont() const | ||
{ | ||||
Jani Honkonen
|
r2131 | if (!m_title) | ||
return QFont(); | ||||
Michal Klocek
|
r1965 | return m_title->font(); | ||
Michal Klocek
|
r1534 | } | ||
Michal Klocek
|
r913 | |||
Michal Klocek
|
r1534 | void ChartPresenter::setTitleBrush(const QBrush &brush) | ||
{ | ||||
createTitleItem(); | ||||
Michal Klocek
|
r1965 | m_title->setBrush(brush); | ||
Michal Klocek
|
r1534 | m_layout->invalidate(); | ||
} | ||||
Michal Klocek
|
r869 | |||
Michal Klocek
|
r1534 | QBrush ChartPresenter::titleBrush() const | ||
{ | ||||
Jani Honkonen
|
r2131 | if (!m_title) | ||
return QBrush(); | ||||
Michal Klocek
|
r1965 | return m_title->brush(); | ||
Michal Klocek
|
r1534 | } | ||
void ChartPresenter::setBackgroundVisible(bool visible) | ||||
{ | ||||
createBackgroundItem(); | ||||
Michal Klocek
|
r1965 | m_background->setVisible(visible); | ||
Michal Klocek
|
r1534 | } | ||
Michal Klocek
|
r871 | |||
Michal Klocek
|
r855 | |||
Michal Klocek
|
r1534 | bool ChartPresenter::isBackgroundVisible() const | ||
{ | ||||
Jani Honkonen
|
r2131 | if (!m_background) | ||
return false; | ||||
Michal Klocek
|
r1965 | return m_background->isVisible(); | ||
Michal Klocek
|
r855 | } | ||
Michal Klocek
|
r1534 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | ||
Michal Klocek
|
r855 | { | ||
Michal Klocek
|
r1534 | createBackgroundItem(); | ||
Michal Klocek
|
r1965 | m_background->setDropShadowEnabled(enabled); | ||
Michal Klocek
|
r855 | } | ||
Michal Klocek
|
r1534 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | ||
Michal Klocek
|
r855 | { | ||
Jani Honkonen
|
r2131 | if (!m_background) | ||
return false; | ||||
Michal Klocek
|
r1965 | return m_background->isDropShadowEnabled(); | ||
Michal Klocek
|
r855 | } | ||
Michal Klocek
|
r143 | |||
Michal Klocek
|
r1534 | |||
Jani Honkonen
|
r2131 | ChartLayout *ChartPresenter::layout() | ||
Michal Klocek
|
r1241 | { | ||
Michal Klocek
|
r1534 | return m_layout; | ||
Michal Klocek
|
r1241 | } | ||
Jani Honkonen
|
r2131 | QLegend *ChartPresenter::legend() | ||
Michal Klocek
|
r1534 | { | ||
return m_chart->legend(); | ||||
} | ||||
Michal Klocek
|
r1965 | void ChartPresenter::setVisible(bool visible) | ||
{ | ||||
m_chart->setVisible(visible); | ||||
} | ||||
Jani Honkonen
|
r2131 | ChartBackground *ChartPresenter::backgroundElement() | ||
Michal Klocek
|
r1965 | { | ||
return m_background; | ||||
} | ||||
Jani Honkonen
|
r2131 | QList<ChartAxis *> ChartPresenter::axisItems() const | ||
Michal Klocek
|
r1534 | { | ||
Michal Klocek
|
r2273 | return m_axisItems; | ||
Michal Klocek
|
r1534 | } | ||
Michal Klocek
|
r2273 | QList<ChartItem *> ChartPresenter::chartItems() const | ||
Michal Klocek
|
r2105 | { | ||
Michal Klocek
|
r2273 | return m_chartItems; | ||
Michal Klocek
|
r2105 | } | ||
Jani Honkonen
|
r2131 | ChartTitle *ChartPresenter::titleElement() | ||
Michal Klocek
|
r1534 | { | ||
Michal Klocek
|
r1965 | return m_title; | ||
Michal Klocek
|
r1241 | } | ||
Michal Klocek
|
r131 | #include "moc_chartpresenter_p.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||