qchart.cpp
887 lines
| 24.5 KiB
| text/x-c
|
CppLexer
|
r2845 | /****************************************************************************** | ||
|
r746 | ** | ||
|
r2845 | ** Copyright (C) 2015 The Qt Company Ltd. | ||
** Contact: http://www.qt.io/licensing/ | ||||
|
r746 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r746 | ** | ||
|
r2845 | ** $QT_BEGIN_LICENSE:COMM$ | ||
|
r746 | ** | ||
|
r2845 | ** Commercial License Usage | ||
** Licensees holding valid commercial Qt licenses may use this file in | ||||
** accordance with the commercial license agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and The Qt Company. For licensing terms | ||||
** and conditions see http://www.qt.io/terms-conditions. For further | ||||
** information use the contact form at http://www.qt.io/contact-us. | ||||
|
r746 | ** | ||
|
r2845 | ** $QT_END_LICENSE$ | ||
** | ||||
******************************************************************************/ | ||||
|
r746 | |||
|
r2714 | #include <QtCharts/QChart> | ||
#include <private/qchart_p.h> | ||||
#include <private/legendscroller_p.h> | ||||
#include <private/qlegend_p.h> | ||||
#include <private/chartbackground_p.h> | ||||
#include <QtCharts/QAbstractAxis> | ||||
#include <private/abstractchartlayout_p.h> | ||||
#include <private/charttheme_p.h> | ||||
#include <private/chartpresenter_p.h> | ||||
#include <private/chartdataset_p.h> | ||||
#include <QtWidgets/QGraphicsScene> | ||||
|
r115 | #include <QGraphicsSceneResizeEvent> | ||
|
r12 | |||
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
|
r277 | |||
/*! | ||||
|
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 | ||||
|
r2632 | \value ChartThemeQt | ||
|
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 | |||
|
r2483 | /*! | ||
\enum QChart::ChartType | ||||
This enum describes the chart type. | ||||
\value ChartTypeUndefined | ||||
\value ChartTypeCartesian | ||||
\value ChartTypePolar | ||||
*/ | ||||
|
r264 | /*! | ||
|
r740 | \class QChart | ||
|
r2639 | \inmodule Qt Charts | ||
|
r2591 | \brief Main chart API for Qt Charts. | ||
|
r264 | |||
|
r740 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | ||
|
r2494 | representation of different types of series and other chart related objects like legend and | ||
axes. If you simply want to show a chart in a layout, you can use the | ||||
|
r740 | convenience class QChartView instead of QChart. | ||
|
r2494 | \sa QChartView, QPolarChart | ||
|
r740 | */ | ||
|
r264 | |||
|
r1526 | /*! | ||
\property QChart::animationOptions | ||||
The animation \a options for the chart. Animations are enabled/disabled based on this setting. | ||||
*/ | ||||
|
r2804 | /*! | ||
\property QChart::animationDuration | ||||
The duration of the animation for the chart. | ||||
*/ | ||||
/*! | ||||
\property QChart::animationEasingCurve | ||||
The easing curve of the animation for the chart. | ||||
*/ | ||||
|
r1526 | /*! | ||
\property QChart::backgroundVisible | ||||
|
r2494 | Specifies whether the chart background is visible or not. | ||
|
r2498 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible | ||
|
r1526 | */ | ||
/*! | ||||
\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. | ||||
*/ | ||||
|
r2549 | /*! | ||
\property QChart::backgroundRoundness | ||||
|
r2785 | The diameter of the rounding circle at the corners of the chart background. | ||
|
r2549 | */ | ||
|
r2360 | /*! | ||
\property QChart::margins | ||||
|
r2494 | Margins between the plot area (axes) and the edge of the chart widget. | ||
|
r2360 | */ | ||
|
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, | ||||
|
r2712 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes example} shows an example with a few | ||
|
r1526 | different themes. | ||
|
r2494 | \note Changing the theme will overwrite all customizations previously applied to the series. | ||
|
r1526 | */ | ||
/*! | ||||
\property QChart::title | ||||
|
r2539 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. | ||
|
r1526 | */ | ||
|
r264 | /*! | ||
|
r2483 | \property QChart::chartType | ||
Chart type indicates if the chart is a cartesian chart or a polar chart. | ||||
|
r2494 | This property is set internally and it is read only. | ||
|
r2483 | \sa QPolarChart | ||
*/ | ||||
|
r2498 | /*! | ||
\property QChart::plotAreaBackgroundVisible | ||||
Specifies whether the chart plot area background is visible or not. | ||||
\note By default the plot area background is not visible and the plot area uses | ||||
the general chart background. | ||||
\sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible | ||||
*/ | ||||
|
r2707 | /*! | ||
\property QChart::localizeNumbers | ||||
\since QtCharts 2.0 | ||||
When \c{true}, all generated numbers appearing in various series and axis labels will be | ||||
|
r2708 | localized using the QLocale set with the locale property. | ||
|
r2707 | When \c{false}, the "C" locale is always used. | ||
|
r2710 | Defaults to \c{false}. | ||
|
r2708 | \note This property doesn't affect QDateTimeAxis labels, which always use the QLocale set with | ||
the locale property. | ||||
\sa locale | ||||
*/ | ||||
/*! | ||||
\property QChart::locale | ||||
\since QtCharts 2.0 | ||||
Sets the locale used to format various chart labels when localizeNumbers is \c{true}. | ||||
This also determines the locale used to format QDateTimeAxis labels regardless of | ||||
localizeNumbers property. | ||||
Defaults to application default locale at the time the chart is constructed. | ||||
\sa localizeNumbers | ||||
|
r2707 | */ | ||
|
r2716 | /*! | ||
\property QChart::plotArea | ||||
Holds the rectangle within which the drawing of the chart is done. | ||||
It does not include the area defined by margins. | ||||
*/ | ||||
|
r2483 | /*! | ||
\internal | ||||
Constructs a chart object of \a type which is a child of a \a parent. | ||||
Parameter \a wFlags is passed to the QGraphicsWidget constructor. | ||||
This constructor is called only by subclasses. | ||||
*/ | ||||
QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) | ||||
: QGraphicsWidget(parent, wFlags), | ||||
d_ptr(new QChartPrivate(this, type)) | ||||
{ | ||||
d_ptr->init(); | ||||
} | ||||
/*! | ||||
Constructs a chart object which is a child of a \a parent. | ||||
Parameter \a wFlags is passed to the QGraphicsWidget constructor. | ||||
|
r740 | */ | ||
|
r2131 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | ||
: QGraphicsWidget(parent, wFlags), | ||||
|
r2483 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) | ||
|
r12 | { | ||
|
r2483 | d_ptr->init(); | ||
|
r12 | } | ||
|
r264 | /*! | ||
|
r2494 | Destroys the chart object and its 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 | /*! | ||
|
r2494 | Adds the \a series onto the chart and takes the ownership of it. | ||
\note A newly added series is attached to no axes by default, including any axes that were created for the chart | ||||
using createDefaultAxes() before the series was added to the chart. If no axes are attached to | ||||
the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges | ||||
that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other | ||||
series that have properly attached axes, so always make sure you either call createDefaultAxes() after | ||||
a series has been added or explicitly attach axes for the series. | ||||
|
r1316 | |||
|
r2494 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() | ||
|
r740 | */ | ||
|
r1541 | void QChart::addSeries(QAbstractSeries *series) | ||
|
r223 | { | ||
|
r895 | Q_ASSERT(series); | ||
|
r1541 | d_ptr->m_dataset->addSeries(series); | ||
|
r223 | } | ||
|
r42 | |||
|
r274 | /*! | ||
|
r2494 | Removes the \a series from the chart. | ||
The chart releases its ownership of the specified \a series object. | ||||
|
r740 | \sa addSeries(), removeAllSeries() | ||
*/ | ||||
|
r988 | void QChart::removeSeries(QAbstractSeries *series) | ||
|
r223 | { | ||
|
r895 | Q_ASSERT(series); | ||
|
r740 | d_ptr->m_dataset->removeSeries(series); | ||
|
r42 | } | ||
|
r48 | |||
|
r274 | /*! | ||
|
r2494 | Removes and deletes all series objects that have been added to the chart. | ||
|
r740 | \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 | /*! | ||
|
r2494 | Gets the brush that is used for painting the background of the chart area. | ||
|
r924 | */ | ||
|
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 | /*! | ||
|
r2494 | Gets the pen that is used for painting the background of the chart area. | ||
|
r924 | */ | ||
|
r645 | QPen QChart::backgroundPen() const | ||
{ | ||||
|
r1534 | return d_ptr->m_presenter->backgroundPen(); | ||
|
r645 | } | ||
|
r2131 | void QChart::setTitle(const QString &title) | ||
|
r69 | { | ||
|
r1534 | d_ptr->m_presenter->setTitle(title); | ||
|
r476 | } | ||
|
r645 | QString QChart::title() const | ||
|
r476 | { | ||
|
r1534 | return d_ptr->m_presenter->title(); | ||
|
r192 | } | ||
|
r274 | /*! | ||
|
r2494 | Sets the \a font that is used for drawing the chart title. | ||
|
r740 | */ | ||
|
r2131 | void QChart::setTitleFont(const QFont &font) | ||
|
r192 | { | ||
|
r1534 | d_ptr->m_presenter->setTitleFont(font); | ||
|
r69 | } | ||
|
r924 | /*! | ||
|
r2494 | Gets the font that is used for drawing the chart title. | ||
|
r924 | */ | ||
|
r895 | QFont QChart::titleFont() const | ||
{ | ||||
|
r1534 | return d_ptr->m_presenter->titleFont(); | ||
|
r895 | } | ||
|
r495 | /*! | ||
|
r2494 | Sets the \a brush used for drawing the title text. | ||
|
r740 | */ | ||
|
r645 | void QChart::setTitleBrush(const QBrush &brush) | ||
|
r495 | { | ||
|
r1534 | d_ptr->m_presenter->setTitleBrush(brush); | ||
|
r495 | } | ||
/*! | ||||
|
r2494 | Returns the brush used for drawing the title text. | ||
|
r740 | */ | ||
|
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 | /*! | ||
|
r2494 | Zooms in the view by a factor of two. | ||
|
r740 | */ | ||
|
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. | ||
|
r2483 | \note This is not supported for polar charts. | ||
|
r740 | */ | ||
|
r2131 | void QChart::zoomIn(const QRectF &rect) | ||
|
r67 | { | ||
|
r2483 | if (d_ptr->m_type == QChart::ChartTypePolar) | ||
return; | ||||
|
r2344 | d_ptr->zoomIn(rect); | ||
|
r67 | } | ||
|
r285 | /*! | ||
|
r2494 | Zooms out the view by a factor of two. | ||
|
r740 | */ | ||
|
r67 | void QChart::zoomOut() | ||
{ | ||||
|
r2273 | d_ptr->zoomOut(2.0); | ||
|
r1187 | } | ||
/*! | ||||
|
r2494 | Zooms in the view by a custom \a factor. | ||
|
r1187 | |||
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 | } | ||
|
r2545 | |||
/*! | ||||
Resets the series domains to what they were before any zoom method was called. | ||||
Note that this will also reset any scrolls and explicit axis range settings done between | ||||
the first zoom operation and calling this method. If no zoom operation has been | ||||
done, this method does nothing. | ||||
*/ | ||||
void QChart::zoomReset() | ||||
{ | ||||
d_ptr->zoomReset(); | ||||
} | ||||
/*! | ||||
Returns true if any series has a zoomed domain. | ||||
*/ | ||||
bool QChart::isZoomed() | ||||
{ | ||||
return d_ptr->isZoomed(); | ||||
} | ||||
|
r277 | /*! | ||
|
r2494 | Returns a pointer to the horizontal axis attached to the specified \a series. | ||
If no \a series is specified, the first horizontal axis added to the chart is returned. | ||||
\sa addAxis(), QAbstractSeries::attachAxis() | ||||
|
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 | /*! | ||
|
r2494 | Returns a pointer to the vertical axis attached to the specified \a series. | ||
If no \a series is specified, the first vertical axis added to the chart is returned. | ||||
\sa addAxis(), QAbstractSeries::attachAxis() | ||||
|
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 | /*! | ||
|
r2494 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, | ||
then all axes added to the chart 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 | /*! | ||
|
r2494 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to | ||
the chart will be deleted. | ||||
|
r1633 | |||
|
r2494 | \note This function has to be called after all series have been added to the chart. The axes created by this function | ||
will NOT get automatically attached to any series added to the chart after this function has been called. | ||||
A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing | ||||
if there are other series with properly attached axes also present. | ||||
|
r1638 | |||
|
r2494 | \table | ||
|
r1638 | \header | ||
|
r2639 | \li Series type | ||
\li X-axis | ||||
\li Y-axis | ||||
|
r1638 | \row | ||
|
r2639 | \li QXYSeries | ||
\li QValueAxis | ||||
\li QValueAxis | ||||
|
r1638 | \row | ||
|
r2639 | \li QBarSeries | ||
\li QBarCategoryAxis | ||||
\li QValueAxis | ||||
|
r1638 | \row | ||
|
r2639 | \li QPieSeries | ||
\li None | ||||
\li None | ||||
|
r2494 | \endtable | ||
|
r1638 | |||
|
r2494 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. | ||
If there are several series of different types added to the chart, then each series gets its own axes pair. | ||||
|
r1633 | |||
|
r2494 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. | ||
|
r1633 | QPieSeries does not create any axes. | ||
|
r2494 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() | ||
|
r1633 | */ | ||
|
r1577 | void QChart::createDefaultAxes() | ||
{ | ||||
|
r2131 | d_ptr->m_dataset->createDefaultAxes(); | ||
|
r1577 | } | ||
|
r524 | /*! | ||
|
r2494 | Returns the legend object of the chart. Ownership stays with the chart. | ||
|
r740 | */ | ||
|
r2131 | QLegend *QChart::legend() const | ||
|
r524 | { | ||
|
r783 | return d_ptr->m_legend; | ||
|
r524 | } | ||
|
r2131 | void QChart::setMargins(const QMargins &margins) | ||
|
r1883 | { | ||
|
r2105 | d_ptr->m_presenter->layout()->setMargins(margins); | ||
|
r1883 | } | ||
|
r1965 | QMargins QChart::margins() const | ||
|
r803 | { | ||
|
r2105 | return d_ptr->m_presenter->layout()->margins(); | ||
|
r803 | } | ||
|
r2483 | QChart::ChartType QChart::chartType() const | ||
{ | ||||
return d_ptr->m_type; | ||||
} | ||||
|
r1648 | QRectF QChart::plotArea() const | ||
{ | ||||
|
r2273 | return d_ptr->m_presenter->geometry(); | ||
|
r1648 | } | ||
|
r2498 | /*! | ||
Sets the \a brush for the background of the plot area of the chart. | ||||
\sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() | ||||
*/ | ||||
void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) | ||||
{ | ||||
d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); | ||||
} | ||||
/*! | ||||
Returns the brush for the background of the plot area of the chart. | ||||
\sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() | ||||
*/ | ||||
QBrush QChart::plotAreaBackgroundBrush() const | ||||
{ | ||||
return d_ptr->m_presenter->plotAreaBackgroundBrush(); | ||||
} | ||||
/*! | ||||
Sets the \a pen for the background of the plot area of the chart. | ||||
\sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() | ||||
*/ | ||||
void QChart::setPlotAreaBackgroundPen(const QPen &pen) | ||||
{ | ||||
d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); | ||||
} | ||||
/*! | ||||
|
r2503 | Returns the pen for the background of the plot area of the chart. | ||
|
r2498 | |||
\sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() | ||||
*/ | ||||
QPen QChart::plotAreaBackgroundPen() const | ||||
{ | ||||
return d_ptr->m_presenter->plotAreaBackgroundPen(); | ||||
} | ||||
void QChart::setPlotAreaBackgroundVisible(bool visible) | ||||
{ | ||||
d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); | ||||
} | ||||
bool QChart::isPlotAreaBackgroundVisible() const | ||||
{ | ||||
return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); | ||||
} | ||||
|
r2707 | void QChart::setLocalizeNumbers(bool localize) | ||
{ | ||||
d_ptr->m_presenter->setLocalizeNumbers(localize); | ||||
} | ||||
bool QChart::localizeNumbers() const | ||||
{ | ||||
return d_ptr->m_presenter->localizeNumbers(); | ||||
} | ||||
|
r2708 | void QChart::setLocale(const QLocale &locale) | ||
{ | ||||
d_ptr->m_presenter->setLocale(locale); | ||||
} | ||||
QLocale QChart::locale() const | ||||
{ | ||||
return d_ptr->m_presenter->locale(); | ||||
} | ||||
|
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 | } | ||
|
r2804 | void QChart::setAnimationDuration(int msecs) | ||
{ | ||||
d_ptr->m_presenter->setAnimationDuration(msecs); | ||||
} | ||||
int QChart::animationDuration() const | ||||
{ | ||||
return d_ptr->m_presenter->animationDuration(); | ||||
} | ||||
void QChart::setAnimationEasingCurve(const QEasingCurve &curve) | ||||
{ | ||||
d_ptr->m_presenter->setAnimationEasingCurve(curve); | ||||
} | ||||
QEasingCurve QChart::animationEasingCurve() const | ||||
{ | ||||
return d_ptr->m_presenter->animationEasingCurve(); | ||||
} | ||||
|
r1187 | /*! | ||
|
r1575 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | ||
|
r2483 | |||
For polar charts, \a dx indicates the angle along angular axis instead of distance. | ||||
|
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 | } | ||
|
r2549 | void QChart::setBackgroundRoundness(qreal diameter) | ||
{ | ||||
d_ptr->m_presenter->setBackgroundRoundness(diameter); | ||||
} | ||||
qreal QChart::backgroundRoundness() const | ||||
{ | ||||
return d_ptr->m_presenter->backgroundRoundness(); | ||||
} | ||||
|
r1316 | /*! | ||
|
r2494 | Returns all series that are added to the chart. | ||
|
r1316 | |||
\sa addSeries(), removeSeries(), removeAllSeries() | ||||
*/ | ||||
|
r2131 | QList<QAbstractSeries *> QChart::series() const | ||
|
r1107 | { | ||
return d_ptr->m_dataset->series(); | ||||
} | ||||
|
r1534 | |||
|
r1633 | /*! | ||
|
r2494 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. | ||
The chart takes ownership of both the \a axis and the \a series. | ||||
Any horizontal axes previously attached to the \a series are deleted. | ||||
|
r1633 | |||
|
r2494 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() | ||
|
r1633 | */ | ||
|
r2494 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) | ||
|
r1541 | { | ||
|
r2494 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); | ||
|
r2273 | |||
|
r2494 | foreach (QAbstractAxis* a, list) { | ||
|
r2278 | d_ptr->m_dataset->removeAxis(a); | ||
delete a; | ||||
|
r2344 | } | ||
|
r2273 | |||
|
r2494 | 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 | /*! | ||
|
r2494 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. | ||
The chart takes ownership of both the \a axis and the \a series. | ||||
Any vertical axes previously attached to the \a series are deleted. | ||||
|
r1633 | |||
|
r2494 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() | ||
|
r1633 | */ | ||
|
r2494 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) | ||
|
r1541 | { | ||
|
r2494 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); | ||
|
r2273 | |||
|
r2494 | foreach (QAbstractAxis* a, list) { | ||
|
r2278 | d_ptr->m_dataset->removeAxis(a); | ||
delete a; | ||||
|
r2273 | } | ||
|
r2494 | if (!d_ptr->m_dataset->axes().contains(axis)) | ||
d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); | ||||
d_ptr->m_dataset->attachAxis(series, axis); | ||||
|
r2273 | } | ||
|
r2360 | /*! | ||
|
r2494 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | ||
|
r2360 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | ||
*/ | ||||
void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | ||||
|
r2273 | { | ||
|
r2360 | d_ptr->m_dataset->addAxis(axis, alignment); | ||
|
r2273 | } | ||
|
r2360 | /*! | ||
|
r2494 | Removes the \a axis from the chart. | ||
The chart releases its ownership of the specified \a axis object. | ||||
|
r2360 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | ||
*/ | ||||
|
r2273 | void QChart::removeAxis(QAbstractAxis *axis) | ||
{ | ||||
|
r2344 | d_ptr->m_dataset->removeAxis(axis); | ||
} | ||||
|
r2357 | /*! | ||
|
r2494 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. | ||
|
r2357 | */ | ||
|
r2344 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | ||
{ | ||||
return d_ptr->m_dataset->mapToValue(position, series); | ||||
} | ||||
|
r2357 | /*! | ||
|
r2494 | Returns the position on the chart 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 | |||
|
r2483 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): | ||
|
r2273 | q_ptr(q), | ||
|
r924 | m_legend(0), | ||
|
r2273 | m_dataset(new ChartDataSet(q)), | ||
|
r2483 | m_presenter(new ChartPresenter(q, type)), | ||
|
r2504 | m_themeManager(new ChartThemeManager(q)), | ||
m_type(type) | ||||
|
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*))); | ||||
|
r2716 | QObject::connect(m_presenter, &ChartPresenter::plotAreaChanged, q, &QChart::plotAreaChanged); | ||
|
r639 | } | ||
|
r740 | QChartPrivate::~QChartPrivate() | ||
|
r639 | { | ||
|
r2733 | delete m_themeManager; | ||
|
r639 | } | ||
|
r2516 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font | ||
// to a series or axis and having theme override it: | ||||
// Initialize pens, brushes, and fonts to something nobody is likely to ever use, | ||||
// so that default theme initialization will always set these properly. | ||||
QPen &QChartPrivate::defaultPen() | ||||
{ | ||||
|
r2543 | static QPen defaultPen(QColor(1, 2, 0), 0.93247536); | ||
return defaultPen; | ||||
|
r2516 | } | ||
QBrush &QChartPrivate::defaultBrush() | ||||
{ | ||||
|
r2543 | static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern); | ||
return defaultBrush; | ||||
|
r2516 | } | ||
QFont &QChartPrivate::defaultFont() | ||||
{ | ||||
|
r2543 | static bool defaultFontInitialized(false); | ||
static QFont defaultFont; | ||||
if (!defaultFontInitialized) { | ||||
defaultFont.setPointSizeF(8.34563465); | ||||
defaultFontInitialized = true; | ||||
|
r2516 | } | ||
|
r2543 | return defaultFont; | ||
|
r2516 | } | ||
|
r2483 | void QChartPrivate::init() | ||
{ | ||||
m_legend = new LegendScroller(q_ptr); | ||||
q_ptr->setTheme(QChart::ChartThemeLight); | ||||
q_ptr->setLayout(m_presenter->layout()); | ||||
} | ||||
|
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()); | ||||
} | ||||
|
r2545 | void QChartPrivate::zoomReset() | ||
{ | ||||
m_dataset->zoomResetDomain(); | ||||
} | ||||
bool QChartPrivate::isZoomed() | ||||
{ | ||||
return m_dataset->isZoomedDomain(); | ||||
} | ||||
|
r2273 | 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 | |||
|
r2712 | QT_CHARTS_END_NAMESPACE | ||