qchart.cpp
654 lines
| 18.2 KiB
| text/x-c
|
CppLexer
/ src / qchart.cpp
|
r746 | /**************************************************************************** | ||
** | ||||
|
r2432 | ** Copyright (C) 2013 Digia Plc | ||
|
r746 | ** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r12 | #include "qchart.h" | ||
|
r740 | #include "qchart_p.h" | ||
|
r950 | #include "legendscroller_p.h" | ||
#include "qlegend_p.h" | ||||
|
r1006 | #include "chartbackground_p.h" | ||
|
r1541 | #include "qabstractaxis.h" | ||
|
r2105 | #include "chartlayout_p.h" | ||
|
r2273 | #include "charttheme_p.h" | ||
#include "chartpresenter_p.h" | ||||
#include "chartdataset_p.h" | ||||
|
r42 | #include <QGraphicsScene> | ||
|
r115 | #include <QGraphicsSceneResizeEvent> | ||
|
r12 | |||
|
r277 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
/*! | ||||
|
r740 | \enum QChart::ChartTheme | ||
|
r277 | |||
|
r740 | This enum describes the theme used by the chart. | ||
|
r277 | |||
|
r853 | \value ChartThemeLight The default theme | ||
|
r740 | \value ChartThemeBlueCerulean | ||
\value ChartThemeDark | ||||
\value ChartThemeBrownSand | ||||
\value ChartThemeBlueNcs | ||||
|
r757 | \value ChartThemeHighContrast | ||
\value ChartThemeBlueIcy | ||||
|
r740 | */ | ||
|
r277 | |||
|
r302 | /*! | ||
|
r740 | \enum QChart::AnimationOption | ||
|
r302 | |||
|
r740 | For enabling/disabling animations. Defaults to NoAnimation. | ||
|
r302 | |||
|
r740 | \value NoAnimation | ||
\value GridAxisAnimations | ||||
\value SeriesAnimations | ||||
\value AllAnimations | ||||
*/ | ||||
|
r302 | |||
|
r264 | /*! | ||
|
r740 | \class QChart | ||
\brief QtCommercial chart API. | ||||
|
r264 | |||
|
r740 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | ||
|
r1023 | representation of different types of series and other chart related objects like | ||
QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | ||||
|
r740 | convenience class QChartView instead of QChart. | ||
\sa QChartView | ||||
*/ | ||||
|
r264 | |||
|
r1526 | /*! | ||
\property QChart::animationOptions | ||||
The animation \a options for the chart. Animations are enabled/disabled based on this setting. | ||||
*/ | ||||
/*! | ||||
\property QChart::backgroundVisible | ||||
Whether the chart background is visible or not. | ||||
\sa setBackgroundBrush(), setBackgroundPen() | ||||
*/ | ||||
/*! | ||||
\property QChart::dropShadowEnabled | ||||
If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | ||||
shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | ||||
*/ | ||||
/*! | ||||
|
r1982 | \property QChart::minimumMargins | ||
Minimum margins between the plot area (axes) and the edge of the chart widget. | ||||
|
r1526 | */ | ||
|
r2360 | /*! | ||
\property QChart::margins | ||||
Minimum between the plot area (axes) and the edge of the chart widget. | ||||
*/ | ||||
|
r1526 | /*! | ||
\property QChart::theme | ||||
Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | ||||
pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few | ||||
different themes. | ||||
Note: changing the theme will overwrite all customizations previously applied to the series. | ||||
*/ | ||||
/*! | ||||
\property QChart::title | ||||
Title is the name (label) of a chart. It is shown as a headline on top of the chart. | ||||
*/ | ||||
|
r264 | /*! | ||
|
r740 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | ||
*/ | ||||
|
r2131 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | ||
: QGraphicsWidget(parent, wFlags), | ||||
|
r2273 | d_ptr(new QChartPrivate(this)) | ||
|
r12 | { | ||
|
r950 | d_ptr->m_legend = new LegendScroller(this); | ||
|
r2273 | setTheme(QChart::ChartThemeLight); | ||
|
r1534 | setLayout(d_ptr->m_presenter->layout()); | ||
|
r12 | } | ||
|
r264 | /*! | ||
|
r1023 | Destroys the object and it's children, like series and axis objects added to it. | ||
|
r740 | */ | ||
|
r264 | QChart::~QChart() | ||
{ | ||||
|
r2273 | //start by deleting dataset, it will remove all series and axes | ||
delete d_ptr->m_dataset; | ||||
d_ptr->m_dataset = 0; | ||||
|
r264 | } | ||
|
r12 | |||
|
r264 | /*! | ||
|
r1575 | Adds the \a series onto the chart and takes the ownership of the object. | ||
|
r740 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | ||
the y axis). | ||||
|
r1316 | |||
\sa removeSeries(), removeAllSeries() | ||||
|
r740 | */ | ||
|
r1541 | void QChart::addSeries(QAbstractSeries *series) | ||
|
r223 | { | ||
|
r895 | Q_ASSERT(series); | ||
|
r1541 | d_ptr->m_dataset->addSeries(series); | ||
|
r223 | } | ||
|
r42 | |||
|
r274 | /*! | ||
|
r740 | Removes the \a series specified in a perameter from the QChartView. | ||
It releses its ownership of the specified QChartSeries object. | ||||
It does not delete the pointed QChartSeries data object | ||||
\sa addSeries(), removeAllSeries() | ||||
*/ | ||||
|
r988 | void QChart::removeSeries(QAbstractSeries *series) | ||
|
r223 | { | ||
|
r895 | Q_ASSERT(series); | ||
|
r740 | d_ptr->m_dataset->removeSeries(series); | ||
|
r42 | } | ||
|
r48 | |||
|
r274 | /*! | ||
|
r740 | Removes all the QChartSeries that have been added to the QChartView | ||
It also deletes the pointed QChartSeries data objects | ||||
\sa addSeries(), removeSeries() | ||||
*/ | ||||
|
r258 | void QChart::removeAllSeries() | ||
{ | ||||
|
r2284 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | ||
removeSeries(s); | ||||
delete s; | ||||
} | ||||
|
r258 | } | ||
|
r287 | /*! | ||
|
r740 | Sets the \a brush that is used for painting the background of the chart area. | ||
*/ | ||||
|
r2131 | void QChart::setBackgroundBrush(const QBrush &brush) | ||
|
r122 | { | ||
|
r1534 | d_ptr->m_presenter->setBackgroundBrush(brush); | ||
|
r122 | } | ||
|
r924 | /*! | ||
Gets the brush that is used for painting the background of the chart area. | ||||
*/ | ||||
|
r645 | QBrush QChart::backgroundBrush() const | ||
{ | ||||
|
r1534 | return d_ptr->m_presenter->backgroundBrush(); | ||
|
r645 | } | ||
|
r287 | /*! | ||
|
r740 | Sets the \a pen that is used for painting the background of the chart area. | ||
*/ | ||||
|
r2131 | void QChart::setBackgroundPen(const QPen &pen) | ||
|
r122 | { | ||
|
r1534 | d_ptr->m_presenter->setBackgroundPen(pen); | ||
|
r122 | } | ||
|
r924 | /*! | ||
Gets the pen that is used for painting the background of the chart area. | ||||
*/ | ||||
|
r645 | QPen QChart::backgroundPen() const | ||
{ | ||||
|
r1534 | return d_ptr->m_presenter->backgroundPen(); | ||
|
r645 | } | ||
|
r274 | /*! | ||
|
r740 | Sets the chart \a title. The description text that is drawn above the chart. | ||
*/ | ||||
|
r2131 | void QChart::setTitle(const QString &title) | ||
|
r69 | { | ||
|
r1534 | d_ptr->m_presenter->setTitle(title); | ||
|
r476 | } | ||
/*! | ||||
|
r740 | Returns the chart title. The description text that is drawn above the chart. | ||
*/ | ||||
|
r645 | QString QChart::title() const | ||
|
r476 | { | ||
|
r1534 | return d_ptr->m_presenter->title(); | ||
|
r192 | } | ||
|
r274 | /*! | ||
|
r924 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | ||
|
r740 | */ | ||
|
r2131 | void QChart::setTitleFont(const QFont &font) | ||
|
r192 | { | ||
|
r1534 | d_ptr->m_presenter->setTitleFont(font); | ||
|
r69 | } | ||
|
r924 | /*! | ||
Gets the font that is used for drawing the chart description text that is rendered above the chart. | ||||
*/ | ||||
|
r895 | QFont QChart::titleFont() const | ||
{ | ||||
|
r1534 | return d_ptr->m_presenter->titleFont(); | ||
|
r895 | } | ||
|
r495 | /*! | ||
|
r740 | Sets the \a brush used for rendering the title text. | ||
*/ | ||||
|
r645 | void QChart::setTitleBrush(const QBrush &brush) | ||
|
r495 | { | ||
|
r1534 | d_ptr->m_presenter->setTitleBrush(brush); | ||
|
r495 | } | ||
/*! | ||||
|
r740 | Returns the brush used for rendering the title text. | ||
*/ | ||||
|
r645 | QBrush QChart::titleBrush() const | ||
|
r495 | { | ||
|
r1534 | return d_ptr->m_presenter->titleBrush(); | ||
|
r223 | } | ||
|
r740 | void QChart::setTheme(QChart::ChartTheme theme) | ||
|
r64 | { | ||
|
r2273 | d_ptr->m_themeManager->setTheme(theme); | ||
|
r64 | } | ||
|
r740 | QChart::ChartTheme QChart::theme() const | ||
|
r120 | { | ||
|
r2273 | return d_ptr->m_themeManager->theme()->id(); | ||
|
r120 | } | ||
|
r285 | /*! | ||
|
r740 | Zooms in the view by a factor of 2 | ||
*/ | ||||
|
r223 | void QChart::zoomIn() | ||
|
r67 | { | ||
|
r2273 | d_ptr->zoomIn(2.0); | ||
|
r67 | } | ||
|
r285 | /*! | ||
|
r740 | Zooms in the view to a maximum level at which \a rect is still fully visible. | ||
*/ | ||||
|
r2131 | void QChart::zoomIn(const QRectF &rect) | ||
|
r67 | { | ||
|
r2344 | d_ptr->zoomIn(rect); | ||
|
r67 | } | ||
|
r285 | /*! | ||
|
r740 | Restores the view zoom level to the previous one. | ||
*/ | ||||
|
r67 | void QChart::zoomOut() | ||
{ | ||||
|
r2273 | d_ptr->zoomOut(2.0); | ||
|
r1187 | } | ||
/*! | ||||
Zooms in the view by a \a factor. | ||||
A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | ||||
*/ | ||||
void QChart::zoom(qreal factor) | ||||
{ | ||||
|
r2242 | if (qFuzzyCompare(factor, 0)) | ||
|
r1187 | return; | ||
|
r1679 | if (qFuzzyCompare(factor, (qreal)1.0)) | ||
|
r1187 | return; | ||
if (factor < 0) | ||||
return; | ||||
if (factor > 1.0) | ||||
|
r2273 | d_ptr->zoomIn(factor); | ||
|
r1187 | else | ||
|
r2273 | d_ptr->zoomOut(1.0 / factor); | ||
|
r67 | } | ||
|
r277 | /*! | ||
|
r1633 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | ||
|
r1638 | If no series is provided then pointer to currently visible axis is provided | ||
|
r740 | */ | ||
|
r2131 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | ||
|
r176 | { | ||
|
r2384 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | ||
if (axisList.count()) | ||||
return axisList[0]; | ||||
return 0; | ||||
|
r176 | } | ||
|
r277 | /*! | ||
|
r1633 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | ||
|
r1638 | If no series is provided then pointer to currently visible axis is provided | ||
|
r740 | */ | ||
|
r2131 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | ||
|
r176 | { | ||
|
r2384 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | ||
if (axisList.count()) | ||||
return axisList[0]; | ||||
return 0; | ||||
|
r2273 | } | ||
|
r2360 | /*! | ||
|
r2384 | Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the | ||
specified orientation are returned. | ||||
|
r2360 | \sa addAxis(), createDefaultAxes() | ||
*/ | ||||
|
r2273 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | ||
{ | ||||
QList<QAbstractAxis *> result ; | ||||
|
r2296 | if (series) { | ||
foreach (QAbstractAxis *axis, series->attachedAxes()){ | ||||
if (orientation.testFlag(axis->orientation())) | ||||
result << axis; | ||||
} | ||||
} else { | ||||
|
r2384 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | ||
if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | ||||
result << axis; | ||||
|
r2296 | } | ||
|
r2273 | } | ||
return result; | ||||
|
r85 | } | ||
|
r1633 | /*! | ||
NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. | ||||
Creates the axes for the chart based on the series that has already been added to the chart. | ||||
|
r1638 | |||
\table | ||||
\header | ||||
\o Series type | ||||
\o X-axis | ||||
\o Y-axis | ||||
\row | ||||
\o QXYSeries | ||||
|
r1804 | \o QValueAxis | ||
\o QValueAxis | ||||
|
r1638 | \row | ||
\o QBarSeries | ||||
|
r1809 | \o QBarCategoryAxis | ||
|
r1804 | \o QValueAxis | ||
|
r1638 | \row | ||
\o QPieSeries | ||||
\o None | ||||
\o None | ||||
\endtable | ||||
|
r1633 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. | ||
If there are sevaral series added of different types then each series gets its own axes pair. | ||||
NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. | ||||
Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. | ||||
QPieSeries does not create any axes. | ||||
\sa axisX(), axisY(), setAxisX(), setAxisY() | ||||
*/ | ||||
|
r1577 | void QChart::createDefaultAxes() | ||
{ | ||||
|
r2131 | d_ptr->m_dataset->createDefaultAxes(); | ||
|
r1577 | } | ||
|
r524 | /*! | ||
|
r740 | Returns the legend object of the chart. Ownership stays in chart. | ||
*/ | ||||
|
r2131 | QLegend *QChart::legend() const | ||
|
r524 | { | ||
|
r783 | return d_ptr->m_legend; | ||
|
r524 | } | ||
|
r2272 | /*! | ||
Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | ||||
Deprecated. Use setMargins(). | ||||
*/ | ||||
void QChart::setMinimumMargins(const QMargins &margins) | ||||
{ | ||||
qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | ||||
d_ptr->m_presenter->layout()->setMargins(margins); | ||||
} | ||||
/*! | ||||
Returns the rect that contains information about margins (distance between chart widget edge and axes). | ||||
Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | ||||
Deprecated. Use margins(). | ||||
*/ | ||||
QMargins QChart::minimumMargins() const | ||||
{ | ||||
qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | ||||
return d_ptr->m_presenter->layout()->margins(); | ||||
} | ||||
|
r1883 | /*! | ||
Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | ||||
*/ | ||||
|
r2131 | void QChart::setMargins(const QMargins &margins) | ||
|
r1883 | { | ||
|
r2105 | d_ptr->m_presenter->layout()->setMargins(margins); | ||
|
r1883 | } | ||
|
r924 | /*! | ||
Returns the rect that contains information about margins (distance between chart widget edge and axes). | ||||
Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | ||||
*/ | ||||
|
r1965 | QMargins QChart::margins() const | ||
|
r803 | { | ||
|
r2105 | return d_ptr->m_presenter->layout()->margins(); | ||
|
r803 | } | ||
|
r1657 | /*! | ||
Returns the the rect within which the drawing of the chart is done. | ||||
It does not include the area defines by margins. | ||||
*/ | ||||
|
r1648 | QRectF QChart::plotArea() const | ||
{ | ||||
|
r2273 | return d_ptr->m_presenter->geometry(); | ||
|
r1648 | } | ||
|
r287 | /*! | ||
|
r1534 | Sets animation \a options for the chart | ||
|
r740 | */ | ||
|
r298 | void QChart::setAnimationOptions(AnimationOptions options) | ||
{ | ||||
|
r740 | d_ptr->m_presenter->setAnimationOptions(options); | ||
|
r298 | } | ||
QChart::AnimationOptions QChart::animationOptions() const | ||||
{ | ||||
|
r740 | return d_ptr->m_presenter->animationOptions(); | ||
|
r298 | } | ||
|
r1187 | /*! | ||
|
r1575 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | ||
|
r1187 | */ | ||
|
r1553 | void QChart::scroll(qreal dx, qreal dy) | ||
|
r1187 | { | ||
|
r2273 | d_ptr->scroll(dx,dy); | ||
|
r1187 | } | ||
|
r740 | void QChart::setBackgroundVisible(bool visible) | ||
{ | ||||
|
r1534 | d_ptr->m_presenter->setBackgroundVisible(visible); | ||
|
r740 | } | ||
|
r716 | |||
|
r740 | bool QChart::isBackgroundVisible() const | ||
{ | ||||
|
r1534 | return d_ptr->m_presenter->isBackgroundVisible(); | ||
|
r716 | } | ||
|
r1462 | void QChart::setDropShadowEnabled(bool enabled) | ||
|
r1001 | { | ||
|
r1534 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | ||
|
r1001 | } | ||
|
r1462 | bool QChart::isDropShadowEnabled() const | ||
|
r1001 | { | ||
|
r1534 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | ||
|
r1001 | } | ||
|
r1316 | /*! | ||
Returns all the series that are added to the chart. | ||||
\sa addSeries(), removeSeries(), removeAllSeries() | ||||
*/ | ||||
|
r2131 | QList<QAbstractSeries *> QChart::series() const | ||
|
r1107 | { | ||
return d_ptr->m_dataset->series(); | ||||
} | ||||
|
r1534 | |||
|
r1633 | /*! | ||
Sets \a axis to the chart, which will control the presentation of the \a series | ||||
\sa axisX(), axisY(), setAxisY(), createDefaultAxes() | ||||
*/ | ||||
|
r2131 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | ||
|
r1541 | { | ||
|
r2344 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); | ||
|
r2273 | |||
|
r2344 | foreach(QAbstractAxis* a, list){ | ||
|
r2278 | d_ptr->m_dataset->removeAxis(a); | ||
delete a; | ||||
|
r2344 | } | ||
|
r2273 | |||
|
r2344 | if(!d_ptr->m_dataset->axes().contains(axis)) | ||
d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); | ||||
d_ptr->m_dataset->attachAxis(series,axis); | ||||
|
r1541 | } | ||
|
r1633 | /*! | ||
Sets \a axis to the chart, which will control the presentation of the \a series | ||||
\sa axisX(), axisY(), setAxisX(), createDefaultAxes() | ||||
*/ | ||||
|
r2131 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) | ||
|
r1541 | { | ||
|
r2273 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); | ||
foreach(QAbstractAxis* a, list) { | ||||
|
r2278 | d_ptr->m_dataset->removeAxis(a); | ||
delete a; | ||||
|
r2273 | } | ||
if(!d_ptr->m_dataset->axes().contains(axis)) | ||||
|
r2344 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); | ||
|
r2273 | d_ptr->m_dataset->attachAxis(series,axis); | ||
} | ||||
|
r2360 | /*! | ||
Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | ||||
\sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | ||||
*/ | ||||
void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | ||||
|
r2273 | { | ||
|
r2360 | d_ptr->m_dataset->addAxis(axis, alignment); | ||
|
r2273 | } | ||
|
r2360 | /*! | ||
Removes \a axis from the chart. The ownership is returned to the caller. | ||||
\sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | ||||
*/ | ||||
|
r2273 | void QChart::removeAxis(QAbstractAxis *axis) | ||
{ | ||||
|
r2344 | d_ptr->m_dataset->removeAxis(axis); | ||
} | ||||
|
r2357 | /*! | ||
|
r2456 | Returns the value in the \a series domain that corresponds to the charts widget point defines by \a position. | ||
|
r2357 | */ | ||
|
r2344 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | ||
{ | ||||
return d_ptr->m_dataset->mapToValue(position, series); | ||||
} | ||||
|
r2357 | /*! | ||
|
r2456 | Returns the position on the charts widget that corresponds to the \a value in the \a series domain. | ||
|
r2357 | */ | ||
|
r2344 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | ||
{ | ||||
return d_ptr->m_dataset->mapToPosition(value, series); | ||||
|
r1541 | } | ||
|
r740 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r639 | |||
|
r2273 | QChartPrivate::QChartPrivate(QChart *q): | ||
q_ptr(q), | ||||
|
r924 | m_legend(0), | ||
|
r2273 | m_dataset(new ChartDataSet(q)), | ||
m_presenter(new ChartPresenter(q)), | ||||
m_themeManager(new ChartThemeManager(q)) | ||||
|
r639 | { | ||
|
r2273 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | ||
QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | ||||
QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | ||||
QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | ||||
QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | ||||
QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | ||||
QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | ||||
QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | ||||
|
r639 | } | ||
|
r740 | QChartPrivate::~QChartPrivate() | ||
|
r639 | { | ||
|
r740 | |||
|
r639 | } | ||
|
r2273 | void QChartPrivate::zoomIn(qreal factor) | ||
|
r871 | { | ||
|
r2273 | QRectF rect = m_presenter->geometry(); | ||
rect.setWidth(rect.width() / factor); | ||||
rect.setHeight(rect.height() / factor); | ||||
rect.moveCenter(m_presenter->geometry().center()); | ||||
zoomIn(rect); | ||||
} | ||||
void QChartPrivate::zoomIn(const QRectF &rect) | ||||
{ | ||||
if (!rect.isValid()) | ||||
|
r2344 | return; | ||
|
r2273 | |||
QRectF r = rect.normalized(); | ||||
const QRectF geometry = m_presenter->geometry(); | ||||
r.translate(-geometry.topLeft()); | ||||
if (!r.isValid()) | ||||
return; | ||||
QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | ||||
m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | ||||
m_dataset->zoomInDomain(r); | ||||
m_presenter->setState(ChartPresenter::ShowState,QPointF()); | ||||
} | ||||
void QChartPrivate::zoomOut(qreal factor) | ||||
{ | ||||
const QRectF geometry = m_presenter->geometry(); | ||||
QRectF r; | ||||
r.setSize(geometry.size() / factor); | ||||
r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | ||||
if (!r.isValid()) | ||||
return; | ||||
QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | ||||
m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | ||||
m_dataset->zoomOutDomain(r); | ||||
m_presenter->setState(ChartPresenter::ShowState,QPointF()); | ||||
} | ||||
void QChartPrivate::scroll(qreal dx, qreal dy) | ||||
{ | ||||
if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | ||||
if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | ||||
if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | ||||
if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | ||||
m_dataset->scrollDomain(dx, dy); | ||||
m_presenter->setState(ChartPresenter::ShowState,QPointF()); | ||||
|
r871 | } | ||
|
r64 | #include "moc_qchart.cpp" | ||
|
r48 | |||
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||