@@ -1,90 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchartsplugin.h" |
|
21 | #include "qchartsplugin.h" | |
22 | #include "qchartview.h" |
|
22 | #include "qchartview.h" | |
23 | #include <QtPlugin> |
|
23 | #include <QtPlugin> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
26 | |||
27 | QChartsPlugin::QChartsPlugin(QObject *parent) : |
|
27 | QChartsPlugin::QChartsPlugin(QObject *parent) : | |
28 | QObject(parent) |
|
28 | QObject(parent) | |
29 | { |
|
29 | { | |
30 | // TODO Auto-generated constructor stub |
|
|||
31 | } |
|
30 | } | |
32 |
|
31 | |||
33 | QChartsPlugin::~QChartsPlugin() |
|
32 | QChartsPlugin::~QChartsPlugin() | |
34 | { |
|
33 | { | |
35 | // TODO Auto-generated destructor stub |
|
|||
36 | } |
|
34 | } | |
37 |
|
35 | |||
38 | QString QChartsPlugin::name() const |
|
36 | QString QChartsPlugin::name() const | |
39 | { |
|
37 | { | |
40 | return "QChartView"; |
|
38 | return "QChartView"; | |
41 | } |
|
39 | } | |
42 |
|
40 | |||
43 | QString QChartsPlugin::includeFile() const |
|
41 | QString QChartsPlugin::includeFile() const | |
44 | { |
|
42 | { | |
45 | #ifdef linux |
|
43 | #ifdef linux | |
46 | QString myNewLine = "\n"; |
|
44 | QString myNewLine = "\n"; | |
47 | #endif |
|
45 | #endif | |
48 | #ifdef WIN32 |
|
46 | #ifdef WIN32 | |
49 | QString myNewLine = "\n\r"; |
|
47 | QString myNewLine = "\n\r"; | |
50 | #endif |
|
48 | #endif | |
51 | #ifdef __APPLE__ |
|
49 | #ifdef __APPLE__ | |
52 | QString myNewLine = "\n"; |
|
50 | QString myNewLine = "\n"; | |
53 | #endif |
|
51 | #endif | |
54 | return "<qchartview.h>" + myNewLine + "#include <chartsnamespace.h>"; |
|
52 | return "<qchartview.h>" + myNewLine + "#include <chartsnamespace.h>"; | |
55 | } |
|
53 | } | |
56 |
|
54 | |||
57 | QString QChartsPlugin::group() const |
|
55 | QString QChartsPlugin::group() const | |
58 | { |
|
56 | { | |
59 | return tr("QCharts Widgets"); |
|
57 | return tr("QCharts Widgets"); | |
60 | } |
|
58 | } | |
61 |
|
59 | |||
62 | QIcon QChartsPlugin::icon() const |
|
60 | QIcon QChartsPlugin::icon() const | |
63 | { |
|
61 | { | |
64 | return QIcon(":/images/qcharts.png"); |
|
62 | return QIcon(":/images/qcharts.png"); | |
65 | } |
|
63 | } | |
66 |
|
64 | |||
67 | QString QChartsPlugin::toolTip() const |
|
65 | QString QChartsPlugin::toolTip() const | |
68 | { |
|
66 | { | |
69 | return tr("An qcharts view widget"); |
|
67 | return tr("An qcharts view widget"); | |
70 | } |
|
68 | } | |
71 |
|
69 | |||
72 | QString QChartsPlugin::whatsThis() const |
|
70 | QString QChartsPlugin::whatsThis() const | |
73 | { |
|
71 | { | |
74 | return tr("This widget is presents QChartView widget"); |
|
72 | return tr("This widget is presents QChartView widget"); | |
75 | } |
|
73 | } | |
76 |
|
74 | |||
77 | bool QChartsPlugin::isContainer() const |
|
75 | bool QChartsPlugin::isContainer() const | |
78 | { |
|
76 | { | |
79 | return false; |
|
77 | return false; | |
80 | } |
|
78 | } | |
81 |
|
79 | |||
82 | QWidget *QChartsPlugin::createWidget(QWidget *parent) |
|
80 | QWidget *QChartsPlugin::createWidget(QWidget *parent) | |
83 | { |
|
81 | { | |
84 | return new QChartView(new QChart(), parent); |
|
82 | return new QChartView(new QChart(), parent); | |
85 | } |
|
83 | } | |
86 |
|
84 | |||
87 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) |
|
85 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |
88 | Q_EXPORT_PLUGIN2(qtcommercialchart, QChartsPlugin) |
|
86 | Q_EXPORT_PLUGIN2(qtcommercialchart, QChartsPlugin) | |
89 | #endif |
|
87 | #endif | |
90 |
|
88 |
@@ -1,173 +1,173 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "areachartitem_p.h" |
|
21 | #include "areachartitem_p.h" | |
22 | #include "qareaseries.h" |
|
22 | #include "qareaseries.h" | |
23 | #include "qareaseries_p.h" |
|
23 | #include "qareaseries_p.h" | |
24 | #include "qlineseries.h" |
|
24 | #include "qlineseries.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include "abstractdomain_p.h" |
|
26 | #include "abstractdomain_p.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QGraphicsSceneMouseEvent> |
|
28 | #include <QGraphicsSceneMouseEvent> | |
29 | #include <QDebug> |
|
29 | #include <QDebug> | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | //TODO: optimize : remove points which are not visible |
|
34 | //TODO: optimize : remove points which are not visible | |
35 |
|
35 | |||
36 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item) |
|
36 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item) | |
37 |
: ChartItem(areaSeries->d_func(),item), |
|
37 | : ChartItem(areaSeries->d_func(),item), | |
38 | m_series(areaSeries), |
|
38 | m_series(areaSeries), | |
39 | m_upper(0), |
|
39 | m_upper(0), | |
40 | m_lower(0), |
|
40 | m_lower(0), | |
41 | m_pointsVisible(false) |
|
41 | m_pointsVisible(false) | |
42 | { |
|
42 | { | |
43 | setAcceptHoverEvents(true); |
|
43 | setAcceptHoverEvents(true); | |
44 | setZValue(ChartPresenter::LineChartZValue); |
|
44 | setZValue(ChartPresenter::LineChartZValue); | |
45 | m_upper = new AreaBoundItem(this, m_series->upperSeries()); |
|
45 | m_upper = new AreaBoundItem(this, m_series->upperSeries()); | |
46 | if (m_series->lowerSeries()) |
|
46 | if (m_series->lowerSeries()) | |
47 | m_lower = new AreaBoundItem(this, m_series->lowerSeries()); |
|
47 | m_lower = new AreaBoundItem(this, m_series->lowerSeries()); | |
48 |
|
48 | |||
49 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
49 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); | |
50 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
50 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
51 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); |
|
51 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); | |
52 | QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF))); |
|
52 | QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF))); | |
53 | QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool))); |
|
53 | QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool))); | |
54 |
|
54 | |||
55 | handleUpdated(); |
|
55 | handleUpdated(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | AreaChartItem::~AreaChartItem() |
|
58 | AreaChartItem::~AreaChartItem() | |
59 | { |
|
59 | { | |
60 | delete m_upper; |
|
60 | delete m_upper; | |
61 | delete m_lower; |
|
61 | delete m_lower; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void AreaChartItem::setPresenter(ChartPresenter *presenter) |
|
64 | void AreaChartItem::setPresenter(ChartPresenter *presenter) | |
65 | { |
|
65 | { | |
66 | m_upper->setPresenter(presenter); |
|
66 | m_upper->setPresenter(presenter); | |
67 | if (m_lower) { |
|
67 | if (m_lower) { | |
68 | m_lower->setPresenter(presenter); |
|
68 | m_lower->setPresenter(presenter); | |
69 | } |
|
69 | } | |
70 | ChartItem::setPresenter(presenter); |
|
70 | ChartItem::setPresenter(presenter); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | QRectF AreaChartItem::boundingRect() const |
|
73 | QRectF AreaChartItem::boundingRect() const | |
74 | { |
|
74 | { | |
75 | return m_rect; |
|
75 | return m_rect; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | QPainterPath AreaChartItem::shape() const |
|
78 | QPainterPath AreaChartItem::shape() const | |
79 | { |
|
79 | { | |
80 | return m_path; |
|
80 | return m_path; | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void AreaChartItem::updatePath() |
|
83 | void AreaChartItem::updatePath() | |
84 | { |
|
84 | { | |
85 | QPainterPath path; |
|
85 | QPainterPath path; | |
86 | QRectF rect(QPointF(0,0),domain()->size()); |
|
86 | QRectF rect(QPointF(0,0),domain()->size()); | |
87 |
|
87 | |||
88 | path = m_upper->path(); |
|
88 | path = m_upper->path(); | |
89 |
|
89 | |||
90 | if (m_lower) { |
|
90 | if (m_lower) { | |
91 | path.connectPath(m_lower->path().toReversed()); |
|
91 | path.connectPath(m_lower->path().toReversed()); | |
92 | } else { |
|
92 | } else { | |
93 | QPointF first = path.pointAtPercent(0); |
|
93 | QPointF first = path.pointAtPercent(0); | |
94 | QPointF last = path.pointAtPercent(1); |
|
94 | QPointF last = path.pointAtPercent(1); | |
95 | path.lineTo(last.x(), rect.bottom()); |
|
95 | path.lineTo(last.x(), rect.bottom()); | |
96 | path.lineTo(first.x(), rect.bottom()); |
|
96 | path.lineTo(first.x(), rect.bottom()); | |
97 | } |
|
97 | } | |
98 | path.closeSubpath(); |
|
98 | path.closeSubpath(); | |
99 | prepareGeometryChange(); |
|
99 | prepareGeometryChange(); | |
100 | m_path = path; |
|
100 | m_path = path; | |
101 | m_rect = path.boundingRect(); |
|
101 | m_rect = path.boundingRect(); | |
102 | update(); |
|
102 | update(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void AreaChartItem::handleUpdated() |
|
105 | void AreaChartItem::handleUpdated() | |
106 | { |
|
106 | { | |
107 | setVisible(m_series->isVisible()); |
|
107 | setVisible(m_series->isVisible()); | |
108 | m_pointsVisible = m_series->pointsVisible(); |
|
108 | m_pointsVisible = m_series->pointsVisible(); | |
109 | m_linePen = m_series->pen(); |
|
109 | m_linePen = m_series->pen(); | |
110 | m_brush = m_series->brush(); |
|
110 | m_brush = m_series->brush(); | |
111 | m_pointPen = m_series->pen(); |
|
111 | m_pointPen = m_series->pen(); | |
112 | m_pointPen.setWidthF(2 * m_pointPen.width()); |
|
112 | m_pointPen.setWidthF(2 * m_pointPen.width()); | |
113 | setOpacity(m_series->opacity()); |
|
113 | setOpacity(m_series->opacity()); | |
114 | update(); |
|
114 | update(); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void AreaChartItem::handleDomainUpdated() |
|
117 | void AreaChartItem::handleDomainUpdated() | |
118 | { |
|
118 | { | |
119 | AbstractDomain* d = m_upper->domain(); |
|
119 | AbstractDomain* d = m_upper->domain(); | |
120 |
|
120 | |||
121 | d->setSize(domain()->size()); |
|
121 | d->setSize(domain()->size()); | |
122 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); |
|
122 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); | |
123 | m_upper->handleDomainUpdated(); |
|
123 | m_upper->handleDomainUpdated(); | |
124 |
|
124 | |||
125 | if (m_lower) { |
|
125 | if (m_lower) { | |
126 | AbstractDomain* d = m_lower->domain(); |
|
126 | AbstractDomain* d = m_lower->domain(); | |
127 | d->setSize(domain()->size()); |
|
127 | d->setSize(domain()->size()); | |
128 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); |
|
128 | d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY()); | |
129 | m_lower->handleDomainUpdated(); |
|
129 | m_lower->handleDomainUpdated(); | |
130 | } |
|
130 | } | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
133 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
134 | { |
|
134 | { | |
135 | Q_UNUSED(widget) |
|
135 | Q_UNUSED(widget) | |
136 | Q_UNUSED(option) |
|
136 | Q_UNUSED(option) | |
137 | painter->save(); |
|
137 | painter->save(); | |
138 | painter->setPen(m_linePen); |
|
138 | painter->setPen(m_linePen); | |
139 | painter->setBrush(m_brush); |
|
139 | painter->setBrush(m_brush); | |
140 | painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); |
|
140 | painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |
141 | painter->drawPath(m_path); |
|
141 | painter->drawPath(m_path); | |
142 | if (m_pointsVisible) { |
|
142 | if (m_pointsVisible) { | |
143 | painter->setPen(m_pointPen); |
|
143 | painter->setPen(m_pointPen); | |
144 | painter->drawPoints(m_upper->geometryPoints()); |
|
144 | painter->drawPoints(m_upper->geometryPoints()); | |
145 | if (m_lower) |
|
145 | if (m_lower) | |
146 | painter->drawPoints(m_lower->geometryPoints()); |
|
146 | painter->drawPoints(m_lower->geometryPoints()); | |
147 | } |
|
147 | } | |
148 | painter->restore(); |
|
148 | painter->restore(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
151 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
152 | { |
|
152 | { | |
153 | emit clicked(m_upper->domain()->calculateDomainPoint(event->pos())); |
|
153 | emit clicked(m_upper->domain()->calculateDomainPoint(event->pos())); | |
154 | ChartItem::mousePressEvent(event); |
|
154 | ChartItem::mousePressEvent(event); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
157 | void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
158 | { |
|
158 | { | |
159 | emit hovered(domain()->calculateDomainPoint(event->pos()), true); |
|
159 | emit hovered(domain()->calculateDomainPoint(event->pos()), true); | |
160 | event->accept(); |
|
160 | event->accept(); | |
161 | // QGraphicsItem::hoverEnterEvent(event); |
|
161 | // QGraphicsItem::hoverEnterEvent(event); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
164 | void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
165 | { |
|
165 | { | |
166 | emit hovered(domain()->calculateDomainPoint(event->pos()), false); |
|
166 | emit hovered(domain()->calculateDomainPoint(event->pos()), false); | |
167 | event->accept(); |
|
167 | event->accept(); | |
168 | // QGraphicsItem::hoverEnterEvent(event); |
|
168 | // QGraphicsItem::hoverEnterEvent(event); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | #include "moc_areachartitem_p.cpp" |
|
171 | #include "moc_areachartitem_p.cpp" | |
172 |
|
172 | |||
173 | QTCOMMERCIALCHART_END_NAMESPACE |
|
173 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,454 +1,452 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
29 | #include "qarealegendmarker.h" |
|
29 | #include "qarealegendmarker.h" | |
30 | #include "qchart_p.h" |
|
30 | #include "qchart_p.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAreaSeries |
|
35 | \class QAreaSeries | |
36 | \brief The QAreaSeries class is used for making area charts. |
|
36 | \brief The QAreaSeries class is used for making area charts. | |
37 |
|
37 | |||
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
45 |
|
45 | |||
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
47 | \image examples_areachart.png |
|
47 | \image examples_areachart.png | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AreaSeries QAreaSeries |
|
50 | \qmlclass AreaSeries QAreaSeries | |
51 |
|
51 | |||
52 | The following QML shows how to create a simple area chart: |
|
52 | The following QML shows how to create a simple area chart: | |
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
54 | \beginfloatleft |
|
54 | \beginfloatleft | |
55 | \image demos_qmlchart4.png |
|
55 | \image demos_qmlchart4.png | |
56 | \endfloat |
|
56 | \endfloat | |
57 | \clearfloat |
|
57 | \clearfloat | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QAreaSeries::upperSeries |
|
61 | \property QAreaSeries::upperSeries | |
62 | \brief The upper one of the two line series used to define area series boundaries. |
|
62 | \brief The upper one of the two line series used to define area series boundaries. | |
63 | */ |
|
63 | */ | |
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
65 | \qmlproperty LineSeries AreaSeries::upperSeries | |
66 | The upper one of the two line series used to define area series boundaries. |
|
66 | The upper one of the two line series used to define area series boundaries. | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QAreaSeries::lowerSeries |
|
70 | \property QAreaSeries::lowerSeries | |
71 | The lower one of the two line series used to define are series boundaries. Note if |
|
71 | The lower one of the two line series used to define are series boundaries. Note if | |
72 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
72 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
73 | */ |
|
73 | */ | |
74 | /*! |
|
74 | /*! | |
75 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
75 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
76 | The lower one of the two line series used to define are series boundaries. Note if |
|
76 | The lower one of the two line series used to define are series boundaries. Note if | |
77 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
77 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QAreaSeries::color |
|
81 | \property QAreaSeries::color | |
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
83 | \sa QAreaSeries::brush() |
|
83 | \sa QAreaSeries::brush() | |
84 | */ |
|
84 | */ | |
85 | /*! |
|
85 | /*! | |
86 | \qmlproperty color AreaSeries::color |
|
86 | \qmlproperty color AreaSeries::color | |
87 | Fill (brush) color of the series. |
|
87 | Fill (brush) color of the series. | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \property QAreaSeries::borderColor |
|
91 | \property QAreaSeries::borderColor | |
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
93 | \sa QAreaSeries::pen() |
|
93 | \sa QAreaSeries::pen() | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlproperty color AreaSeries::borderColor |
|
96 | \qmlproperty color AreaSeries::borderColor | |
97 | Line (pen) color of the series. |
|
97 | Line (pen) color of the series. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \qmlproperty real AreaSeries::borderWidth |
|
101 | \qmlproperty real AreaSeries::borderWidth | |
102 | The width of the border line. By default the width is 2.0. |
|
102 | The width of the border line. By default the width is 2.0. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \fn QPen QAreaSeries::pen() const |
|
106 | \fn QPen QAreaSeries::pen() const | |
107 | \brief Returns the pen used to draw line for this series. |
|
107 | \brief Returns the pen used to draw line for this series. | |
108 | \sa setPen() |
|
108 | \sa setPen() | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | \fn QPen QAreaSeries::brush() const |
|
112 | \fn QPen QAreaSeries::brush() const | |
113 | \brief Returns the brush used to draw line for this series. |
|
113 | \brief Returns the brush used to draw line for this series. | |
114 | \sa setBrush() |
|
114 | \sa setBrush() | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QAreaSeries::colorChanged(QColor color) |
|
118 | \fn void QAreaSeries::colorChanged(QColor color) | |
119 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
119 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
122 | \qmlsignal AreaSeries::onColorChanged(color color) | |
123 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
123 | Signal is emitted when the fill (brush) color has changed to \a color. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
127 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
128 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
128 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
129 | */ |
|
129 | */ | |
130 | /*! |
|
130 | /*! | |
131 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
131 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
132 | Signal is emitted when the line (pen) color has changed to \a color. |
|
132 | Signal is emitted when the line (pen) color has changed to \a color. | |
133 | */ |
|
133 | */ | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
136 | \fn void QAreaSeries::clicked(const QPointF& point) | |
137 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
137 | \brief Signal is emitted when user clicks the \a point on area chart. | |
138 | */ |
|
138 | */ | |
139 | /*! |
|
139 | /*! | |
140 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
140 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
141 | Signal is emitted when user clicks the \a point on area chart. |
|
141 | Signal is emitted when user clicks the \a point on area chart. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QAreaSeries::hovered(const QPointF &point, bool state) |
|
145 | \fn void QAreaSeries::hovered(const QPointF &point, bool state) | |
146 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
146 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
147 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
147 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
148 | the series. |
|
148 | the series. | |
149 | */ |
|
149 | */ | |
150 | /*! |
|
150 | /*! | |
151 | \qmlsignal AreaSeries::onHovered(point point, bool state) |
|
151 | \qmlsignal AreaSeries::onHovered(point point, bool state) | |
152 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
152 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
153 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
153 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
154 | the series. |
|
154 | the series. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \fn void QAreaSeries::selected() |
|
158 | \fn void QAreaSeries::selected() | |
159 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
159 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
160 | implemented by the user of QAreaSeries API. |
|
160 | implemented by the user of QAreaSeries API. | |
161 | */ |
|
161 | */ | |
162 | /*! |
|
162 | /*! | |
163 | \qmlsignal AreaSeries::onSelected() |
|
163 | \qmlsignal AreaSeries::onSelected() | |
164 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
164 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
165 | implemented by the user of AreaSeries API. |
|
165 | implemented by the user of AreaSeries API. | |
166 | */ |
|
166 | */ | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | \fn void QAreaSeriesPrivate::updated() |
|
169 | \fn void QAreaSeriesPrivate::updated() | |
170 | \brief \internal |
|
170 | \brief \internal | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
174 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
175 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
175 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
176 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
176 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
177 | */ |
|
177 | */ | |
178 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
178 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
179 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
|
179 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) | |
180 | { |
|
180 | { | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | Constructs area series object without upper or lower series with \a parent object. |
|
184 | Constructs area series object without upper or lower series with \a parent object. | |
185 | */ |
|
185 | */ | |
186 | QAreaSeries::QAreaSeries(QObject *parent) |
|
186 | QAreaSeries::QAreaSeries(QObject *parent) | |
187 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
187 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
188 | { |
|
188 | { | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Destroys the object. |
|
192 | Destroys the object. | |
193 | */ |
|
193 | */ | |
194 | QAreaSeries::~QAreaSeries() |
|
194 | QAreaSeries::~QAreaSeries() | |
195 | { |
|
195 | { | |
196 | Q_D(QAreaSeries); |
|
196 | Q_D(QAreaSeries); | |
197 | if (d->m_chart) |
|
197 | if (d->m_chart) | |
198 | d->m_chart->removeSeries(this); |
|
198 | d->m_chart->removeSeries(this); | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | Returns QChartSeries::SeriesTypeArea. |
|
202 | Returns QChartSeries::SeriesTypeArea. | |
203 | */ |
|
203 | */ | |
204 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
204 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
205 | { |
|
205 | { | |
206 | return QAbstractSeries::SeriesTypeArea; |
|
206 | return QAbstractSeries::SeriesTypeArea; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Sets the \a series that is to be used as the area chart upper series. |
|
210 | Sets the \a series that is to be used as the area chart upper series. | |
211 | */ |
|
211 | */ | |
212 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
212 | void QAreaSeries::setUpperSeries(QLineSeries *series) | |
213 | { |
|
213 | { | |
214 | Q_D(QAreaSeries); |
|
214 | Q_D(QAreaSeries); | |
215 |
if(d->m_upperSeries!=series) |
|
215 | if (d->m_upperSeries != series) | |
216 | d->m_upperSeries = series; |
|
216 | d->m_upperSeries = series; | |
217 | //TODO: |
|
|||
218 | } |
|
|||
219 | } |
|
217 | } | |
220 |
|
218 | |||
221 | QLineSeries *QAreaSeries::upperSeries() const |
|
219 | QLineSeries *QAreaSeries::upperSeries() const | |
222 | { |
|
220 | { | |
223 | Q_D(const QAreaSeries); |
|
221 | Q_D(const QAreaSeries); | |
224 | return d->m_upperSeries; |
|
222 | return d->m_upperSeries; | |
225 | } |
|
223 | } | |
226 |
|
224 | |||
227 | /*! |
|
225 | /*! | |
228 | Sets the \a series that is to be used as the area chart lower series. |
|
226 | Sets the \a series that is to be used as the area chart lower series. | |
229 | */ |
|
227 | */ | |
230 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
|
228 | void QAreaSeries::setLowerSeries(QLineSeries *series) | |
231 | { |
|
229 | { | |
232 | Q_D(QAreaSeries); |
|
230 | Q_D(QAreaSeries); | |
233 | d->m_lowerSeries = series; |
|
231 | d->m_lowerSeries = series; | |
234 | } |
|
232 | } | |
235 |
|
233 | |||
236 | QLineSeries *QAreaSeries::lowerSeries() const |
|
234 | QLineSeries *QAreaSeries::lowerSeries() const | |
237 | { |
|
235 | { | |
238 | Q_D(const QAreaSeries); |
|
236 | Q_D(const QAreaSeries); | |
239 | return d->m_lowerSeries; |
|
237 | return d->m_lowerSeries; | |
240 | } |
|
238 | } | |
241 |
|
239 | |||
242 | /*! |
|
240 | /*! | |
243 | Sets \a pen used for drawing area outline. |
|
241 | Sets \a pen used for drawing area outline. | |
244 | */ |
|
242 | */ | |
245 | void QAreaSeries::setPen(const QPen &pen) |
|
243 | void QAreaSeries::setPen(const QPen &pen) | |
246 | { |
|
244 | { | |
247 | Q_D(QAreaSeries); |
|
245 | Q_D(QAreaSeries); | |
248 | if (d->m_pen != pen) { |
|
246 | if (d->m_pen != pen) { | |
249 | d->m_pen = pen; |
|
247 | d->m_pen = pen; | |
250 | emit d->updated(); |
|
248 | emit d->updated(); | |
251 | } |
|
249 | } | |
252 | } |
|
250 | } | |
253 |
|
251 | |||
254 | QPen QAreaSeries::pen() const |
|
252 | QPen QAreaSeries::pen() const | |
255 | { |
|
253 | { | |
256 | Q_D(const QAreaSeries); |
|
254 | Q_D(const QAreaSeries); | |
257 | return d->m_pen; |
|
255 | return d->m_pen; | |
258 | } |
|
256 | } | |
259 |
|
257 | |||
260 | /*! |
|
258 | /*! | |
261 | Sets \a brush used for filling the area. |
|
259 | Sets \a brush used for filling the area. | |
262 | */ |
|
260 | */ | |
263 | void QAreaSeries::setBrush(const QBrush &brush) |
|
261 | void QAreaSeries::setBrush(const QBrush &brush) | |
264 | { |
|
262 | { | |
265 | Q_D(QAreaSeries); |
|
263 | Q_D(QAreaSeries); | |
266 | if (d->m_brush != brush) { |
|
264 | if (d->m_brush != brush) { | |
267 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
|
265 | bool emitColorChanged = brush.color() != d->m_brush.color(); | |
268 | d->m_brush = brush; |
|
266 | d->m_brush = brush; | |
269 | emit d->updated(); |
|
267 | emit d->updated(); | |
270 | if (emitColorChanged) |
|
268 | if (emitColorChanged) | |
271 | emit colorChanged(brush.color()); |
|
269 | emit colorChanged(brush.color()); | |
272 | } |
|
270 | } | |
273 | } |
|
271 | } | |
274 |
|
272 | |||
275 | QBrush QAreaSeries::brush() const |
|
273 | QBrush QAreaSeries::brush() const | |
276 | { |
|
274 | { | |
277 | Q_D(const QAreaSeries); |
|
275 | Q_D(const QAreaSeries); | |
278 | return d->m_brush; |
|
276 | return d->m_brush; | |
279 | } |
|
277 | } | |
280 |
|
278 | |||
281 | void QAreaSeries::setColor(const QColor &color) |
|
279 | void QAreaSeries::setColor(const QColor &color) | |
282 | { |
|
280 | { | |
283 | QBrush b = brush(); |
|
281 | QBrush b = brush(); | |
284 | if (b == QBrush()) |
|
282 | if (b == QBrush()) | |
285 | b.setStyle(Qt::SolidPattern); |
|
283 | b.setStyle(Qt::SolidPattern); | |
286 | b.setColor(color); |
|
284 | b.setColor(color); | |
287 | setBrush(b); |
|
285 | setBrush(b); | |
288 | } |
|
286 | } | |
289 |
|
287 | |||
290 | QColor QAreaSeries::color() const |
|
288 | QColor QAreaSeries::color() const | |
291 | { |
|
289 | { | |
292 | return brush().color(); |
|
290 | return brush().color(); | |
293 | } |
|
291 | } | |
294 |
|
292 | |||
295 | void QAreaSeries::setBorderColor(const QColor &color) |
|
293 | void QAreaSeries::setBorderColor(const QColor &color) | |
296 | { |
|
294 | { | |
297 | QPen p = pen(); |
|
295 | QPen p = pen(); | |
298 | if (p.color() != color) { |
|
296 | if (p.color() != color) { | |
299 | p.setColor(color); |
|
297 | p.setColor(color); | |
300 | setPen(p); |
|
298 | setPen(p); | |
301 | emit borderColorChanged(color); |
|
299 | emit borderColorChanged(color); | |
302 | } |
|
300 | } | |
303 | } |
|
301 | } | |
304 |
|
302 | |||
305 | QColor QAreaSeries::borderColor() const |
|
303 | QColor QAreaSeries::borderColor() const | |
306 | { |
|
304 | { | |
307 | return pen().color(); |
|
305 | return pen().color(); | |
308 | } |
|
306 | } | |
309 |
|
307 | |||
310 | /*! |
|
308 | /*! | |
311 | Sets if data points are \a visible and should be drawn on line. |
|
309 | Sets if data points are \a visible and should be drawn on line. | |
312 | */ |
|
310 | */ | |
313 | void QAreaSeries::setPointsVisible(bool visible) |
|
311 | void QAreaSeries::setPointsVisible(bool visible) | |
314 | { |
|
312 | { | |
315 | Q_D(QAreaSeries); |
|
313 | Q_D(QAreaSeries); | |
316 | if (d->m_pointsVisible != visible) { |
|
314 | if (d->m_pointsVisible != visible) { | |
317 | d->m_pointsVisible = visible; |
|
315 | d->m_pointsVisible = visible; | |
318 | emit d->updated(); |
|
316 | emit d->updated(); | |
319 | } |
|
317 | } | |
320 | } |
|
318 | } | |
321 |
|
319 | |||
322 | /*! |
|
320 | /*! | |
323 | Returns if the points are drawn for this series. |
|
321 | Returns if the points are drawn for this series. | |
324 | \sa setPointsVisible() |
|
322 | \sa setPointsVisible() | |
325 | */ |
|
323 | */ | |
326 | bool QAreaSeries::pointsVisible() const |
|
324 | bool QAreaSeries::pointsVisible() const | |
327 | { |
|
325 | { | |
328 | Q_D(const QAreaSeries); |
|
326 | Q_D(const QAreaSeries); | |
329 | return d->m_pointsVisible; |
|
327 | return d->m_pointsVisible; | |
330 | } |
|
328 | } | |
331 |
|
329 | |||
332 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
330 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
333 |
|
331 | |||
334 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
|
332 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) | |
335 | : QAbstractSeriesPrivate(q), |
|
333 | : QAbstractSeriesPrivate(q), | |
336 | m_upperSeries(upperSeries), |
|
334 | m_upperSeries(upperSeries), | |
337 | m_lowerSeries(lowerSeries), |
|
335 | m_lowerSeries(lowerSeries), | |
338 | m_pointsVisible(false) |
|
336 | m_pointsVisible(false) | |
339 | { |
|
337 | { | |
340 | } |
|
338 | } | |
341 |
|
339 | |||
342 | void QAreaSeriesPrivate::initializeDomain() |
|
340 | void QAreaSeriesPrivate::initializeDomain() | |
343 | { |
|
341 | { | |
344 | Q_Q(QAreaSeries); |
|
342 | Q_Q(QAreaSeries); | |
345 |
|
343 | |||
346 | qreal minX(domain()->minX()); |
|
344 | qreal minX(domain()->minX()); | |
347 | qreal minY(domain()->minY()); |
|
345 | qreal minY(domain()->minY()); | |
348 | qreal maxX(domain()->maxX()); |
|
346 | qreal maxX(domain()->maxX()); | |
349 | qreal maxY(domain()->maxY()); |
|
347 | qreal maxY(domain()->maxY()); | |
350 |
|
348 | |||
351 | QLineSeries *upperSeries = q->upperSeries(); |
|
349 | QLineSeries *upperSeries = q->upperSeries(); | |
352 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
350 | QLineSeries *lowerSeries = q->lowerSeries(); | |
353 |
|
351 | |||
354 | const QList<QPointF>& points = upperSeries->points(); |
|
352 | const QList<QPointF>& points = upperSeries->points(); | |
355 |
|
353 | |||
356 | for (int i = 0; i < points.count(); i++) { |
|
354 | for (int i = 0; i < points.count(); i++) { | |
357 | qreal x = points[i].x(); |
|
355 | qreal x = points[i].x(); | |
358 | qreal y = points[i].y(); |
|
356 | qreal y = points[i].y(); | |
359 | minX = qMin(minX, x); |
|
357 | minX = qMin(minX, x); | |
360 | minY = qMin(minY, y); |
|
358 | minY = qMin(minY, y); | |
361 | maxX = qMax(maxX, x); |
|
359 | maxX = qMax(maxX, x); | |
362 | maxY = qMax(maxY, y); |
|
360 | maxY = qMax(maxY, y); | |
363 | } |
|
361 | } | |
364 | if (lowerSeries) { |
|
362 | if (lowerSeries) { | |
365 |
|
363 | |||
366 | const QList<QPointF>& points = lowerSeries->points(); |
|
364 | const QList<QPointF>& points = lowerSeries->points(); | |
367 |
|
365 | |||
368 | for (int i = 0; i < points.count(); i++) { |
|
366 | for (int i = 0; i < points.count(); i++) { | |
369 | qreal x = points[i].x(); |
|
367 | qreal x = points[i].x(); | |
370 | qreal y = points[i].y(); |
|
368 | qreal y = points[i].y(); | |
371 | minX = qMin(minX, x); |
|
369 | minX = qMin(minX, x); | |
372 | minY = qMin(minY, y); |
|
370 | minY = qMin(minY, y); | |
373 | maxX = qMax(maxX, x); |
|
371 | maxX = qMax(maxX, x); | |
374 | maxY = qMax(maxY, y); |
|
372 | maxY = qMax(maxY, y); | |
375 | } |
|
373 | } | |
376 | } |
|
374 | } | |
377 |
|
375 | |||
378 | domain()->setRange(minX, maxX, minY, maxY); |
|
376 | domain()->setRange(minX, maxX, minY, maxY); | |
379 | } |
|
377 | } | |
380 |
|
378 | |||
381 | void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
379 | void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
382 | { |
|
380 | { | |
383 | Q_Q(QAreaSeries); |
|
381 | Q_Q(QAreaSeries); | |
384 | AreaChartItem *area = new AreaChartItem(q,parent); |
|
382 | AreaChartItem *area = new AreaChartItem(q,parent); | |
385 | m_item.reset(area); |
|
383 | m_item.reset(area); | |
386 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
384 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
387 | } |
|
385 | } | |
388 | void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
386 | void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |
389 | { |
|
387 | { | |
390 | Q_Q(QAreaSeries); |
|
388 | Q_Q(QAreaSeries); | |
391 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); |
|
389 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); | |
392 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
390 | if (options.testFlag(QChart::SeriesAnimations)) { | |
393 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
391 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
394 | if (q->lowerSeries()) |
|
392 | if (q->lowerSeries()) | |
395 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
393 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
396 | }else{ |
|
394 | }else{ | |
397 | area->upperLineItem()->setAnimation(0); |
|
395 | area->upperLineItem()->setAnimation(0); | |
398 | if (q->lowerSeries()) |
|
396 | if (q->lowerSeries()) | |
399 | area->lowerLineItem()->setAnimation(0); |
|
397 | area->lowerLineItem()->setAnimation(0); | |
400 | } |
|
398 | } | |
401 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
399 | QAbstractSeriesPrivate::initializeAnimations(options); | |
402 | } |
|
400 | } | |
403 |
|
401 | |||
404 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
402 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |
405 | { |
|
403 | { | |
406 | Q_Q(QAreaSeries); |
|
404 | Q_Q(QAreaSeries); | |
407 | QList<QLegendMarker*> list; |
|
405 | QList<QLegendMarker*> list; | |
408 | return list << new QAreaLegendMarker(q,legend); |
|
406 | return list << new QAreaLegendMarker(q,legend); | |
409 | } |
|
407 | } | |
410 |
|
408 | |||
411 |
|
409 | |||
412 | void QAreaSeriesPrivate::initializeAxes() |
|
410 | void QAreaSeriesPrivate::initializeAxes() | |
413 | { |
|
411 | { | |
414 |
|
412 | |||
415 | } |
|
413 | } | |
416 |
|
414 | |||
417 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
415 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
418 | { |
|
416 | { | |
419 | Q_UNUSED(orientation); |
|
417 | Q_UNUSED(orientation); | |
420 | return QAbstractAxis::AxisTypeValue; |
|
418 | return QAbstractAxis::AxisTypeValue; | |
421 | } |
|
419 | } | |
422 |
|
420 | |||
423 | QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
421 | QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
424 | { |
|
422 | { | |
425 | Q_UNUSED(orientation); |
|
423 | Q_UNUSED(orientation); | |
426 | return 0; |
|
424 | return 0; | |
427 | } |
|
425 | } | |
428 |
|
426 | |||
429 | void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
427 | void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
430 | { |
|
428 | { | |
431 | Q_Q(QAreaSeries); |
|
429 | Q_Q(QAreaSeries); | |
432 | QPen pen; |
|
430 | QPen pen; | |
433 | QBrush brush; |
|
431 | QBrush brush; | |
434 |
|
432 | |||
435 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
433 | const QList<QGradient> gradients = theme->seriesGradients(); | |
436 | const QList<QColor> colors = theme->seriesColors(); |
|
434 | const QList<QColor> colors = theme->seriesColors(); | |
437 |
|
435 | |||
438 | if (forced || pen == m_pen) { |
|
436 | if (forced || pen == m_pen) { | |
439 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
437 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); | |
440 | pen.setWidthF(2); |
|
438 | pen.setWidthF(2); | |
441 | q->setPen(pen); |
|
439 | q->setPen(pen); | |
442 | } |
|
440 | } | |
443 |
|
441 | |||
444 | if (forced || brush == m_brush) { |
|
442 | if (forced || brush == m_brush) { | |
445 | QBrush brush(colors.at(index % colors.size())); |
|
443 | QBrush brush(colors.at(index % colors.size())); | |
446 | q->setBrush(brush); |
|
444 | q->setBrush(brush); | |
447 | } |
|
445 | } | |
448 | } |
|
446 | } | |
449 |
|
447 | |||
450 |
|
448 | |||
451 | #include "moc_qareaseries.cpp" |
|
449 | #include "moc_qareaseries.cpp" | |
452 | #include "moc_qareaseries_p.cpp" |
|
450 | #include "moc_qareaseries_p.cpp" | |
453 |
|
451 | |||
454 | QTCOMMERCIALCHART_END_NAMESPACE |
|
452 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,121 +1,120 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartcategoryaxisx_p.h" |
|
21 | #include "chartcategoryaxisx_p.h" | |
22 | #include "qcategoryaxis.h" |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item) |
|
31 | ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item) | |
32 | : HorizontalAxis(axis, item, true), |
|
32 | : HorizontalAxis(axis, item, true), | |
33 | m_axis(axis) |
|
33 | m_axis(axis) | |
34 | { |
|
34 | { | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | ChartCategoryAxisX::~ChartCategoryAxisX() |
|
37 | ChartCategoryAxisX::~ChartCategoryAxisX() | |
38 | { |
|
38 | { | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const |
|
41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |
42 | { |
|
42 | { | |
43 | int tickCount = m_axis->categoriesLabels().count() + 1; |
|
43 | int tickCount = m_axis->categoriesLabels().count() + 1; | |
44 | QVector<qreal> points; |
|
44 | QVector<qreal> points; | |
45 |
|
45 | |||
46 | if (tickCount < 2) |
|
46 | if (tickCount < 2) | |
47 | return points; |
|
47 | return points; | |
48 |
|
48 | |||
49 | const QRectF &gridRect = gridGeometry(); |
|
49 | const QRectF &gridRect = gridGeometry(); | |
50 | qreal range = max() - min(); |
|
50 | qreal range = max() - min(); | |
51 | if (range > 0) { |
|
51 | if (range > 0) { | |
52 | points.resize(tickCount); |
|
52 | points.resize(tickCount); | |
53 | qreal scale = gridRect.width() / range; |
|
53 | qreal scale = gridRect.width() / range; | |
54 | for (int i = 0; i < tickCount; ++i) { |
|
54 | for (int i = 0; i < tickCount; ++i) { | |
55 | if (i < tickCount - 1) { |
|
55 | if (i < tickCount - 1) { | |
56 | qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left(); |
|
56 | qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left(); | |
57 | points[i] = x; |
|
57 | points[i] = x; | |
58 | } else { |
|
58 | } else { | |
59 | qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left(); |
|
59 | qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left(); | |
60 | points[i] = x; |
|
60 | points[i] = x; | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | return points; |
|
65 | return points; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void ChartCategoryAxisX::updateGeometry() |
|
68 | void ChartCategoryAxisX::updateGeometry() | |
69 | { |
|
69 | { | |
70 | //TODO: this is not optimal when many categories :( , create only visible lables |
|
70 | //TODO: this is not optimal when many categories :( , create only visible lables | |
71 | setLabels(m_axis->categoriesLabels() << ""); |
|
71 | setLabels(m_axis->categoriesLabels() << ""); | |
72 | HorizontalAxis::updateGeometry(); |
|
72 | HorizontalAxis::updateGeometry(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void ChartCategoryAxisX::handleAxisUpdated() |
|
75 | void ChartCategoryAxisX::handleAxisUpdated() | |
76 | { |
|
76 | { | |
77 | updateGeometry(); |
|
77 | updateGeometry(); | |
78 | //TODO :: ChartAxis::handleAxisUpdated(); |
|
|||
79 | } |
|
78 | } | |
80 |
|
79 | |||
81 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
80 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
82 | { |
|
81 | { | |
83 | Q_UNUSED(constraint) |
|
82 | Q_UNUSED(constraint) | |
84 |
|
83 | |||
85 | QFontMetrics fn(font()); |
|
84 | QFontMetrics fn(font()); | |
86 | QSizeF sh; |
|
85 | QSizeF sh; | |
87 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |
88 | QStringList ticksList = m_axis->categoriesLabels(); |
|
87 | QStringList ticksList = m_axis->categoriesLabels(); | |
89 | qreal width = 0; |
|
88 | qreal width = 0; | |
90 | qreal height = 0; |
|
89 | qreal height = 0; | |
91 |
|
90 | |||
92 | switch (which) { |
|
91 | switch (which) { | |
93 | case Qt::MinimumSize: { |
|
92 | case Qt::MinimumSize: { | |
94 | QRectF boundingRect = labelBoundingRect(fn, "..."); |
|
93 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
95 | width = qMax(boundingRect.width(), base.width()); |
|
94 | width = qMax(boundingRect.width(), base.width()); | |
96 | height = boundingRect.height() + labelPadding(); |
|
95 | height = boundingRect.height() + labelPadding(); | |
97 | height += base.height(); |
|
96 | height += base.height(); | |
98 | sh = QSizeF(width, height); |
|
97 | sh = QSizeF(width, height); | |
99 | break; |
|
98 | break; | |
100 | } |
|
99 | } | |
101 | case Qt::PreferredSize: { |
|
100 | case Qt::PreferredSize: { | |
102 | int labelHeight = 0; |
|
101 | int labelHeight = 0; | |
103 | foreach (const QString& s, ticksList) { |
|
102 | foreach (const QString& s, ticksList) { | |
104 | QRect rect = labelBoundingRect(fn, s); |
|
103 | QRect rect = labelBoundingRect(fn, s); | |
105 | labelHeight = qMax(rect.height(), labelHeight); |
|
104 | labelHeight = qMax(rect.height(), labelHeight); | |
106 | width += rect.width(); |
|
105 | width += rect.width(); | |
107 | } |
|
106 | } | |
108 | height = labelHeight + labelPadding(); |
|
107 | height = labelHeight + labelPadding(); | |
109 | height += base.height(); |
|
108 | height += base.height(); | |
110 | width = qMax(width, base.width()); |
|
109 | width = qMax(width, base.width()); | |
111 | sh = QSizeF(width, height); |
|
110 | sh = QSizeF(width, height); | |
112 | break; |
|
111 | break; | |
113 | } |
|
112 | } | |
114 | default: |
|
113 | default: | |
115 | break; |
|
114 | break; | |
116 | } |
|
115 | } | |
117 |
|
116 | |||
118 | return sh; |
|
117 | return sh; | |
119 | } |
|
118 | } | |
120 |
|
119 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,119 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartcategoryaxisy_p.h" |
|
21 | #include "chartcategoryaxisy_p.h" | |
22 | #include "qcategoryaxis.h" |
|
22 | #include "qcategoryaxis.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item) |
|
32 | ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item) | |
33 | : VerticalAxis(axis, item, true), |
|
33 | : VerticalAxis(axis, item, true), | |
34 | m_axis(axis) |
|
34 | m_axis(axis) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | ChartCategoryAxisY::~ChartCategoryAxisY() |
|
38 | ChartCategoryAxisY::~ChartCategoryAxisY() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const |
|
42 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const | |
43 | { |
|
43 | { | |
44 | int tickCount = m_axis->categoriesLabels().count() + 1; |
|
44 | int tickCount = m_axis->categoriesLabels().count() + 1; | |
45 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
46 |
|
46 | |||
47 | if (tickCount < 2) |
|
47 | if (tickCount < 2) | |
48 | return points; |
|
48 | return points; | |
49 |
|
49 | |||
50 | const QRectF &gridRect = gridGeometry(); |
|
50 | const QRectF &gridRect = gridGeometry(); | |
51 | qreal range = max() - min(); |
|
51 | qreal range = max() - min(); | |
52 | if (range > 0) { |
|
52 | if (range > 0) { | |
53 | points.resize(tickCount); |
|
53 | points.resize(tickCount); | |
54 | qreal scale = gridRect.height() / range; |
|
54 | qreal scale = gridRect.height() / range; | |
55 | for (int i = 0; i < tickCount; ++i) { |
|
55 | for (int i = 0; i < tickCount; ++i) { | |
56 | if (i < tickCount - 1) { |
|
56 | if (i < tickCount - 1) { | |
57 | qreal y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom(); |
|
57 | qreal y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom(); | |
58 | points[i] = y; |
|
58 | points[i] = y; | |
59 | } else { |
|
59 | } else { | |
60 | qreal y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom(); |
|
60 | qreal y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom(); | |
61 | points[i] = y; |
|
61 | points[i] = y; | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | return points; |
|
66 | return points; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartCategoryAxisY::updateGeometry() |
|
69 | void ChartCategoryAxisY::updateGeometry() | |
70 | { |
|
70 | { | |
71 | setLabels(m_axis->categoriesLabels() << ""); |
|
71 | setLabels(m_axis->categoriesLabels() << ""); | |
72 | VerticalAxis::updateGeometry(); |
|
72 | VerticalAxis::updateGeometry(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void ChartCategoryAxisY::handleAxisUpdated() |
|
75 | void ChartCategoryAxisY::handleAxisUpdated() | |
76 | { |
|
76 | { | |
77 | updateGeometry(); |
|
77 | updateGeometry(); | |
78 | //TODO:: ChartAxis::handleAxisUpdated(); |
|
|||
79 | } |
|
78 | } | |
80 |
|
79 | |||
81 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
80 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
82 | { |
|
81 | { | |
83 | Q_UNUSED(constraint) |
|
82 | Q_UNUSED(constraint) | |
84 |
|
83 | |||
85 | QFontMetrics fn(font()); |
|
84 | QFontMetrics fn(font()); | |
86 | QSizeF sh; |
|
85 | QSizeF sh; | |
87 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
88 | QStringList ticksList = m_axis->categoriesLabels(); |
|
87 | QStringList ticksList = m_axis->categoriesLabels(); | |
89 | qreal width = 0; |
|
88 | qreal width = 0; | |
90 | qreal height = 0; |
|
89 | qreal height = 0; | |
91 |
|
90 | |||
92 | switch (which) { |
|
91 | switch (which) { | |
93 | case Qt::MinimumSize: { |
|
92 | case Qt::MinimumSize: { | |
94 | QRectF boundingRect = labelBoundingRect(fn, "..."); |
|
93 | QRectF boundingRect = labelBoundingRect(fn, "..."); | |
95 | width = boundingRect.width() + labelPadding(); |
|
94 | width = boundingRect.width() + labelPadding(); | |
96 | width += base.width(); |
|
95 | width += base.width(); | |
97 | height = qMax(boundingRect.height(), base.height()); |
|
96 | height = qMax(boundingRect.height(), base.height()); | |
98 | sh = QSizeF(width, height); |
|
97 | sh = QSizeF(width, height); | |
99 | break; |
|
98 | break; | |
100 | } |
|
99 | } | |
101 | case Qt::PreferredSize: { |
|
100 | case Qt::PreferredSize: { | |
102 | int labelWidth = 0; |
|
101 | int labelWidth = 0; | |
103 | foreach (const QString& s, ticksList) { |
|
102 | foreach (const QString& s, ticksList) { | |
104 | QRect rect = labelBoundingRect(fn, s); |
|
103 | QRect rect = labelBoundingRect(fn, s); | |
105 | labelWidth = qMax(rect.width(), labelWidth); |
|
104 | labelWidth = qMax(rect.width(), labelWidth); | |
106 | height += rect.height(); |
|
105 | height += rect.height(); | |
107 | } |
|
106 | } | |
108 | width = labelWidth + labelPadding() + 1; |
|
107 | width = labelWidth + labelPadding() + 1; | |
109 | width += base.width(); |
|
108 | width += base.width(); | |
110 | height = qMax(height, base.height()); |
|
109 | height = qMax(height, base.height()); | |
111 | sh = QSizeF(width, height); |
|
110 | sh = QSizeF(width, height); | |
112 | break; |
|
111 | break; | |
113 | } |
|
112 | } | |
114 | default: |
|
113 | default: | |
115 | break; |
|
114 | break; | |
116 | } |
|
115 | } | |
117 | return sh; |
|
116 | return sh; | |
118 | } |
|
117 | } | |
119 |
|
118 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,553 +1,547 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartlayout_p.h" |
|
25 | #include "chartlayout_p.h" | |
26 | #include "abstractdomain_p.h" |
|
26 | #include "abstractdomain_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDateTime> |
|
28 | #include <QDateTime> | |
29 | #include <QValueAxis> |
|
29 | #include <QValueAxis> | |
30 | #include <QLogValueAxis> |
|
30 | #include <QLogValueAxis> | |
31 | #include <QGraphicsLayout> |
|
31 | #include <QGraphicsLayout> | |
32 | #include <QFontMetrics> |
|
32 | #include <QFontMetrics> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) |
|
36 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) | |
37 | : ChartElement(item), |
|
37 | : ChartElement(item), | |
38 | m_axis(axis), |
|
38 | m_axis(axis), | |
39 | m_labelsAngle(axis->labelsAngle()), |
|
39 | m_labelsAngle(axis->labelsAngle()), | |
40 | m_grid(new QGraphicsItemGroup(item)), |
|
40 | m_grid(new QGraphicsItemGroup(item)), | |
41 | m_arrow(new QGraphicsItemGroup(item)), |
|
41 | m_arrow(new QGraphicsItemGroup(item)), | |
42 | m_shades(new QGraphicsItemGroup(item)), |
|
42 | m_shades(new QGraphicsItemGroup(item)), | |
43 | m_labels(new QGraphicsItemGroup(item)), |
|
43 | m_labels(new QGraphicsItemGroup(item)), | |
44 | m_title(new QGraphicsSimpleTextItem(item)), |
|
44 | m_title(new QGraphicsSimpleTextItem(item)), | |
45 | m_animation(0), |
|
45 | m_animation(0), | |
46 | m_labelPadding(5), |
|
46 | m_labelPadding(5), | |
47 | m_intervalAxis(intervalAxis), |
|
47 | m_intervalAxis(intervalAxis), | |
48 | m_titlePadding(3) |
|
48 | m_titlePadding(3) | |
49 | { |
|
49 | { | |
50 | Q_ASSERT(item); |
|
50 | Q_ASSERT(item); | |
51 | //initial initialization |
|
51 | //initial initialization | |
52 | m_arrow->setHandlesChildEvents(false); |
|
52 | m_arrow->setHandlesChildEvents(false); | |
53 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
53 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
54 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
54 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
55 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
55 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
56 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
56 | m_grid->setZValue(ChartPresenter::GridZValue); | |
57 | m_title->setZValue(ChartPresenter::GridZValue); |
|
57 | m_title->setZValue(ChartPresenter::GridZValue); | |
58 | handleVisibleChanged(m_axis->isVisible()); |
|
58 | handleVisibleChanged(m_axis->isVisible()); | |
59 | connectSlots(); |
|
59 | connectSlots(); | |
60 |
|
60 | |||
61 | setFlag(QGraphicsItem::ItemHasNoContents,true); |
|
61 | setFlag(QGraphicsItem::ItemHasNoContents,true); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void ChartAxis::connectSlots() |
|
64 | void ChartAxis::connectSlots() | |
65 | { |
|
65 | { | |
66 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); |
|
66 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); | |
67 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); |
|
67 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); | |
68 | QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); |
|
68 | QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); | |
69 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); |
|
69 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); | |
70 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); |
|
70 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); | |
71 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); |
|
71 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); | |
72 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); |
|
72 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); | |
73 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); |
|
73 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); | |
74 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); |
|
74 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); | |
75 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); |
|
75 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); | |
76 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); |
|
76 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); | |
77 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); |
|
77 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); | |
78 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); |
|
78 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); | |
79 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); |
|
79 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); | |
80 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); |
|
80 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); | |
81 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); |
|
81 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); | |
82 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); |
|
82 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); | |
83 | QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool))); |
|
83 | QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool))); | |
84 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); |
|
84 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | ChartAxis::~ChartAxis() |
|
87 | ChartAxis::~ChartAxis() | |
88 | { |
|
88 | { | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void ChartAxis::setAnimation(AxisAnimation *animation) |
|
91 | void ChartAxis::setAnimation(AxisAnimation *animation) | |
92 | { |
|
92 | { | |
93 | m_animation = animation; |
|
93 | m_animation = animation; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
96 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
97 | { |
|
97 | { | |
98 | m_layoutVector = layout; |
|
98 | m_layoutVector = layout; | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void ChartAxis::createItems(int count) |
|
101 | void ChartAxis::createItems(int count) | |
102 | { |
|
102 | { | |
103 | if (m_arrow->childItems().size() == 0){ |
|
103 | if (m_arrow->childItems().size() == 0){ | |
104 | QGraphicsLineItem* arrow = new ArrowItem(this, this); |
|
104 | QGraphicsLineItem* arrow = new ArrowItem(this, this); | |
105 | arrow->setPen(m_axis->linePen()); |
|
105 | arrow->setPen(m_axis->linePen()); | |
106 | m_arrow->addToGroup(arrow); |
|
106 | m_arrow->addToGroup(arrow); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | if (m_intervalAxis && m_grid->childItems().size() == 0) { |
|
109 | if (m_intervalAxis && m_grid->childItems().size() == 0) { | |
110 | for (int i = 0 ; i < 2 ; i ++){ |
|
110 | for (int i = 0 ; i < 2 ; i ++){ | |
111 | QGraphicsLineItem* item = new QGraphicsLineItem(this); |
|
111 | QGraphicsLineItem* item = new QGraphicsLineItem(this); | |
112 | item->setPen(m_axis->gridLinePen()); |
|
112 | item->setPen(m_axis->gridLinePen()); | |
113 | m_grid->addToGroup(item); |
|
113 | m_grid->addToGroup(item); | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | for (int i = 0; i < count; ++i) { |
|
117 | for (int i = 0; i < count; ++i) { | |
118 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); |
|
118 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); | |
119 | arrow->setPen(m_axis->linePen()); |
|
119 | arrow->setPen(m_axis->linePen()); | |
120 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); |
|
120 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); | |
121 | grid->setPen(m_axis->gridLinePen()); |
|
121 | grid->setPen(m_axis->gridLinePen()); | |
122 | QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); |
|
122 | QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); | |
123 | label->setFont(m_axis->labelsFont()); |
|
123 | label->setFont(m_axis->labelsFont()); | |
124 | label->setPen(m_axis->labelsPen()); |
|
124 | label->setPen(m_axis->labelsPen()); | |
125 | label->setBrush(m_axis->labelsBrush()); |
|
125 | label->setBrush(m_axis->labelsBrush()); | |
126 | label->setRotation(m_labelsAngle); |
|
126 | label->setRotation(m_labelsAngle); | |
127 | m_arrow->addToGroup(arrow); |
|
127 | m_arrow->addToGroup(arrow); | |
128 | m_grid->addToGroup(grid); |
|
128 | m_grid->addToGroup(grid); | |
129 | m_labels->addToGroup(label); |
|
129 | m_labels->addToGroup(label); | |
130 |
|
130 | |||
131 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ |
|
131 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ | |
132 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); |
|
132 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); | |
133 | shades->setPen(m_axis->shadesPen()); |
|
133 | shades->setPen(m_axis->shadesPen()); | |
134 | shades->setBrush(m_axis->shadesBrush()); |
|
134 | shades->setBrush(m_axis->shadesBrush()); | |
135 | m_shades->addToGroup(shades); |
|
135 | m_shades->addToGroup(shades); | |
136 | } |
|
136 | } | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void ChartAxis::deleteItems(int count) |
|
141 | void ChartAxis::deleteItems(int count) | |
142 | { |
|
142 | { | |
143 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
143 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
144 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
144 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
145 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
145 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
146 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
146 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
147 |
|
147 | |||
148 | for (int i = 0; i < count; ++i) { |
|
148 | for (int i = 0; i < count; ++i) { | |
149 | if (lines.size() % 2 && lines.size() > 1) |
|
149 | if (lines.size() % 2 && lines.size() > 1) | |
150 | delete(shades.takeLast()); |
|
150 | delete(shades.takeLast()); | |
151 | delete(lines.takeLast()); |
|
151 | delete(lines.takeLast()); | |
152 | delete(labels.takeLast()); |
|
152 | delete(labels.takeLast()); | |
153 | delete(axis.takeLast()); |
|
153 | delete(axis.takeLast()); | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
157 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
158 | { |
|
158 | { | |
159 | int diff = m_layoutVector.size() - layout.size(); |
|
159 | int diff = m_layoutVector.size() - layout.size(); | |
160 |
|
160 | |||
161 | if (diff > 0) |
|
161 | if (diff > 0) | |
162 | deleteItems(diff); |
|
162 | deleteItems(diff); | |
163 | else if (diff < 0) |
|
163 | else if (diff < 0) | |
164 | createItems(-diff); |
|
164 | createItems(-diff); | |
165 |
|
165 | |||
166 | if (m_animation) { |
|
166 | if (m_animation) { | |
167 | switch (presenter()->state()) { |
|
167 | switch (presenter()->state()) { | |
168 | case ChartPresenter::ZoomInState: |
|
168 | case ChartPresenter::ZoomInState: | |
169 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
169 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
170 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
170 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
171 | break; |
|
171 | break; | |
172 | case ChartPresenter::ZoomOutState: |
|
172 | case ChartPresenter::ZoomOutState: | |
173 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
173 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
174 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
174 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
175 | break; |
|
175 | break; | |
176 | case ChartPresenter::ScrollUpState: |
|
176 | case ChartPresenter::ScrollUpState: | |
177 | case ChartPresenter::ScrollLeftState: |
|
177 | case ChartPresenter::ScrollLeftState: | |
178 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
178 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
179 | break; |
|
179 | break; | |
180 | case ChartPresenter::ScrollDownState: |
|
180 | case ChartPresenter::ScrollDownState: | |
181 | case ChartPresenter::ScrollRightState: |
|
181 | case ChartPresenter::ScrollRightState: | |
182 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
182 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
183 | break; |
|
183 | break; | |
184 | case ChartPresenter::ShowState: |
|
184 | case ChartPresenter::ShowState: | |
185 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
185 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
186 | break; |
|
186 | break; | |
187 | } |
|
187 | } | |
188 | m_animation->setValues(m_layoutVector, layout); |
|
188 | m_animation->setValues(m_layoutVector, layout); | |
189 | presenter()->startAnimation(m_animation); |
|
189 | presenter()->startAnimation(m_animation); | |
190 | } else { |
|
190 | } else { | |
191 | setLayout(layout); |
|
191 | setLayout(layout); | |
192 | updateGeometry(); |
|
192 | updateGeometry(); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void ChartAxis::setLabelPadding(int padding) |
|
196 | void ChartAxis::setLabelPadding(int padding) | |
197 | { |
|
197 | { | |
198 | m_labelPadding = padding; |
|
198 | m_labelPadding = padding; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | void ChartAxis::setTitlePadding(int padding) |
|
201 | void ChartAxis::setTitlePadding(int padding) | |
202 | { |
|
202 | { | |
203 | m_titlePadding = padding; |
|
203 | m_titlePadding = padding; | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | bool ChartAxis::isEmpty() |
|
206 | bool ChartAxis::isEmpty() | |
207 | { |
|
207 | { | |
208 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); |
|
208 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
211 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | |
212 | { |
|
212 | { | |
213 | m_gridRect = grid; |
|
213 | m_gridRect = grid; | |
214 | m_axisRect = axis; |
|
214 | m_axisRect = axis; | |
215 |
|
215 | |||
216 | if (isEmpty()) |
|
216 | if (isEmpty()) | |
217 | return; |
|
217 | return; | |
218 |
|
218 | |||
219 | QVector<qreal> layout = calculateLayout(); |
|
219 | QVector<qreal> layout = calculateLayout(); | |
220 | updateLayout(layout); |
|
220 | updateLayout(layout); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | qreal ChartAxis::min() const |
|
223 | qreal ChartAxis::min() const | |
224 | { |
|
224 | { | |
225 | return m_axis->d_ptr->min(); |
|
225 | return m_axis->d_ptr->min(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | qreal ChartAxis::max() const |
|
228 | qreal ChartAxis::max() const | |
229 | { |
|
229 | { | |
230 | return m_axis->d_ptr->max(); |
|
230 | return m_axis->d_ptr->max(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | QFont ChartAxis::font() const |
|
233 | QFont ChartAxis::font() const | |
234 | { |
|
234 | { | |
235 | return m_axis->labelsFont(); |
|
235 | return m_axis->labelsFont(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | QFont ChartAxis::titleFont() const |
|
238 | QFont ChartAxis::titleFont() const | |
239 | { |
|
239 | { | |
240 | return m_axis->titleFont(); |
|
240 | return m_axis->titleFont(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | QString ChartAxis::titleText() const |
|
243 | QString ChartAxis::titleText() const | |
244 | { |
|
244 | { | |
245 | return m_axis->titleText(); |
|
245 | return m_axis->titleText(); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | void ChartAxis::axisSelected() |
|
248 | void ChartAxis::axisSelected() | |
249 | { |
|
249 | { | |
250 | emit clicked(); |
|
250 | emit clicked(); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | Qt::Orientation ChartAxis::orientation() const |
|
253 | Qt::Orientation ChartAxis::orientation() const | |
254 | { |
|
254 | { | |
255 | return m_axis->orientation(); |
|
255 | return m_axis->orientation(); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | Qt::Alignment ChartAxis::alignment() const |
|
258 | Qt::Alignment ChartAxis::alignment() const | |
259 | { |
|
259 | { | |
260 | return m_axis->alignment(); |
|
260 | return m_axis->alignment(); | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | void ChartAxis::setLabels(const QStringList &labels) |
|
263 | void ChartAxis::setLabels(const QStringList &labels) | |
264 | { |
|
264 | { | |
265 | m_labelsList = labels; |
|
265 | m_labelsList = labels; | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
268 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
269 | { |
|
269 | { | |
270 | Q_UNUSED(which); |
|
270 | Q_UNUSED(which); | |
271 | Q_UNUSED(constraint); |
|
271 | Q_UNUSED(constraint); | |
272 | return QSizeF(); |
|
272 | return QSizeF(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | //handlers |
|
275 | //handlers | |
276 |
|
276 | |||
277 | void ChartAxis::handleArrowVisibleChanged(bool visible) |
|
277 | void ChartAxis::handleArrowVisibleChanged(bool visible) | |
278 | { |
|
278 | { | |
279 | m_arrow->setVisible(visible); |
|
279 | m_arrow->setVisible(visible); | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void ChartAxis::handleGridVisibleChanged(bool visible) |
|
282 | void ChartAxis::handleGridVisibleChanged(bool visible) | |
283 | { |
|
283 | { | |
284 | m_grid->setVisible(visible); |
|
284 | m_grid->setVisible(visible); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | void ChartAxis::handleLabelsVisibleChanged(bool visible) |
|
287 | void ChartAxis::handleLabelsVisibleChanged(bool visible) | |
288 | { |
|
288 | { | |
289 | m_labels->setVisible(visible); |
|
289 | m_labels->setVisible(visible); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void ChartAxis::handleShadesVisibleChanged(bool visible) |
|
292 | void ChartAxis::handleShadesVisibleChanged(bool visible) | |
293 | { |
|
293 | { | |
294 | m_shades->setVisible(visible); |
|
294 | m_shades->setVisible(visible); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void ChartAxis::handleTitleVisibleChanged(bool visible) |
|
297 | void ChartAxis::handleTitleVisibleChanged(bool visible) | |
298 | { |
|
298 | { | |
299 | QGraphicsLayoutItem::updateGeometry(); |
|
299 | QGraphicsLayoutItem::updateGeometry(); | |
300 | presenter()->layout()->invalidate(); |
|
300 | presenter()->layout()->invalidate(); | |
301 | m_title->setVisible(visible); |
|
301 | m_title->setVisible(visible); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void ChartAxis::handleLabelsAngleChanged(int angle) |
|
304 | void ChartAxis::handleLabelsAngleChanged(int angle) | |
305 | { |
|
305 | { | |
306 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
306 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
307 | item->setRotation(angle); |
|
307 | item->setRotation(angle); | |
308 |
|
308 | |||
309 | m_labelsAngle = angle; |
|
309 | m_labelsAngle = angle; | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) |
|
312 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) | |
313 | { |
|
313 | { | |
314 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
314 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
315 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); |
|
315 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) |
|
318 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) | |
319 | { |
|
319 | { | |
320 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
320 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
321 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); |
|
321 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void ChartAxis::handleLabelsFontChanged(const QFont &font) |
|
324 | void ChartAxis::handleLabelsFontChanged(const QFont &font) | |
325 | { |
|
325 | { | |
326 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
326 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
327 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); |
|
327 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
328 | QGraphicsLayoutItem::updateGeometry(); |
|
328 | QGraphicsLayoutItem::updateGeometry(); | |
329 | presenter()->layout()->invalidate(); |
|
329 | presenter()->layout()->invalidate(); | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) |
|
332 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) | |
333 | { |
|
333 | { | |
334 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
334 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
335 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); |
|
335 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void ChartAxis::handleShadesPenChanged(const QPen &pen) |
|
338 | void ChartAxis::handleShadesPenChanged(const QPen &pen) | |
339 | { |
|
339 | { | |
340 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
340 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
341 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); |
|
341 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | void ChartAxis::handleArrowPenChanged(const QPen &pen) |
|
344 | void ChartAxis::handleArrowPenChanged(const QPen &pen) | |
345 | { |
|
345 | { | |
346 | foreach (QGraphicsItem *item , m_arrow->childItems()) |
|
346 | foreach (QGraphicsItem *item , m_arrow->childItems()) | |
347 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
347 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | void ChartAxis::handleGridPenChanged(const QPen &pen) |
|
350 | void ChartAxis::handleGridPenChanged(const QPen &pen) | |
351 | { |
|
351 | { | |
352 | foreach (QGraphicsItem *item , m_grid->childItems()) |
|
352 | foreach (QGraphicsItem *item , m_grid->childItems()) | |
353 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
353 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | void ChartAxis::handleTitleTextChanged(const QString &title) |
|
356 | void ChartAxis::handleTitleTextChanged(const QString &title) | |
357 | { |
|
357 | { | |
358 | QGraphicsLayoutItem::updateGeometry(); |
|
358 | QGraphicsLayoutItem::updateGeometry(); | |
359 | presenter()->layout()->invalidate(); |
|
359 | presenter()->layout()->invalidate(); | |
360 | m_title->setText(title); |
|
360 | m_title->setText(title); | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 |
|
363 | |||
364 | void ChartAxis::handleTitlePenChanged(const QPen &pen) |
|
364 | void ChartAxis::handleTitlePenChanged(const QPen &pen) | |
365 | { |
|
365 | { | |
366 | m_title->setPen(pen); |
|
366 | m_title->setPen(pen); | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) |
|
369 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) | |
370 | { |
|
370 | { | |
371 | m_title->setBrush(brush); |
|
371 | m_title->setBrush(brush); | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | void ChartAxis::handleTitleFontChanged(const QFont &font) |
|
374 | void ChartAxis::handleTitleFontChanged(const QFont &font) | |
375 | { |
|
375 | { | |
376 | if(m_title->font() != font){ |
|
376 | if(m_title->font() != font){ | |
377 | m_title->setFont(font); |
|
377 | m_title->setFont(font); | |
378 | QGraphicsLayoutItem::updateGeometry(); |
|
378 | QGraphicsLayoutItem::updateGeometry(); | |
379 | presenter()->layout()->invalidate(); |
|
379 | presenter()->layout()->invalidate(); | |
380 | } |
|
380 | } | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void ChartAxis::handleVisibleChanged(bool visible) |
|
383 | void ChartAxis::handleVisibleChanged(bool visible) | |
384 | { |
|
384 | { | |
385 | setVisible(visible); |
|
385 | setVisible(visible); | |
386 | if(!visible) { |
|
386 | if(!visible) { | |
387 | m_grid->setVisible(visible); |
|
387 | m_grid->setVisible(visible); | |
388 | m_arrow->setVisible(visible); |
|
388 | m_arrow->setVisible(visible); | |
389 | m_shades->setVisible(visible); |
|
389 | m_shades->setVisible(visible); | |
390 | m_labels->setVisible(visible); |
|
390 | m_labels->setVisible(visible); | |
391 | m_title->setVisible(visible); |
|
391 | m_title->setVisible(visible); | |
392 | }else { |
|
392 | }else { | |
393 | m_grid->setVisible(m_axis->isGridLineVisible()); |
|
393 | m_grid->setVisible(m_axis->isGridLineVisible()); | |
394 | m_arrow->setVisible(m_axis->isLineVisible()); |
|
394 | m_arrow->setVisible(m_axis->isLineVisible()); | |
395 | m_shades->setVisible(m_axis->shadesVisible()); |
|
395 | m_shades->setVisible(m_axis->shadesVisible()); | |
396 | m_labels->setVisible(m_axis->labelsVisible()); |
|
396 | m_labels->setVisible(m_axis->labelsVisible()); | |
397 | m_title->setVisible(m_axis->isTitleVisible()); |
|
397 | m_title->setVisible(m_axis->isTitleVisible()); | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | if(presenter()) presenter()->layout()->invalidate(); |
|
400 | if(presenter()) presenter()->layout()->invalidate(); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void ChartAxis::handleRangeChanged(qreal min, qreal max) |
|
403 | void ChartAxis::handleRangeChanged(qreal min, qreal max) | |
404 | { |
|
404 | { | |
405 | Q_UNUSED(min); |
|
405 | Q_UNUSED(min); | |
406 | Q_UNUSED(max); |
|
406 | Q_UNUSED(max); | |
407 |
|
407 | |||
408 | if (!isEmpty()) { |
|
408 | if (!isEmpty()) { | |
409 |
|
409 | |||
410 | QVector<qreal> layout = calculateLayout(); |
|
410 | QVector<qreal> layout = calculateLayout(); | |
411 | updateLayout(layout); |
|
411 | updateLayout(layout); | |
412 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); |
|
412 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
413 | QSizeF after = sizeHint(Qt::PreferredSize); |
|
413 | QSizeF after = sizeHint(Qt::PreferredSize); | |
414 |
|
414 | |||
415 | if (before != after) { |
|
415 | if (before != after) { | |
416 | QGraphicsLayoutItem::updateGeometry(); |
|
416 | QGraphicsLayoutItem::updateGeometry(); | |
417 | //we don't want to call invalidate on layout, since it will change minimum size of component, |
|
417 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |
418 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, |
|
418 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |
419 | //instead recalculate layout and use plotArea for extra space. |
|
419 | //instead recalculate layout and use plotArea for extra space. | |
420 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); |
|
420 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
421 | } |
|
421 | } | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | //helpers |
|
426 | //helpers | |
427 |
|
427 | |||
428 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) |
|
428 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) | |
429 | { |
|
429 | { | |
430 | //TODO: Q_ASSERT(m_max > m_min); |
|
|||
431 | //TODO: Q_ASSERT(ticks > 1); |
|
|||
432 |
|
||||
433 | QStringList labels; |
|
430 | QStringList labels; | |
434 |
|
431 | |||
435 |
if(max <= min || ticks < 1) |
|
432 | if (max <= min || ticks < 1) | |
436 | return labels; |
|
433 | return labels; | |
437 | } |
|
|||
438 |
|
434 | |||
439 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
435 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
440 | n++; |
|
436 | n++; | |
441 |
|
437 | |||
442 | if (format.isNull()) { |
|
438 | if (format.isNull()) { | |
443 | for (int i = 0; i < ticks; i++) { |
|
439 | for (int i = 0; i < ticks; i++) { | |
444 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
440 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
445 | labels << QString::number(value, 'f', n); |
|
441 | labels << QString::number(value, 'f', n); | |
446 | } |
|
442 | } | |
447 | } else { |
|
443 | } else { | |
448 | QByteArray array = format.toLatin1(); |
|
444 | QByteArray array = format.toLatin1(); | |
449 | for (int i = 0; i < ticks; i++) { |
|
445 | for (int i = 0; i < ticks; i++) { | |
450 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
446 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
451 | if (format.contains("d") |
|
447 | if (format.contains("d") | |
452 | || format.contains("i") |
|
448 | || format.contains("i") | |
453 | || format.contains("c")) |
|
449 | || format.contains("c")) | |
454 | labels << QString().sprintf(array, (qint64)value); |
|
450 | labels << QString().sprintf(array, (qint64)value); | |
455 | else if (format.contains("u") |
|
451 | else if (format.contains("u") | |
456 | || format.contains("o") |
|
452 | || format.contains("o") | |
457 | || format.contains("x", Qt::CaseInsensitive)) |
|
453 | || format.contains("x", Qt::CaseInsensitive)) | |
458 | labels << QString().sprintf(array, (quint64)value); |
|
454 | labels << QString().sprintf(array, (quint64)value); | |
459 | else if (format.contains("f", Qt::CaseInsensitive) |
|
455 | else if (format.contains("f", Qt::CaseInsensitive) | |
460 | || format.contains("e", Qt::CaseInsensitive) |
|
456 | || format.contains("e", Qt::CaseInsensitive) | |
461 | || format.contains("g", Qt::CaseInsensitive)) |
|
457 | || format.contains("g", Qt::CaseInsensitive)) | |
462 | labels << QString().sprintf(array, value); |
|
458 | labels << QString().sprintf(array, value); | |
463 | else |
|
459 | else | |
464 | labels << QString(); |
|
460 | labels << QString(); | |
465 | } |
|
461 | } | |
466 | } |
|
462 | } | |
467 |
|
463 | |||
468 | return labels; |
|
464 | return labels; | |
469 | } |
|
465 | } | |
470 |
|
466 | |||
471 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) |
|
467 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) | |
472 | { |
|
468 | { | |
473 | // Q_ASSERT(m_max > m_min); |
|
469 | // Q_ASSERT(m_max > m_min); | |
474 | // Q_ASSERT(ticks > 1); |
|
470 | // Q_ASSERT(ticks > 1); | |
475 |
|
471 | |||
476 | QStringList labels; |
|
472 | QStringList labels; | |
477 |
|
473 | |||
478 | int n = 0; |
|
474 | int n = 0; | |
479 | if (ticks > 1) |
|
475 | if (ticks > 1) | |
480 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
476 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
481 | n++; |
|
477 | n++; | |
482 |
|
478 | |||
483 | int firstTick; |
|
479 | int firstTick; | |
484 | if (base > 1) |
|
480 | if (base > 1) | |
485 | firstTick = ceil(log10(min) / log10(base)); |
|
481 | firstTick = ceil(log10(min) / log10(base)); | |
486 | else |
|
482 | else | |
487 | firstTick = ceil(log10(max) / log10(base)); |
|
483 | firstTick = ceil(log10(max) / log10(base)); | |
488 |
|
484 | |||
489 | if (format.isNull()) { |
|
485 | if (format.isNull()) { | |
490 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
486 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
491 | qreal value = qPow(base, i); |
|
487 | qreal value = qPow(base, i); | |
492 | labels << QString::number(value, 'f', n); |
|
488 | labels << QString::number(value, 'f', n); | |
493 | } |
|
489 | } | |
494 | } else { |
|
490 | } else { | |
495 | QByteArray array = format.toLatin1(); |
|
491 | QByteArray array = format.toLatin1(); | |
496 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
492 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
497 | qreal value = qPow(base, i); |
|
493 | qreal value = qPow(base, i); | |
498 | if (format.contains("d") |
|
494 | if (format.contains("d") | |
499 | || format.contains("i") |
|
495 | || format.contains("i") | |
500 | || format.contains("c")) |
|
496 | || format.contains("c")) | |
501 | labels << QString().sprintf(array, (qint64)value); |
|
497 | labels << QString().sprintf(array, (qint64)value); | |
502 | else if (format.contains("u") |
|
498 | else if (format.contains("u") | |
503 | || format.contains("o") |
|
499 | || format.contains("o") | |
504 | || format.contains("x", Qt::CaseInsensitive)) |
|
500 | || format.contains("x", Qt::CaseInsensitive)) | |
505 | labels << QString().sprintf(array, (quint64)value); |
|
501 | labels << QString().sprintf(array, (quint64)value); | |
506 | else if (format.contains("f", Qt::CaseInsensitive) |
|
502 | else if (format.contains("f", Qt::CaseInsensitive) | |
507 | || format.contains("e", Qt::CaseInsensitive) |
|
503 | || format.contains("e", Qt::CaseInsensitive) | |
508 | || format.contains("g", Qt::CaseInsensitive)) |
|
504 | || format.contains("g", Qt::CaseInsensitive)) | |
509 | labels << QString().sprintf(array, value); |
|
505 | labels << QString().sprintf(array, value); | |
510 | else |
|
506 | else | |
511 | labels << QString(); |
|
507 | labels << QString(); | |
512 | } |
|
508 | } | |
513 | } |
|
509 | } | |
514 |
|
510 | |||
515 | return labels; |
|
511 | return labels; | |
516 | } |
|
512 | } | |
517 |
|
513 | |||
518 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) |
|
514 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) | |
519 | { |
|
515 | { | |
520 | //TODO: Q_ASSERT(m_max > m_min); |
|
|||
521 | //TODO: Q_ASSERT(ticks > 1); |
|
|||
522 | QStringList labels; |
|
516 | QStringList labels; | |
523 |
|
517 | |||
524 | if(max <= min || ticks < 1) { |
|
518 | if (max <= min || ticks < 1) { | |
525 | return labels; |
|
519 | return labels; | |
526 | } |
|
520 | } | |
527 |
|
521 | |||
528 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); |
|
522 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | |
529 | n++; |
|
523 | n++; | |
530 | for (int i = 0; i < ticks; i++) { |
|
524 | for (int i = 0; i < ticks; i++) { | |
531 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
525 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
532 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
526 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
533 | } |
|
527 | } | |
534 | return labels; |
|
528 | return labels; | |
535 | } |
|
529 | } | |
536 |
|
530 | |||
537 | QRect ChartAxis::labelBoundingRect(const QFontMetrics &fn, const QString &label) const |
|
531 | QRect ChartAxis::labelBoundingRect(const QFontMetrics &fn, const QString &label) const | |
538 | { |
|
532 | { | |
539 | QRect boundingRect = fn.boundingRect(label); |
|
533 | QRect boundingRect = fn.boundingRect(label); | |
540 |
|
534 | |||
541 | // Take label rotation into account |
|
535 | // Take label rotation into account | |
542 | if (m_labelsAngle) { |
|
536 | if (m_labelsAngle) { | |
543 | QTransform transform; |
|
537 | QTransform transform; | |
544 | transform.rotate(m_labelsAngle); |
|
538 | transform.rotate(m_labelsAngle); | |
545 | boundingRect = transform.mapRect(boundingRect); |
|
539 | boundingRect = transform.mapRect(boundingRect); | |
546 | } |
|
540 | } | |
547 |
|
541 | |||
548 | return boundingRect; |
|
542 | return boundingRect; | |
549 | } |
|
543 | } | |
550 |
|
544 | |||
551 | #include "moc_chartaxis_p.cpp" |
|
545 | #include "moc_chartaxis_p.cpp" | |
552 |
|
546 | |||
553 | QTCOMMERCIALCHART_END_NAMESPACE |
|
547 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,1008 +1,1007 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractaxis.h" |
|
21 | #include "qabstractaxis.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 | #include "charttheme_p.h" |
|
24 | #include "charttheme_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QAbstractAxis |
|
29 | \class QAbstractAxis | |
30 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
30 | \brief The QAbstractAxis class is used for manipulating chart's axis. | |
31 | \mainclass |
|
31 | \mainclass | |
32 |
|
32 | |||
33 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
33 | There is only one x Axis visible at the time, however there can be multiple y axes. | |
34 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
34 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
35 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \qmlclass AbstractAxis QAbstractAxis |
|
39 | \qmlclass AbstractAxis QAbstractAxis | |
40 | \brief The Axis element is used for manipulating chart's axes |
|
40 | \brief The Axis element is used for manipulating chart's axes | |
41 |
|
41 | |||
42 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
42 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. | |
43 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
43 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
45 |
|
45 | |||
46 | To access Axes you can use ChartView API. For example: |
|
46 | To access Axes you can use ChartView API. For example: | |
47 | \code |
|
47 | \code | |
48 | ChartView { |
|
48 | ChartView { | |
49 | axisX.min: 0 |
|
49 | axisX.min: 0 | |
50 | axisX.max: 3 |
|
50 | axisX.max: 3 | |
51 | axisX.ticksCount: 4 |
|
51 | axisX.ticksCount: 4 | |
52 | axisY.min: 0 |
|
52 | axisY.min: 0 | |
53 | axisY.max: 4 |
|
53 | axisY.max: 4 | |
54 | // Add a few series... |
|
54 | // Add a few series... | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \enum QAbstractAxis::AxisType |
|
60 | \enum QAbstractAxis::AxisType | |
61 |
|
61 | |||
62 | The type of the series object. |
|
62 | The type of the series object. | |
63 |
|
63 | |||
64 | \value AxisTypeNoAxis |
|
64 | \value AxisTypeNoAxis | |
65 | \value AxisTypeValue |
|
65 | \value AxisTypeValue | |
66 | \value AxisTypeBarCategory |
|
66 | \value AxisTypeBarCategory | |
67 | \value AxisTypeCategory |
|
67 | \value AxisTypeCategory | |
68 | \value AxisTypeDateTime |
|
68 | \value AxisTypeDateTime | |
69 | \value AxisTypeLogValue |
|
69 | \value AxisTypeLogValue | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | *\fn void QAbstractAxis::type() const |
|
73 | *\fn void QAbstractAxis::type() const | |
74 | Returns the type of the axis |
|
74 | Returns the type of the axis | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QAbstractAxis::lineVisible |
|
78 | \property QAbstractAxis::lineVisible | |
79 | The visibility of the axis line |
|
79 | The visibility of the axis line | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty bool AbstractAxis::lineVisible |
|
82 | \qmlproperty bool AbstractAxis::lineVisible | |
83 | The visibility of the axis line |
|
83 | The visibility of the axis line | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \property QAbstractAxis::linePen |
|
87 | \property QAbstractAxis::linePen | |
88 | The pen of the line. |
|
88 | The pen of the line. | |
89 | */ |
|
89 | */ | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \property QAbstractAxis::labelsVisible |
|
92 | \property QAbstractAxis::labelsVisible | |
93 | Defines if axis labels are visible. |
|
93 | Defines if axis labels are visible. | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlproperty bool AbstractAxis::labelsVisible |
|
96 | \qmlproperty bool AbstractAxis::labelsVisible | |
97 | Defines if axis labels are visible. |
|
97 | Defines if axis labels are visible. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \property QAbstractAxis::labelsPen |
|
101 | \property QAbstractAxis::labelsPen | |
102 | The pen of the labels. |
|
102 | The pen of the labels. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \property QAbstractAxis::labelsBrush |
|
106 | \property QAbstractAxis::labelsBrush | |
107 | The brush of the labels. |
|
107 | The brush of the labels. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \property QAbstractAxis::visible |
|
111 | \property QAbstractAxis::visible | |
112 | The visibility of the axis. |
|
112 | The visibility of the axis. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty bool AbstractAxis::visible |
|
115 | \qmlproperty bool AbstractAxis::visible | |
116 | The visibility of the axis. |
|
116 | The visibility of the axis. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \property QAbstractAxis::gridVisible |
|
120 | \property QAbstractAxis::gridVisible | |
121 | The visibility of the grid lines. |
|
121 | The visibility of the grid lines. | |
122 | */ |
|
122 | */ | |
123 | /*! |
|
123 | /*! | |
124 | \qmlproperty bool AbstractAxis::gridVisible |
|
124 | \qmlproperty bool AbstractAxis::gridVisible | |
125 | The visibility of the grid lines. |
|
125 | The visibility of the grid lines. | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \property QAbstractAxis::color |
|
129 | \property QAbstractAxis::color | |
130 | The color of the axis and ticks. |
|
130 | The color of the axis and ticks. | |
131 | */ |
|
131 | */ | |
132 | /*! |
|
132 | /*! | |
133 | \qmlproperty color AbstractAxis::color |
|
133 | \qmlproperty color AbstractAxis::color | |
134 | The color of the axis and ticks. |
|
134 | The color of the axis and ticks. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \property QAbstractAxis::gridLinePen |
|
138 | \property QAbstractAxis::gridLinePen | |
139 | The pen of the grid line. |
|
139 | The pen of the grid line. | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \property QAbstractAxis::labelsFont |
|
143 | \property QAbstractAxis::labelsFont | |
144 | The font of the axis labels. |
|
144 | The font of the axis labels. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \qmlproperty Font AbstractAxis::labelsFont |
|
148 | \qmlproperty Font AbstractAxis::labelsFont | |
149 | The font of the axis labels. |
|
149 | The font of the axis labels. | |
150 |
|
150 | |||
151 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
151 | See the \l {Font} {QML Font Element} for detailed documentation. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \property QAbstractAxis::labelsColor |
|
155 | \property QAbstractAxis::labelsColor | |
156 | The color of the axis labels. |
|
156 | The color of the axis labels. | |
157 | */ |
|
157 | */ | |
158 | /*! |
|
158 | /*! | |
159 | \qmlproperty color AbstractAxis::labelsColor |
|
159 | \qmlproperty color AbstractAxis::labelsColor | |
160 | The color of the axis labels. |
|
160 | The color of the axis labels. | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \property QAbstractAxis::labelsAngle |
|
164 | \property QAbstractAxis::labelsAngle | |
165 | The angle of the axis labels in degrees. |
|
165 | The angle of the axis labels in degrees. | |
166 | */ |
|
166 | */ | |
167 | /*! |
|
167 | /*! | |
168 | \qmlproperty int AbstractAxis::labelsAngle |
|
168 | \qmlproperty int AbstractAxis::labelsAngle | |
169 | The angle of the axis labels in degrees. |
|
169 | The angle of the axis labels in degrees. | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \property QAbstractAxis::shadesVisible |
|
173 | \property QAbstractAxis::shadesVisible | |
174 | The visibility of the axis shades. |
|
174 | The visibility of the axis shades. | |
175 | */ |
|
175 | */ | |
176 | /*! |
|
176 | /*! | |
177 | \qmlproperty bool AbstractAxis::shadesVisible |
|
177 | \qmlproperty bool AbstractAxis::shadesVisible | |
178 | The visibility of the axis shades. |
|
178 | The visibility of the axis shades. | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \property QAbstractAxis::shadesColor |
|
182 | \property QAbstractAxis::shadesColor | |
183 | The fill (brush) color of the axis shades. |
|
183 | The fill (brush) color of the axis shades. | |
184 | */ |
|
184 | */ | |
185 | /*! |
|
185 | /*! | |
186 | \qmlproperty color AbstractAxis::shadesColor |
|
186 | \qmlproperty color AbstractAxis::shadesColor | |
187 | The fill (brush) color of the axis shades. |
|
187 | The fill (brush) color of the axis shades. | |
188 | */ |
|
188 | */ | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | \property QAbstractAxis::shadesBorderColor |
|
191 | \property QAbstractAxis::shadesBorderColor | |
192 | The border (pen) color of the axis shades. |
|
192 | The border (pen) color of the axis shades. | |
193 | */ |
|
193 | */ | |
194 | /*! |
|
194 | /*! | |
195 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
195 | \qmlproperty color AbstractAxis::shadesBorderColor | |
196 | The border (pen) color of the axis shades. |
|
196 | The border (pen) color of the axis shades. | |
197 | */ |
|
197 | */ | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | \property QAbstractAxis::shadesPen |
|
200 | \property QAbstractAxis::shadesPen | |
201 | The pen of the axis shades (area between grid lines). |
|
201 | The pen of the axis shades (area between grid lines). | |
202 | */ |
|
202 | */ | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | \property QAbstractAxis::shadesBrush |
|
205 | \property QAbstractAxis::shadesBrush | |
206 | The brush of the axis shades (area between grid lines). |
|
206 | The brush of the axis shades (area between grid lines). | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \property QAbstractAxis::titleVisible |
|
210 | \property QAbstractAxis::titleVisible | |
211 | The visibility of the axis title. By default the value is true. |
|
211 | The visibility of the axis title. By default the value is true. | |
212 | */ |
|
212 | */ | |
213 | /*! |
|
213 | /*! | |
214 | \qmlproperty bool AbstractAxis::titleVisible |
|
214 | \qmlproperty bool AbstractAxis::titleVisible | |
215 | The visibility of the axis title. By default the value is true. |
|
215 | The visibility of the axis title. By default the value is true. | |
216 | */ |
|
216 | */ | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | \property QAbstractAxis::titleText |
|
219 | \property QAbstractAxis::titleText | |
220 | The title of the axis. Empty by default. |
|
220 | The title of the axis. Empty by default. | |
221 | */ |
|
221 | */ | |
222 | /*! |
|
222 | /*! | |
223 | \qmlproperty String AbstractAxis::titleText |
|
223 | \qmlproperty String AbstractAxis::titleText | |
224 | The title of the axis. Empty by default. |
|
224 | The title of the axis. Empty by default. | |
225 | */ |
|
225 | */ | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | \property QAbstractAxis::titlePen |
|
228 | \property QAbstractAxis::titlePen | |
229 | The pen of the title text. |
|
229 | The pen of the title text. | |
230 | */ |
|
230 | */ | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | \property QAbstractAxis::titleBrush |
|
233 | \property QAbstractAxis::titleBrush | |
234 | The brush of the title text. |
|
234 | The brush of the title text. | |
235 | */ |
|
235 | */ | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | \property QAbstractAxis::titleFont |
|
238 | \property QAbstractAxis::titleFont | |
239 | The font of the title of the axis. |
|
239 | The font of the title of the axis. | |
240 | */ |
|
240 | */ | |
241 | /*! |
|
241 | /*! | |
242 | \qmlproperty Font AbstractAxis::titleFont |
|
242 | \qmlproperty Font AbstractAxis::titleFont | |
243 | The font of the title of the axis. |
|
243 | The font of the title of the axis. | |
244 | */ |
|
244 | */ | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | \property QAbstractAxis::orientation |
|
247 | \property QAbstractAxis::orientation | |
248 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. |
|
248 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. | |
249 | */ |
|
249 | */ | |
250 | /*! |
|
250 | /*! | |
251 | \qmlproperty Qt.Orientation AbstractAxis::orientation |
|
251 | \qmlproperty Qt.Orientation AbstractAxis::orientation | |
252 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a Chart/Series. |
|
252 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a Chart/Series. | |
253 | */ |
|
253 | */ | |
254 |
|
254 | |||
255 | /*! |
|
255 | /*! | |
256 | \property QAbstractAxis::alignment |
|
256 | \property QAbstractAxis::alignment | |
257 | The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom. |
|
257 | The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom. | |
258 | */ |
|
258 | */ | |
259 | /*! |
|
259 | /*! | |
260 | \qmlproperty alignment AbstractAxis::alignment |
|
260 | \qmlproperty alignment AbstractAxis::alignment | |
261 | The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom. |
|
261 | The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom. | |
262 | */ |
|
262 | */ | |
263 |
|
263 | |||
264 | /*! |
|
264 | /*! | |
265 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
265 | \fn void QAbstractAxis::visibleChanged(bool visible) | |
266 | Visibility of the axis has changed to \a visible. |
|
266 | Visibility of the axis has changed to \a visible. | |
267 | */ |
|
267 | */ | |
268 | /*! |
|
268 | /*! | |
269 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
269 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) | |
270 | Visibility of the axis has changed to \a visible. |
|
270 | Visibility of the axis has changed to \a visible. | |
271 | */ |
|
271 | */ | |
272 |
|
272 | |||
273 | /*! |
|
273 | /*! | |
274 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) |
|
274 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) | |
275 | The pen of the line of the axis has changed to \a pen. |
|
275 | The pen of the line of the axis has changed to \a pen. | |
276 | */ |
|
276 | */ | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
279 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) | |
280 | Visibility of the axis line has changed to \a visible. |
|
280 | Visibility of the axis line has changed to \a visible. | |
281 | */ |
|
281 | */ | |
282 | /*! |
|
282 | /*! | |
283 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
283 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) | |
284 | Visibility of the axis line has changed to \a visible. |
|
284 | Visibility of the axis line has changed to \a visible. | |
285 | */ |
|
285 | */ | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
288 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) | |
289 | Visibility of the labels of the axis has changed to \a visible. |
|
289 | Visibility of the labels of the axis has changed to \a visible. | |
290 | */ |
|
290 | */ | |
291 | /*! |
|
291 | /*! | |
292 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
292 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) | |
293 | Visibility of the labels of the axis has changed to \a visible. |
|
293 | Visibility of the labels of the axis has changed to \a visible. | |
294 | */ |
|
294 | */ | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) |
|
297 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) | |
298 | The font of the axis labels has changed to \a font. |
|
298 | The font of the axis labels has changed to \a font. | |
299 | */ |
|
299 | */ | |
300 | /*! |
|
300 | /*! | |
301 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) |
|
301 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) | |
302 | The font of the axis labels has changed to \a font. |
|
302 | The font of the axis labels has changed to \a font. | |
303 | */ |
|
303 | */ | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) |
|
306 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) | |
307 | The pen of the axis labels has changed to \a pen. |
|
307 | The pen of the axis labels has changed to \a pen. | |
308 | */ |
|
308 | */ | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) |
|
311 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) | |
312 | The brush of the axis labels has changed to \a brush. |
|
312 | The brush of the axis labels has changed to \a brush. | |
313 | */ |
|
313 | */ | |
314 |
|
314 | |||
315 | /*! |
|
315 | /*! | |
316 | \fn void QAbstractAxis::labelsAngleChanged(int angle) |
|
316 | \fn void QAbstractAxis::labelsAngleChanged(int angle) | |
317 | The angle of the axis labels has changed to \a angle. |
|
317 | The angle of the axis labels has changed to \a angle. | |
318 | */ |
|
318 | */ | |
319 | /*! |
|
319 | /*! | |
320 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) |
|
320 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) | |
321 | The angle of the axis labels has changed to \a angle. |
|
321 | The angle of the axis labels has changed to \a angle. | |
322 | */ |
|
322 | */ | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
325 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) | |
326 | Visibility of the grid lines of the axis has changed to \a visible. |
|
326 | Visibility of the grid lines of the axis has changed to \a visible. | |
327 | */ |
|
327 | */ | |
328 | /*! |
|
328 | /*! | |
329 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
329 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) | |
330 | Visibility of the grid lines of the axis has changed to \a visible. |
|
330 | Visibility of the grid lines of the axis has changed to \a visible. | |
331 | */ |
|
331 | */ | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) |
|
334 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) | |
335 | The pen of the grid line has changed to \a pen. |
|
335 | The pen of the grid line has changed to \a pen. | |
336 | */ |
|
336 | */ | |
337 |
|
337 | |||
338 | /*! |
|
338 | /*! | |
339 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
339 | \fn void QAbstractAxis::colorChanged(QColor color) | |
340 | Emitted if the \a color of the axis is changed. |
|
340 | Emitted if the \a color of the axis is changed. | |
341 | */ |
|
341 | */ | |
342 | /*! |
|
342 | /*! | |
343 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
343 | \qmlsignal AbstractAxis::onColorChanged(QColor color) | |
344 | Emitted if the \a color of the axis is changed. |
|
344 | Emitted if the \a color of the axis is changed. | |
345 | */ |
|
345 | */ | |
346 |
|
346 | |||
347 | /*! |
|
347 | /*! | |
348 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
348 | \fn void QAbstractAxis::labelsColorChanged(QColor color) | |
349 | Emitted if the \a color of the axis labels is changed. |
|
349 | Emitted if the \a color of the axis labels is changed. | |
350 | */ |
|
350 | */ | |
351 | /*! |
|
351 | /*! | |
352 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
352 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) | |
353 | Emitted if the \a color of the axis labels is changed. |
|
353 | Emitted if the \a color of the axis labels is changed. | |
354 | */ |
|
354 | */ | |
355 |
|
355 | |||
356 | /*! |
|
356 | /*! | |
357 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) |
|
357 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) | |
358 | Visibility of the title text of the axis has changed to \a visible. |
|
358 | Visibility of the title text of the axis has changed to \a visible. | |
359 | */ |
|
359 | */ | |
360 | /*! |
|
360 | /*! | |
361 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) |
|
361 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) | |
362 | Visibility of the title text of the axis has changed to \a visible. |
|
362 | Visibility of the title text of the axis has changed to \a visible. | |
363 | */ |
|
363 | */ | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | \fn void QAbstractAxis::titleTextChanged(const QString& text) |
|
366 | \fn void QAbstractAxis::titleTextChanged(const QString& text) | |
367 | The text of the axis title has changed to \a text. |
|
367 | The text of the axis title has changed to \a text. | |
368 | */ |
|
368 | */ | |
369 | /*! |
|
369 | /*! | |
370 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) |
|
370 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) | |
371 | The text of the axis title has changed to \a text. |
|
371 | The text of the axis title has changed to \a text. | |
372 | */ |
|
372 | */ | |
373 |
|
373 | |||
374 | /*! |
|
374 | /*! | |
375 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) |
|
375 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) | |
376 | The pen of the axis shades has changed to \a pen. |
|
376 | The pen of the axis shades has changed to \a pen. | |
377 | */ |
|
377 | */ | |
378 |
|
378 | |||
379 | /*! |
|
379 | /*! | |
380 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) |
|
380 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) | |
381 | The brush of the axis title has changed to \a brush. |
|
381 | The brush of the axis title has changed to \a brush. | |
382 | */ |
|
382 | */ | |
383 |
|
383 | |||
384 | /*! |
|
384 | /*! | |
385 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) |
|
385 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) | |
386 | The font of the axis title has changed to \a font. |
|
386 | The font of the axis title has changed to \a font. | |
387 | */ |
|
387 | */ | |
388 | /*! |
|
388 | /*! | |
389 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) |
|
389 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) | |
390 | The font of the axis title has changed to \a font. |
|
390 | The font of the axis title has changed to \a font. | |
391 | */ |
|
391 | */ | |
392 |
|
392 | |||
393 | /*! |
|
393 | /*! | |
394 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
394 | \fn void QAbstractAxis::shadesVisibleChanged(bool) | |
395 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
395 | Emitted if the visibility of the axis shades is changed to \a visible. | |
396 | */ |
|
396 | */ | |
397 | /*! |
|
397 | /*! | |
398 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
398 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) | |
399 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
399 | Emitted if the visibility of the axis shades is changed to \a visible. | |
400 | */ |
|
400 | */ | |
401 |
|
401 | |||
402 | /*! |
|
402 | /*! | |
403 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
403 | \fn void QAbstractAxis::shadesColorChanged(QColor color) | |
404 | Emitted if the \a color of the axis shades is changed. |
|
404 | Emitted if the \a color of the axis shades is changed. | |
405 | */ |
|
405 | */ | |
406 | /*! |
|
406 | /*! | |
407 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
407 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) | |
408 | Emitted if the \a color of the axis shades is changed. |
|
408 | Emitted if the \a color of the axis shades is changed. | |
409 | */ |
|
409 | */ | |
410 |
|
410 | |||
411 | /*! |
|
411 | /*! | |
412 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
412 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) | |
413 | Emitted if the border \a color of the axis shades is changed. |
|
413 | Emitted if the border \a color of the axis shades is changed. | |
414 | */ |
|
414 | */ | |
415 | /*! |
|
415 | /*! | |
416 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
416 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) | |
417 | Emitted if the border \a color of the axis shades is changed. |
|
417 | Emitted if the border \a color of the axis shades is changed. | |
418 | */ |
|
418 | */ | |
419 |
|
419 | |||
420 | /*! |
|
420 | /*! | |
421 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) |
|
421 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) | |
422 | The brush of the axis shades has changed to \a brush. |
|
422 | The brush of the axis shades has changed to \a brush. | |
423 | */ |
|
423 | */ | |
424 |
|
424 | |||
425 | /*! |
|
425 | /*! | |
426 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) |
|
426 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) | |
427 | The pen of the axis shades has changed to \a pen. |
|
427 | The pen of the axis shades has changed to \a pen. | |
428 | */ |
|
428 | */ | |
429 |
|
429 | |||
430 | /*! |
|
430 | /*! | |
431 | \internal |
|
431 | \internal | |
432 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
432 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
433 | QChart when axis added. |
|
433 | QChart when axis added. | |
434 | */ |
|
434 | */ | |
435 |
|
435 | |||
436 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
436 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) | |
437 | : QObject(parent), |
|
437 | : QObject(parent), | |
438 | d_ptr(&d) |
|
438 | d_ptr(&d) | |
439 | { |
|
439 | { | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | /*! |
|
442 | /*! | |
443 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
443 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
444 | */ |
|
444 | */ | |
445 |
|
445 | |||
446 | QAbstractAxis::~QAbstractAxis() |
|
446 | QAbstractAxis::~QAbstractAxis() | |
447 | { |
|
447 | { | |
448 | if (d_ptr->m_chart) |
|
448 | if (d_ptr->m_chart) | |
449 | qFatal("Still binded axis detected !"); |
|
449 | qFatal("Still binded axis detected !"); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | /*! |
|
452 | /*! | |
453 | Sets \a pen used to draw axis line and ticks. |
|
453 | Sets \a pen used to draw axis line and ticks. | |
454 | */ |
|
454 | */ | |
455 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
455 | void QAbstractAxis::setLinePen(const QPen &pen) | |
456 | { |
|
456 | { | |
457 | if (d_ptr->m_axisPen != pen) { |
|
457 | if (d_ptr->m_axisPen != pen) { | |
458 | d_ptr->m_axisPen = pen; |
|
458 | d_ptr->m_axisPen = pen; | |
459 | emit linePenChanged(pen); |
|
459 | emit linePenChanged(pen); | |
460 | } |
|
460 | } | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | /*! |
|
463 | /*! | |
464 | Returns pen used to draw axis and ticks. |
|
464 | Returns pen used to draw axis and ticks. | |
465 | */ |
|
465 | */ | |
466 | QPen QAbstractAxis::linePen() const |
|
466 | QPen QAbstractAxis::linePen() const | |
467 | { |
|
467 | { | |
468 | return d_ptr->m_axisPen; |
|
468 | return d_ptr->m_axisPen; | |
469 | } |
|
469 | } | |
470 |
|
470 | |||
471 | //TODO: remove me |
|
471 | //TODO: remove me 2.0 | |
472 | void QAbstractAxis::setLinePenColor(QColor color) |
|
472 | void QAbstractAxis::setLinePenColor(QColor color) | |
473 | { |
|
473 | { | |
474 | QPen p = d_ptr->m_axisPen; |
|
474 | QPen p = d_ptr->m_axisPen; | |
475 | if (p.color() != color) { |
|
475 | if (p.color() != color) { | |
476 | p.setColor(color); |
|
476 | p.setColor(color); | |
477 | setLinePen(p); |
|
477 | setLinePen(p); | |
478 | emit colorChanged(color); |
|
478 | emit colorChanged(color); | |
479 | } |
|
479 | } | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | QColor QAbstractAxis::linePenColor() const |
|
482 | QColor QAbstractAxis::linePenColor() const | |
483 | { |
|
483 | { | |
484 | return d_ptr->m_axisPen.color(); |
|
484 | return d_ptr->m_axisPen.color(); | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | /*! |
|
487 | /*! | |
488 | Sets if axis and ticks are \a visible. |
|
488 | Sets if axis and ticks are \a visible. | |
489 | */ |
|
489 | */ | |
490 | void QAbstractAxis::setLineVisible(bool visible) |
|
490 | void QAbstractAxis::setLineVisible(bool visible) | |
491 | { |
|
491 | { | |
492 | if (d_ptr->m_arrowVisible != visible) { |
|
492 | if (d_ptr->m_arrowVisible != visible) { | |
493 | d_ptr->m_arrowVisible = visible; |
|
493 | d_ptr->m_arrowVisible = visible; | |
494 | emit lineVisibleChanged(visible); |
|
494 | emit lineVisibleChanged(visible); | |
495 | } |
|
495 | } | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | bool QAbstractAxis::isLineVisible() const |
|
498 | bool QAbstractAxis::isLineVisible() const | |
499 | { |
|
499 | { | |
500 | return d_ptr->m_arrowVisible; |
|
500 | return d_ptr->m_arrowVisible; | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
503 | void QAbstractAxis::setGridLineVisible(bool visible) | |
504 | { |
|
504 | { | |
505 | if (d_ptr->m_gridLineVisible != visible) { |
|
505 | if (d_ptr->m_gridLineVisible != visible) { | |
506 | d_ptr->m_gridLineVisible = visible; |
|
506 | d_ptr->m_gridLineVisible = visible; | |
507 | emit gridVisibleChanged(visible); |
|
507 | emit gridVisibleChanged(visible); | |
508 | } |
|
508 | } | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | bool QAbstractAxis::isGridLineVisible() const |
|
511 | bool QAbstractAxis::isGridLineVisible() const | |
512 | { |
|
512 | { | |
513 | return d_ptr->m_gridLineVisible; |
|
513 | return d_ptr->m_gridLineVisible; | |
514 | } |
|
514 | } | |
515 |
|
515 | |||
516 | /*! |
|
516 | /*! | |
517 | Sets \a pen used to draw grid line. |
|
517 | Sets \a pen used to draw grid line. | |
518 | */ |
|
518 | */ | |
519 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
519 | void QAbstractAxis::setGridLinePen(const QPen &pen) | |
520 | { |
|
520 | { | |
521 | if (d_ptr->m_gridLinePen != pen) { |
|
521 | if (d_ptr->m_gridLinePen != pen) { | |
522 | d_ptr->m_gridLinePen = pen; |
|
522 | d_ptr->m_gridLinePen = pen; | |
523 | emit gridLinePenChanged(pen); |
|
523 | emit gridLinePenChanged(pen); | |
524 | } |
|
524 | } | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | /*! |
|
527 | /*! | |
528 | Returns pen used to draw grid. |
|
528 | Returns pen used to draw grid. | |
529 | */ |
|
529 | */ | |
530 | QPen QAbstractAxis::gridLinePen() const |
|
530 | QPen QAbstractAxis::gridLinePen() const | |
531 | { |
|
531 | { | |
532 | return d_ptr->m_gridLinePen; |
|
532 | return d_ptr->m_gridLinePen; | |
533 | } |
|
533 | } | |
534 |
|
534 | |||
535 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
535 | void QAbstractAxis::setLabelsVisible(bool visible) | |
536 | { |
|
536 | { | |
537 | if (d_ptr->m_labelsVisible != visible) { |
|
537 | if (d_ptr->m_labelsVisible != visible) { | |
538 | d_ptr->m_labelsVisible = visible; |
|
538 | d_ptr->m_labelsVisible = visible; | |
539 | emit labelsVisibleChanged(visible); |
|
539 | emit labelsVisibleChanged(visible); | |
540 | } |
|
540 | } | |
541 | } |
|
541 | } | |
542 |
|
542 | |||
543 | bool QAbstractAxis::labelsVisible() const |
|
543 | bool QAbstractAxis::labelsVisible() const | |
544 | { |
|
544 | { | |
545 | return d_ptr->m_labelsVisible; |
|
545 | return d_ptr->m_labelsVisible; | |
546 | } |
|
546 | } | |
547 |
|
547 | |||
548 | /*! |
|
548 | /*! | |
549 | Sets \a pen used to draw labels. |
|
549 | Sets \a pen used to draw labels. | |
550 | */ |
|
550 | */ | |
551 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
551 | void QAbstractAxis::setLabelsPen(const QPen &pen) | |
552 | { |
|
552 | { | |
553 | if (d_ptr->m_labelsPen != pen) { |
|
553 | if (d_ptr->m_labelsPen != pen) { | |
554 | d_ptr->m_labelsPen = pen; |
|
554 | d_ptr->m_labelsPen = pen; | |
555 | emit labelsPenChanged(pen); |
|
555 | emit labelsPenChanged(pen); | |
556 | } |
|
556 | } | |
557 | } |
|
557 | } | |
558 |
|
558 | |||
559 | /*! |
|
559 | /*! | |
560 | Returns the pen used to labels. |
|
560 | Returns the pen used to labels. | |
561 | */ |
|
561 | */ | |
562 | QPen QAbstractAxis::labelsPen() const |
|
562 | QPen QAbstractAxis::labelsPen() const | |
563 | { |
|
563 | { | |
564 | return d_ptr->m_labelsPen; |
|
564 | return d_ptr->m_labelsPen; | |
565 | } |
|
565 | } | |
566 |
|
566 | |||
567 | /*! |
|
567 | /*! | |
568 | Sets \a brush used to draw labels. |
|
568 | Sets \a brush used to draw labels. | |
569 | */ |
|
569 | */ | |
570 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
570 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |
571 | { |
|
571 | { | |
572 | if (d_ptr->m_labelsBrush != brush) { |
|
572 | if (d_ptr->m_labelsBrush != brush) { | |
573 | d_ptr->m_labelsBrush = brush; |
|
573 | d_ptr->m_labelsBrush = brush; | |
574 | emit labelsBrushChanged(brush); |
|
574 | emit labelsBrushChanged(brush); | |
575 | } |
|
575 | } | |
576 | } |
|
576 | } | |
577 |
|
577 | |||
578 | /*! |
|
578 | /*! | |
579 | Returns brush used to draw labels. |
|
579 | Returns brush used to draw labels. | |
580 | */ |
|
580 | */ | |
581 | QBrush QAbstractAxis::labelsBrush() const |
|
581 | QBrush QAbstractAxis::labelsBrush() const | |
582 | { |
|
582 | { | |
583 | return d_ptr->m_labelsBrush; |
|
583 | return d_ptr->m_labelsBrush; | |
584 | } |
|
584 | } | |
585 |
|
585 | |||
586 | /*! |
|
586 | /*! | |
587 | Sets \a font used to draw labels. |
|
587 | Sets \a font used to draw labels. | |
588 | */ |
|
588 | */ | |
589 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
589 | void QAbstractAxis::setLabelsFont(const QFont &font) | |
590 | { |
|
590 | { | |
591 | if (d_ptr->m_labelsFont != font) { |
|
591 | if (d_ptr->m_labelsFont != font) { | |
592 | d_ptr->m_labelsFont = font; |
|
592 | d_ptr->m_labelsFont = font; | |
593 | emit labelsFontChanged(font); |
|
593 | emit labelsFontChanged(font); | |
594 | } |
|
594 | } | |
595 | } |
|
595 | } | |
596 |
|
596 | |||
597 | /*! |
|
597 | /*! | |
598 | Returns font used to draw labels. |
|
598 | Returns font used to draw labels. | |
599 | */ |
|
599 | */ | |
600 | QFont QAbstractAxis::labelsFont() const |
|
600 | QFont QAbstractAxis::labelsFont() const | |
601 | { |
|
601 | { | |
602 | return d_ptr->m_labelsFont; |
|
602 | return d_ptr->m_labelsFont; | |
603 | } |
|
603 | } | |
604 |
|
604 | |||
605 | void QAbstractAxis::setLabelsAngle(int angle) |
|
605 | void QAbstractAxis::setLabelsAngle(int angle) | |
606 | { |
|
606 | { | |
607 | if (d_ptr->m_labelsAngle != angle) { |
|
607 | if (d_ptr->m_labelsAngle != angle) { | |
608 | d_ptr->m_labelsAngle = angle; |
|
608 | d_ptr->m_labelsAngle = angle; | |
609 | emit labelsAngleChanged(angle); |
|
609 | emit labelsAngleChanged(angle); | |
610 | } |
|
610 | } | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | int QAbstractAxis::labelsAngle() const |
|
613 | int QAbstractAxis::labelsAngle() const | |
614 | { |
|
614 | { | |
615 | return d_ptr->m_labelsAngle; |
|
615 | return d_ptr->m_labelsAngle; | |
616 | } |
|
616 | } | |
617 | //TODO: remove me |
|
617 | //TODO: remove me 2.0 | |
618 | void QAbstractAxis::setLabelsColor(QColor color) |
|
618 | void QAbstractAxis::setLabelsColor(QColor color) | |
619 | { |
|
619 | { | |
620 | QBrush b = d_ptr->m_labelsBrush; |
|
620 | QBrush b = d_ptr->m_labelsBrush; | |
621 | if (b.color() != color) { |
|
621 | if (b.color() != color) { | |
622 | b.setColor(color); |
|
622 | b.setColor(color); | |
623 | setLabelsBrush(b); |
|
623 | setLabelsBrush(b); | |
624 | emit labelsColorChanged(color); |
|
624 | emit labelsColorChanged(color); | |
625 | } |
|
625 | } | |
626 | } |
|
626 | } | |
627 |
|
627 | |||
628 | QColor QAbstractAxis::labelsColor() const |
|
628 | QColor QAbstractAxis::labelsColor() const | |
629 | { |
|
629 | { | |
630 | return d_ptr->m_labelsBrush.color(); |
|
630 | return d_ptr->m_labelsBrush.color(); | |
631 | } |
|
631 | } | |
632 |
|
632 | |||
633 | void QAbstractAxis::setTitleVisible(bool visible) |
|
633 | void QAbstractAxis::setTitleVisible(bool visible) | |
634 | { |
|
634 | { | |
635 | if (d_ptr->m_titleVisible != visible) { |
|
635 | if (d_ptr->m_titleVisible != visible) { | |
636 | d_ptr->m_titleVisible = visible; |
|
636 | d_ptr->m_titleVisible = visible; | |
637 | emit titleVisibleChanged(visible); |
|
637 | emit titleVisibleChanged(visible); | |
638 | } |
|
638 | } | |
639 | } |
|
639 | } | |
640 |
|
640 | |||
641 | bool QAbstractAxis::isTitleVisible() const |
|
641 | bool QAbstractAxis::isTitleVisible() const | |
642 | { |
|
642 | { | |
643 | return d_ptr->m_titleVisible; |
|
643 | return d_ptr->m_titleVisible; | |
644 | } |
|
644 | } | |
645 |
|
645 | |||
646 | /*! |
|
646 | /*! | |
647 | Sets \a pen used to draw title. |
|
647 | Sets \a pen used to draw title. | |
648 | */ |
|
648 | */ | |
649 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
649 | void QAbstractAxis::setTitlePen(const QPen &pen) | |
650 | { |
|
650 | { | |
651 | if (d_ptr->m_titlePen != pen) { |
|
651 | if (d_ptr->m_titlePen != pen) { | |
652 | d_ptr->m_titlePen = pen; |
|
652 | d_ptr->m_titlePen = pen; | |
653 | emit titlePenChanged(pen); |
|
653 | emit titlePenChanged(pen); | |
654 | } |
|
654 | } | |
655 | } |
|
655 | } | |
656 |
|
656 | |||
657 | /*! |
|
657 | /*! | |
658 | Returns the pen used to title. |
|
658 | Returns the pen used to title. | |
659 | */ |
|
659 | */ | |
660 | QPen QAbstractAxis::titlePen() const |
|
660 | QPen QAbstractAxis::titlePen() const | |
661 | { |
|
661 | { | |
662 | return d_ptr->m_titlePen; |
|
662 | return d_ptr->m_titlePen; | |
663 | } |
|
663 | } | |
664 |
|
664 | |||
665 | /*! |
|
665 | /*! | |
666 | Sets \a brush used to draw title. |
|
666 | Sets \a brush used to draw title. | |
667 | */ |
|
667 | */ | |
668 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
668 | void QAbstractAxis::setTitleBrush(const QBrush &brush) | |
669 | { |
|
669 | { | |
670 | if (d_ptr->m_titleBrush != brush) { |
|
670 | if (d_ptr->m_titleBrush != brush) { | |
671 | d_ptr->m_titleBrush = brush; |
|
671 | d_ptr->m_titleBrush = brush; | |
672 | emit titleBrushChanged(brush); |
|
672 | emit titleBrushChanged(brush); | |
673 | } |
|
673 | } | |
674 | } |
|
674 | } | |
675 |
|
675 | |||
676 | /*! |
|
676 | /*! | |
677 | Returns brush used to draw title. |
|
677 | Returns brush used to draw title. | |
678 | */ |
|
678 | */ | |
679 | QBrush QAbstractAxis::titleBrush() const |
|
679 | QBrush QAbstractAxis::titleBrush() const | |
680 | { |
|
680 | { | |
681 | return d_ptr->m_titleBrush; |
|
681 | return d_ptr->m_titleBrush; | |
682 | } |
|
682 | } | |
683 |
|
683 | |||
684 | /*! |
|
684 | /*! | |
685 | Sets \a font used to draw title. |
|
685 | Sets \a font used to draw title. | |
686 | */ |
|
686 | */ | |
687 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
687 | void QAbstractAxis::setTitleFont(const QFont &font) | |
688 | { |
|
688 | { | |
689 | if (d_ptr->m_titleFont != font) { |
|
689 | if (d_ptr->m_titleFont != font) { | |
690 | d_ptr->m_titleFont = font; |
|
690 | d_ptr->m_titleFont = font; | |
691 | emit titleFontChanged(font); |
|
691 | emit titleFontChanged(font); | |
692 | } |
|
692 | } | |
693 | } |
|
693 | } | |
694 |
|
694 | |||
695 | /*! |
|
695 | /*! | |
696 | Returns font used to draw title. |
|
696 | Returns font used to draw title. | |
697 | */ |
|
697 | */ | |
698 | QFont QAbstractAxis::titleFont() const |
|
698 | QFont QAbstractAxis::titleFont() const | |
699 | { |
|
699 | { | |
700 | return d_ptr->m_titleFont; |
|
700 | return d_ptr->m_titleFont; | |
701 | } |
|
701 | } | |
702 |
|
702 | |||
703 | void QAbstractAxis::setTitleText(const QString &title) |
|
703 | void QAbstractAxis::setTitleText(const QString &title) | |
704 | { |
|
704 | { | |
705 | if (d_ptr->m_title != title) { |
|
705 | if (d_ptr->m_title != title) { | |
706 | d_ptr->m_title = title; |
|
706 | d_ptr->m_title = title; | |
707 | emit titleTextChanged(title); |
|
707 | emit titleTextChanged(title); | |
708 | } |
|
708 | } | |
709 | } |
|
709 | } | |
710 |
|
710 | |||
711 | QString QAbstractAxis::titleText() const |
|
711 | QString QAbstractAxis::titleText() const | |
712 | { |
|
712 | { | |
713 | return d_ptr->m_title; |
|
713 | return d_ptr->m_title; | |
714 | } |
|
714 | } | |
715 |
|
715 | |||
716 |
|
716 | |||
717 | void QAbstractAxis::setShadesVisible(bool visible) |
|
717 | void QAbstractAxis::setShadesVisible(bool visible) | |
718 | { |
|
718 | { | |
719 | if (d_ptr->m_shadesVisible != visible) { |
|
719 | if (d_ptr->m_shadesVisible != visible) { | |
720 | d_ptr->m_shadesVisible = visible; |
|
720 | d_ptr->m_shadesVisible = visible; | |
721 | emit shadesVisibleChanged(visible); |
|
721 | emit shadesVisibleChanged(visible); | |
722 | } |
|
722 | } | |
723 | } |
|
723 | } | |
724 |
|
724 | |||
725 | bool QAbstractAxis::shadesVisible() const |
|
725 | bool QAbstractAxis::shadesVisible() const | |
726 | { |
|
726 | { | |
727 | return d_ptr->m_shadesVisible; |
|
727 | return d_ptr->m_shadesVisible; | |
728 | } |
|
728 | } | |
729 |
|
729 | |||
730 | /*! |
|
730 | /*! | |
731 | Sets \a pen used to draw shades. |
|
731 | Sets \a pen used to draw shades. | |
732 | */ |
|
732 | */ | |
733 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
733 | void QAbstractAxis::setShadesPen(const QPen &pen) | |
734 | { |
|
734 | { | |
735 | if (d_ptr->m_shadesPen != pen) { |
|
735 | if (d_ptr->m_shadesPen != pen) { | |
736 | d_ptr->m_shadesPen = pen; |
|
736 | d_ptr->m_shadesPen = pen; | |
737 | emit shadesPenChanged(pen); |
|
737 | emit shadesPenChanged(pen); | |
738 | } |
|
738 | } | |
739 | } |
|
739 | } | |
740 |
|
740 | |||
741 | /*! |
|
741 | /*! | |
742 | Returns pen used to draw shades. |
|
742 | Returns pen used to draw shades. | |
743 | */ |
|
743 | */ | |
744 | QPen QAbstractAxis::shadesPen() const |
|
744 | QPen QAbstractAxis::shadesPen() const | |
745 | { |
|
745 | { | |
746 | return d_ptr->m_shadesPen; |
|
746 | return d_ptr->m_shadesPen; | |
747 | } |
|
747 | } | |
748 |
|
748 | |||
749 | /*! |
|
749 | /*! | |
750 | Sets \a brush used to draw shades. |
|
750 | Sets \a brush used to draw shades. | |
751 | */ |
|
751 | */ | |
752 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
752 | void QAbstractAxis::setShadesBrush(const QBrush &brush) | |
753 | { |
|
753 | { | |
754 | if (d_ptr->m_shadesBrush != brush) { |
|
754 | if (d_ptr->m_shadesBrush != brush) { | |
755 | d_ptr->m_shadesBrush = brush; |
|
755 | d_ptr->m_shadesBrush = brush; | |
756 | emit shadesBrushChanged(brush); |
|
756 | emit shadesBrushChanged(brush); | |
757 | } |
|
757 | } | |
758 | } |
|
758 | } | |
759 |
|
759 | |||
760 | /*! |
|
760 | /*! | |
761 | Returns brush used to draw shades. |
|
761 | Returns brush used to draw shades. | |
762 | */ |
|
762 | */ | |
763 | QBrush QAbstractAxis::shadesBrush() const |
|
763 | QBrush QAbstractAxis::shadesBrush() const | |
764 | { |
|
764 | { | |
765 | return d_ptr->m_shadesBrush; |
|
765 | return d_ptr->m_shadesBrush; | |
766 | } |
|
766 | } | |
767 |
|
767 | |||
768 | void QAbstractAxis::setShadesColor(QColor color) |
|
768 | void QAbstractAxis::setShadesColor(QColor color) | |
769 | { |
|
769 | { | |
770 | QBrush b = d_ptr->m_shadesBrush; |
|
770 | QBrush b = d_ptr->m_shadesBrush; | |
771 | if (b.color() != color) { |
|
771 | if (b.color() != color) { | |
772 | b.setColor(color); |
|
772 | b.setColor(color); | |
773 | setShadesBrush(b); |
|
773 | setShadesBrush(b); | |
774 | emit shadesColorChanged(color); |
|
774 | emit shadesColorChanged(color); | |
775 | } |
|
775 | } | |
776 | } |
|
776 | } | |
777 |
|
777 | |||
778 | QColor QAbstractAxis::shadesColor() const |
|
778 | QColor QAbstractAxis::shadesColor() const | |
779 | { |
|
779 | { | |
780 | return d_ptr->m_shadesBrush.color(); |
|
780 | return d_ptr->m_shadesBrush.color(); | |
781 | } |
|
781 | } | |
782 |
|
782 | |||
783 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
783 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
784 | { |
|
784 | { | |
785 | QPen p = d_ptr->m_shadesPen; |
|
785 | QPen p = d_ptr->m_shadesPen; | |
786 | if (p.color() != color) { |
|
786 | if (p.color() != color) { | |
787 | p.setColor(color); |
|
787 | p.setColor(color); | |
788 | setShadesPen(p); |
|
788 | setShadesPen(p); | |
789 | emit shadesColorChanged(color); |
|
789 | emit shadesColorChanged(color); | |
790 | } |
|
790 | } | |
791 | } |
|
791 | } | |
792 |
|
792 | |||
793 | QColor QAbstractAxis::shadesBorderColor() const |
|
793 | QColor QAbstractAxis::shadesBorderColor() const | |
794 | { |
|
794 | { | |
795 | return d_ptr->m_shadesPen.color(); |
|
795 | return d_ptr->m_shadesPen.color(); | |
796 | } |
|
796 | } | |
797 |
|
797 | |||
798 |
|
798 | |||
799 | bool QAbstractAxis::isVisible() const |
|
799 | bool QAbstractAxis::isVisible() const | |
800 | { |
|
800 | { | |
801 | return d_ptr->m_visible; |
|
801 | return d_ptr->m_visible; | |
802 | } |
|
802 | } | |
803 |
|
803 | |||
804 | /*! |
|
804 | /*! | |
805 | Sets axis, shades, labels and grid lines to be visible. |
|
805 | Sets axis, shades, labels and grid lines to be visible. | |
806 | */ |
|
806 | */ | |
807 | void QAbstractAxis::setVisible(bool visible) |
|
807 | void QAbstractAxis::setVisible(bool visible) | |
808 | { |
|
808 | { | |
809 | if (d_ptr->m_visible != visible) { |
|
809 | if (d_ptr->m_visible != visible) { | |
810 | d_ptr->m_visible = visible; |
|
810 | d_ptr->m_visible = visible; | |
811 | emit visibleChanged(visible); |
|
811 | emit visibleChanged(visible); | |
812 | } |
|
812 | } | |
813 | } |
|
813 | } | |
814 |
|
814 | |||
815 |
|
815 | |||
816 | /*! |
|
816 | /*! | |
817 | Sets axis, shades, labels and grid lines to be visible. |
|
817 | Sets axis, shades, labels and grid lines to be visible. | |
818 | */ |
|
818 | */ | |
819 | void QAbstractAxis::show() |
|
819 | void QAbstractAxis::show() | |
820 | { |
|
820 | { | |
821 | setVisible(true); |
|
821 | setVisible(true); | |
822 | } |
|
822 | } | |
823 |
|
823 | |||
824 | /*! |
|
824 | /*! | |
825 | Sets axis, shades, labels and grid lines to not be visible. |
|
825 | Sets axis, shades, labels and grid lines to not be visible. | |
826 | */ |
|
826 | */ | |
827 | void QAbstractAxis::hide() |
|
827 | void QAbstractAxis::hide() | |
828 | { |
|
828 | { | |
829 | setVisible(false); |
|
829 | setVisible(false); | |
830 | } |
|
830 | } | |
831 |
|
831 | |||
832 | /*! |
|
832 | /*! | |
833 | Sets the minimum value shown on the axis. |
|
833 | Sets the minimum value shown on the axis. | |
834 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
834 | Depending on the actual axis type the \a min parameter is converted to appropriate type. | |
835 | If the conversion is impossible then the function call does nothing |
|
835 | If the conversion is impossible then the function call does nothing | |
836 | */ |
|
836 | */ | |
837 | void QAbstractAxis::setMin(const QVariant &min) |
|
837 | void QAbstractAxis::setMin(const QVariant &min) | |
838 | { |
|
838 | { | |
839 | d_ptr->setMin(min); |
|
839 | d_ptr->setMin(min); | |
840 | } |
|
840 | } | |
841 |
|
841 | |||
842 | /*! |
|
842 | /*! | |
843 | Sets the maximum value shown on the axis. |
|
843 | Sets the maximum value shown on the axis. | |
844 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
844 | Depending on the actual axis type the \a max parameter is converted to appropriate type. | |
845 | If the conversion is impossible then the function call does nothing |
|
845 | If the conversion is impossible then the function call does nothing | |
846 | */ |
|
846 | */ | |
847 | void QAbstractAxis::setMax(const QVariant &max) |
|
847 | void QAbstractAxis::setMax(const QVariant &max) | |
848 | { |
|
848 | { | |
849 | d_ptr->setMax(max); |
|
849 | d_ptr->setMax(max); | |
850 | } |
|
850 | } | |
851 |
|
851 | |||
852 | /*! |
|
852 | /*! | |
853 | Sets the range shown on the axis. |
|
853 | Sets the range shown on the axis. | |
854 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
854 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. | |
855 | If the conversion is impossible then the function call does nothing. |
|
855 | If the conversion is impossible then the function call does nothing. | |
856 | */ |
|
856 | */ | |
857 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
857 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
858 | { |
|
858 | { | |
859 | d_ptr->setRange(min, max); |
|
859 | d_ptr->setRange(min, max); | |
860 | } |
|
860 | } | |
861 |
|
861 | |||
862 |
|
862 | |||
863 | /*! |
|
863 | /*! | |
864 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
864 | Returns the orientation in which the axis is being used (Vertical or Horizontal) | |
865 | */ |
|
865 | */ | |
866 | // NOTE: should have const but it breaks BC: |
|
866 | // NOTE: should have const but it breaks BC: | |
867 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function |
|
867 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function | |
868 | Qt::Orientation QAbstractAxis::orientation() |
|
868 | Qt::Orientation QAbstractAxis::orientation() | |
869 | { |
|
869 | { | |
870 | return d_ptr->orientation(); |
|
870 | return d_ptr->orientation(); | |
871 | } |
|
871 | } | |
872 |
|
872 | |||
873 | Qt::Alignment QAbstractAxis::alignment() const |
|
873 | Qt::Alignment QAbstractAxis::alignment() const | |
874 | { |
|
874 | { | |
875 | return d_ptr->alignment(); |
|
875 | return d_ptr->alignment(); | |
876 | } |
|
876 | } | |
877 |
|
877 | |||
878 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
878 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
879 |
|
879 | |||
880 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
880 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) | |
881 | : q_ptr(q), |
|
881 | : q_ptr(q), | |
882 | m_chart(0), |
|
882 | m_chart(0), | |
883 | m_alignment(0), |
|
883 | m_alignment(0), | |
884 | m_orientation(Qt::Orientation(0)), |
|
884 | m_orientation(Qt::Orientation(0)), | |
885 | m_visible(true), |
|
885 | m_visible(true), | |
886 | m_arrowVisible(true), |
|
886 | m_arrowVisible(true), | |
887 | m_gridLineVisible(true), |
|
887 | m_gridLineVisible(true), | |
888 | m_labelsVisible(true), |
|
888 | m_labelsVisible(true), | |
889 | m_labelsAngle(0), |
|
889 | m_labelsAngle(0), | |
890 | m_titleVisible(true), |
|
890 | m_titleVisible(true), | |
891 | m_shadesVisible(false), |
|
891 | m_shadesVisible(false), | |
892 | m_shadesBrush(Qt::SolidPattern), |
|
892 | m_shadesBrush(Qt::SolidPattern), | |
893 | m_shadesOpacity(1.0), |
|
893 | m_shadesOpacity(1.0), | |
894 | m_dirty(false) |
|
894 | m_dirty(false) | |
895 | { |
|
895 | { | |
896 |
|
896 | |||
897 | } |
|
897 | } | |
898 |
|
898 | |||
899 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
899 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
900 | { |
|
900 | { | |
901 | } |
|
901 | } | |
902 |
|
902 | |||
903 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
903 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) | |
904 | { |
|
904 | { | |
905 | switch(alignment) { |
|
905 | switch(alignment) { | |
906 | case Qt::AlignTop: |
|
906 | case Qt::AlignTop: | |
907 | case Qt::AlignBottom: |
|
907 | case Qt::AlignBottom: | |
908 | m_orientation = Qt::Horizontal; |
|
908 | m_orientation = Qt::Horizontal; | |
909 | break; |
|
909 | break; | |
910 | case Qt::AlignLeft: |
|
910 | case Qt::AlignLeft: | |
911 | case Qt::AlignRight: |
|
911 | case Qt::AlignRight: | |
912 | m_orientation = Qt::Vertical; |
|
912 | m_orientation = Qt::Vertical; | |
913 | break; |
|
913 | break; | |
914 | default: |
|
914 | default: | |
915 | qWarning()<<"No alignment specified !"; |
|
915 | qWarning()<<"No alignment specified !"; | |
916 | break; |
|
916 | break; | |
917 | }; |
|
917 | }; | |
918 | m_alignment=alignment; |
|
918 | m_alignment=alignment; | |
919 | } |
|
919 | } | |
920 |
|
920 | |||
921 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
921 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) | |
922 | { |
|
922 | { | |
923 | QPen pen; |
|
923 | QPen pen; | |
924 | QBrush brush; |
|
924 | QBrush brush; | |
925 | QFont font; |
|
925 | QFont font; | |
926 |
|
926 | |||
927 | bool axisX = m_orientation == Qt::Horizontal; |
|
927 | bool axisX = m_orientation == Qt::Horizontal; | |
928 |
|
928 | |||
929 | //TODO: introduce axis brush |
|
929 | //TODO: introduce axis brush | |
930 | if (m_visible) { |
|
930 | if (m_visible) { | |
931 | if (m_arrowVisible) { |
|
931 | if (m_arrowVisible) { | |
932 | if (forced || pen == m_axisPen) { |
|
932 | if (forced || pen == m_axisPen) { | |
933 | q_ptr->setLinePen(theme->axisLinePen()); |
|
933 | q_ptr->setLinePen(theme->axisLinePen()); | |
934 | } |
|
934 | } | |
935 | } |
|
935 | } | |
936 | if (m_gridLineVisible) { |
|
936 | if (m_gridLineVisible) { | |
937 | if (forced || pen == m_gridLinePen) { |
|
937 | if (forced || pen == m_gridLinePen) { | |
938 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
938 | q_ptr->setGridLinePen(theme->girdLinePen()); | |
939 | } |
|
939 | } | |
940 | } |
|
940 | } | |
941 | if (m_labelsVisible) { |
|
941 | if (m_labelsVisible) { | |
942 | if (forced || brush == m_labelsBrush){ |
|
942 | if (forced || brush == m_labelsBrush){ | |
943 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
943 | q_ptr->setLabelsBrush(theme->labelBrush()); | |
944 | } |
|
944 | } | |
945 | if (forced || pen == m_labelsPen){ |
|
945 | if (forced || pen == m_labelsPen){ | |
946 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons |
|
946 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons | |
947 | } |
|
947 | } | |
948 | if (forced || font == m_labelsFont){ |
|
948 | if (forced || font == m_labelsFont){ | |
949 | q_ptr->setLabelsFont(theme->labelFont()); |
|
949 | q_ptr->setLabelsFont(theme->labelFont()); | |
950 | } |
|
950 | } | |
951 | } |
|
951 | } | |
952 | if (m_titleVisible) { |
|
952 | if (m_titleVisible) { | |
953 | if (forced || brush == m_titleBrush){ |
|
953 | if (forced || brush == m_titleBrush){ | |
954 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
954 | q_ptr->setTitleBrush(theme->labelBrush()); | |
955 | } |
|
955 | } | |
956 | if (forced || pen == m_titlePen){ |
|
956 | if (forced || pen == m_titlePen){ | |
957 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons |
|
957 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons | |
958 | } |
|
958 | } | |
959 | //TODO: discuss with Tero |
|
|||
960 | if (forced || font == m_titleFont){ |
|
959 | if (forced || font == m_titleFont){ | |
961 | QFont font(m_labelsFont); |
|
960 | QFont font(m_labelsFont); | |
962 | font.setBold(true); |
|
961 | font.setBold(true); | |
963 | q_ptr->setTitleFont(font); |
|
962 | q_ptr->setTitleFont(font); | |
964 | } |
|
963 | } | |
965 | } |
|
964 | } | |
966 | if (forced || m_shadesVisible) { |
|
965 | if (forced || m_shadesVisible) { | |
967 | if (forced || brush == m_shadesBrush){ |
|
966 | if (forced || brush == m_shadesBrush){ | |
968 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
967 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); | |
969 | } |
|
968 | } | |
970 | if (forced || pen == m_shadesPen){ |
|
969 | if (forced || pen == m_shadesPen){ | |
971 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
970 | q_ptr->setShadesPen(theme->backgroundShadesPen()); | |
972 | } |
|
971 | } | |
973 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
972 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth | |
974 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
973 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) | |
975 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
974 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { | |
976 | q_ptr->setShadesVisible(true); |
|
975 | q_ptr->setShadesVisible(true); | |
977 | } |
|
976 | } | |
978 | } |
|
977 | } | |
979 | } |
|
978 | } | |
980 | } |
|
979 | } | |
981 |
|
980 | |||
982 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
981 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) | |
983 | { |
|
982 | { | |
984 | setRange(min,max); |
|
983 | setRange(min,max); | |
985 | } |
|
984 | } | |
986 |
|
985 | |||
987 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
986 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
988 | { |
|
987 | { | |
989 | Q_UNUSED(parent); |
|
988 | Q_UNUSED(parent); | |
990 | } |
|
989 | } | |
991 |
|
990 | |||
992 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
991 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) | |
993 | { |
|
992 | { | |
994 | ChartAxis* axis = m_item.data(); |
|
993 | ChartAxis* axis = m_item.data(); | |
995 | Q_ASSERT(axis); |
|
994 | Q_ASSERT(axis); | |
996 | if(options.testFlag(QChart::GridAxisAnimations)) { |
|
995 | if(options.testFlag(QChart::GridAxisAnimations)) { | |
997 | axis->setAnimation(new AxisAnimation(axis)); |
|
996 | axis->setAnimation(new AxisAnimation(axis)); | |
998 | }else{ |
|
997 | }else{ | |
999 | axis->setAnimation(0); |
|
998 | axis->setAnimation(0); | |
1000 | } |
|
999 | } | |
1001 | } |
|
1000 | } | |
1002 |
|
1001 | |||
1003 |
|
1002 | |||
1004 |
|
1003 | |||
1005 | #include "moc_qabstractaxis.cpp" |
|
1004 | #include "moc_qabstractaxis.cpp" | |
1006 | #include "moc_qabstractaxis_p.cpp" |
|
1005 | #include "moc_qabstractaxis_p.cpp" | |
1007 |
|
1006 | |||
1008 | QTCOMMERCIALCHART_END_NAMESPACE |
|
1007 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,193 +1,192 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QABSTRACTAXIS_H |
|
21 | #ifndef QABSTRACTAXIS_H | |
22 | #define QABSTRACTAXIS_H |
|
22 | #define QABSTRACTAXIS_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QFont> |
|
26 | #include <QFont> | |
27 | #include <QVariant> |
|
27 | #include <QVariant> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAbstractAxisPrivate; |
|
31 | class QAbstractAxisPrivate; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | //visibility |
|
36 | //visibility | |
37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
38 | //arrow |
|
38 | //arrow | |
39 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
39 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) | |
40 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) |
|
40 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) | |
41 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
41 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) | |
42 | //labels |
|
42 | //labels | |
43 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
43 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
44 | Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged) |
|
44 | Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged) | |
45 | Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) |
|
45 | Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) | |
46 | //TODO: fix labels angles to work with layout |
|
|||
47 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) |
|
46 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) | |
48 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) |
|
47 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) | |
49 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
48 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) | |
50 | //grid |
|
49 | //grid | |
51 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
50 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) | |
52 | Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) |
|
51 | Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) | |
53 | //shades |
|
52 | //shades | |
54 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
53 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) | |
55 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
54 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) | |
56 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
55 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) | |
57 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) |
|
56 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) | |
58 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) |
|
57 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) | |
59 | //title |
|
58 | //title | |
60 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) |
|
59 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) | |
61 | Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) |
|
60 | Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) | |
62 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) |
|
61 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) | |
63 | Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged) |
|
62 | Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged) | |
64 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged) |
|
63 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged) | |
65 | //orientation |
|
64 | //orientation | |
66 | Q_PROPERTY(Qt::Orientation orientation READ orientation) |
|
65 | Q_PROPERTY(Qt::Orientation orientation READ orientation) | |
67 | //aligment |
|
66 | //aligment | |
68 | Q_PROPERTY(Qt::Alignment alignment READ alignment) |
|
67 | Q_PROPERTY(Qt::Alignment alignment READ alignment) | |
69 |
|
68 | |||
70 | public: |
|
69 | public: | |
71 |
|
70 | |||
72 | enum AxisType { |
|
71 | enum AxisType { | |
73 | AxisTypeNoAxis = 0x0, |
|
72 | AxisTypeNoAxis = 0x0, | |
74 | AxisTypeValue = 0x1, |
|
73 | AxisTypeValue = 0x1, | |
75 | AxisTypeBarCategory = 0x2, |
|
74 | AxisTypeBarCategory = 0x2, | |
76 | AxisTypeCategory = 0x3, |
|
75 | AxisTypeCategory = 0x3, | |
77 | AxisTypeDateTime = 0x4, |
|
76 | AxisTypeDateTime = 0x4, | |
78 | AxisTypeLogValue = 0x5 |
|
77 | AxisTypeLogValue = 0x5 | |
79 | }; |
|
78 | }; | |
80 |
|
79 | |||
81 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
80 | Q_DECLARE_FLAGS(AxisTypes, AxisType) | |
82 |
|
81 | |||
83 | protected: |
|
82 | protected: | |
84 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0); |
|
83 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0); | |
85 |
|
84 | |||
86 | public: |
|
85 | public: | |
87 | ~QAbstractAxis(); |
|
86 | ~QAbstractAxis(); | |
88 |
|
87 | |||
89 | virtual AxisType type() const = 0; |
|
88 | virtual AxisType type() const = 0; | |
90 |
|
89 | |||
91 | //visibility handling |
|
90 | //visibility handling | |
92 | bool isVisible() const; |
|
91 | bool isVisible() const; | |
93 | void setVisible(bool visible = true); |
|
92 | void setVisible(bool visible = true); | |
94 | void show(); |
|
93 | void show(); | |
95 | void hide(); |
|
94 | void hide(); | |
96 |
|
95 | |||
97 | //arrow handling |
|
96 | //arrow handling | |
98 | bool isLineVisible() const; |
|
97 | bool isLineVisible() const; | |
99 | void setLineVisible(bool visible = true); |
|
98 | void setLineVisible(bool visible = true); | |
100 | void setLinePen(const QPen &pen); |
|
99 | void setLinePen(const QPen &pen); | |
101 | QPen linePen() const; |
|
100 | QPen linePen() const; | |
102 | void setLinePenColor(QColor color); |
|
101 | void setLinePenColor(QColor color); | |
103 | QColor linePenColor() const; |
|
102 | QColor linePenColor() const; | |
104 |
|
103 | |||
105 | //grid handling |
|
104 | //grid handling | |
106 | bool isGridLineVisible() const; |
|
105 | bool isGridLineVisible() const; | |
107 | void setGridLineVisible(bool visible = true); |
|
106 | void setGridLineVisible(bool visible = true); | |
108 | void setGridLinePen(const QPen &pen); |
|
107 | void setGridLinePen(const QPen &pen); | |
109 | QPen gridLinePen() const; |
|
108 | QPen gridLinePen() const; | |
110 |
|
109 | |||
111 | //labels handling |
|
110 | //labels handling | |
112 | bool labelsVisible() const; |
|
111 | bool labelsVisible() const; | |
113 | void setLabelsVisible(bool visible = true); |
|
112 | void setLabelsVisible(bool visible = true); | |
114 | void setLabelsPen(const QPen &pen); |
|
113 | void setLabelsPen(const QPen &pen); | |
115 | QPen labelsPen() const; |
|
114 | QPen labelsPen() const; | |
116 | void setLabelsBrush(const QBrush &brush); |
|
115 | void setLabelsBrush(const QBrush &brush); | |
117 | QBrush labelsBrush() const; |
|
116 | QBrush labelsBrush() const; | |
118 | void setLabelsFont(const QFont &font); |
|
117 | void setLabelsFont(const QFont &font); | |
119 | QFont labelsFont() const; |
|
118 | QFont labelsFont() const; | |
120 | void setLabelsAngle(int angle); |
|
119 | void setLabelsAngle(int angle); | |
121 | int labelsAngle() const; |
|
120 | int labelsAngle() const; | |
122 | void setLabelsColor(QColor color); |
|
121 | void setLabelsColor(QColor color); | |
123 | QColor labelsColor() const; |
|
122 | QColor labelsColor() const; | |
124 |
|
123 | |||
125 | //title handling |
|
124 | //title handling | |
126 | bool isTitleVisible() const; |
|
125 | bool isTitleVisible() const; | |
127 | void setTitleVisible(bool visible = true); |
|
126 | void setTitleVisible(bool visible = true); | |
128 | void setTitlePen(const QPen &pen); |
|
127 | void setTitlePen(const QPen &pen); | |
129 | QPen titlePen() const; |
|
128 | QPen titlePen() const; | |
130 | void setTitleBrush(const QBrush &brush); |
|
129 | void setTitleBrush(const QBrush &brush); | |
131 | QBrush titleBrush() const; |
|
130 | QBrush titleBrush() const; | |
132 | void setTitleFont(const QFont &font); |
|
131 | void setTitleFont(const QFont &font); | |
133 | QFont titleFont() const; |
|
132 | QFont titleFont() const; | |
134 | void setTitleText(const QString &title); |
|
133 | void setTitleText(const QString &title); | |
135 | QString titleText() const; |
|
134 | QString titleText() const; | |
136 |
|
135 | |||
137 | //shades handling |
|
136 | //shades handling | |
138 | bool shadesVisible() const; |
|
137 | bool shadesVisible() const; | |
139 | void setShadesVisible(bool visible = true); |
|
138 | void setShadesVisible(bool visible = true); | |
140 | void setShadesPen(const QPen &pen); |
|
139 | void setShadesPen(const QPen &pen); | |
141 | QPen shadesPen() const; |
|
140 | QPen shadesPen() const; | |
142 | void setShadesBrush(const QBrush &brush); |
|
141 | void setShadesBrush(const QBrush &brush); | |
143 | QBrush shadesBrush() const; |
|
142 | QBrush shadesBrush() const; | |
144 | void setShadesColor(QColor color); |
|
143 | void setShadesColor(QColor color); | |
145 | QColor shadesColor() const; |
|
144 | QColor shadesColor() const; | |
146 | void setShadesBorderColor(QColor color); |
|
145 | void setShadesBorderColor(QColor color); | |
147 | QColor shadesBorderColor() const; |
|
146 | QColor shadesBorderColor() const; | |
148 |
|
147 | |||
149 | Qt::Orientation orientation(); //TODO: missing const <- BC |
|
148 | Qt::Orientation orientation(); //TODO: missing const <- BC (2.0) | |
150 | Qt::Alignment alignment() const; |
|
149 | Qt::Alignment alignment() const; | |
151 |
|
150 | |||
152 | //range handling |
|
151 | //range handling | |
153 | void setMin(const QVariant &min); |
|
152 | void setMin(const QVariant &min); | |
154 | void setMax(const QVariant &max); |
|
153 | void setMax(const QVariant &max); | |
155 | void setRange(const QVariant &min, const QVariant &max); |
|
154 | void setRange(const QVariant &min, const QVariant &max); | |
156 |
|
155 | |||
157 | Q_SIGNALS: |
|
156 | Q_SIGNALS: | |
158 | void visibleChanged(bool visible); |
|
157 | void visibleChanged(bool visible); | |
159 | void linePenChanged(const QPen& pen); |
|
158 | void linePenChanged(const QPen& pen); | |
160 | void lineVisibleChanged(bool visible); |
|
159 | void lineVisibleChanged(bool visible); | |
161 | void labelsVisibleChanged(bool visible); |
|
160 | void labelsVisibleChanged(bool visible); | |
162 | void labelsPenChanged(const QPen& pen); |
|
161 | void labelsPenChanged(const QPen& pen); | |
163 | void labelsBrushChanged(const QBrush& brush); |
|
162 | void labelsBrushChanged(const QBrush& brush); | |
164 | void labelsFontChanged(const QFont& pen); |
|
163 | void labelsFontChanged(const QFont& pen); | |
165 | void labelsAngleChanged(int angle); |
|
164 | void labelsAngleChanged(int angle); | |
166 | void gridLinePenChanged(const QPen& pen); |
|
165 | void gridLinePenChanged(const QPen& pen); | |
167 | void gridVisibleChanged(bool visible); |
|
166 | void gridVisibleChanged(bool visible); | |
168 | void colorChanged(QColor color); |
|
167 | void colorChanged(QColor color); | |
169 | void labelsColorChanged(QColor color); |
|
168 | void labelsColorChanged(QColor color); | |
170 | void titleTextChanged(const QString& title); |
|
169 | void titleTextChanged(const QString& title); | |
171 | void titlePenChanged(const QPen& pen); |
|
170 | void titlePenChanged(const QPen& pen); | |
172 | void titleBrushChanged(const QBrush& brush); |
|
171 | void titleBrushChanged(const QBrush& brush); | |
173 | void titleVisibleChanged(bool visible); |
|
172 | void titleVisibleChanged(bool visible); | |
174 | void titleFontChanged(const QFont& font); |
|
173 | void titleFontChanged(const QFont& font); | |
175 | void shadesVisibleChanged(bool visible); |
|
174 | void shadesVisibleChanged(bool visible); | |
176 | void shadesColorChanged(QColor color); |
|
175 | void shadesColorChanged(QColor color); | |
177 | void shadesBorderColorChanged(QColor color); |
|
176 | void shadesBorderColorChanged(QColor color); | |
178 | void shadesPenChanged(const QPen& pen); |
|
177 | void shadesPenChanged(const QPen& pen); | |
179 | void shadesBrushChanged(const QBrush& brush); |
|
178 | void shadesBrushChanged(const QBrush& brush); | |
180 |
|
179 | |||
181 | protected: |
|
180 | protected: | |
182 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
181 | QScopedPointer<QAbstractAxisPrivate> d_ptr; | |
183 | Q_DISABLE_COPY(QAbstractAxis) |
|
182 | Q_DISABLE_COPY(QAbstractAxis) | |
184 | friend class ChartDataSet; |
|
183 | friend class ChartDataSet; | |
185 | friend class ChartAxis; |
|
184 | friend class ChartAxis; | |
186 | friend class ChartPresenter; |
|
185 | friend class ChartPresenter; | |
187 | friend class ChartThemeManager; |
|
186 | friend class ChartThemeManager; | |
188 | friend class AbstractDomain; |
|
187 | friend class AbstractDomain; | |
189 | }; |
|
188 | }; | |
190 |
|
189 | |||
191 | QTCOMMERCIALCHART_END_NAMESPACE |
|
190 | QTCOMMERCIALCHART_END_NAMESPACE | |
192 |
|
191 | |||
193 | #endif // QABSTRACTAXIS_H |
|
192 | #endif // QABSTRACTAXIS_H |
@@ -1,84 +1,84 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QVALUEAXIS_H |
|
21 | #ifndef QVALUEAXIS_H | |
22 | #define QVALUEAXIS_H |
|
22 | #define QVALUEAXIS_H | |
23 |
|
23 | |||
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QValueAxisPrivate; |
|
28 | class QValueAxisPrivate; | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis |
|
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) |
|
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) | |
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) |
|
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) | |
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) | |
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) | |
37 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) |
|
37 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | explicit QValueAxis(QObject *parent = 0); |
|
40 | explicit QValueAxis(QObject *parent = 0); | |
41 | ~QValueAxis(); |
|
41 | ~QValueAxis(); | |
42 |
|
42 | |||
43 | protected: |
|
43 | protected: | |
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); |
|
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | AxisType type() const; |
|
47 | AxisType type() const; | |
48 |
|
48 | |||
49 | //range handling |
|
49 | //range handling | |
50 | void setMin(qreal min); |
|
50 | void setMin(qreal min); | |
51 | qreal min() const; |
|
51 | qreal min() const; | |
52 | void setMax(qreal max); |
|
52 | void setMax(qreal max); | |
53 | qreal max() const; |
|
53 | qreal max() const; | |
54 | void setRange(qreal min, qreal max); |
|
54 | void setRange(qreal min, qreal max); | |
55 |
|
55 | |||
56 | //ticks handling |
|
56 | //ticks handling | |
57 | void setTickCount(int count); |
|
57 | void setTickCount(int count); | |
58 | int tickCount() const; |
|
58 | int tickCount() const; | |
59 |
|
59 | |||
60 | void setLabelFormat(const QString &format); |
|
60 | void setLabelFormat(const QString &format); | |
61 | QString labelFormat() const; |
|
61 | QString labelFormat() const; | |
62 |
|
62 | |||
63 |
//TODO: deprec |
|
63 | //TODO: deprecated! (2.0) | |
64 | void setNiceNumbersEnabled(bool enable = true); |
|
64 | void setNiceNumbersEnabled(bool enable = true); | |
65 | bool niceNumbersEnabled() const; |
|
65 | bool niceNumbersEnabled() const; | |
66 |
|
66 | |||
67 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
68 | void applyNiceNumbers(); |
|
68 | void applyNiceNumbers(); | |
69 |
|
69 | |||
70 | Q_SIGNALS: |
|
70 | Q_SIGNALS: | |
71 | void minChanged(qreal min); |
|
71 | void minChanged(qreal min); | |
72 | void maxChanged(qreal max); |
|
72 | void maxChanged(qreal max); | |
73 | void rangeChanged(qreal min, qreal max); |
|
73 | void rangeChanged(qreal min, qreal max); | |
74 | void tickCountChanged(int tickCount); |
|
74 | void tickCountChanged(int tickCount); | |
75 | void labelFormatChanged(const QString &format); |
|
75 | void labelFormatChanged(const QString &format); | |
76 |
|
76 | |||
77 | private: |
|
77 | private: | |
78 | Q_DECLARE_PRIVATE(QValueAxis) |
|
78 | Q_DECLARE_PRIVATE(QValueAxis) | |
79 | Q_DISABLE_COPY(QValueAxis) |
|
79 | Q_DISABLE_COPY(QValueAxis) | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
83 | |||
84 | #endif // QVALUEAXIS_H |
|
84 | #endif // QVALUEAXIS_H |
@@ -1,70 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QVALUEAXIS_P_H |
|
30 | #ifndef QVALUEAXIS_P_H | |
31 | #define QVALUEAXIS_P_H |
|
31 | #define QVALUEAXIS_P_H | |
32 |
|
32 | |||
33 | #include "qvalueaxis.h" |
|
33 | #include "qvalueaxis.h" | |
34 | #include "qabstractaxis_p.h" |
|
34 | #include "qabstractaxis_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class QValueAxisPrivate : public QAbstractAxisPrivate |
|
38 | class QValueAxisPrivate : public QAbstractAxisPrivate | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | QValueAxisPrivate(QValueAxis *q); |
|
42 | QValueAxisPrivate(QValueAxis *q); | |
43 | ~QValueAxisPrivate(); |
|
43 | ~QValueAxisPrivate(); | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | void initializeGraphics(QGraphicsItem* parent); |
|
46 | void initializeGraphics(QGraphicsItem* parent); | |
47 | void initializeDomain(AbstractDomain *domain); |
|
47 | void initializeDomain(AbstractDomain *domain); | |
48 |
|
48 | |||
49 | qreal min() { return m_min; }; |
|
49 | qreal min() { return m_min; }; | |
50 | qreal max() { return m_max; }; |
|
50 | qreal max() { return m_max; }; | |
51 | void setRange(qreal min,qreal max); |
|
51 | void setRange(qreal min,qreal max); | |
52 |
|
52 | |||
53 | protected: |
|
53 | protected: | |
54 | void setMin(const QVariant &min); |
|
54 | void setMin(const QVariant &min); | |
55 | void setMax(const QVariant &max); |
|
55 | void setMax(const QVariant &max); | |
56 | void setRange(const QVariant &min, const QVariant &max); |
|
56 | void setRange(const QVariant &min, const QVariant &max); | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | qreal m_min; |
|
59 | qreal m_min; | |
60 | qreal m_max; |
|
60 | qreal m_max; | |
61 | int m_tickCount; |
|
61 | int m_tickCount; | |
62 | QString m_format; |
|
62 | QString m_format; | |
63 | bool m_applying; |
|
63 | bool m_applying; | |
64 |
bool m_niceNumbersEnabled; //TODO: this deprec |
|
64 | bool m_niceNumbersEnabled; //TODO: this deprecated (2.0) | |
65 | Q_DECLARE_PUBLIC(QValueAxis) |
|
65 | Q_DECLARE_PUBLIC(QValueAxis) | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
69 | |||
70 | #endif // QVALUEAXIS_P_H |
|
70 | #endif // QVALUEAXIS_P_H |
@@ -1,394 +1,392 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartlayout_p.h" |
|
21 | #include "chartlayout_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qlegend_p.h" |
|
23 | #include "qlegend_p.h" | |
24 | #include "chartaxis_p.h" |
|
24 | #include "chartaxis_p.h" | |
25 | #include "charttitle_p.h" |
|
25 | #include "charttitle_p.h" | |
26 | #include "chartbackground_p.h" |
|
26 | #include "chartbackground_p.h" | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | static const qreal maxAxisPortion = 0.4; |
|
31 | static const qreal maxAxisPortion = 0.4; | |
32 |
|
32 | |||
33 | ChartLayout::ChartLayout(ChartPresenter *presenter) |
|
33 | ChartLayout::ChartLayout(ChartPresenter *presenter) | |
34 | : m_presenter(presenter), |
|
34 | : m_presenter(presenter), | |
35 | m_margins(20, 20, 20, 20), |
|
35 | m_margins(20, 20, 20, 20), | |
36 | m_minChartRect(0, 0, 200, 200) |
|
36 | m_minChartRect(0, 0, 200, 200) | |
37 | { |
|
37 | { | |
38 |
|
38 | |||
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ChartLayout::~ChartLayout() |
|
41 | ChartLayout::~ChartLayout() | |
42 | { |
|
42 | { | |
43 |
|
43 | |||
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void ChartLayout::setGeometry(const QRectF &rect) |
|
46 | void ChartLayout::setGeometry(const QRectF &rect) | |
47 | { |
|
47 | { | |
48 | if (!rect.isValid()) |
|
48 | if (!rect.isValid()) | |
49 | return; |
|
49 | return; | |
50 |
|
50 | |||
51 | QList<ChartAxis *> axes = m_presenter->axisItems(); |
|
51 | QList<ChartAxis *> axes = m_presenter->axisItems(); | |
52 | ChartTitle *title = m_presenter->titleElement(); |
|
52 | ChartTitle *title = m_presenter->titleElement(); | |
53 | QLegend *legend = m_presenter->legend(); |
|
53 | QLegend *legend = m_presenter->legend(); | |
54 | ChartBackground *background = m_presenter->backgroundElement(); |
|
54 | ChartBackground *background = m_presenter->backgroundElement(); | |
55 |
|
55 | |||
56 | QRectF contentGeometry = calculateBackgroundGeometry(rect, background); |
|
56 | QRectF contentGeometry = calculateBackgroundGeometry(rect, background); | |
57 |
|
57 | |||
58 | contentGeometry = calculateContentGeometry(contentGeometry); |
|
58 | contentGeometry = calculateContentGeometry(contentGeometry); | |
59 |
|
59 | |||
60 | if (title && title->isVisible()) |
|
60 | if (title && title->isVisible()) | |
61 | contentGeometry = calculateTitleGeometry(contentGeometry, title); |
|
61 | contentGeometry = calculateTitleGeometry(contentGeometry, title); | |
62 |
|
62 | |||
63 | if (legend->isAttachedToChart() && legend->isVisible()) |
|
63 | if (legend->isAttachedToChart() && legend->isVisible()) | |
64 | contentGeometry = calculateLegendGeometry(contentGeometry, legend); |
|
64 | contentGeometry = calculateLegendGeometry(contentGeometry, legend); | |
65 |
|
65 | |||
66 | contentGeometry = calculateAxisGeometry(contentGeometry, axes); |
|
66 | contentGeometry = calculateAxisGeometry(contentGeometry, axes); | |
67 |
|
67 | |||
68 | m_presenter->setGeometry(contentGeometry); |
|
68 | m_presenter->setGeometry(contentGeometry); | |
69 |
|
69 | |||
70 | QGraphicsLayout::setGeometry(rect); |
|
70 | QGraphicsLayout::setGeometry(rect); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | QRectF ChartLayout::calculateContentGeometry(const QRectF &geometry) const |
|
73 | QRectF ChartLayout::calculateContentGeometry(const QRectF &geometry) const | |
74 | { |
|
74 | { | |
75 | return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom()); |
|
75 | return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom()); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | QRectF ChartLayout::calculateContentMinimum(const QRectF &minimum) const |
|
78 | QRectF ChartLayout::calculateContentMinimum(const QRectF &minimum) const | |
79 | { |
|
79 | { | |
80 | return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom()); |
|
80 | return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom()); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | QRectF ChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const |
|
84 | QRectF ChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const | |
85 | { |
|
85 | { | |
86 | qreal left, top, right, bottom; |
|
86 | qreal left, top, right, bottom; | |
87 | getContentsMargins(&left, &top, &right, &bottom); |
|
87 | getContentsMargins(&left, &top, &right, &bottom); | |
88 | QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom); |
|
88 | QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom); | |
89 | if (background) |
|
89 | if (background) | |
90 | background->setRect(backgroundGeometry); |
|
90 | background->setRect(backgroundGeometry); | |
91 | return backgroundGeometry; |
|
91 | return backgroundGeometry; | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | QRectF ChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const |
|
94 | QRectF ChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const | |
95 | { |
|
95 | { | |
96 | qreal left, top, right, bottom; |
|
96 | qreal left, top, right, bottom; | |
97 | getContentsMargins(&left, &top, &right, &bottom); |
|
97 | getContentsMargins(&left, &top, &right, &bottom); | |
98 | return minimum.adjusted(0, 0, left + right, top + bottom); |
|
98 | return minimum.adjusted(0, 0, left + right, top + bottom); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const |
|
102 | QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const | |
103 | { |
|
103 | { | |
104 | QSizeF left(0,0); |
|
104 | QSizeF left(0,0); | |
105 | QSizeF minLeft(0,0); |
|
105 | QSizeF minLeft(0,0); | |
106 | QSizeF right(0,0); |
|
106 | QSizeF right(0,0); | |
107 | QSizeF minRight(0,0); |
|
107 | QSizeF minRight(0,0); | |
108 | QSizeF bottom(0,0); |
|
108 | QSizeF bottom(0,0); | |
109 | QSizeF minBottom(0,0); |
|
109 | QSizeF minBottom(0,0); | |
110 | QSizeF top(0,0); |
|
110 | QSizeF top(0,0); | |
111 | QSizeF minTop(0,0); |
|
111 | QSizeF minTop(0,0); | |
112 | int leftCount = 0; |
|
112 | int leftCount = 0; | |
113 | int rightCount = 0; |
|
113 | int rightCount = 0; | |
114 | int topCount = 0; |
|
114 | int topCount = 0; | |
115 | int bottomCount = 0; |
|
115 | int bottomCount = 0; | |
116 |
|
116 | |||
117 | foreach (ChartAxis *axis , axes) { |
|
117 | foreach (ChartAxis *axis , axes) { | |
118 |
|
118 | |||
119 | if (!axis->isVisible()) |
|
119 | if (!axis->isVisible()) | |
120 | continue; |
|
120 | continue; | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); |
|
123 | QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); | |
124 | //this is used to get single thick font size |
|
124 | //this is used to get single thick font size | |
125 | QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize); |
|
125 | QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize); | |
126 |
|
126 | |||
127 | switch (axis->alignment()) { |
|
127 | switch (axis->alignment()) { | |
128 | case Qt::AlignLeft: |
|
128 | case Qt::AlignLeft: | |
129 | left.setWidth(left.width()+size.width()); |
|
129 | left.setWidth(left.width()+size.width()); | |
130 | left.setHeight(qMax(left.height(),size.height())); |
|
130 | left.setHeight(qMax(left.height(),size.height())); | |
131 | minLeft.setWidth(minLeft.width()+minSize.width()); |
|
131 | minLeft.setWidth(minLeft.width()+minSize.width()); | |
132 | minLeft.setHeight(qMax(minLeft.height(),minSize.height())); |
|
132 | minLeft.setHeight(qMax(minLeft.height(),minSize.height())); | |
133 | leftCount++; |
|
133 | leftCount++; | |
134 | break; |
|
134 | break; | |
135 | case Qt::AlignRight: |
|
135 | case Qt::AlignRight: | |
136 | right.setWidth(right.width()+size.width()); |
|
136 | right.setWidth(right.width()+size.width()); | |
137 | right.setHeight(qMax(right.height(),size.height())); |
|
137 | right.setHeight(qMax(right.height(),size.height())); | |
138 | minRight.setWidth(minRight.width()+minSize.width()); |
|
138 | minRight.setWidth(minRight.width()+minSize.width()); | |
139 | minRight.setHeight(qMax(minRight.height(),minSize.height())); |
|
139 | minRight.setHeight(qMax(minRight.height(),minSize.height())); | |
140 | rightCount++; |
|
140 | rightCount++; | |
141 | break; |
|
141 | break; | |
142 | case Qt::AlignTop: |
|
142 | case Qt::AlignTop: | |
143 | top.setWidth(qMax(top.width(),size.width())); |
|
143 | top.setWidth(qMax(top.width(),size.width())); | |
144 | top.setHeight(top.height()+size.height()); |
|
144 | top.setHeight(top.height()+size.height()); | |
145 | minTop.setWidth(qMax(minTop.width(),minSize.width())); |
|
145 | minTop.setWidth(qMax(minTop.width(),minSize.width())); | |
146 | minTop.setHeight(minTop.height()+minSize.height()); |
|
146 | minTop.setHeight(minTop.height()+minSize.height()); | |
147 | topCount++; |
|
147 | topCount++; | |
148 | break; |
|
148 | break; | |
149 | case Qt::AlignBottom: |
|
149 | case Qt::AlignBottom: | |
150 | bottom.setWidth(qMax(bottom.width(), size.width())); |
|
150 | bottom.setWidth(qMax(bottom.width(), size.width())); | |
151 | bottom.setHeight(bottom.height() + size.height()); |
|
151 | bottom.setHeight(bottom.height() + size.height()); | |
152 | minBottom.setWidth(qMax(minBottom.width(),minSize.width())); |
|
152 | minBottom.setWidth(qMax(minBottom.width(),minSize.width())); | |
153 | minBottom.setHeight(minBottom.height() + minSize.height()); |
|
153 | minBottom.setHeight(minBottom.height() + minSize.height()); | |
154 | bottomCount++; |
|
154 | bottomCount++; | |
155 | break; |
|
155 | break; | |
156 | default: |
|
156 | default: | |
157 | qWarning()<<"Axis is without alignment !"; |
|
157 | qWarning()<<"Axis is without alignment !"; | |
158 | break; |
|
158 | break; | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | int totalVerticalAxes = leftCount + rightCount; |
|
162 | int totalVerticalAxes = leftCount + rightCount; | |
163 | qreal leftSqueezeRatio = 1.0; |
|
163 | qreal leftSqueezeRatio = 1.0; | |
164 | qreal rightSqueezeRatio = 1.0; |
|
164 | qreal rightSqueezeRatio = 1.0; | |
165 | qreal vratio = 0; |
|
165 | qreal vratio = 0; | |
166 |
|
166 | |||
167 | if (totalVerticalAxes > 0) |
|
167 | if (totalVerticalAxes > 0) | |
168 | vratio = (maxAxisPortion * geometry.width()) / totalVerticalAxes; |
|
168 | vratio = (maxAxisPortion * geometry.width()) / totalVerticalAxes; | |
169 |
|
169 | |||
170 | if (leftCount > 0) { |
|
170 | if (leftCount > 0) { | |
171 | int maxWidth = vratio * leftCount; |
|
171 | int maxWidth = vratio * leftCount; | |
172 | if (left.width() > maxWidth) { |
|
172 | if (left.width() > maxWidth) { | |
173 | leftSqueezeRatio = maxWidth / left.width(); |
|
173 | leftSqueezeRatio = maxWidth / left.width(); | |
174 | left.setWidth(maxWidth); |
|
174 | left.setWidth(maxWidth); | |
175 | } |
|
175 | } | |
176 | } |
|
176 | } | |
177 | if (rightCount > 0) { |
|
177 | if (rightCount > 0) { | |
178 | int maxWidth = vratio * rightCount; |
|
178 | int maxWidth = vratio * rightCount; | |
179 | if (right.width() > maxWidth) { |
|
179 | if (right.width() > maxWidth) { | |
180 | rightSqueezeRatio = maxWidth / right.width(); |
|
180 | rightSqueezeRatio = maxWidth / right.width(); | |
181 | right.setWidth(maxWidth); |
|
181 | right.setWidth(maxWidth); | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | int totalHorizontalAxes = topCount + bottomCount; |
|
185 | int totalHorizontalAxes = topCount + bottomCount; | |
186 | qreal topSqueezeRatio = 1.0; |
|
186 | qreal topSqueezeRatio = 1.0; | |
187 | qreal bottomSqueezeRatio = 1.0; |
|
187 | qreal bottomSqueezeRatio = 1.0; | |
188 | qreal hratio = 0; |
|
188 | qreal hratio = 0; | |
189 |
|
189 | |||
190 | if (totalHorizontalAxes > 0) |
|
190 | if (totalHorizontalAxes > 0) | |
191 | hratio = (maxAxisPortion * geometry.height()) / totalHorizontalAxes; |
|
191 | hratio = (maxAxisPortion * geometry.height()) / totalHorizontalAxes; | |
192 |
|
192 | |||
193 | if (topCount > 0) { |
|
193 | if (topCount > 0) { | |
194 | int maxHeight = hratio * topCount; |
|
194 | int maxHeight = hratio * topCount; | |
195 | if (top.height() > maxHeight) { |
|
195 | if (top.height() > maxHeight) { | |
196 | topSqueezeRatio = maxHeight / top.height(); |
|
196 | topSqueezeRatio = maxHeight / top.height(); | |
197 | top.setHeight(maxHeight); |
|
197 | top.setHeight(maxHeight); | |
198 | } |
|
198 | } | |
199 | } |
|
199 | } | |
200 | if (bottomCount > 0) { |
|
200 | if (bottomCount > 0) { | |
201 | int maxHeight = hratio * bottomCount; |
|
201 | int maxHeight = hratio * bottomCount; | |
202 | if (bottom.height() > maxHeight) { |
|
202 | if (bottom.height() > maxHeight) { | |
203 | bottomSqueezeRatio = maxHeight / bottom.height(); |
|
203 | bottomSqueezeRatio = maxHeight / bottom.height(); | |
204 | bottom.setHeight(maxHeight); |
|
204 | bottom.setHeight(maxHeight); | |
205 | } |
|
205 | } | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | qreal minHeight = qMax(minLeft.height(),minRight.height()) + 1; |
|
208 | qreal minHeight = qMax(minLeft.height(),minRight.height()) + 1; | |
209 | qreal minWidth = qMax(minTop.width(),minBottom.width()) + 1; |
|
209 | qreal minWidth = qMax(minTop.width(),minBottom.width()) + 1; | |
210 |
|
210 | |||
211 | QRectF chartRect = geometry.adjusted(qMax(left.width(),minWidth/2), qMax(top.height(), minHeight/2),-qMax(right.width(),minWidth/2),-qMax(bottom.height(),minHeight/2)); |
|
211 | QRectF chartRect = geometry.adjusted(qMax(left.width(),minWidth/2), qMax(top.height(), minHeight/2),-qMax(right.width(),minWidth/2),-qMax(bottom.height(),minHeight/2)); | |
212 |
|
212 | |||
213 | qreal leftOffset = 0; |
|
213 | qreal leftOffset = 0; | |
214 | qreal rightOffset = 0; |
|
214 | qreal rightOffset = 0; | |
215 | qreal topOffset = 0; |
|
215 | qreal topOffset = 0; | |
216 | qreal bottomOffset = 0; |
|
216 | qreal bottomOffset = 0; | |
217 |
|
217 | |||
218 | foreach(ChartElement *axisElement , axes) { |
|
218 | foreach(ChartElement *axisElement , axes) { | |
219 |
|
||||
220 | //TODO fixme |
|
|||
221 | ChartAxis* axis = qobject_cast<ChartAxis*>(axisElement); |
|
219 | ChartAxis* axis = qobject_cast<ChartAxis*>(axisElement); | |
222 |
|
220 | |||
223 | if (!axis->isVisible()) |
|
221 | if (!axis->isVisible()) | |
224 | continue; |
|
222 | continue; | |
225 |
|
223 | |||
226 | QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); |
|
224 | QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); | |
227 |
|
225 | |||
228 | switch(axis->alignment()){ |
|
226 | switch(axis->alignment()){ | |
229 | case Qt::AlignLeft:{ |
|
227 | case Qt::AlignLeft:{ | |
230 | qreal width = size.width(); |
|
228 | qreal width = size.width(); | |
231 | if (leftSqueezeRatio < 1.0) |
|
229 | if (leftSqueezeRatio < 1.0) | |
232 | width *= leftSqueezeRatio; |
|
230 | width *= leftSqueezeRatio; | |
233 | leftOffset+=width; |
|
231 | leftOffset+=width; | |
234 | axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect); |
|
232 | axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect); | |
235 | break; |
|
233 | break; | |
236 | } |
|
234 | } | |
237 | case Qt::AlignRight:{ |
|
235 | case Qt::AlignRight:{ | |
238 | qreal width = size.width(); |
|
236 | qreal width = size.width(); | |
239 | if (rightSqueezeRatio < 1.0) |
|
237 | if (rightSqueezeRatio < 1.0) | |
240 | width *= rightSqueezeRatio; |
|
238 | width *= rightSqueezeRatio; | |
241 | axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect); |
|
239 | axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect); | |
242 | rightOffset+=width; |
|
240 | rightOffset+=width; | |
243 | break; |
|
241 | break; | |
244 | } |
|
242 | } | |
245 | case Qt::AlignTop: { |
|
243 | case Qt::AlignTop: { | |
246 | qreal height = size.height(); |
|
244 | qreal height = size.height(); | |
247 | if (topSqueezeRatio < 1.0) |
|
245 | if (topSqueezeRatio < 1.0) | |
248 | height *= topSqueezeRatio; |
|
246 | height *= topSqueezeRatio; | |
249 | axis->setGeometry(QRect(geometry.left(), chartRect.top() - topOffset - height, geometry.width(), height), chartRect); |
|
247 | axis->setGeometry(QRect(geometry.left(), chartRect.top() - topOffset - height, geometry.width(), height), chartRect); | |
250 | topOffset += height; |
|
248 | topOffset += height; | |
251 | break; |
|
249 | break; | |
252 | } |
|
250 | } | |
253 | case Qt::AlignBottom: |
|
251 | case Qt::AlignBottom: | |
254 | qreal height = size.height(); |
|
252 | qreal height = size.height(); | |
255 | if (bottomSqueezeRatio < 1.0) |
|
253 | if (bottomSqueezeRatio < 1.0) | |
256 | height *= bottomSqueezeRatio; |
|
254 | height *= bottomSqueezeRatio; | |
257 | axis->setGeometry(QRect(geometry.left(), chartRect.bottom() + bottomOffset, geometry.width(), height), chartRect); |
|
255 | axis->setGeometry(QRect(geometry.left(), chartRect.bottom() + bottomOffset, geometry.width(), height), chartRect); | |
258 | bottomOffset += height; |
|
256 | bottomOffset += height; | |
259 | break; |
|
257 | break; | |
260 | } |
|
258 | } | |
261 | } |
|
259 | } | |
262 |
|
260 | |||
263 | return chartRect; |
|
261 | return chartRect; | |
264 | } |
|
262 | } | |
265 |
|
263 | |||
266 | QRectF ChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const |
|
264 | QRectF ChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const | |
267 | { |
|
265 | { | |
268 | QSizeF left; |
|
266 | QSizeF left; | |
269 | QSizeF right; |
|
267 | QSizeF right; | |
270 | QSizeF bottom; |
|
268 | QSizeF bottom; | |
271 | QSizeF top; |
|
269 | QSizeF top; | |
272 |
|
270 | |||
273 | foreach (ChartAxis *axis, axes) { |
|
271 | foreach (ChartAxis *axis, axes) { | |
274 |
|
272 | |||
275 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); |
|
273 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); | |
276 |
|
274 | |||
277 | if (!axis->isVisible()) |
|
275 | if (!axis->isVisible()) | |
278 | continue; |
|
276 | continue; | |
279 |
|
277 | |||
280 | switch (axis->alignment()) { |
|
278 | switch (axis->alignment()) { | |
281 | case Qt::AlignLeft: |
|
279 | case Qt::AlignLeft: | |
282 | left.setWidth(left.width() + size.width()); |
|
280 | left.setWidth(left.width() + size.width()); | |
283 | left.setHeight(qMax(left.height() * 2, size.height())); |
|
281 | left.setHeight(qMax(left.height() * 2, size.height())); | |
284 | break; |
|
282 | break; | |
285 | case Qt::AlignRight: |
|
283 | case Qt::AlignRight: | |
286 | right.setWidth(right.width() + size.width()); |
|
284 | right.setWidth(right.width() + size.width()); | |
287 | right.setHeight(qMax(right.height() * 2, size.height())); |
|
285 | right.setHeight(qMax(right.height() * 2, size.height())); | |
288 | break; |
|
286 | break; | |
289 | case Qt::AlignTop: |
|
287 | case Qt::AlignTop: | |
290 | top.setWidth(qMax(top.width(), size.width())); |
|
288 | top.setWidth(qMax(top.width(), size.width())); | |
291 | top.setHeight(top.height() + size.height()); |
|
289 | top.setHeight(top.height() + size.height()); | |
292 | break; |
|
290 | break; | |
293 | case Qt::AlignBottom: |
|
291 | case Qt::AlignBottom: | |
294 | bottom.setWidth(qMax(bottom.width(), size.width())); |
|
292 | bottom.setWidth(qMax(bottom.width(), size.width())); | |
295 | bottom.setHeight(bottom.height() + size.height()); |
|
293 | bottom.setHeight(bottom.height() + size.height()); | |
296 | break; |
|
294 | break; | |
297 | } |
|
295 | } | |
298 | } |
|
296 | } | |
299 | return minimum.adjusted(0, 0, left.width() + right.width() + qMax(top.width(), bottom.width()), top.height() + bottom.height() + qMax(left.height(), right.height())); |
|
297 | return minimum.adjusted(0, 0, left.width() + right.width() + qMax(top.width(), bottom.width()), top.height() + bottom.height() + qMax(left.height(), right.height())); | |
300 | } |
|
298 | } | |
301 |
|
299 | |||
302 | QRectF ChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const |
|
300 | QRectF ChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const | |
303 | { |
|
301 | { | |
304 | QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)); |
|
302 | QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)); | |
305 | QRectF legendRect; |
|
303 | QRectF legendRect; | |
306 | QRectF result; |
|
304 | QRectF result; | |
307 |
|
305 | |||
308 | switch (legend->alignment()) { |
|
306 | switch (legend->alignment()) { | |
309 | case Qt::AlignTop: { |
|
307 | case Qt::AlignTop: { | |
310 | legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height())); |
|
308 | legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height())); | |
311 | result = geometry.adjusted(0, legendRect.height(), 0, 0); |
|
309 | result = geometry.adjusted(0, legendRect.height(), 0, 0); | |
312 | break; |
|
310 | break; | |
313 | } |
|
311 | } | |
314 | case Qt::AlignBottom: { |
|
312 | case Qt::AlignBottom: { | |
315 | legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height())); |
|
313 | legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height())); | |
316 | result = geometry.adjusted(0, 0, 0, -legendRect.height()); |
|
314 | result = geometry.adjusted(0, 0, 0, -legendRect.height()); | |
317 | break; |
|
315 | break; | |
318 | } |
|
316 | } | |
319 | case Qt::AlignLeft: { |
|
317 | case Qt::AlignLeft: { | |
320 | qreal width = qMin(size.width(), geometry.width() * maxAxisPortion); |
|
318 | qreal width = qMin(size.width(), geometry.width() * maxAxisPortion); | |
321 | legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height())); |
|
319 | legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height())); | |
322 | result = geometry.adjusted(width, 0, 0, 0); |
|
320 | result = geometry.adjusted(width, 0, 0, 0); | |
323 | break; |
|
321 | break; | |
324 | } |
|
322 | } | |
325 | case Qt::AlignRight: { |
|
323 | case Qt::AlignRight: { | |
326 | qreal width = qMin(size.width(), geometry.width() * maxAxisPortion); |
|
324 | qreal width = qMin(size.width(), geometry.width() * maxAxisPortion); | |
327 | legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height())); |
|
325 | legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height())); | |
328 | result = geometry.adjusted(0, 0, -width, 0); |
|
326 | result = geometry.adjusted(0, 0, -width, 0); | |
329 | break; |
|
327 | break; | |
330 | } |
|
328 | } | |
331 | default: { |
|
329 | default: { | |
332 | legendRect = QRectF(0, 0, 0, 0); |
|
330 | legendRect = QRectF(0, 0, 0, 0); | |
333 | result = geometry; |
|
331 | result = geometry; | |
334 | break; |
|
332 | break; | |
335 | } |
|
333 | } | |
336 | } |
|
334 | } | |
337 |
|
335 | |||
338 | legend->setGeometry(legendRect); |
|
336 | legend->setGeometry(legendRect); | |
339 |
|
337 | |||
340 | return result; |
|
338 | return result; | |
341 | } |
|
339 | } | |
342 |
|
340 | |||
343 | QRectF ChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const |
|
341 | QRectF ChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const | |
344 | { |
|
342 | { | |
345 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)); |
|
343 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)); | |
346 | return geometry.adjusted(0, 0, minSize.width(), minSize.height()); |
|
344 | return geometry.adjusted(0, 0, minSize.width(), minSize.height()); | |
347 | } |
|
345 | } | |
348 |
|
346 | |||
349 | QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const |
|
347 | QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const | |
350 | { |
|
348 | { | |
351 | title->setGeometry(geometry); |
|
349 | title->setGeometry(geometry); | |
352 | QPointF center = geometry.center() - title->boundingRect().center(); |
|
350 | QPointF center = geometry.center() - title->boundingRect().center(); | |
353 | title->setPos(center.x(),title->pos().y()); |
|
351 | title->setPos(center.x(),title->pos().y()); | |
354 | return geometry.adjusted(0,title->boundingRect().height()+1,0,0); |
|
352 | return geometry.adjusted(0,title->boundingRect().height()+1,0,0); | |
355 | } |
|
353 | } | |
356 |
|
354 | |||
357 | QRectF ChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const |
|
355 | QRectF ChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const | |
358 | { |
|
356 | { | |
359 | QSizeF min = title->sizeHint(Qt::MinimumSize); |
|
357 | QSizeF min = title->sizeHint(Qt::MinimumSize); | |
360 | return minimum.adjusted(0, 0, min.width(), min.height()); |
|
358 | return minimum.adjusted(0, 0, min.width(), min.height()); | |
361 | } |
|
359 | } | |
362 |
|
360 | |||
363 | QSizeF ChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
361 | QSizeF ChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
364 | { |
|
362 | { | |
365 | Q_UNUSED(constraint); |
|
363 | Q_UNUSED(constraint); | |
366 | if (which == Qt::MinimumSize) { |
|
364 | if (which == Qt::MinimumSize) { | |
367 | QList<ChartAxis *> axes = m_presenter->axisItems(); |
|
365 | QList<ChartAxis *> axes = m_presenter->axisItems(); | |
368 | ChartTitle *title = m_presenter->titleElement(); |
|
366 | ChartTitle *title = m_presenter->titleElement(); | |
369 | QLegend *legend = m_presenter->legend(); |
|
367 | QLegend *legend = m_presenter->legend(); | |
370 | QRectF minimumRect(0, 0, 0, 0); |
|
368 | QRectF minimumRect(0, 0, 0, 0); | |
371 | minimumRect = calculateBackgroundMinimum(minimumRect); |
|
369 | minimumRect = calculateBackgroundMinimum(minimumRect); | |
372 | minimumRect = calculateContentMinimum(minimumRect); |
|
370 | minimumRect = calculateContentMinimum(minimumRect); | |
373 | minimumRect = calculateTitleMinimum(minimumRect, title); |
|
371 | minimumRect = calculateTitleMinimum(minimumRect, title); | |
374 | minimumRect = calculateLegendMinimum(minimumRect, legend); |
|
372 | minimumRect = calculateLegendMinimum(minimumRect, legend); | |
375 | minimumRect = calculateAxisMinimum(minimumRect, axes); |
|
373 | minimumRect = calculateAxisMinimum(minimumRect, axes); | |
376 | return minimumRect.united(m_minChartRect).size().toSize(); |
|
374 | return minimumRect.united(m_minChartRect).size().toSize(); | |
377 | } |
|
375 | } | |
378 | return QSize(-1, -1); |
|
376 | return QSize(-1, -1); | |
379 | } |
|
377 | } | |
380 |
|
378 | |||
381 | void ChartLayout::setMargins(const QMargins &margins) |
|
379 | void ChartLayout::setMargins(const QMargins &margins) | |
382 | { |
|
380 | { | |
383 | if (m_margins != margins) { |
|
381 | if (m_margins != margins) { | |
384 | m_margins = margins; |
|
382 | m_margins = margins; | |
385 | updateGeometry(); |
|
383 | updateGeometry(); | |
386 | } |
|
384 | } | |
387 | } |
|
385 | } | |
388 |
|
386 | |||
389 | QMargins ChartLayout::margins() const |
|
387 | QMargins ChartLayout::margins() const | |
390 | { |
|
388 | { | |
391 | return m_margins; |
|
389 | return m_margins; | |
392 | } |
|
390 | } | |
393 |
|
391 | |||
394 | QTCOMMERCIALCHART_END_NAMESPACE |
|
392 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,167 +1,167 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTPRESENTER_H |
|
30 | #ifndef CHARTPRESENTER_H | |
31 | #define CHARTPRESENTER_H |
|
31 | #define CHARTPRESENTER_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 |
#include "qchart.h" //bec |
|
34 | #include "qchart.h" //because of QChart::ChartThemeId | |
35 | #include <QRectF> |
|
35 | #include <QRectF> | |
36 | #include <QMargins> |
|
36 | #include <QMargins> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class ChartItem; |
|
40 | class ChartItem; | |
41 | class AxisItem; |
|
41 | class AxisItem; | |
42 | class QAbstractSeries; |
|
42 | class QAbstractSeries; | |
43 | class ChartDataSet; |
|
43 | class ChartDataSet; | |
44 | class AbstractDomain; |
|
44 | class AbstractDomain; | |
45 | class ChartAxis; |
|
45 | class ChartAxis; | |
46 | class ChartAnimator; |
|
46 | class ChartAnimator; | |
47 | class ChartBackground; |
|
47 | class ChartBackground; | |
48 | class ChartTitle; |
|
48 | class ChartTitle; | |
49 | class ChartAnimation; |
|
49 | class ChartAnimation; | |
50 | class ChartLayout; |
|
50 | class ChartLayout; | |
51 |
|
51 | |||
52 | class ChartPresenter: public QObject |
|
52 | class ChartPresenter: public QObject | |
53 | { |
|
53 | { | |
54 | Q_OBJECT |
|
54 | Q_OBJECT | |
55 | public: |
|
55 | public: | |
56 | enum ZValues { |
|
56 | enum ZValues { | |
57 | BackgroundZValue = -1, |
|
57 | BackgroundZValue = -1, | |
58 | ShadesZValue , |
|
58 | ShadesZValue , | |
59 | GridZValue, |
|
59 | GridZValue, | |
60 | AxisZValue, |
|
60 | AxisZValue, | |
61 | SeriesZValue, |
|
61 | SeriesZValue, | |
62 | LineChartZValue = SeriesZValue, |
|
62 | LineChartZValue = SeriesZValue, | |
63 | SplineChartZValue = SeriesZValue, |
|
63 | SplineChartZValue = SeriesZValue, | |
64 | BarSeriesZValue = SeriesZValue, |
|
64 | BarSeriesZValue = SeriesZValue, | |
65 | ScatterSeriesZValue = SeriesZValue, |
|
65 | ScatterSeriesZValue = SeriesZValue, | |
66 | PieSeriesZValue = SeriesZValue, |
|
66 | PieSeriesZValue = SeriesZValue, | |
67 | LegendZValue, |
|
67 | LegendZValue, | |
68 | TopMostZValue |
|
68 | TopMostZValue | |
69 | }; |
|
69 | }; | |
70 |
|
70 | |||
71 | enum State { |
|
71 | enum State { | |
72 | ShowState, |
|
72 | ShowState, | |
73 | ScrollUpState, |
|
73 | ScrollUpState, | |
74 | ScrollDownState, |
|
74 | ScrollDownState, | |
75 | ScrollLeftState, |
|
75 | ScrollLeftState, | |
76 | ScrollRightState, |
|
76 | ScrollRightState, | |
77 | ZoomInState, |
|
77 | ZoomInState, | |
78 | ZoomOutState |
|
78 | ZoomOutState | |
79 | }; |
|
79 | }; | |
80 |
|
80 | |||
81 | ChartPresenter(QChart *chart); |
|
81 | ChartPresenter(QChart *chart); | |
82 | virtual ~ChartPresenter(); |
|
82 | virtual ~ChartPresenter(); | |
83 |
|
83 | |||
84 |
|
84 | |||
85 | void setGeometry(QRectF rect); |
|
85 | void setGeometry(QRectF rect); | |
86 | QRectF geometry() const; |
|
86 | QRectF geometry() const; | |
87 |
|
87 | |||
88 | QGraphicsItem *rootItem(){ return m_chart; } |
|
88 | QGraphicsItem *rootItem(){ return m_chart; } | |
89 | ChartBackground *backgroundElement(); |
|
89 | ChartBackground *backgroundElement(); | |
90 | ChartTitle *titleElement(); |
|
90 | ChartTitle *titleElement(); | |
91 | QList<ChartAxis *> axisItems() const; |
|
91 | QList<ChartAxis *> axisItems() const; | |
92 | QList<ChartItem *> chartItems() const; |
|
92 | QList<ChartItem *> chartItems() const; | |
93 |
|
93 | |||
94 | ChartItem* chartElement(QAbstractSeries* series) const; |
|
94 | ChartItem* chartElement(QAbstractSeries* series) const; | |
95 | ChartAxis* chartElement(QAbstractAxis* axis) const; |
|
95 | ChartAxis* chartElement(QAbstractAxis* axis) const; | |
96 |
|
96 | |||
97 | QLegend *legend(); |
|
97 | QLegend *legend(); | |
98 |
|
98 | |||
99 | void setBackgroundBrush(const QBrush &brush); |
|
99 | void setBackgroundBrush(const QBrush &brush); | |
100 | QBrush backgroundBrush() const; |
|
100 | QBrush backgroundBrush() const; | |
101 |
|
101 | |||
102 | void setBackgroundPen(const QPen &pen); |
|
102 | void setBackgroundPen(const QPen &pen); | |
103 | QPen backgroundPen() const; |
|
103 | QPen backgroundPen() const; | |
104 |
|
104 | |||
105 | void setTitle(const QString &title); |
|
105 | void setTitle(const QString &title); | |
106 | QString title() const; |
|
106 | QString title() const; | |
107 |
|
107 | |||
108 | void setTitleFont(const QFont &font); |
|
108 | void setTitleFont(const QFont &font); | |
109 | QFont titleFont() const; |
|
109 | QFont titleFont() const; | |
110 |
|
110 | |||
111 | void setTitleBrush(const QBrush &brush); |
|
111 | void setTitleBrush(const QBrush &brush); | |
112 | QBrush titleBrush() const; |
|
112 | QBrush titleBrush() const; | |
113 |
|
113 | |||
114 | void setBackgroundVisible(bool visible); |
|
114 | void setBackgroundVisible(bool visible); | |
115 | bool isBackgroundVisible() const; |
|
115 | bool isBackgroundVisible() const; | |
116 |
|
116 | |||
117 | void setBackgroundDropShadowEnabled(bool enabled); |
|
117 | void setBackgroundDropShadowEnabled(bool enabled); | |
118 | bool isBackgroundDropShadowEnabled() const; |
|
118 | bool isBackgroundDropShadowEnabled() const; | |
119 |
|
119 | |||
120 | void setVisible(bool visible); |
|
120 | void setVisible(bool visible); | |
121 |
|
121 | |||
122 | void setAnimationOptions(QChart::AnimationOptions options); |
|
122 | void setAnimationOptions(QChart::AnimationOptions options); | |
123 | QChart::AnimationOptions animationOptions() const; |
|
123 | QChart::AnimationOptions animationOptions() const; | |
124 |
|
124 | |||
125 | void startAnimation(ChartAnimation *animation); |
|
125 | void startAnimation(ChartAnimation *animation); | |
126 |
|
126 | |||
127 | //TODO refactor |
|
127 | //TODO refactor | |
128 | void setState(State state,QPointF point); |
|
128 | void setState(State state,QPointF point); | |
129 | State state() const { return m_state; } |
|
129 | State state() const { return m_state; } | |
130 | QPointF statePoint() const { return m_statePoint; } |
|
130 | QPointF statePoint() const { return m_statePoint; } | |
131 | ChartLayout *layout(); |
|
131 | ChartLayout *layout(); | |
132 |
|
132 | |||
133 | private: |
|
133 | private: | |
134 | void createBackgroundItem(); |
|
134 | void createBackgroundItem(); | |
135 | void createTitleItem(); |
|
135 | void createTitleItem(); | |
136 |
|
136 | |||
137 | public Q_SLOTS: |
|
137 | public Q_SLOTS: | |
138 | void handleSeriesAdded(QAbstractSeries *series); |
|
138 | void handleSeriesAdded(QAbstractSeries *series); | |
139 | void handleSeriesRemoved(QAbstractSeries *series); |
|
139 | void handleSeriesRemoved(QAbstractSeries *series); | |
140 | void handleAxisAdded(QAbstractAxis *axis); |
|
140 | void handleAxisAdded(QAbstractAxis *axis); | |
141 | void handleAxisRemoved(QAbstractAxis *axis); |
|
141 | void handleAxisRemoved(QAbstractAxis *axis); | |
142 |
|
142 | |||
143 | private Q_SLOTS: |
|
143 | private Q_SLOTS: | |
144 | void handleAnimationFinished(); |
|
144 | void handleAnimationFinished(); | |
145 |
|
145 | |||
146 | Q_SIGNALS: |
|
146 | Q_SIGNALS: | |
147 | void animationsFinished(); |
|
147 | void animationsFinished(); | |
148 |
|
148 | |||
149 | private: |
|
149 | private: | |
150 | QChart *m_chart; |
|
150 | QChart *m_chart; | |
151 | QList<ChartItem *> m_chartItems; |
|
151 | QList<ChartItem *> m_chartItems; | |
152 | QList<ChartAxis *> m_axisItems; |
|
152 | QList<ChartAxis *> m_axisItems; | |
153 | QList<QAbstractSeries *> m_series; |
|
153 | QList<QAbstractSeries *> m_series; | |
154 | QList<QAbstractAxis *> m_axes; |
|
154 | QList<QAbstractAxis *> m_axes; | |
155 | QChart::AnimationOptions m_options; |
|
155 | QChart::AnimationOptions m_options; | |
156 | State m_state; |
|
156 | State m_state; | |
157 | QPointF m_statePoint; |
|
157 | QPointF m_statePoint; | |
158 | QList<ChartAnimation *> m_animations; |
|
158 | QList<ChartAnimation *> m_animations; | |
159 | ChartLayout *m_layout; |
|
159 | ChartLayout *m_layout; | |
160 | ChartBackground *m_background; |
|
160 | ChartBackground *m_background; | |
161 | ChartTitle *m_title; |
|
161 | ChartTitle *m_title; | |
162 | QRectF m_rect; |
|
162 | QRectF m_rect; | |
163 | }; |
|
163 | }; | |
164 |
|
164 | |||
165 | QTCOMMERCIALCHART_END_NAMESPACE |
|
165 | QTCOMMERCIALCHART_END_NAMESPACE | |
166 |
|
166 | |||
167 | #endif /* CHARTPRESENTER_H */ |
|
167 | #endif /* CHARTPRESENTER_H */ |
@@ -1,319 +1,314 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 | #include "qchart.h" |
|
24 | #include "qchart.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "chartitem_p.h" |
|
26 | #include "chartitem_p.h" | |
27 | #include "xydomain_p.h" |
|
27 | #include "xydomain_p.h" | |
28 | #include "xlogydomain_p.h" |
|
28 | #include "xlogydomain_p.h" | |
29 | #include "logxydomain_p.h" |
|
29 | #include "logxydomain_p.h" | |
30 | #include "logxlogydomain_p.h" |
|
30 | #include "logxlogydomain_p.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractSeries |
|
35 | \class QAbstractSeries | |
36 | \brief Base class for all QtCommercial Chart series. |
|
36 | \brief Base class for all QtCommercial Chart series. | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | Usually you use the series type specific inherited classes instead of the base class. |
|
39 | Usually you use the series type specific inherited classes instead of the base class. | |
40 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
40 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, | |
41 | QPercentBarSeries, QPieSeries |
|
41 | QPercentBarSeries, QPieSeries | |
42 | */ |
|
42 | */ | |
43 | /*! |
|
43 | /*! | |
44 | \qmlclass AbstractSeries |
|
44 | \qmlclass AbstractSeries | |
45 | AbstractSeries is the base class for all series. |
|
45 | AbstractSeries is the base class for all series. | |
46 | The class cannot be instantiated by the user. |
|
46 | The class cannot be instantiated by the user. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \enum QAbstractSeries::SeriesType |
|
50 | \enum QAbstractSeries::SeriesType | |
51 |
|
51 | |||
52 | The type of the series object. |
|
52 | The type of the series object. | |
53 |
|
53 | |||
54 | \value SeriesTypeLine |
|
54 | \value SeriesTypeLine | |
55 | \value SeriesTypeArea |
|
55 | \value SeriesTypeArea | |
56 | \value SeriesTypeBar |
|
56 | \value SeriesTypeBar | |
57 | \value SeriesTypeStackedBar |
|
57 | \value SeriesTypeStackedBar | |
58 | \value SeriesTypePercentBar |
|
58 | \value SeriesTypePercentBar | |
59 | \value SeriesTypePie |
|
59 | \value SeriesTypePie | |
60 | \value SeriesTypeScatter |
|
60 | \value SeriesTypeScatter | |
61 | \value SeriesTypeSpline |
|
61 | \value SeriesTypeSpline | |
62 | \value SeriesTypeHorizontalBar |
|
62 | \value SeriesTypeHorizontalBar | |
63 | \value SeriesTypeHorizontalStackedBar |
|
63 | \value SeriesTypeHorizontalStackedBar | |
64 | \value SeriesTypeHorizontalPercentBar |
|
64 | \value SeriesTypeHorizontalPercentBar | |
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | \property QAbstractSeries::type |
|
68 | \property QAbstractSeries::type | |
69 | The type of the series. |
|
69 | The type of the series. | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
72 | \qmlproperty ChartView.SeriesType AbstractSeries::type | |
73 | The type of the series. |
|
73 | The type of the series. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QAbstractSeries::name |
|
77 | \property QAbstractSeries::name | |
78 | \brief name of the series property. The name is shown in legend for QXYSeries. |
|
78 | \brief name of the series property. The name is shown in legend for QXYSeries. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty string AbstractSeries::name |
|
81 | \qmlproperty string AbstractSeries::name | |
82 | Name of the series. The name is shown in legend for QXYSeries. |
|
82 | Name of the series. The name is shown in legend for QXYSeries. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \fn void QAbstractSeries::nameChanged() |
|
86 | \fn void QAbstractSeries::nameChanged() | |
87 | This signal is emitted when the series name changes. |
|
87 | This signal is emitted when the series name changes. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlsignal AbstractSeries::onNameChanged() |
|
90 | \qmlsignal AbstractSeries::onNameChanged() | |
91 | This signal is emitted when the series name changes. |
|
91 | This signal is emitted when the series name changes. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QAbstractSeries::visible |
|
95 | \property QAbstractSeries::visible | |
96 | \brief whether the series is visible or not; true by default. |
|
96 | \brief whether the series is visible or not; true by default. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty bool AbstractSeries::visible |
|
99 | \qmlproperty bool AbstractSeries::visible | |
100 | Visibility of the series. True by default. |
|
100 | Visibility of the series. True by default. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \fn void QAbstractSeries::visibleChanged() |
|
104 | \fn void QAbstractSeries::visibleChanged() | |
105 | Emitted when the series visibility changes. |
|
105 | Emitted when the series visibility changes. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlsignal AbstractSeries::onVisibleChanged() |
|
108 | \qmlsignal AbstractSeries::onVisibleChanged() | |
109 | Emitted when the series visibility changes. |
|
109 | Emitted when the series visibility changes. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \property QAbstractSeries::opacity |
|
113 | \property QAbstractSeries::opacity | |
114 | \brief The opacity of the series. |
|
114 | \brief The opacity of the series. | |
115 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
115 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). | |
116 | */ |
|
116 | */ | |
117 | /*! |
|
117 | /*! | |
118 | \qmlproperty real AbstractSeries::opacity |
|
118 | \qmlproperty real AbstractSeries::opacity | |
119 | The opacity of the series. By default the opacity is 1.0. |
|
119 | The opacity of the series. By default the opacity is 1.0. | |
120 | The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
120 | The valid values range from 0.0 (transparent) to 1.0 (opaque). | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QAbstractSeries::opacityChanged() |
|
124 | \fn void QAbstractSeries::opacityChanged() | |
125 | Emitted when the opacity of the series changes. |
|
125 | Emitted when the opacity of the series changes. | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlsignal AbstractSeries::onOpacityChanged() |
|
128 | \qmlsignal AbstractSeries::onOpacityChanged() | |
129 | Emitted when the opacity of the series changes. |
|
129 | Emitted when the opacity of the series changes. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \internal |
|
133 | \internal | |
134 | \brief Constructs ChartSeries object with \a parent. |
|
134 | \brief Constructs ChartSeries object with \a parent. | |
135 | */ |
|
135 | */ | |
136 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
136 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
137 | QObject(parent), |
|
137 | QObject(parent), | |
138 | d_ptr(&d) |
|
138 | d_ptr(&d) | |
139 | { |
|
139 | { | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \brief Virtual destructor for the chart series. |
|
143 | \brief Virtual destructor for the chart series. | |
144 | */ |
|
144 | */ | |
145 | QAbstractSeries::~QAbstractSeries() |
|
145 | QAbstractSeries::~QAbstractSeries() | |
146 | { |
|
146 | { | |
147 | if (d_ptr->m_chart) |
|
147 | if (d_ptr->m_chart) | |
148 | qFatal("Still binded series detected !"); |
|
148 | qFatal("Still binded series detected !"); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void QAbstractSeries::setName(const QString &name) |
|
151 | void QAbstractSeries::setName(const QString &name) | |
152 | { |
|
152 | { | |
153 | if (name != d_ptr->m_name) { |
|
153 | if (name != d_ptr->m_name) { | |
154 | d_ptr->m_name = name; |
|
154 | d_ptr->m_name = name; | |
155 | emit nameChanged(); |
|
155 | emit nameChanged(); | |
156 | } |
|
156 | } | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | QString QAbstractSeries::name() const |
|
159 | QString QAbstractSeries::name() const | |
160 | { |
|
160 | { | |
161 | return d_ptr->m_name; |
|
161 | return d_ptr->m_name; | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Sets the visibility of series to \a visible |
|
165 | Sets the visibility of series to \a visible | |
166 | */ |
|
166 | */ | |
167 | void QAbstractSeries::setVisible(bool visible) |
|
167 | void QAbstractSeries::setVisible(bool visible) | |
168 | { |
|
168 | { | |
169 | if (visible != d_ptr->m_visible) { |
|
169 | if (visible != d_ptr->m_visible) { | |
170 | d_ptr->m_visible = visible; |
|
170 | d_ptr->m_visible = visible; | |
171 | emit visibleChanged(); |
|
171 | emit visibleChanged(); | |
172 | } |
|
172 | } | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | Returns the visibility of series |
|
176 | Returns the visibility of series | |
177 | */ |
|
177 | */ | |
178 | bool QAbstractSeries::isVisible() const |
|
178 | bool QAbstractSeries::isVisible() const | |
179 | { |
|
179 | { | |
180 | return d_ptr->m_visible; |
|
180 | return d_ptr->m_visible; | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | qreal QAbstractSeries::opacity() const |
|
183 | qreal QAbstractSeries::opacity() const | |
184 | { |
|
184 | { | |
185 | return d_ptr->m_opacity; |
|
185 | return d_ptr->m_opacity; | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void QAbstractSeries::setOpacity(qreal opacity) |
|
188 | void QAbstractSeries::setOpacity(qreal opacity) | |
189 | { |
|
189 | { | |
190 | if (opacity != d_ptr->m_opacity) { |
|
190 | if (opacity != d_ptr->m_opacity) { | |
191 | d_ptr->m_opacity = opacity; |
|
191 | d_ptr->m_opacity = opacity; | |
192 | emit opacityChanged(); |
|
192 | emit opacityChanged(); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | /*! |
|
196 | /*! | |
197 | \brief Returns the chart where series belongs to. |
|
197 | \brief Returns the chart where series belongs to. | |
198 |
|
198 | |||
199 | Set automatically when the series is added to the chart |
|
199 | Set automatically when the series is added to the chart | |
200 | and unset when the series is removed from the chart. |
|
200 | and unset when the series is removed from the chart. | |
201 | */ |
|
201 | */ | |
202 | QChart *QAbstractSeries::chart() const |
|
202 | QChart *QAbstractSeries::chart() const | |
203 | { |
|
203 | { | |
204 | return d_ptr->m_chart; |
|
204 | return d_ptr->m_chart; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | //void QAbstractSeries::adjustView() |
|
|||
208 | //{ |
|
|||
209 | // //TODO: |
|
|||
210 | //} |
|
|||
211 |
|
||||
212 | /*! |
|
207 | /*! | |
213 | \brief Sets the visibility of the series to true |
|
208 | \brief Sets the visibility of the series to true | |
214 |
|
209 | |||
215 | \sa setVisible(), isVisible() |
|
210 | \sa setVisible(), isVisible() | |
216 | */ |
|
211 | */ | |
217 | void QAbstractSeries::show() |
|
212 | void QAbstractSeries::show() | |
218 | { |
|
213 | { | |
219 | setVisible(true); |
|
214 | setVisible(true); | |
220 | } |
|
215 | } | |
221 |
|
216 | |||
222 | /*! |
|
217 | /*! | |
223 | \brief Sets the visibility of the series to false |
|
218 | \brief Sets the visibility of the series to false | |
224 |
|
219 | |||
225 | \sa setVisible(), isVisible() |
|
220 | \sa setVisible(), isVisible() | |
226 | */ |
|
221 | */ | |
227 | void QAbstractSeries::hide() |
|
222 | void QAbstractSeries::hide() | |
228 | { |
|
223 | { | |
229 | setVisible(false); |
|
224 | setVisible(false); | |
230 | } |
|
225 | } | |
231 |
|
226 | |||
232 | /*! |
|
227 | /*! | |
233 | Attach \a axis to the series. |
|
228 | Attach \a axis to the series. | |
234 | \return true if the axis was attached successfully, false otherwise. |
|
229 | \return true if the axis was attached successfully, false otherwise. | |
235 | \sa QChart::addAxis(), QChart::createDefaultAxes() |
|
230 | \sa QChart::addAxis(), QChart::createDefaultAxes() | |
236 | */ |
|
231 | */ | |
237 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) |
|
232 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) | |
238 | { |
|
233 | { | |
239 | if(d_ptr->m_chart) { |
|
234 | if(d_ptr->m_chart) { | |
240 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); |
|
235 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); | |
241 | } else { |
|
236 | } else { | |
242 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
237 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |
243 | return false; |
|
238 | return false; | |
244 | } |
|
239 | } | |
245 | } |
|
240 | } | |
246 |
|
241 | |||
247 | /*! |
|
242 | /*! | |
248 | Detach \a axis from the series. |
|
243 | Detach \a axis from the series. | |
249 | \return true if the axis was detached successfully, false otherwise. |
|
244 | \return true if the axis was detached successfully, false otherwise. | |
250 | \sa QChart::removeAxis() |
|
245 | \sa QChart::removeAxis() | |
251 | */ |
|
246 | */ | |
252 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) |
|
247 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) | |
253 | { |
|
248 | { | |
254 | if(d_ptr->m_chart) { |
|
249 | if(d_ptr->m_chart) { | |
255 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); |
|
250 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); | |
256 | } |
|
251 | } | |
257 | else { |
|
252 | else { | |
258 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
253 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |
259 | return false; |
|
254 | return false; | |
260 | } |
|
255 | } | |
261 | } |
|
256 | } | |
262 |
|
257 | |||
263 | /*! |
|
258 | /*! | |
264 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except |
|
259 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except | |
265 | in case of a QPieSeries, which does not have any axes attached. |
|
260 | in case of a QPieSeries, which does not have any axes attached. | |
266 | \sa attachAxis(), detachAxis() |
|
261 | \sa attachAxis(), detachAxis() | |
267 | */ |
|
262 | */ | |
268 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() |
|
263 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() | |
269 | { |
|
264 | { | |
270 | return d_ptr->m_axes; |
|
265 | return d_ptr->m_axes; | |
271 | } |
|
266 | } | |
272 |
|
267 | |||
273 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
268 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
274 |
|
269 | |||
275 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) |
|
270 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) | |
276 | : q_ptr(q), |
|
271 | : q_ptr(q), | |
277 | m_chart(0), |
|
272 | m_chart(0), | |
278 | m_item(0), |
|
273 | m_item(0), | |
279 | m_domain(new XYDomain()), |
|
274 | m_domain(new XYDomain()), | |
280 | m_visible(true), |
|
275 | m_visible(true), | |
281 | m_opacity(1.0) |
|
276 | m_opacity(1.0) | |
282 | { |
|
277 | { | |
283 | } |
|
278 | } | |
284 |
|
279 | |||
285 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
280 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
286 | { |
|
281 | { | |
287 | } |
|
282 | } | |
288 |
|
283 | |||
289 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) |
|
284 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) | |
290 | { |
|
285 | { | |
291 | Q_ASSERT(domain); |
|
286 | Q_ASSERT(domain); | |
292 | if(m_domain.data()!=domain) { |
|
287 | if(m_domain.data()!=domain) { | |
293 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); |
|
288 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); | |
294 | m_domain.reset(domain); |
|
289 | m_domain.reset(domain); | |
295 | if(!m_item.isNull()) { |
|
290 | if(!m_item.isNull()) { | |
296 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
291 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |
297 | m_item->handleDomainUpdated(); |
|
292 | m_item->handleDomainUpdated(); | |
298 | } |
|
293 | } | |
299 | } |
|
294 | } | |
300 | } |
|
295 | } | |
301 |
|
296 | |||
302 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
297 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
303 | { |
|
298 | { | |
304 | Q_ASSERT(!m_item.isNull()); |
|
299 | Q_ASSERT(!m_item.isNull()); | |
305 | Q_UNUSED(parent); |
|
300 | Q_UNUSED(parent); | |
306 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
301 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |
307 | } |
|
302 | } | |
308 |
|
303 | |||
309 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
304 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |
310 | { |
|
305 | { | |
311 | Q_UNUSED(options); |
|
306 | Q_UNUSED(options); | |
312 | } |
|
307 | } | |
313 |
|
308 | |||
314 | #include "moc_qabstractseries.cpp" |
|
309 | #include "moc_qabstractseries.cpp" | |
315 | #include "moc_qabstractseries_p.cpp" |
|
310 | #include "moc_qabstractseries_p.cpp" | |
316 |
|
311 | |||
317 | QTCOMMERCIALCHART_END_NAMESPACE |
|
312 | QTCOMMERCIALCHART_END_NAMESPACE | |
318 |
|
313 | |||
319 |
|
314 |
@@ -1,665 +1,663 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "chartlayout_p.h" |
|
27 | #include "chartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \enum QChart::AnimationOption |
|
51 | \enum QChart::AnimationOption | |
52 |
|
52 | |||
53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
53 | For enabling/disabling animations. Defaults to NoAnimation. | |
54 |
|
54 | |||
55 | \value NoAnimation |
|
55 | \value NoAnimation | |
56 | \value GridAxisAnimations |
|
56 | \value GridAxisAnimations | |
57 | \value SeriesAnimations |
|
57 | \value SeriesAnimations | |
58 | \value AllAnimations |
|
58 | \value AllAnimations | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \class QChart |
|
62 | \class QChart | |
63 | \brief QtCommercial chart API. |
|
63 | \brief QtCommercial chart API. | |
64 |
|
64 | |||
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
66 | representation of different types of series and other chart related objects like |
|
66 | representation of different types of series and other chart related objects like | |
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
68 | convenience class QChartView instead of QChart. |
|
68 | convenience class QChartView instead of QChart. | |
69 | \sa QChartView |
|
69 | \sa QChartView | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QChart::animationOptions |
|
73 | \property QChart::animationOptions | |
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QChart::backgroundVisible |
|
78 | \property QChart::backgroundVisible | |
79 | Whether the chart background is visible or not. |
|
79 | Whether the chart background is visible or not. | |
80 | \sa setBackgroundBrush(), setBackgroundPen() |
|
80 | \sa setBackgroundBrush(), setBackgroundPen() | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QChart::dropShadowEnabled |
|
84 | \property QChart::dropShadowEnabled | |
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QChart::minimumMargins |
|
90 | \property QChart::minimumMargins | |
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QChart::margins |
|
95 | \property QChart::margins | |
96 | Minimum between the plot area (axes) and the edge of the chart widget. |
|
96 | Minimum between the plot area (axes) and the edge of the chart widget. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::theme |
|
100 | \property QChart::theme | |
101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few | |
103 | different themes. |
|
103 | different themes. | |
104 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
104 | Note: changing the theme will overwrite all customizations previously applied to the series. | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QChart::title |
|
108 | \property QChart::title | |
109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
114 | */ |
|
114 | */ | |
115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
116 | : QGraphicsWidget(parent, wFlags), |
|
116 | : QGraphicsWidget(parent, wFlags), | |
117 | d_ptr(new QChartPrivate(this)) |
|
117 | d_ptr(new QChartPrivate(this)) | |
118 | { |
|
118 | { | |
119 | d_ptr->m_legend = new LegendScroller(this); |
|
119 | d_ptr->m_legend = new LegendScroller(this); | |
120 | setTheme(QChart::ChartThemeLight); |
|
120 | setTheme(QChart::ChartThemeLight); | |
121 | //TODO: what is that ? |
|
|||
122 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
|||
123 | setLayout(d_ptr->m_presenter->layout()); |
|
121 | setLayout(d_ptr->m_presenter->layout()); | |
124 | } |
|
122 | } | |
125 |
|
123 | |||
126 | /*! |
|
124 | /*! | |
127 | Destroys the object and it's children, like series and axis objects added to it. |
|
125 | Destroys the object and it's children, like series and axis objects added to it. | |
128 | */ |
|
126 | */ | |
129 | QChart::~QChart() |
|
127 | QChart::~QChart() | |
130 | { |
|
128 | { | |
131 | //start by deleting dataset, it will remove all series and axes |
|
129 | //start by deleting dataset, it will remove all series and axes | |
132 | delete d_ptr->m_dataset; |
|
130 | delete d_ptr->m_dataset; | |
133 | d_ptr->m_dataset = 0; |
|
131 | d_ptr->m_dataset = 0; | |
134 | } |
|
132 | } | |
135 |
|
133 | |||
136 | /*! |
|
134 | /*! | |
137 | Adds the \a series onto the chart and takes the ownership of the object. |
|
135 | Adds the \a series onto the chart and takes the ownership of the object. | |
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
136 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
139 | the y axis). |
|
137 | the y axis). | |
140 |
|
138 | |||
141 | \sa removeSeries(), removeAllSeries() |
|
139 | \sa removeSeries(), removeAllSeries() | |
142 | */ |
|
140 | */ | |
143 | void QChart::addSeries(QAbstractSeries *series) |
|
141 | void QChart::addSeries(QAbstractSeries *series) | |
144 | { |
|
142 | { | |
145 | Q_ASSERT(series); |
|
143 | Q_ASSERT(series); | |
146 | d_ptr->m_dataset->addSeries(series); |
|
144 | d_ptr->m_dataset->addSeries(series); | |
147 | } |
|
145 | } | |
148 |
|
146 | |||
149 | /*! |
|
147 | /*! | |
150 | Removes the \a series specified in a perameter from the QChartView. |
|
148 | Removes the \a series specified in a perameter from the QChartView. | |
151 | It releses its ownership of the specified QChartSeries object. |
|
149 | It releses its ownership of the specified QChartSeries object. | |
152 | It does not delete the pointed QChartSeries data object |
|
150 | It does not delete the pointed QChartSeries data object | |
153 | \sa addSeries(), removeAllSeries() |
|
151 | \sa addSeries(), removeAllSeries() | |
154 | */ |
|
152 | */ | |
155 | void QChart::removeSeries(QAbstractSeries *series) |
|
153 | void QChart::removeSeries(QAbstractSeries *series) | |
156 | { |
|
154 | { | |
157 | Q_ASSERT(series); |
|
155 | Q_ASSERT(series); | |
158 | d_ptr->m_dataset->removeSeries(series); |
|
156 | d_ptr->m_dataset->removeSeries(series); | |
159 | } |
|
157 | } | |
160 |
|
158 | |||
161 | /*! |
|
159 | /*! | |
162 | Removes all the QChartSeries that have been added to the QChartView |
|
160 | Removes all the QChartSeries that have been added to the QChartView | |
163 | It also deletes the pointed QChartSeries data objects |
|
161 | It also deletes the pointed QChartSeries data objects | |
164 | \sa addSeries(), removeSeries() |
|
162 | \sa addSeries(), removeSeries() | |
165 | */ |
|
163 | */ | |
166 | void QChart::removeAllSeries() |
|
164 | void QChart::removeAllSeries() | |
167 | { |
|
165 | { | |
168 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
166 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
169 | removeSeries(s); |
|
167 | removeSeries(s); | |
170 | delete s; |
|
168 | delete s; | |
171 | } |
|
169 | } | |
172 | } |
|
170 | } | |
173 |
|
171 | |||
174 | /*! |
|
172 | /*! | |
175 | Sets the \a brush that is used for painting the background of the chart area. |
|
173 | Sets the \a brush that is used for painting the background of the chart area. | |
176 | */ |
|
174 | */ | |
177 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
175 | void QChart::setBackgroundBrush(const QBrush &brush) | |
178 | { |
|
176 | { | |
179 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
177 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
180 | } |
|
178 | } | |
181 |
|
179 | |||
182 | /*! |
|
180 | /*! | |
183 | Gets the brush that is used for painting the background of the chart area. |
|
181 | Gets the brush that is used for painting the background of the chart area. | |
184 | */ |
|
182 | */ | |
185 | QBrush QChart::backgroundBrush() const |
|
183 | QBrush QChart::backgroundBrush() const | |
186 | { |
|
184 | { | |
187 | return d_ptr->m_presenter->backgroundBrush(); |
|
185 | return d_ptr->m_presenter->backgroundBrush(); | |
188 | } |
|
186 | } | |
189 |
|
187 | |||
190 | /*! |
|
188 | /*! | |
191 | Sets the \a pen that is used for painting the background of the chart area. |
|
189 | Sets the \a pen that is used for painting the background of the chart area. | |
192 | */ |
|
190 | */ | |
193 | void QChart::setBackgroundPen(const QPen &pen) |
|
191 | void QChart::setBackgroundPen(const QPen &pen) | |
194 | { |
|
192 | { | |
195 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
193 | d_ptr->m_presenter->setBackgroundPen(pen); | |
196 | } |
|
194 | } | |
197 |
|
195 | |||
198 | /*! |
|
196 | /*! | |
199 | Gets the pen that is used for painting the background of the chart area. |
|
197 | Gets the pen that is used for painting the background of the chart area. | |
200 | */ |
|
198 | */ | |
201 | QPen QChart::backgroundPen() const |
|
199 | QPen QChart::backgroundPen() const | |
202 | { |
|
200 | { | |
203 | return d_ptr->m_presenter->backgroundPen(); |
|
201 | return d_ptr->m_presenter->backgroundPen(); | |
204 | } |
|
202 | } | |
205 |
|
203 | |||
206 | /*! |
|
204 | /*! | |
207 | Sets the chart \a title. The description text that is drawn above the chart. |
|
205 | Sets the chart \a title. The description text that is drawn above the chart. | |
208 | */ |
|
206 | */ | |
209 | void QChart::setTitle(const QString &title) |
|
207 | void QChart::setTitle(const QString &title) | |
210 | { |
|
208 | { | |
211 | d_ptr->m_presenter->setTitle(title); |
|
209 | d_ptr->m_presenter->setTitle(title); | |
212 | } |
|
210 | } | |
213 |
|
211 | |||
214 | /*! |
|
212 | /*! | |
215 | Returns the chart title. The description text that is drawn above the chart. |
|
213 | Returns the chart title. The description text that is drawn above the chart. | |
216 | */ |
|
214 | */ | |
217 | QString QChart::title() const |
|
215 | QString QChart::title() const | |
218 | { |
|
216 | { | |
219 | return d_ptr->m_presenter->title(); |
|
217 | return d_ptr->m_presenter->title(); | |
220 | } |
|
218 | } | |
221 |
|
219 | |||
222 | /*! |
|
220 | /*! | |
223 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
221 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
224 | */ |
|
222 | */ | |
225 | void QChart::setTitleFont(const QFont &font) |
|
223 | void QChart::setTitleFont(const QFont &font) | |
226 | { |
|
224 | { | |
227 | d_ptr->m_presenter->setTitleFont(font); |
|
225 | d_ptr->m_presenter->setTitleFont(font); | |
228 | } |
|
226 | } | |
229 |
|
227 | |||
230 | /*! |
|
228 | /*! | |
231 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
229 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
232 | */ |
|
230 | */ | |
233 | QFont QChart::titleFont() const |
|
231 | QFont QChart::titleFont() const | |
234 | { |
|
232 | { | |
235 | return d_ptr->m_presenter->titleFont(); |
|
233 | return d_ptr->m_presenter->titleFont(); | |
236 | } |
|
234 | } | |
237 |
|
235 | |||
238 | /*! |
|
236 | /*! | |
239 | Sets the \a brush used for rendering the title text. |
|
237 | Sets the \a brush used for rendering the title text. | |
240 | */ |
|
238 | */ | |
241 | void QChart::setTitleBrush(const QBrush &brush) |
|
239 | void QChart::setTitleBrush(const QBrush &brush) | |
242 | { |
|
240 | { | |
243 | d_ptr->m_presenter->setTitleBrush(brush); |
|
241 | d_ptr->m_presenter->setTitleBrush(brush); | |
244 | } |
|
242 | } | |
245 |
|
243 | |||
246 | /*! |
|
244 | /*! | |
247 | Returns the brush used for rendering the title text. |
|
245 | Returns the brush used for rendering the title text. | |
248 | */ |
|
246 | */ | |
249 | QBrush QChart::titleBrush() const |
|
247 | QBrush QChart::titleBrush() const | |
250 | { |
|
248 | { | |
251 | return d_ptr->m_presenter->titleBrush(); |
|
249 | return d_ptr->m_presenter->titleBrush(); | |
252 | } |
|
250 | } | |
253 |
|
251 | |||
254 | void QChart::setTheme(QChart::ChartTheme theme) |
|
252 | void QChart::setTheme(QChart::ChartTheme theme) | |
255 | { |
|
253 | { | |
256 | d_ptr->m_themeManager->setTheme(theme); |
|
254 | d_ptr->m_themeManager->setTheme(theme); | |
257 | } |
|
255 | } | |
258 |
|
256 | |||
259 | QChart::ChartTheme QChart::theme() const |
|
257 | QChart::ChartTheme QChart::theme() const | |
260 | { |
|
258 | { | |
261 | return d_ptr->m_themeManager->theme()->id(); |
|
259 | return d_ptr->m_themeManager->theme()->id(); | |
262 | } |
|
260 | } | |
263 |
|
261 | |||
264 | /*! |
|
262 | /*! | |
265 | Zooms in the view by a factor of 2 |
|
263 | Zooms in the view by a factor of 2 | |
266 | */ |
|
264 | */ | |
267 | void QChart::zoomIn() |
|
265 | void QChart::zoomIn() | |
268 | { |
|
266 | { | |
269 | d_ptr->zoomIn(2.0); |
|
267 | d_ptr->zoomIn(2.0); | |
270 | } |
|
268 | } | |
271 |
|
269 | |||
272 | /*! |
|
270 | /*! | |
273 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
271 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
274 | */ |
|
272 | */ | |
275 | void QChart::zoomIn(const QRectF &rect) |
|
273 | void QChart::zoomIn(const QRectF &rect) | |
276 | { |
|
274 | { | |
277 | d_ptr->zoomIn(rect); |
|
275 | d_ptr->zoomIn(rect); | |
278 | } |
|
276 | } | |
279 |
|
277 | |||
280 | /*! |
|
278 | /*! | |
281 | Restores the view zoom level to the previous one. |
|
279 | Restores the view zoom level to the previous one. | |
282 | */ |
|
280 | */ | |
283 | void QChart::zoomOut() |
|
281 | void QChart::zoomOut() | |
284 | { |
|
282 | { | |
285 | d_ptr->zoomOut(2.0); |
|
283 | d_ptr->zoomOut(2.0); | |
286 | } |
|
284 | } | |
287 |
|
285 | |||
288 | /*! |
|
286 | /*! | |
289 | Zooms in the view by a \a factor. |
|
287 | Zooms in the view by a \a factor. | |
290 |
|
288 | |||
291 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
292 | */ |
|
290 | */ | |
293 | void QChart::zoom(qreal factor) |
|
291 | void QChart::zoom(qreal factor) | |
294 | { |
|
292 | { | |
295 | if (qFuzzyCompare(factor, 0)) |
|
293 | if (qFuzzyCompare(factor, 0)) | |
296 | return; |
|
294 | return; | |
297 |
|
295 | |||
298 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
296 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
299 | return; |
|
297 | return; | |
300 |
|
298 | |||
301 | if (factor < 0) |
|
299 | if (factor < 0) | |
302 | return; |
|
300 | return; | |
303 |
|
301 | |||
304 | if (factor > 1.0) |
|
302 | if (factor > 1.0) | |
305 | d_ptr->zoomIn(factor); |
|
303 | d_ptr->zoomIn(factor); | |
306 | else |
|
304 | else | |
307 | d_ptr->zoomOut(1.0 / factor); |
|
305 | d_ptr->zoomOut(1.0 / factor); | |
308 | } |
|
306 | } | |
309 |
|
307 | |||
310 | /*! |
|
308 | /*! | |
311 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | |
312 | If no series is provided then pointer to currently visible axis is provided |
|
310 | If no series is provided then pointer to currently visible axis is provided | |
313 | */ |
|
311 | */ | |
314 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
312 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
315 | { |
|
313 | { | |
316 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
314 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
317 | if (axisList.count()) |
|
315 | if (axisList.count()) | |
318 | return axisList[0]; |
|
316 | return axisList[0]; | |
319 | return 0; |
|
317 | return 0; | |
320 | } |
|
318 | } | |
321 |
|
319 | |||
322 | /*! |
|
320 | /*! | |
323 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
321 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | |
324 | If no series is provided then pointer to currently visible axis is provided |
|
322 | If no series is provided then pointer to currently visible axis is provided | |
325 | */ |
|
323 | */ | |
326 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
324 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
327 | { |
|
325 | { | |
328 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
326 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
329 | if (axisList.count()) |
|
327 | if (axisList.count()) | |
330 | return axisList[0]; |
|
328 | return axisList[0]; | |
331 | return 0; |
|
329 | return 0; | |
332 | } |
|
330 | } | |
333 |
|
331 | |||
334 | /*! |
|
332 | /*! | |
335 | Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the |
|
333 | Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the | |
336 | specified orientation are returned. |
|
334 | specified orientation are returned. | |
337 | \sa addAxis(), createDefaultAxes() |
|
335 | \sa addAxis(), createDefaultAxes() | |
338 | */ |
|
336 | */ | |
339 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
337 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
340 | { |
|
338 | { | |
341 | QList<QAbstractAxis *> result ; |
|
339 | QList<QAbstractAxis *> result ; | |
342 |
|
340 | |||
343 | if (series) { |
|
341 | if (series) { | |
344 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
342 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
345 | if (orientation.testFlag(axis->orientation())) |
|
343 | if (orientation.testFlag(axis->orientation())) | |
346 | result << axis; |
|
344 | result << axis; | |
347 | } |
|
345 | } | |
348 | } else { |
|
346 | } else { | |
349 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
347 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
350 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
348 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
351 | result << axis; |
|
349 | result << axis; | |
352 | } |
|
350 | } | |
353 | } |
|
351 | } | |
354 |
|
352 | |||
355 | return result; |
|
353 | return result; | |
356 | } |
|
354 | } | |
357 |
|
355 | |||
358 | /*! |
|
356 | /*! | |
359 | 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. |
|
357 | 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. | |
360 |
|
358 | |||
361 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
359 | Creates the axes for the chart based on the series that has already been added to the chart. | |
362 |
|
360 | |||
363 | \table |
|
361 | \table | |
364 | \header |
|
362 | \header | |
365 | \o Series type |
|
363 | \o Series type | |
366 | \o X-axis |
|
364 | \o X-axis | |
367 | \o Y-axis |
|
365 | \o Y-axis | |
368 | \row |
|
366 | \row | |
369 | \o QXYSeries |
|
367 | \o QXYSeries | |
370 | \o QValueAxis |
|
368 | \o QValueAxis | |
371 | \o QValueAxis |
|
369 | \o QValueAxis | |
372 | \row |
|
370 | \row | |
373 | \o QBarSeries |
|
371 | \o QBarSeries | |
374 | \o QBarCategoryAxis |
|
372 | \o QBarCategoryAxis | |
375 | \o QValueAxis |
|
373 | \o QValueAxis | |
376 | \row |
|
374 | \row | |
377 | \o QPieSeries |
|
375 | \o QPieSeries | |
378 | \o None |
|
376 | \o None | |
379 | \o None |
|
377 | \o None | |
380 | \endtable |
|
378 | \endtable | |
381 |
|
379 | |||
382 | 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. |
|
380 | 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. | |
383 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
381 | If there are sevaral series added of different types then each series gets its own axes pair. | |
384 |
|
382 | |||
385 | 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. |
|
383 | 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. | |
386 |
|
384 | |||
387 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
385 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. | |
388 | QPieSeries does not create any axes. |
|
386 | QPieSeries does not create any axes. | |
389 |
|
387 | |||
390 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
388 | \sa axisX(), axisY(), setAxisX(), setAxisY() | |
391 | */ |
|
389 | */ | |
392 | void QChart::createDefaultAxes() |
|
390 | void QChart::createDefaultAxes() | |
393 | { |
|
391 | { | |
394 | d_ptr->m_dataset->createDefaultAxes(); |
|
392 | d_ptr->m_dataset->createDefaultAxes(); | |
395 | } |
|
393 | } | |
396 |
|
394 | |||
397 | /*! |
|
395 | /*! | |
398 | Returns the legend object of the chart. Ownership stays in chart. |
|
396 | Returns the legend object of the chart. Ownership stays in chart. | |
399 | */ |
|
397 | */ | |
400 | QLegend *QChart::legend() const |
|
398 | QLegend *QChart::legend() const | |
401 | { |
|
399 | { | |
402 | return d_ptr->m_legend; |
|
400 | return d_ptr->m_legend; | |
403 | } |
|
401 | } | |
404 |
|
402 | |||
405 | /*! |
|
403 | /*! | |
406 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
404 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
407 | Deprecated. Use setMargins(). |
|
405 | Deprecated. Use setMargins(). | |
408 | */ |
|
406 | */ | |
409 | void QChart::setMinimumMargins(const QMargins &margins) |
|
407 | void QChart::setMinimumMargins(const QMargins &margins) | |
410 | { |
|
408 | { | |
411 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
409 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
412 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
410 | d_ptr->m_presenter->layout()->setMargins(margins); | |
413 | } |
|
411 | } | |
414 |
|
412 | |||
415 | /*! |
|
413 | /*! | |
416 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
414 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
417 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
415 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
418 | Deprecated. Use margins(). |
|
416 | Deprecated. Use margins(). | |
419 | */ |
|
417 | */ | |
420 | QMargins QChart::minimumMargins() const |
|
418 | QMargins QChart::minimumMargins() const | |
421 | { |
|
419 | { | |
422 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
420 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
423 | return d_ptr->m_presenter->layout()->margins(); |
|
421 | return d_ptr->m_presenter->layout()->margins(); | |
424 | } |
|
422 | } | |
425 |
|
423 | |||
426 | /*! |
|
424 | /*! | |
427 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
425 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
428 | */ |
|
426 | */ | |
429 | void QChart::setMargins(const QMargins &margins) |
|
427 | void QChart::setMargins(const QMargins &margins) | |
430 | { |
|
428 | { | |
431 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
429 | d_ptr->m_presenter->layout()->setMargins(margins); | |
432 | } |
|
430 | } | |
433 |
|
431 | |||
434 | /*! |
|
432 | /*! | |
435 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
433 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
436 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
434 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
437 | */ |
|
435 | */ | |
438 | QMargins QChart::margins() const |
|
436 | QMargins QChart::margins() const | |
439 | { |
|
437 | { | |
440 | return d_ptr->m_presenter->layout()->margins(); |
|
438 | return d_ptr->m_presenter->layout()->margins(); | |
441 | } |
|
439 | } | |
442 |
|
440 | |||
443 | /*! |
|
441 | /*! | |
444 | Returns the the rect within which the drawing of the chart is done. |
|
442 | Returns the the rect within which the drawing of the chart is done. | |
445 | It does not include the area defines by margins. |
|
443 | It does not include the area defines by margins. | |
446 | */ |
|
444 | */ | |
447 | QRectF QChart::plotArea() const |
|
445 | QRectF QChart::plotArea() const | |
448 | { |
|
446 | { | |
449 | return d_ptr->m_presenter->geometry(); |
|
447 | return d_ptr->m_presenter->geometry(); | |
450 | } |
|
448 | } | |
451 |
|
449 | |||
452 | ///*! |
|
450 | ///*! | |
453 | // TODO: Dummy. |
|
451 | // TODO: Dummy. | |
454 |
// Adj |
|
452 | // Adjust the ranges of the axes so that all the data of the specified \a series is visible | |
455 | // */ |
|
453 | // */ | |
456 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
454 | //void QChart::adjustViewToSeries(QAbstractSeries* series) | |
457 | //{ |
|
455 | //{ | |
458 | // // |
|
456 | // // | |
459 | //} |
|
457 | //} | |
460 |
|
458 | |||
461 | /*! |
|
459 | /*! | |
462 | Sets animation \a options for the chart |
|
460 | Sets animation \a options for the chart | |
463 | */ |
|
461 | */ | |
464 | void QChart::setAnimationOptions(AnimationOptions options) |
|
462 | void QChart::setAnimationOptions(AnimationOptions options) | |
465 | { |
|
463 | { | |
466 | d_ptr->m_presenter->setAnimationOptions(options); |
|
464 | d_ptr->m_presenter->setAnimationOptions(options); | |
467 | } |
|
465 | } | |
468 |
|
466 | |||
469 | QChart::AnimationOptions QChart::animationOptions() const |
|
467 | QChart::AnimationOptions QChart::animationOptions() const | |
470 | { |
|
468 | { | |
471 | return d_ptr->m_presenter->animationOptions(); |
|
469 | return d_ptr->m_presenter->animationOptions(); | |
472 | } |
|
470 | } | |
473 |
|
471 | |||
474 | /*! |
|
472 | /*! | |
475 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
473 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
476 | */ |
|
474 | */ | |
477 | void QChart::scroll(qreal dx, qreal dy) |
|
475 | void QChart::scroll(qreal dx, qreal dy) | |
478 | { |
|
476 | { | |
479 | d_ptr->scroll(dx,dy); |
|
477 | d_ptr->scroll(dx,dy); | |
480 | } |
|
478 | } | |
481 |
|
479 | |||
482 | void QChart::setBackgroundVisible(bool visible) |
|
480 | void QChart::setBackgroundVisible(bool visible) | |
483 | { |
|
481 | { | |
484 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
482 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
485 | } |
|
483 | } | |
486 |
|
484 | |||
487 | bool QChart::isBackgroundVisible() const |
|
485 | bool QChart::isBackgroundVisible() const | |
488 | { |
|
486 | { | |
489 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
487 | return d_ptr->m_presenter->isBackgroundVisible(); | |
490 | } |
|
488 | } | |
491 |
|
489 | |||
492 | void QChart::setDropShadowEnabled(bool enabled) |
|
490 | void QChart::setDropShadowEnabled(bool enabled) | |
493 | { |
|
491 | { | |
494 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
492 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
495 | } |
|
493 | } | |
496 |
|
494 | |||
497 | bool QChart::isDropShadowEnabled() const |
|
495 | bool QChart::isDropShadowEnabled() const | |
498 | { |
|
496 | { | |
499 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
497 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
500 | } |
|
498 | } | |
501 |
|
499 | |||
502 | /*! |
|
500 | /*! | |
503 | Returns all the series that are added to the chart. |
|
501 | Returns all the series that are added to the chart. | |
504 |
|
502 | |||
505 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
503 | \sa addSeries(), removeSeries(), removeAllSeries() | |
506 | */ |
|
504 | */ | |
507 | QList<QAbstractSeries *> QChart::series() const |
|
505 | QList<QAbstractSeries *> QChart::series() const | |
508 | { |
|
506 | { | |
509 | return d_ptr->m_dataset->series(); |
|
507 | return d_ptr->m_dataset->series(); | |
510 | } |
|
508 | } | |
511 |
|
509 | |||
512 | /*! |
|
510 | /*! | |
513 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
511 | Sets \a axis to the chart, which will control the presentation of the \a series | |
514 |
|
512 | |||
515 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
513 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() | |
516 | */ |
|
514 | */ | |
517 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
515 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | |
518 | { |
|
516 | { | |
519 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
517 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); | |
520 |
|
518 | |||
521 | foreach(QAbstractAxis* a, list){ |
|
519 | foreach(QAbstractAxis* a, list){ | |
522 | d_ptr->m_dataset->removeAxis(a); |
|
520 | d_ptr->m_dataset->removeAxis(a); | |
523 | delete a; |
|
521 | delete a; | |
524 | } |
|
522 | } | |
525 |
|
523 | |||
526 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
524 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
527 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
525 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); | |
528 | d_ptr->m_dataset->attachAxis(series,axis); |
|
526 | d_ptr->m_dataset->attachAxis(series,axis); | |
529 | } |
|
527 | } | |
530 |
|
528 | |||
531 | /*! |
|
529 | /*! | |
532 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
530 | Sets \a axis to the chart, which will control the presentation of the \a series | |
533 |
|
531 | |||
534 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
532 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() | |
535 | */ |
|
533 | */ | |
536 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
534 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) | |
537 | { |
|
535 | { | |
538 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
536 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); | |
539 |
|
537 | |||
540 | foreach(QAbstractAxis* a, list) { |
|
538 | foreach(QAbstractAxis* a, list) { | |
541 | d_ptr->m_dataset->removeAxis(a); |
|
539 | d_ptr->m_dataset->removeAxis(a); | |
542 | delete a; |
|
540 | delete a; | |
543 | } |
|
541 | } | |
544 |
|
542 | |||
545 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
543 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
546 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
544 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); | |
547 | d_ptr->m_dataset->attachAxis(series,axis); |
|
545 | d_ptr->m_dataset->attachAxis(series,axis); | |
548 | } |
|
546 | } | |
549 |
|
547 | |||
550 | /*! |
|
548 | /*! | |
551 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
549 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
552 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
550 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
553 | */ |
|
551 | */ | |
554 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
552 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
555 | { |
|
553 | { | |
556 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
554 | d_ptr->m_dataset->addAxis(axis, alignment); | |
557 | } |
|
555 | } | |
558 |
|
556 | |||
559 | /*! |
|
557 | /*! | |
560 | Removes \a axis from the chart. The ownership is returned to the caller. |
|
558 | Removes \a axis from the chart. The ownership is returned to the caller. | |
561 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
559 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
562 | */ |
|
560 | */ | |
563 | void QChart::removeAxis(QAbstractAxis *axis) |
|
561 | void QChart::removeAxis(QAbstractAxis *axis) | |
564 | { |
|
562 | { | |
565 | d_ptr->m_dataset->removeAxis(axis); |
|
563 | d_ptr->m_dataset->removeAxis(axis); | |
566 | } |
|
564 | } | |
567 |
|
565 | |||
568 | /*! |
|
566 | /*! | |
569 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. |
|
567 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. | |
570 | */ |
|
568 | */ | |
571 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
569 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
572 | { |
|
570 | { | |
573 | return d_ptr->m_dataset->mapToValue(position, series); |
|
571 | return d_ptr->m_dataset->mapToValue(position, series); | |
574 | } |
|
572 | } | |
575 |
|
573 | |||
576 | /*! |
|
574 | /*! | |
577 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. |
|
575 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. | |
578 | */ |
|
576 | */ | |
579 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
577 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
580 | { |
|
578 | { | |
581 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
579 | return d_ptr->m_dataset->mapToPosition(value, series); | |
582 | } |
|
580 | } | |
583 |
|
581 | |||
584 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
582 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
585 |
|
583 | |||
586 | QChartPrivate::QChartPrivate(QChart *q): |
|
584 | QChartPrivate::QChartPrivate(QChart *q): | |
587 | q_ptr(q), |
|
585 | q_ptr(q), | |
588 | m_legend(0), |
|
586 | m_legend(0), | |
589 | m_dataset(new ChartDataSet(q)), |
|
587 | m_dataset(new ChartDataSet(q)), | |
590 | m_presenter(new ChartPresenter(q)), |
|
588 | m_presenter(new ChartPresenter(q)), | |
591 | m_themeManager(new ChartThemeManager(q)) |
|
589 | m_themeManager(new ChartThemeManager(q)) | |
592 | { |
|
590 | { | |
593 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
591 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
594 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
592 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
595 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
593 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
596 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
594 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
597 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
595 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
598 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
596 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
599 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
597 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
600 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
598 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
601 | } |
|
599 | } | |
602 |
|
600 | |||
603 | QChartPrivate::~QChartPrivate() |
|
601 | QChartPrivate::~QChartPrivate() | |
604 | { |
|
602 | { | |
605 |
|
603 | |||
606 | } |
|
604 | } | |
607 |
|
605 | |||
608 | void QChartPrivate::zoomIn(qreal factor) |
|
606 | void QChartPrivate::zoomIn(qreal factor) | |
609 | { |
|
607 | { | |
610 | QRectF rect = m_presenter->geometry(); |
|
608 | QRectF rect = m_presenter->geometry(); | |
611 | rect.setWidth(rect.width() / factor); |
|
609 | rect.setWidth(rect.width() / factor); | |
612 | rect.setHeight(rect.height() / factor); |
|
610 | rect.setHeight(rect.height() / factor); | |
613 | rect.moveCenter(m_presenter->geometry().center()); |
|
611 | rect.moveCenter(m_presenter->geometry().center()); | |
614 | zoomIn(rect); |
|
612 | zoomIn(rect); | |
615 | } |
|
613 | } | |
616 |
|
614 | |||
617 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
615 | void QChartPrivate::zoomIn(const QRectF &rect) | |
618 | { |
|
616 | { | |
619 | if (!rect.isValid()) |
|
617 | if (!rect.isValid()) | |
620 | return; |
|
618 | return; | |
621 |
|
619 | |||
622 | QRectF r = rect.normalized(); |
|
620 | QRectF r = rect.normalized(); | |
623 | const QRectF geometry = m_presenter->geometry(); |
|
621 | const QRectF geometry = m_presenter->geometry(); | |
624 | r.translate(-geometry.topLeft()); |
|
622 | r.translate(-geometry.topLeft()); | |
625 |
|
623 | |||
626 | if (!r.isValid()) |
|
624 | if (!r.isValid()) | |
627 | return; |
|
625 | return; | |
628 |
|
626 | |||
629 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
627 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
630 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
628 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
631 | m_dataset->zoomInDomain(r); |
|
629 | m_dataset->zoomInDomain(r); | |
632 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
630 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
633 |
|
631 | |||
634 | } |
|
632 | } | |
635 |
|
633 | |||
636 | void QChartPrivate::zoomOut(qreal factor) |
|
634 | void QChartPrivate::zoomOut(qreal factor) | |
637 | { |
|
635 | { | |
638 | const QRectF geometry = m_presenter->geometry(); |
|
636 | const QRectF geometry = m_presenter->geometry(); | |
639 |
|
637 | |||
640 | QRectF r; |
|
638 | QRectF r; | |
641 | r.setSize(geometry.size() / factor); |
|
639 | r.setSize(geometry.size() / factor); | |
642 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
640 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
643 | if (!r.isValid()) |
|
641 | if (!r.isValid()) | |
644 | return; |
|
642 | return; | |
645 |
|
643 | |||
646 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
644 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
647 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
645 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
648 | m_dataset->zoomOutDomain(r); |
|
646 | m_dataset->zoomOutDomain(r); | |
649 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
647 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
650 | } |
|
648 | } | |
651 |
|
649 | |||
652 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
650 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
653 | { |
|
651 | { | |
654 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
652 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
655 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
653 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
656 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
654 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
657 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
655 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
658 |
|
656 | |||
659 | m_dataset->scrollDomain(dx, dy); |
|
657 | m_dataset->scrollDomain(dx, dy); | |
660 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
658 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
661 | } |
|
659 | } | |
662 |
|
660 | |||
663 | #include "moc_qchart.cpp" |
|
661 | #include "moc_qchart.cpp" | |
664 |
|
662 | |||
665 | QTCOMMERCIALCHART_END_NAMESPACE |
|
663 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,863 +1,859 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "tst_qabstractaxis.h" |
|
21 | #include "tst_qabstractaxis.h" | |
22 |
|
22 | |||
23 | Q_DECLARE_METATYPE(QPen) |
|
23 | Q_DECLARE_METATYPE(QPen) | |
24 | Q_DECLARE_METATYPE(Qt::Orientation) |
|
24 | Q_DECLARE_METATYPE(Qt::Orientation) | |
25 |
|
25 | |||
26 | void tst_QAbstractAxis::initTestCase() |
|
26 | void tst_QAbstractAxis::initTestCase() | |
27 | { |
|
27 | { | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | void tst_QAbstractAxis::cleanupTestCase() |
|
30 | void tst_QAbstractAxis::cleanupTestCase() | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void tst_QAbstractAxis::init(QAbstractAxis* axis, QAbstractSeries* series) |
|
34 | void tst_QAbstractAxis::init(QAbstractAxis* axis, QAbstractSeries* series) | |
35 | { |
|
35 | { | |
36 | m_axis = axis; |
|
36 | m_axis = axis; | |
37 | m_series = series; |
|
37 | m_series = series; | |
38 | m_view = new QChartView(new QChart()); |
|
38 | m_view = new QChartView(new QChart()); | |
39 | m_chart = m_view->chart(); |
|
39 | m_chart = m_view->chart(); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | void tst_QAbstractAxis::cleanup() |
|
42 | void tst_QAbstractAxis::cleanup() | |
43 | { |
|
43 | { | |
44 | delete m_view; |
|
44 | delete m_view; | |
45 | m_view = 0; |
|
45 | m_view = 0; | |
46 | m_chart = 0; |
|
46 | m_chart = 0; | |
47 | m_axis = 0; |
|
47 | m_axis = 0; | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void tst_QAbstractAxis::qabstractaxis() |
|
50 | void tst_QAbstractAxis::qabstractaxis() | |
51 | { |
|
51 | { | |
52 | QCOMPARE(m_axis->linePen(), QPen()); |
|
52 | QCOMPARE(m_axis->linePen(), QPen()); | |
53 | //TODO QCOMPARE(m_axis->axisPenColor(), QColor()); |
|
|||
54 | QCOMPARE(m_axis->gridLinePen(), QPen()); |
|
53 | QCOMPARE(m_axis->gridLinePen(), QPen()); | |
55 | QCOMPARE(m_axis->isLineVisible(), true); |
|
54 | QCOMPARE(m_axis->isLineVisible(), true); | |
56 | QCOMPARE(m_axis->isGridLineVisible(), true); |
|
55 | QCOMPARE(m_axis->isGridLineVisible(), true); | |
57 | QCOMPARE(m_axis->isVisible(), true); |
|
56 | QCOMPARE(m_axis->isVisible(), true); | |
58 | QCOMPARE(m_axis->labelsAngle(), 0); |
|
57 | QCOMPARE(m_axis->labelsAngle(), 0); | |
59 | QCOMPARE(m_axis->labelsBrush(), QBrush()); |
|
58 | QCOMPARE(m_axis->labelsBrush(), QBrush()); | |
60 | //TODO QCOMPARE(m_axis->labelsColor(), QColor()); |
|
|||
61 | QCOMPARE(m_axis->labelsFont(), QFont()); |
|
59 | QCOMPARE(m_axis->labelsFont(), QFont()); | |
62 | QCOMPARE(m_axis->labelsPen(), QPen()); |
|
60 | QCOMPARE(m_axis->labelsPen(), QPen()); | |
63 | QCOMPARE(m_axis->labelsVisible(), true); |
|
61 | QCOMPARE(m_axis->labelsVisible(), true); | |
64 | QCOMPARE(m_axis->orientation(), Qt::Orientation(0)); |
|
62 | QCOMPARE(m_axis->orientation(), Qt::Orientation(0)); | |
65 | m_axis->setLineVisible(false); |
|
63 | m_axis->setLineVisible(false); | |
66 | m_axis->setLinePen(QPen()); |
|
64 | m_axis->setLinePen(QPen()); | |
67 | m_axis->setLinePenColor(QColor()); |
|
65 | m_axis->setLinePenColor(QColor()); | |
68 | m_axis->setGridLinePen(QPen()); |
|
66 | m_axis->setGridLinePen(QPen()); | |
69 | m_axis->setGridLineVisible(false); |
|
67 | m_axis->setGridLineVisible(false); | |
70 | m_axis->setLabelsAngle(-1); |
|
68 | m_axis->setLabelsAngle(-1); | |
71 | m_axis->setLabelsBrush(QBrush()); |
|
69 | m_axis->setLabelsBrush(QBrush()); | |
72 | m_axis->setLabelsColor(QColor()); |
|
70 | m_axis->setLabelsColor(QColor()); | |
73 | m_axis->setLabelsFont(QFont()); |
|
71 | m_axis->setLabelsFont(QFont()); | |
74 | m_axis->setLabelsPen(QPen()); |
|
72 | m_axis->setLabelsPen(QPen()); | |
75 | m_axis->setLabelsVisible(false); |
|
73 | m_axis->setLabelsVisible(false); | |
76 | m_axis->setMax(QVariant()); |
|
74 | m_axis->setMax(QVariant()); | |
77 | m_axis->setMin(QVariant()); |
|
75 | m_axis->setMin(QVariant()); | |
78 | m_axis->setRange(QVariant(), QVariant()); |
|
76 | m_axis->setRange(QVariant(), QVariant()); | |
79 | m_axis->setShadesBorderColor(QColor()); |
|
77 | m_axis->setShadesBorderColor(QColor()); | |
80 | m_axis->setShadesBrush(QBrush()); |
|
78 | m_axis->setShadesBrush(QBrush()); | |
81 | m_axis->setShadesColor(QColor()); |
|
79 | m_axis->setShadesColor(QColor()); | |
82 | m_axis->setShadesPen(QPen()); |
|
80 | m_axis->setShadesPen(QPen()); | |
83 | m_axis->setShadesVisible(false); |
|
81 | m_axis->setShadesVisible(false); | |
84 | m_axis->setVisible(false); |
|
82 | m_axis->setVisible(false); | |
85 | //TODO QCOMPARE(m_axis->shadesBorderColor(), QColor()); |
|
|||
86 | //TODO QCOMPARE(m_axis->shadesBrush(), QBrush()); |
|
83 | //TODO QCOMPARE(m_axis->shadesBrush(), QBrush()); | |
87 | //TODO QCOMPARE(m_axis->shadesColor(), QColor()); |
|
|||
88 | QCOMPARE(m_axis->shadesPen(), QPen()); |
|
84 | QCOMPARE(m_axis->shadesPen(), QPen()); | |
89 | QCOMPARE(m_axis->shadesVisible(), false); |
|
85 | QCOMPARE(m_axis->shadesVisible(), false); | |
90 | m_axis->show(); |
|
86 | m_axis->show(); | |
91 | m_axis->hide(); |
|
87 | m_axis->hide(); | |
92 | } |
|
88 | } | |
93 |
|
89 | |||
94 | void tst_QAbstractAxis::axisPen_data() |
|
90 | void tst_QAbstractAxis::axisPen_data() | |
95 | { |
|
91 | { | |
96 | QTest::addColumn<QPen>("axisPen"); |
|
92 | QTest::addColumn<QPen>("axisPen"); | |
97 | QTest::newRow("null") << QPen(); |
|
93 | QTest::newRow("null") << QPen(); | |
98 | QTest::newRow("blue") << QPen(Qt::blue); |
|
94 | QTest::newRow("blue") << QPen(Qt::blue); | |
99 | QTest::newRow("black") << QPen(Qt::black); |
|
95 | QTest::newRow("black") << QPen(Qt::black); | |
100 | QTest::newRow("red") << QPen(Qt::red); |
|
96 | QTest::newRow("red") << QPen(Qt::red); | |
101 | } |
|
97 | } | |
102 |
|
98 | |||
103 | void tst_QAbstractAxis::axisPen() |
|
99 | void tst_QAbstractAxis::axisPen() | |
104 | { |
|
100 | { | |
105 | QFETCH(QPen, axisPen); |
|
101 | QFETCH(QPen, axisPen); | |
106 |
|
102 | |||
107 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
103 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
108 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
104 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
109 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
105 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
110 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
106 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
111 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
107 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
112 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
108 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
113 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
109 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
114 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
110 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
115 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
111 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
116 |
|
112 | |||
117 | m_axis->setLinePen(axisPen); |
|
113 | m_axis->setLinePen(axisPen); | |
118 | QCOMPARE(m_axis->linePen(), axisPen); |
|
114 | QCOMPARE(m_axis->linePen(), axisPen); | |
119 |
|
115 | |||
120 | QCOMPARE(spy0.count(), 0); |
|
116 | QCOMPARE(spy0.count(), 0); | |
121 | QCOMPARE(spy1.count(), 0); |
|
117 | QCOMPARE(spy1.count(), 0); | |
122 | QCOMPARE(spy2.count(), 0); |
|
118 | QCOMPARE(spy2.count(), 0); | |
123 | QCOMPARE(spy3.count(), 0); |
|
119 | QCOMPARE(spy3.count(), 0); | |
124 | QCOMPARE(spy4.count(), 0); |
|
120 | QCOMPARE(spy4.count(), 0); | |
125 | QCOMPARE(spy5.count(), 0); |
|
121 | QCOMPARE(spy5.count(), 0); | |
126 | QCOMPARE(spy6.count(), 0); |
|
122 | QCOMPARE(spy6.count(), 0); | |
127 | QCOMPARE(spy7.count(), 0); |
|
123 | QCOMPARE(spy7.count(), 0); | |
128 | QCOMPARE(spy8.count(), 0); |
|
124 | QCOMPARE(spy8.count(), 0); | |
129 |
|
125 | |||
130 | m_chart->setAxisX(m_axis, m_series); |
|
126 | m_chart->setAxisX(m_axis, m_series); | |
131 | m_view->show(); |
|
127 | m_view->show(); | |
132 | QTest::qWaitForWindowShown(m_view); |
|
128 | QTest::qWaitForWindowShown(m_view); | |
133 | //TODO QCOMPARE(m_axis->axisPen(), axisPen); |
|
129 | //TODO QCOMPARE(m_axis->axisPen(), axisPen); | |
134 | } |
|
130 | } | |
135 |
|
131 | |||
136 | void tst_QAbstractAxis::axisPenColor_data() |
|
132 | void tst_QAbstractAxis::axisPenColor_data() | |
137 | { |
|
133 | { | |
138 | } |
|
134 | } | |
139 |
|
135 | |||
140 | void tst_QAbstractAxis::axisPenColor() |
|
136 | void tst_QAbstractAxis::axisPenColor() | |
141 | { |
|
137 | { | |
142 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
138 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
143 | QSKIP("Test is not implemented. This is deprecated function"); |
|
139 | QSKIP("Test is not implemented. This is deprecated function"); | |
144 | #else |
|
140 | #else | |
145 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); |
|
141 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); | |
146 | #endif |
|
142 | #endif | |
147 | } |
|
143 | } | |
148 |
|
144 | |||
149 | void tst_QAbstractAxis::gridLinePen_data() |
|
145 | void tst_QAbstractAxis::gridLinePen_data() | |
150 | { |
|
146 | { | |
151 |
|
147 | |||
152 | QTest::addColumn<QPen>("gridLinePen"); |
|
148 | QTest::addColumn<QPen>("gridLinePen"); | |
153 | QTest::newRow("null") << QPen(); |
|
149 | QTest::newRow("null") << QPen(); | |
154 | QTest::newRow("blue") << QPen(Qt::blue); |
|
150 | QTest::newRow("blue") << QPen(Qt::blue); | |
155 | QTest::newRow("black") << QPen(Qt::black); |
|
151 | QTest::newRow("black") << QPen(Qt::black); | |
156 | QTest::newRow("red") << QPen(Qt::red); |
|
152 | QTest::newRow("red") << QPen(Qt::red); | |
157 |
|
153 | |||
158 | } |
|
154 | } | |
159 |
|
155 | |||
160 | void tst_QAbstractAxis::gridLinePen() |
|
156 | void tst_QAbstractAxis::gridLinePen() | |
161 | { |
|
157 | { | |
162 | QFETCH(QPen, gridLinePen); |
|
158 | QFETCH(QPen, gridLinePen); | |
163 |
|
159 | |||
164 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
160 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
165 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
161 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
166 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
162 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
167 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
163 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
168 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
164 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
169 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
165 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
170 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
166 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
171 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
167 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
172 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
168 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
173 |
|
169 | |||
174 | m_axis->setGridLinePen(gridLinePen); |
|
170 | m_axis->setGridLinePen(gridLinePen); | |
175 | QCOMPARE(m_axis->gridLinePen(), gridLinePen); |
|
171 | QCOMPARE(m_axis->gridLinePen(), gridLinePen); | |
176 |
|
172 | |||
177 | QCOMPARE(spy0.count(), 0); |
|
173 | QCOMPARE(spy0.count(), 0); | |
178 | QCOMPARE(spy1.count(), 0); |
|
174 | QCOMPARE(spy1.count(), 0); | |
179 | QCOMPARE(spy2.count(), 0); |
|
175 | QCOMPARE(spy2.count(), 0); | |
180 | QCOMPARE(spy3.count(), 0); |
|
176 | QCOMPARE(spy3.count(), 0); | |
181 | QCOMPARE(spy4.count(), 0); |
|
177 | QCOMPARE(spy4.count(), 0); | |
182 | QCOMPARE(spy5.count(), 0); |
|
178 | QCOMPARE(spy5.count(), 0); | |
183 | QCOMPARE(spy6.count(), 0); |
|
179 | QCOMPARE(spy6.count(), 0); | |
184 | QCOMPARE(spy7.count(), 0); |
|
180 | QCOMPARE(spy7.count(), 0); | |
185 | QCOMPARE(spy8.count(), 0); |
|
181 | QCOMPARE(spy8.count(), 0); | |
186 |
|
182 | |||
187 | m_chart->setAxisX(m_axis, m_series); |
|
183 | m_chart->setAxisX(m_axis, m_series); | |
188 | m_view->show(); |
|
184 | m_view->show(); | |
189 | QTest::qWaitForWindowShown(m_view); |
|
185 | QTest::qWaitForWindowShown(m_view); | |
190 | //TODO QCOMPARE(m_axis->gridLinePen(), gridLinePen); |
|
186 | //TODO QCOMPARE(m_axis->gridLinePen(), gridLinePen); | |
191 | } |
|
187 | } | |
192 |
|
188 | |||
193 | void tst_QAbstractAxis::lineVisible_data() |
|
189 | void tst_QAbstractAxis::lineVisible_data() | |
194 | { |
|
190 | { | |
195 | QTest::addColumn<bool>("lineVisible"); |
|
191 | QTest::addColumn<bool>("lineVisible"); | |
196 | QTest::newRow("true") << true; |
|
192 | QTest::newRow("true") << true; | |
197 | QTest::newRow("false") << false; |
|
193 | QTest::newRow("false") << false; | |
198 | } |
|
194 | } | |
199 |
|
195 | |||
200 | void tst_QAbstractAxis::lineVisible() |
|
196 | void tst_QAbstractAxis::lineVisible() | |
201 | { |
|
197 | { | |
202 | QFETCH(bool, lineVisible); |
|
198 | QFETCH(bool, lineVisible); | |
203 |
|
199 | |||
204 | m_axis->setLineVisible(!lineVisible); |
|
200 | m_axis->setLineVisible(!lineVisible); | |
205 |
|
201 | |||
206 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
202 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
207 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
203 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
208 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
204 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
209 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
205 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
210 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
206 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
211 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
207 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
212 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
208 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
213 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
209 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
214 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
210 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
215 |
|
211 | |||
216 | m_axis->setLineVisible(lineVisible); |
|
212 | m_axis->setLineVisible(lineVisible); | |
217 | QCOMPARE(m_axis->isLineVisible(), lineVisible); |
|
213 | QCOMPARE(m_axis->isLineVisible(), lineVisible); | |
218 |
|
214 | |||
219 | QCOMPARE(spy0.count(), 1); |
|
215 | QCOMPARE(spy0.count(), 1); | |
220 | QCOMPARE(spy1.count(), 0); |
|
216 | QCOMPARE(spy1.count(), 0); | |
221 | QCOMPARE(spy2.count(), 0); |
|
217 | QCOMPARE(spy2.count(), 0); | |
222 | QCOMPARE(spy3.count(), 0); |
|
218 | QCOMPARE(spy3.count(), 0); | |
223 | QCOMPARE(spy4.count(), 0); |
|
219 | QCOMPARE(spy4.count(), 0); | |
224 | QCOMPARE(spy5.count(), 0); |
|
220 | QCOMPARE(spy5.count(), 0); | |
225 | QCOMPARE(spy6.count(), 0); |
|
221 | QCOMPARE(spy6.count(), 0); | |
226 | QCOMPARE(spy7.count(), 0); |
|
222 | QCOMPARE(spy7.count(), 0); | |
227 | QCOMPARE(spy8.count(), 0); |
|
223 | QCOMPARE(spy8.count(), 0); | |
228 |
|
224 | |||
229 | m_chart->setAxisX(m_axis, m_series); |
|
225 | m_chart->setAxisX(m_axis, m_series); | |
230 | m_view->show(); |
|
226 | m_view->show(); | |
231 | QTest::qWaitForWindowShown(m_view); |
|
227 | QTest::qWaitForWindowShown(m_view); | |
232 | QCOMPARE(m_axis->isLineVisible(), lineVisible); |
|
228 | QCOMPARE(m_axis->isLineVisible(), lineVisible); | |
233 | } |
|
229 | } | |
234 |
|
230 | |||
235 | void tst_QAbstractAxis::gridLineVisible_data() |
|
231 | void tst_QAbstractAxis::gridLineVisible_data() | |
236 | { |
|
232 | { | |
237 | QTest::addColumn<bool>("gridLineVisible"); |
|
233 | QTest::addColumn<bool>("gridLineVisible"); | |
238 | QTest::newRow("true") << true; |
|
234 | QTest::newRow("true") << true; | |
239 | QTest::newRow("false") << false; |
|
235 | QTest::newRow("false") << false; | |
240 | } |
|
236 | } | |
241 |
|
237 | |||
242 | void tst_QAbstractAxis::gridLineVisible() |
|
238 | void tst_QAbstractAxis::gridLineVisible() | |
243 | { |
|
239 | { | |
244 | QFETCH(bool, gridLineVisible); |
|
240 | QFETCH(bool, gridLineVisible); | |
245 |
|
241 | |||
246 | m_axis->setGridLineVisible(!gridLineVisible); |
|
242 | m_axis->setGridLineVisible(!gridLineVisible); | |
247 |
|
243 | |||
248 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
244 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
249 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
245 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
250 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
246 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
251 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
247 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
252 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
248 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
253 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
249 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
254 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
250 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
255 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
251 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
256 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
252 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
257 |
|
253 | |||
258 | m_axis->setGridLineVisible(gridLineVisible); |
|
254 | m_axis->setGridLineVisible(gridLineVisible); | |
259 | QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible); |
|
255 | QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible); | |
260 |
|
256 | |||
261 | QCOMPARE(spy0.count(), 0); |
|
257 | QCOMPARE(spy0.count(), 0); | |
262 | QCOMPARE(spy1.count(), 0); |
|
258 | QCOMPARE(spy1.count(), 0); | |
263 | QCOMPARE(spy2.count(), 1); |
|
259 | QCOMPARE(spy2.count(), 1); | |
264 | QCOMPARE(spy3.count(), 0); |
|
260 | QCOMPARE(spy3.count(), 0); | |
265 | QCOMPARE(spy4.count(), 0); |
|
261 | QCOMPARE(spy4.count(), 0); | |
266 | QCOMPARE(spy5.count(), 0); |
|
262 | QCOMPARE(spy5.count(), 0); | |
267 | QCOMPARE(spy6.count(), 0); |
|
263 | QCOMPARE(spy6.count(), 0); | |
268 | QCOMPARE(spy7.count(), 0); |
|
264 | QCOMPARE(spy7.count(), 0); | |
269 | QCOMPARE(spy8.count(), 0); |
|
265 | QCOMPARE(spy8.count(), 0); | |
270 |
|
266 | |||
271 | m_chart->setAxisX(m_axis, m_series); |
|
267 | m_chart->setAxisX(m_axis, m_series); | |
272 | m_view->show(); |
|
268 | m_view->show(); | |
273 | QTest::qWaitForWindowShown(m_view); |
|
269 | QTest::qWaitForWindowShown(m_view); | |
274 | QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible); |
|
270 | QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible); | |
275 |
|
271 | |||
276 | } |
|
272 | } | |
277 |
|
273 | |||
278 | void tst_QAbstractAxis::visible_data() |
|
274 | void tst_QAbstractAxis::visible_data() | |
279 | { |
|
275 | { | |
280 | QTest::addColumn<bool>("visible"); |
|
276 | QTest::addColumn<bool>("visible"); | |
281 | QTest::newRow("true") << true; |
|
277 | QTest::newRow("true") << true; | |
282 | QTest::newRow("false") << false; |
|
278 | QTest::newRow("false") << false; | |
283 | } |
|
279 | } | |
284 |
|
280 | |||
285 | void tst_QAbstractAxis::visible() |
|
281 | void tst_QAbstractAxis::visible() | |
286 | { |
|
282 | { | |
287 | QFETCH(bool, visible); |
|
283 | QFETCH(bool, visible); | |
288 |
|
284 | |||
289 | m_axis->setVisible(!visible); |
|
285 | m_axis->setVisible(!visible); | |
290 |
|
286 | |||
291 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
287 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
292 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
288 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
293 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
289 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
294 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
290 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
295 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
291 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
296 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
292 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
297 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
293 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
298 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
294 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
299 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
295 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
300 |
|
296 | |||
301 | m_axis->setVisible(visible); |
|
297 | m_axis->setVisible(visible); | |
302 | QCOMPARE(m_axis->isVisible(), visible); |
|
298 | QCOMPARE(m_axis->isVisible(), visible); | |
303 |
|
299 | |||
304 | QCOMPARE(spy0.count(), 0); |
|
300 | QCOMPARE(spy0.count(), 0); | |
305 | QCOMPARE(spy1.count(), 0); |
|
301 | QCOMPARE(spy1.count(), 0); | |
306 | QCOMPARE(spy2.count(), 0); |
|
302 | QCOMPARE(spy2.count(), 0); | |
307 | QCOMPARE(spy3.count(), 0); |
|
303 | QCOMPARE(spy3.count(), 0); | |
308 | QCOMPARE(spy4.count(), 0); |
|
304 | QCOMPARE(spy4.count(), 0); | |
309 | QCOMPARE(spy5.count(), 0); |
|
305 | QCOMPARE(spy5.count(), 0); | |
310 | QCOMPARE(spy6.count(), 0); |
|
306 | QCOMPARE(spy6.count(), 0); | |
311 | QCOMPARE(spy7.count(), 0); |
|
307 | QCOMPARE(spy7.count(), 0); | |
312 | QCOMPARE(spy8.count(), 1); |
|
308 | QCOMPARE(spy8.count(), 1); | |
313 |
|
309 | |||
314 | m_chart->setAxisX(m_axis, m_series); |
|
310 | m_chart->setAxisX(m_axis, m_series); | |
315 | m_view->show(); |
|
311 | m_view->show(); | |
316 | QTest::qWaitForWindowShown(m_view); |
|
312 | QTest::qWaitForWindowShown(m_view); | |
317 | QCOMPARE(m_axis->isVisible(), visible); |
|
313 | QCOMPARE(m_axis->isVisible(), visible); | |
318 | } |
|
314 | } | |
319 |
|
315 | |||
320 | void tst_QAbstractAxis::labelsAngle_data() |
|
316 | void tst_QAbstractAxis::labelsAngle_data() | |
321 | { |
|
317 | { | |
322 | QTest::addColumn<int>("labelsAngle"); |
|
318 | QTest::addColumn<int>("labelsAngle"); | |
323 | QTest::newRow("0") << 0; |
|
319 | QTest::newRow("0") << 0; | |
324 | QTest::newRow("45") << 45; |
|
320 | QTest::newRow("45") << 45; | |
325 | QTest::newRow("90") << 90; |
|
321 | QTest::newRow("90") << 90; | |
326 | } |
|
322 | } | |
327 |
|
323 | |||
328 | void tst_QAbstractAxis::labelsAngle() |
|
324 | void tst_QAbstractAxis::labelsAngle() | |
329 | { |
|
325 | { | |
330 | QFETCH(int, labelsAngle); |
|
326 | QFETCH(int, labelsAngle); | |
331 |
|
327 | |||
332 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
328 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
333 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
329 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
334 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
330 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
335 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
331 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
336 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
332 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
337 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
333 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
338 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
334 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
339 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
335 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
340 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
336 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
341 |
|
337 | |||
342 | m_axis->setLabelsAngle(labelsAngle); |
|
338 | m_axis->setLabelsAngle(labelsAngle); | |
343 | QCOMPARE(m_axis->labelsAngle(), labelsAngle); |
|
339 | QCOMPARE(m_axis->labelsAngle(), labelsAngle); | |
344 |
|
340 | |||
345 | QCOMPARE(spy0.count(), 0); |
|
341 | QCOMPARE(spy0.count(), 0); | |
346 | QCOMPARE(spy1.count(), 0); |
|
342 | QCOMPARE(spy1.count(), 0); | |
347 | QCOMPARE(spy2.count(), 0); |
|
343 | QCOMPARE(spy2.count(), 0); | |
348 | QCOMPARE(spy3.count(), 0); |
|
344 | QCOMPARE(spy3.count(), 0); | |
349 | QCOMPARE(spy4.count(), 0); |
|
345 | QCOMPARE(spy4.count(), 0); | |
350 | QCOMPARE(spy5.count(), 0); |
|
346 | QCOMPARE(spy5.count(), 0); | |
351 | QCOMPARE(spy6.count(), 0); |
|
347 | QCOMPARE(spy6.count(), 0); | |
352 | QCOMPARE(spy7.count(), 0); |
|
348 | QCOMPARE(spy7.count(), 0); | |
353 | QCOMPARE(spy8.count(), 0); |
|
349 | QCOMPARE(spy8.count(), 0); | |
354 |
|
350 | |||
355 | m_chart->setAxisX(m_axis, m_series); |
|
351 | m_chart->setAxisX(m_axis, m_series); | |
356 | m_view->show(); |
|
352 | m_view->show(); | |
357 | QTest::qWaitForWindowShown(m_view); |
|
353 | QTest::qWaitForWindowShown(m_view); | |
358 | QCOMPARE(m_axis->labelsAngle(), labelsAngle); |
|
354 | QCOMPARE(m_axis->labelsAngle(), labelsAngle); | |
359 | } |
|
355 | } | |
360 |
|
356 | |||
361 | void tst_QAbstractAxis::labelsBrush_data() |
|
357 | void tst_QAbstractAxis::labelsBrush_data() | |
362 | { |
|
358 | { | |
363 | QTest::addColumn<QBrush>("labelsBrush"); |
|
359 | QTest::addColumn<QBrush>("labelsBrush"); | |
364 | QTest::newRow("null") << QBrush(); |
|
360 | QTest::newRow("null") << QBrush(); | |
365 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
361 | QTest::newRow("blue") << QBrush(Qt::blue); | |
366 | QTest::newRow("black") << QBrush(Qt::black); |
|
362 | QTest::newRow("black") << QBrush(Qt::black); | |
367 |
|
363 | |||
368 | } |
|
364 | } | |
369 |
|
365 | |||
370 | void tst_QAbstractAxis::labelsBrush() |
|
366 | void tst_QAbstractAxis::labelsBrush() | |
371 | { |
|
367 | { | |
372 |
|
368 | |||
373 | QFETCH(QBrush, labelsBrush); |
|
369 | QFETCH(QBrush, labelsBrush); | |
374 |
|
370 | |||
375 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
371 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
376 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
372 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
377 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
373 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
378 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
374 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
379 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
375 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
380 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
376 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
381 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
377 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
382 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
378 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
383 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
379 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
384 |
|
380 | |||
385 | m_axis->setLabelsBrush(labelsBrush); |
|
381 | m_axis->setLabelsBrush(labelsBrush); | |
386 | QCOMPARE(m_axis->labelsBrush(), labelsBrush); |
|
382 | QCOMPARE(m_axis->labelsBrush(), labelsBrush); | |
387 |
|
383 | |||
388 | QCOMPARE(spy0.count(), 0); |
|
384 | QCOMPARE(spy0.count(), 0); | |
389 | QCOMPARE(spy1.count(), 0); |
|
385 | QCOMPARE(spy1.count(), 0); | |
390 | QCOMPARE(spy2.count(), 0); |
|
386 | QCOMPARE(spy2.count(), 0); | |
391 | QCOMPARE(spy3.count(), 0); |
|
387 | QCOMPARE(spy3.count(), 0); | |
392 | QCOMPARE(spy4.count(), 0); |
|
388 | QCOMPARE(spy4.count(), 0); | |
393 | QCOMPARE(spy5.count(), 0); |
|
389 | QCOMPARE(spy5.count(), 0); | |
394 | //TODO QCOMPARE(spy6.count(), 0); |
|
390 | //TODO QCOMPARE(spy6.count(), 0); | |
395 | QCOMPARE(spy7.count(), 0); |
|
391 | QCOMPARE(spy7.count(), 0); | |
396 | QCOMPARE(spy8.count(), 0); |
|
392 | QCOMPARE(spy8.count(), 0); | |
397 |
|
393 | |||
398 | m_view->show(); |
|
394 | m_view->show(); | |
399 | QTest::qWaitForWindowShown(m_view); |
|
395 | QTest::qWaitForWindowShown(m_view); | |
400 | QCOMPARE(m_axis->labelsBrush(), labelsBrush); |
|
396 | QCOMPARE(m_axis->labelsBrush(), labelsBrush); | |
401 |
|
397 | |||
402 | } |
|
398 | } | |
403 |
|
399 | |||
404 | void tst_QAbstractAxis::labelsColor_data() |
|
400 | void tst_QAbstractAxis::labelsColor_data() | |
405 | { |
|
401 | { | |
406 |
|
402 | |||
407 | } |
|
403 | } | |
408 |
|
404 | |||
409 | void tst_QAbstractAxis::labelsColor() |
|
405 | void tst_QAbstractAxis::labelsColor() | |
410 | { |
|
406 | { | |
411 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
407 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
412 | QSKIP("Test is not implemented. This is deprecated function"); |
|
408 | QSKIP("Test is not implemented. This is deprecated function"); | |
413 | #else |
|
409 | #else | |
414 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); |
|
410 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); | |
415 | #endif |
|
411 | #endif | |
416 | } |
|
412 | } | |
417 |
|
413 | |||
418 | void tst_QAbstractAxis::labelsFont_data() |
|
414 | void tst_QAbstractAxis::labelsFont_data() | |
419 | { |
|
415 | { | |
420 | QTest::addColumn<QFont>("labelsFont"); |
|
416 | QTest::addColumn<QFont>("labelsFont"); | |
421 | QTest::newRow("null") << QFont(); |
|
417 | QTest::newRow("null") << QFont(); | |
422 | QTest::newRow("serif") << QFont("SansSerif"); |
|
418 | QTest::newRow("serif") << QFont("SansSerif"); | |
423 | } |
|
419 | } | |
424 |
|
420 | |||
425 | void tst_QAbstractAxis::labelsFont() |
|
421 | void tst_QAbstractAxis::labelsFont() | |
426 | { |
|
422 | { | |
427 |
|
423 | |||
428 | QFETCH(QFont, labelsFont); |
|
424 | QFETCH(QFont, labelsFont); | |
429 |
|
425 | |||
430 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
426 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
431 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
427 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
432 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
428 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
433 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
429 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
434 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
430 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
435 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
431 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
436 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
432 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
437 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
433 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
438 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
434 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
439 |
|
435 | |||
440 | m_axis->setLabelsFont(labelsFont); |
|
436 | m_axis->setLabelsFont(labelsFont); | |
441 | QCOMPARE(m_axis->labelsFont(), labelsFont); |
|
437 | QCOMPARE(m_axis->labelsFont(), labelsFont); | |
442 |
|
438 | |||
443 | QCOMPARE(spy0.count(), 0); |
|
439 | QCOMPARE(spy0.count(), 0); | |
444 | QCOMPARE(spy1.count(), 0); |
|
440 | QCOMPARE(spy1.count(), 0); | |
445 | QCOMPARE(spy2.count(), 0); |
|
441 | QCOMPARE(spy2.count(), 0); | |
446 | QCOMPARE(spy3.count(), 0); |
|
442 | QCOMPARE(spy3.count(), 0); | |
447 | QCOMPARE(spy4.count(), 0); |
|
443 | QCOMPARE(spy4.count(), 0); | |
448 | QCOMPARE(spy5.count(), 0); |
|
444 | QCOMPARE(spy5.count(), 0); | |
449 | QCOMPARE(spy6.count(), 0); |
|
445 | QCOMPARE(spy6.count(), 0); | |
450 | QCOMPARE(spy7.count(), 0); |
|
446 | QCOMPARE(spy7.count(), 0); | |
451 | QCOMPARE(spy8.count(), 0); |
|
447 | QCOMPARE(spy8.count(), 0); | |
452 |
|
448 | |||
453 | m_view->show(); |
|
449 | m_view->show(); | |
454 | QTest::qWaitForWindowShown(m_view); |
|
450 | QTest::qWaitForWindowShown(m_view); | |
455 | QCOMPARE(m_axis->labelsFont(), labelsFont); |
|
451 | QCOMPARE(m_axis->labelsFont(), labelsFont); | |
456 |
|
452 | |||
457 | } |
|
453 | } | |
458 |
|
454 | |||
459 | void tst_QAbstractAxis::labelsPen_data() |
|
455 | void tst_QAbstractAxis::labelsPen_data() | |
460 | { |
|
456 | { | |
461 | QTest::addColumn<QPen>("labelsPen"); |
|
457 | QTest::addColumn<QPen>("labelsPen"); | |
462 | QTest::newRow("null") << QPen(); |
|
458 | QTest::newRow("null") << QPen(); | |
463 | QTest::newRow("blue") << QPen(Qt::blue); |
|
459 | QTest::newRow("blue") << QPen(Qt::blue); | |
464 | QTest::newRow("black") << QPen(Qt::black); |
|
460 | QTest::newRow("black") << QPen(Qt::black); | |
465 | QTest::newRow("red") << QPen(Qt::red); |
|
461 | QTest::newRow("red") << QPen(Qt::red); | |
466 | } |
|
462 | } | |
467 |
|
463 | |||
468 | void tst_QAbstractAxis::labelsPen() |
|
464 | void tst_QAbstractAxis::labelsPen() | |
469 | { |
|
465 | { | |
470 | QFETCH(QPen, labelsPen); |
|
466 | QFETCH(QPen, labelsPen); | |
471 |
|
467 | |||
472 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
468 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
473 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
469 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
474 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
470 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
475 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
471 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
476 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
472 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
477 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
473 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
478 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
474 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
479 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
475 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
480 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
476 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
481 |
|
477 | |||
482 | m_axis->setLabelsPen(labelsPen); |
|
478 | m_axis->setLabelsPen(labelsPen); | |
483 | QCOMPARE(m_axis->labelsPen(), labelsPen); |
|
479 | QCOMPARE(m_axis->labelsPen(), labelsPen); | |
484 |
|
480 | |||
485 | QCOMPARE(spy0.count(), 0); |
|
481 | QCOMPARE(spy0.count(), 0); | |
486 | QCOMPARE(spy1.count(), 0); |
|
482 | QCOMPARE(spy1.count(), 0); | |
487 | QCOMPARE(spy2.count(), 0); |
|
483 | QCOMPARE(spy2.count(), 0); | |
488 | QCOMPARE(spy3.count(), 0); |
|
484 | QCOMPARE(spy3.count(), 0); | |
489 | QCOMPARE(spy4.count(), 0); |
|
485 | QCOMPARE(spy4.count(), 0); | |
490 | QCOMPARE(spy5.count(), 0); |
|
486 | QCOMPARE(spy5.count(), 0); | |
491 | QCOMPARE(spy6.count(), 0); |
|
487 | QCOMPARE(spy6.count(), 0); | |
492 | QCOMPARE(spy7.count(), 0); |
|
488 | QCOMPARE(spy7.count(), 0); | |
493 | QCOMPARE(spy8.count(), 0); |
|
489 | QCOMPARE(spy8.count(), 0); | |
494 |
|
490 | |||
495 | m_chart->setAxisX(m_axis, m_series); |
|
491 | m_chart->setAxisX(m_axis, m_series); | |
496 | m_view->show(); |
|
492 | m_view->show(); | |
497 | QTest::qWaitForWindowShown(m_view); |
|
493 | QTest::qWaitForWindowShown(m_view); | |
498 | //TODO QCOMPARE(m_axis->labelsPen(), labelsPen); |
|
494 | //TODO QCOMPARE(m_axis->labelsPen(), labelsPen); | |
499 | } |
|
495 | } | |
500 |
|
496 | |||
501 | void tst_QAbstractAxis::labelsVisible_data() |
|
497 | void tst_QAbstractAxis::labelsVisible_data() | |
502 | { |
|
498 | { | |
503 | QTest::addColumn<bool>("labelsVisible"); |
|
499 | QTest::addColumn<bool>("labelsVisible"); | |
504 | QTest::newRow("true") << true; |
|
500 | QTest::newRow("true") << true; | |
505 | QTest::newRow("false") << false; |
|
501 | QTest::newRow("false") << false; | |
506 | } |
|
502 | } | |
507 |
|
503 | |||
508 | void tst_QAbstractAxis::labelsVisible() |
|
504 | void tst_QAbstractAxis::labelsVisible() | |
509 | { |
|
505 | { | |
510 | QFETCH(bool, labelsVisible); |
|
506 | QFETCH(bool, labelsVisible); | |
511 |
|
507 | |||
512 | m_axis->setLabelsVisible(!labelsVisible); |
|
508 | m_axis->setLabelsVisible(!labelsVisible); | |
513 |
|
509 | |||
514 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
510 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
515 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
511 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
516 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
512 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
517 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
513 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
518 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
514 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
519 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
515 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
520 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
516 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
521 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
517 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
522 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
518 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
523 |
|
519 | |||
524 | m_axis->setLabelsVisible(labelsVisible); |
|
520 | m_axis->setLabelsVisible(labelsVisible); | |
525 | QCOMPARE(m_axis->labelsVisible(), labelsVisible); |
|
521 | QCOMPARE(m_axis->labelsVisible(), labelsVisible); | |
526 |
|
522 | |||
527 | QCOMPARE(spy0.count(), 0); |
|
523 | QCOMPARE(spy0.count(), 0); | |
528 | QCOMPARE(spy1.count(), 0); |
|
524 | QCOMPARE(spy1.count(), 0); | |
529 | QCOMPARE(spy2.count(), 0); |
|
525 | QCOMPARE(spy2.count(), 0); | |
530 | QCOMPARE(spy3.count(), 0); |
|
526 | QCOMPARE(spy3.count(), 0); | |
531 | QCOMPARE(spy4.count(), 1); |
|
527 | QCOMPARE(spy4.count(), 1); | |
532 | QCOMPARE(spy5.count(), 0); |
|
528 | QCOMPARE(spy5.count(), 0); | |
533 | QCOMPARE(spy6.count(), 0); |
|
529 | QCOMPARE(spy6.count(), 0); | |
534 | QCOMPARE(spy7.count(), 0); |
|
530 | QCOMPARE(spy7.count(), 0); | |
535 | QCOMPARE(spy8.count(), 0); |
|
531 | QCOMPARE(spy8.count(), 0); | |
536 |
|
532 | |||
537 | m_chart->setAxisX(m_axis, m_series); |
|
533 | m_chart->setAxisX(m_axis, m_series); | |
538 | m_view->show(); |
|
534 | m_view->show(); | |
539 | QTest::qWaitForWindowShown(m_view); |
|
535 | QTest::qWaitForWindowShown(m_view); | |
540 | QCOMPARE(m_axis->labelsVisible(), labelsVisible); |
|
536 | QCOMPARE(m_axis->labelsVisible(), labelsVisible); | |
541 | } |
|
537 | } | |
542 |
|
538 | |||
543 | void tst_QAbstractAxis::orientation_data() |
|
539 | void tst_QAbstractAxis::orientation_data() | |
544 | { |
|
540 | { | |
545 | QTest::addColumn<Qt::Orientation>("orientation"); |
|
541 | QTest::addColumn<Qt::Orientation>("orientation"); | |
546 | QTest::newRow("Vertical") << Qt::Vertical; |
|
542 | QTest::newRow("Vertical") << Qt::Vertical; | |
547 | QTest::newRow("Horizontal") << Qt::Horizontal; |
|
543 | QTest::newRow("Horizontal") << Qt::Horizontal; | |
548 | } |
|
544 | } | |
549 |
|
545 | |||
550 | void tst_QAbstractAxis::orientation() |
|
546 | void tst_QAbstractAxis::orientation() | |
551 | { |
|
547 | { | |
552 | QFETCH(Qt::Orientation, orientation); |
|
548 | QFETCH(Qt::Orientation, orientation); | |
553 |
|
549 | |||
554 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
550 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
555 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
551 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
556 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
552 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
557 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
553 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
558 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
554 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
559 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
555 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
560 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
556 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
561 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
557 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
562 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
558 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
563 |
|
559 | |||
564 | if(orientation==Qt::Vertical){ |
|
560 | if(orientation==Qt::Vertical){ | |
565 | m_chart->setAxisY(m_axis,m_series); |
|
561 | m_chart->setAxisY(m_axis,m_series); | |
566 | }else{ |
|
562 | }else{ | |
567 | m_chart->setAxisX(m_axis,m_series); |
|
563 | m_chart->setAxisX(m_axis,m_series); | |
568 | } |
|
564 | } | |
569 | QCOMPARE(m_axis->orientation(), orientation); |
|
565 | QCOMPARE(m_axis->orientation(), orientation); | |
570 |
|
566 | |||
571 | QCOMPARE(spy0.count(), 0); |
|
567 | QCOMPARE(spy0.count(), 0); | |
572 | QCOMPARE(spy1.count(), 0); |
|
568 | QCOMPARE(spy1.count(), 0); | |
573 | QCOMPARE(spy2.count(), 0); |
|
569 | QCOMPARE(spy2.count(), 0); | |
574 | QCOMPARE(spy3.count(), 0); |
|
570 | QCOMPARE(spy3.count(), 0); | |
575 | QCOMPARE(spy4.count(), 0); |
|
571 | QCOMPARE(spy4.count(), 0); | |
576 | QCOMPARE(spy5.count(), 0); |
|
572 | QCOMPARE(spy5.count(), 0); | |
577 | QCOMPARE(spy6.count(), 0); |
|
573 | QCOMPARE(spy6.count(), 0); | |
578 | QCOMPARE(spy7.count(), 0); |
|
574 | QCOMPARE(spy7.count(), 0); | |
579 | QCOMPARE(spy8.count(), 0); |
|
575 | QCOMPARE(spy8.count(), 0); | |
580 |
|
576 | |||
581 | m_view->show(); |
|
577 | m_view->show(); | |
582 | QTest::qWaitForWindowShown(m_view); |
|
578 | QTest::qWaitForWindowShown(m_view); | |
583 | QCOMPARE(m_axis->orientation(), orientation); |
|
579 | QCOMPARE(m_axis->orientation(), orientation); | |
584 | } |
|
580 | } | |
585 |
|
581 | |||
586 | void tst_QAbstractAxis::setMax_data() |
|
582 | void tst_QAbstractAxis::setMax_data() | |
587 | { |
|
583 | { | |
588 | //just check if it does not crash |
|
584 | //just check if it does not crash | |
589 | QTest::addColumn<QVariant>("max"); |
|
585 | QTest::addColumn<QVariant>("max"); | |
590 | QTest::newRow("something") << QVariant("something"); |
|
586 | QTest::newRow("something") << QVariant("something"); | |
591 | QTest::newRow("1.0") << QVariant(1.0); |
|
587 | QTest::newRow("1.0") << QVariant(1.0); | |
592 | } |
|
588 | } | |
593 |
|
589 | |||
594 | void tst_QAbstractAxis::setMax() |
|
590 | void tst_QAbstractAxis::setMax() | |
595 | { |
|
591 | { | |
596 | QFETCH(QVariant, max); |
|
592 | QFETCH(QVariant, max); | |
597 | m_axis->setMax(max); |
|
593 | m_axis->setMax(max); | |
598 | } |
|
594 | } | |
599 |
|
595 | |||
600 | void tst_QAbstractAxis::setMin_data() |
|
596 | void tst_QAbstractAxis::setMin_data() | |
601 | { |
|
597 | { | |
602 | //just check if it does not crash |
|
598 | //just check if it does not crash | |
603 | QTest::addColumn<QVariant>("min"); |
|
599 | QTest::addColumn<QVariant>("min"); | |
604 | QTest::newRow("something") << QVariant("something"); |
|
600 | QTest::newRow("something") << QVariant("something"); | |
605 | QTest::newRow("1.0") << QVariant(1.0); |
|
601 | QTest::newRow("1.0") << QVariant(1.0); | |
606 | } |
|
602 | } | |
607 |
|
603 | |||
608 | // public void setMin(QVariant const& min) |
|
604 | // public void setMin(QVariant const& min) | |
609 | void tst_QAbstractAxis::setMin() |
|
605 | void tst_QAbstractAxis::setMin() | |
610 | { |
|
606 | { | |
611 | QFETCH(QVariant, min); |
|
607 | QFETCH(QVariant, min); | |
612 | m_axis->setMin(min); |
|
608 | m_axis->setMin(min); | |
613 | } |
|
609 | } | |
614 |
|
610 | |||
615 | void tst_QAbstractAxis::setRange_data() |
|
611 | void tst_QAbstractAxis::setRange_data() | |
616 | { |
|
612 | { | |
617 | //just check if it does not crash |
|
613 | //just check if it does not crash | |
618 | QTest::addColumn<QVariant>("min"); |
|
614 | QTest::addColumn<QVariant>("min"); | |
619 | QTest::addColumn<QVariant>("max"); |
|
615 | QTest::addColumn<QVariant>("max"); | |
620 | QTest::newRow("something") << QVariant("something0") << QVariant("something1"); |
|
616 | QTest::newRow("something") << QVariant("something0") << QVariant("something1"); | |
621 | QTest::newRow("-1 1") << QVariant(-1.0) << QVariant(1.0); |
|
617 | QTest::newRow("-1 1") << QVariant(-1.0) << QVariant(1.0); | |
622 | } |
|
618 | } | |
623 |
|
619 | |||
624 | // public void setRange(QVariant const& min, QVariant const& max) |
|
620 | // public void setRange(QVariant const& min, QVariant const& max) | |
625 | void tst_QAbstractAxis::setRange() |
|
621 | void tst_QAbstractAxis::setRange() | |
626 | { |
|
622 | { | |
627 |
|
623 | |||
628 | QFETCH(QVariant, min); |
|
624 | QFETCH(QVariant, min); | |
629 | QFETCH(QVariant, max); |
|
625 | QFETCH(QVariant, max); | |
630 | m_axis->setRange(min,max); |
|
626 | m_axis->setRange(min,max); | |
631 | } |
|
627 | } | |
632 |
|
628 | |||
633 | void tst_QAbstractAxis::shadesBorderColor_data() |
|
629 | void tst_QAbstractAxis::shadesBorderColor_data() | |
634 | { |
|
630 | { | |
635 |
|
631 | |||
636 | } |
|
632 | } | |
637 |
|
633 | |||
638 | void tst_QAbstractAxis::shadesBorderColor() |
|
634 | void tst_QAbstractAxis::shadesBorderColor() | |
639 | { |
|
635 | { | |
640 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
636 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
641 | QSKIP("Test is not implemented. This is deprecated function"); |
|
637 | QSKIP("Test is not implemented. This is deprecated function"); | |
642 | #else |
|
638 | #else | |
643 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); |
|
639 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); | |
644 | #endif |
|
640 | #endif | |
645 | } |
|
641 | } | |
646 |
|
642 | |||
647 | void tst_QAbstractAxis::shadesBrush_data() |
|
643 | void tst_QAbstractAxis::shadesBrush_data() | |
648 | { |
|
644 | { | |
649 | QTest::addColumn<QBrush>("shadesBrush"); |
|
645 | QTest::addColumn<QBrush>("shadesBrush"); | |
650 | QTest::newRow("null") << QBrush(); |
|
646 | QTest::newRow("null") << QBrush(); | |
651 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
647 | QTest::newRow("blue") << QBrush(Qt::blue); | |
652 | QTest::newRow("black") << QBrush(Qt::black); |
|
648 | QTest::newRow("black") << QBrush(Qt::black); | |
653 | } |
|
649 | } | |
654 |
|
650 | |||
655 | void tst_QAbstractAxis::shadesBrush() |
|
651 | void tst_QAbstractAxis::shadesBrush() | |
656 | { |
|
652 | { | |
657 | QFETCH(QBrush, shadesBrush); |
|
653 | QFETCH(QBrush, shadesBrush); | |
658 |
|
654 | |||
659 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
655 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
660 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
656 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
661 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
657 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
662 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
658 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
663 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
659 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
664 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
660 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
665 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
661 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
666 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
662 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
667 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
663 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
668 |
|
664 | |||
669 | m_axis->setShadesBrush(shadesBrush); |
|
665 | m_axis->setShadesBrush(shadesBrush); | |
670 | QCOMPARE(m_axis->shadesBrush(), shadesBrush); |
|
666 | QCOMPARE(m_axis->shadesBrush(), shadesBrush); | |
671 |
|
667 | |||
672 | QCOMPARE(spy0.count(), 0); |
|
668 | QCOMPARE(spy0.count(), 0); | |
673 | QCOMPARE(spy1.count(), 0); |
|
669 | QCOMPARE(spy1.count(), 0); | |
674 | QCOMPARE(spy2.count(), 0); |
|
670 | QCOMPARE(spy2.count(), 0); | |
675 | QCOMPARE(spy3.count(), 0); |
|
671 | QCOMPARE(spy3.count(), 0); | |
676 | QCOMPARE(spy4.count(), 0); |
|
672 | QCOMPARE(spy4.count(), 0); | |
677 | QCOMPARE(spy5.count(), 0); |
|
673 | QCOMPARE(spy5.count(), 0); | |
678 | //TODO QCOMPARE(spy6.count(), 0); |
|
674 | //TODO QCOMPARE(spy6.count(), 0); | |
679 | QCOMPARE(spy7.count(), 0); |
|
675 | QCOMPARE(spy7.count(), 0); | |
680 | QCOMPARE(spy8.count(), 0); |
|
676 | QCOMPARE(spy8.count(), 0); | |
681 |
|
677 | |||
682 | m_view->show(); |
|
678 | m_view->show(); | |
683 | QTest::qWaitForWindowShown(m_view); |
|
679 | QTest::qWaitForWindowShown(m_view); | |
684 | QCOMPARE(m_axis->shadesBrush(), shadesBrush); |
|
680 | QCOMPARE(m_axis->shadesBrush(), shadesBrush); | |
685 | } |
|
681 | } | |
686 |
|
682 | |||
687 | void tst_QAbstractAxis::shadesColor_data() |
|
683 | void tst_QAbstractAxis::shadesColor_data() | |
688 | { |
|
684 | { | |
689 | } |
|
685 | } | |
690 |
|
686 | |||
691 | // public QColor shadesColor() const |
|
687 | // public QColor shadesColor() const | |
692 | void tst_QAbstractAxis::shadesColor() |
|
688 | void tst_QAbstractAxis::shadesColor() | |
693 | { |
|
689 | { | |
694 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
690 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
695 | QSKIP("Test is not implemented. This is deprecated function"); |
|
691 | QSKIP("Test is not implemented. This is deprecated function"); | |
696 | #else |
|
692 | #else | |
697 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); |
|
693 | QSKIP("Test is not implemented. This is deprecated function", SkipAll); | |
698 | #endif |
|
694 | #endif | |
699 | } |
|
695 | } | |
700 |
|
696 | |||
701 | void tst_QAbstractAxis::shadesPen_data() |
|
697 | void tst_QAbstractAxis::shadesPen_data() | |
702 | { |
|
698 | { | |
703 | QTest::addColumn<QPen>("shadesPen"); |
|
699 | QTest::addColumn<QPen>("shadesPen"); | |
704 | QTest::newRow("null") << QPen(); |
|
700 | QTest::newRow("null") << QPen(); | |
705 | QTest::newRow("blue") << QPen(Qt::blue); |
|
701 | QTest::newRow("blue") << QPen(Qt::blue); | |
706 | QTest::newRow("black") << QPen(Qt::black); |
|
702 | QTest::newRow("black") << QPen(Qt::black); | |
707 | QTest::newRow("red") << QPen(Qt::red); |
|
703 | QTest::newRow("red") << QPen(Qt::red); | |
708 | } |
|
704 | } | |
709 |
|
705 | |||
710 | void tst_QAbstractAxis::shadesPen() |
|
706 | void tst_QAbstractAxis::shadesPen() | |
711 | { |
|
707 | { | |
712 | QFETCH(QPen, shadesPen); |
|
708 | QFETCH(QPen, shadesPen); | |
713 |
|
709 | |||
714 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
710 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
715 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
711 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
716 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
712 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
717 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
713 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
718 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
714 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
719 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
715 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
720 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
716 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
721 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
717 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
722 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
718 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
723 |
|
719 | |||
724 | m_axis->setShadesPen(shadesPen); |
|
720 | m_axis->setShadesPen(shadesPen); | |
725 | QCOMPARE(m_axis->shadesPen(), shadesPen); |
|
721 | QCOMPARE(m_axis->shadesPen(), shadesPen); | |
726 |
|
722 | |||
727 | QCOMPARE(spy0.count(), 0); |
|
723 | QCOMPARE(spy0.count(), 0); | |
728 | QCOMPARE(spy1.count(), 0); |
|
724 | QCOMPARE(spy1.count(), 0); | |
729 | QCOMPARE(spy2.count(), 0); |
|
725 | QCOMPARE(spy2.count(), 0); | |
730 | QCOMPARE(spy3.count(), 0); |
|
726 | QCOMPARE(spy3.count(), 0); | |
731 | QCOMPARE(spy4.count(), 0); |
|
727 | QCOMPARE(spy4.count(), 0); | |
732 | QCOMPARE(spy5.count(), 0); |
|
728 | QCOMPARE(spy5.count(), 0); | |
733 | QCOMPARE(spy6.count(), 0); |
|
729 | QCOMPARE(spy6.count(), 0); | |
734 | QCOMPARE(spy7.count(), 0); |
|
730 | QCOMPARE(spy7.count(), 0); | |
735 | QCOMPARE(spy8.count(), 0); |
|
731 | QCOMPARE(spy8.count(), 0); | |
736 |
|
732 | |||
737 | m_chart->setAxisX(m_axis, m_series); |
|
733 | m_chart->setAxisX(m_axis, m_series); | |
738 | m_view->show(); |
|
734 | m_view->show(); | |
739 | QTest::qWaitForWindowShown(m_view); |
|
735 | QTest::qWaitForWindowShown(m_view); | |
740 | QCOMPARE(m_axis->shadesPen(), shadesPen); |
|
736 | QCOMPARE(m_axis->shadesPen(), shadesPen); | |
741 | } |
|
737 | } | |
742 |
|
738 | |||
743 | void tst_QAbstractAxis::shadesVisible_data() |
|
739 | void tst_QAbstractAxis::shadesVisible_data() | |
744 | { |
|
740 | { | |
745 | QTest::addColumn<bool>("shadesVisible"); |
|
741 | QTest::addColumn<bool>("shadesVisible"); | |
746 | QTest::newRow("true") << true; |
|
742 | QTest::newRow("true") << true; | |
747 | QTest::newRow("false") << false; |
|
743 | QTest::newRow("false") << false; | |
748 | } |
|
744 | } | |
749 |
|
745 | |||
750 | void tst_QAbstractAxis::shadesVisible() |
|
746 | void tst_QAbstractAxis::shadesVisible() | |
751 | { |
|
747 | { | |
752 | QFETCH(bool, shadesVisible); |
|
748 | QFETCH(bool, shadesVisible); | |
753 |
|
749 | |||
754 | m_axis->setShadesVisible(!shadesVisible); |
|
750 | m_axis->setShadesVisible(!shadesVisible); | |
755 |
|
751 | |||
756 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
752 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
757 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
753 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
758 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
754 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
759 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
755 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
760 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
756 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
761 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
757 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
762 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
758 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
763 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
759 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
764 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
760 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
765 |
|
761 | |||
766 | m_axis->setShadesVisible(shadesVisible); |
|
762 | m_axis->setShadesVisible(shadesVisible); | |
767 | QCOMPARE(m_axis->shadesVisible(), shadesVisible); |
|
763 | QCOMPARE(m_axis->shadesVisible(), shadesVisible); | |
768 |
|
764 | |||
769 | QCOMPARE(spy0.count(), 0); |
|
765 | QCOMPARE(spy0.count(), 0); | |
770 | QCOMPARE(spy1.count(), 0); |
|
766 | QCOMPARE(spy1.count(), 0); | |
771 | QCOMPARE(spy2.count(), 0); |
|
767 | QCOMPARE(spy2.count(), 0); | |
772 | QCOMPARE(spy3.count(), 0); |
|
768 | QCOMPARE(spy3.count(), 0); | |
773 | QCOMPARE(spy4.count(), 0); |
|
769 | QCOMPARE(spy4.count(), 0); | |
774 | QCOMPARE(spy5.count(), 0); |
|
770 | QCOMPARE(spy5.count(), 0); | |
775 | QCOMPARE(spy6.count(), 0); |
|
771 | QCOMPARE(spy6.count(), 0); | |
776 | QCOMPARE(spy7.count(), 1); |
|
772 | QCOMPARE(spy7.count(), 1); | |
777 | QCOMPARE(spy8.count(), 0); |
|
773 | QCOMPARE(spy8.count(), 0); | |
778 |
|
774 | |||
779 | m_chart->setAxisX(m_axis, m_series); |
|
775 | m_chart->setAxisX(m_axis, m_series); | |
780 | m_view->show(); |
|
776 | m_view->show(); | |
781 | QTest::qWaitForWindowShown(m_view); |
|
777 | QTest::qWaitForWindowShown(m_view); | |
782 | QCOMPARE(m_axis->shadesVisible(), shadesVisible); |
|
778 | QCOMPARE(m_axis->shadesVisible(), shadesVisible); | |
783 | } |
|
779 | } | |
784 |
|
780 | |||
785 | void tst_QAbstractAxis::show_data() |
|
781 | void tst_QAbstractAxis::show_data() | |
786 | { |
|
782 | { | |
787 |
|
783 | |||
788 | } |
|
784 | } | |
789 |
|
785 | |||
790 | void tst_QAbstractAxis::show() |
|
786 | void tst_QAbstractAxis::show() | |
791 | { |
|
787 | { | |
792 | m_axis->hide(); |
|
788 | m_axis->hide(); | |
793 | QCOMPARE(m_axis->isVisible(), false); |
|
789 | QCOMPARE(m_axis->isVisible(), false); | |
794 |
|
790 | |||
795 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
791 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
796 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
792 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
797 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
793 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
798 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
794 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
799 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
795 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
800 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
796 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
801 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
797 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
802 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
798 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
803 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
799 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
804 |
|
800 | |||
805 | m_axis->show(); |
|
801 | m_axis->show(); | |
806 |
|
802 | |||
807 | QCOMPARE(spy0.count(), 0); |
|
803 | QCOMPARE(spy0.count(), 0); | |
808 | QCOMPARE(spy1.count(), 0); |
|
804 | QCOMPARE(spy1.count(), 0); | |
809 | QCOMPARE(spy2.count(), 0); |
|
805 | QCOMPARE(spy2.count(), 0); | |
810 | QCOMPARE(spy3.count(), 0); |
|
806 | QCOMPARE(spy3.count(), 0); | |
811 | QCOMPARE(spy4.count(), 0); |
|
807 | QCOMPARE(spy4.count(), 0); | |
812 | QCOMPARE(spy5.count(), 0); |
|
808 | QCOMPARE(spy5.count(), 0); | |
813 | QCOMPARE(spy6.count(), 0); |
|
809 | QCOMPARE(spy6.count(), 0); | |
814 | QCOMPARE(spy7.count(), 0); |
|
810 | QCOMPARE(spy7.count(), 0); | |
815 | QCOMPARE(spy8.count(), 1); |
|
811 | QCOMPARE(spy8.count(), 1); | |
816 | QCOMPARE(m_axis->isVisible(), true); |
|
812 | QCOMPARE(m_axis->isVisible(), true); | |
817 | } |
|
813 | } | |
818 |
|
814 | |||
819 | void tst_QAbstractAxis::hide_data() |
|
815 | void tst_QAbstractAxis::hide_data() | |
820 | { |
|
816 | { | |
821 |
|
817 | |||
822 | } |
|
818 | } | |
823 |
|
819 | |||
824 | void tst_QAbstractAxis::hide() |
|
820 | void tst_QAbstractAxis::hide() | |
825 | { |
|
821 | { | |
826 | m_axis->show(); |
|
822 | m_axis->show(); | |
827 | QCOMPARE(m_axis->isVisible(),true); |
|
823 | QCOMPARE(m_axis->isVisible(),true); | |
828 |
|
824 | |||
829 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); |
|
825 | QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); | |
830 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); |
|
826 | QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); | |
831 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); |
|
827 | QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); | |
832 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); |
|
828 | QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); | |
833 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); |
|
829 | QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); | |
834 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); |
|
830 | QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); | |
835 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); |
|
831 | QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); | |
836 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); |
|
832 | QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); | |
837 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); |
|
833 | QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); | |
838 |
|
834 | |||
839 | m_axis->hide(); |
|
835 | m_axis->hide(); | |
840 |
|
836 | |||
841 | QCOMPARE(spy0.count(), 0); |
|
837 | QCOMPARE(spy0.count(), 0); | |
842 | QCOMPARE(spy1.count(), 0); |
|
838 | QCOMPARE(spy1.count(), 0); | |
843 | QCOMPARE(spy2.count(), 0); |
|
839 | QCOMPARE(spy2.count(), 0); | |
844 | QCOMPARE(spy3.count(), 0); |
|
840 | QCOMPARE(spy3.count(), 0); | |
845 | QCOMPARE(spy4.count(), 0); |
|
841 | QCOMPARE(spy4.count(), 0); | |
846 | QCOMPARE(spy5.count(), 0); |
|
842 | QCOMPARE(spy5.count(), 0); | |
847 | QCOMPARE(spy6.count(), 0); |
|
843 | QCOMPARE(spy6.count(), 0); | |
848 | QCOMPARE(spy7.count(), 0); |
|
844 | QCOMPARE(spy7.count(), 0); | |
849 | QCOMPARE(spy8.count(), 1); |
|
845 | QCOMPARE(spy8.count(), 1); | |
850 | QCOMPARE(m_axis->isVisible(),false); |
|
846 | QCOMPARE(m_axis->isVisible(),false); | |
851 | } |
|
847 | } | |
852 |
|
848 | |||
853 |
|
849 | |||
854 |
|
850 | |||
855 |
|
851 | |||
856 |
|
852 | |||
857 |
|
853 | |||
858 |
|
854 | |||
859 |
|
855 | |||
860 |
|
856 | |||
861 |
|
857 | |||
862 |
|
858 | |||
863 |
|
859 |
@@ -1,344 +1,343 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "engine.h" |
|
21 | #include "engine.h" | |
22 | #include <QItemSelectionModel> |
|
22 | #include <QItemSelectionModel> | |
23 | #include <QStandardItemModel> |
|
23 | #include <QStandardItemModel> | |
24 | #include <QVXYModelMapper> |
|
24 | #include <QVXYModelMapper> | |
25 | #include <QHBarModelMapper> |
|
25 | #include <QHBarModelMapper> | |
26 | #include <QVPieModelMapper> |
|
26 | #include <QVPieModelMapper> | |
27 | #include <QLineSeries> |
|
27 | #include <QLineSeries> | |
28 | #include <QSplineSeries> |
|
28 | #include <QSplineSeries> | |
29 | #include <QScatterSeries> |
|
29 | #include <QScatterSeries> | |
30 | #include <QBarSeries> |
|
30 | #include <QBarSeries> | |
31 | #include <QPercentBarSeries> |
|
31 | #include <QPercentBarSeries> | |
32 | #include <QStackedBarSeries> |
|
32 | #include <QStackedBarSeries> | |
33 | #include <QAreaSeries> |
|
33 | #include <QAreaSeries> | |
34 | #include <QPieSeries> |
|
34 | #include <QPieSeries> | |
35 | #include <QChart> |
|
35 | #include <QChart> | |
36 | #include <QBarSet> |
|
36 | #include <QBarSet> | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | const qint32 MAGIC_NUMBER = 0x66666666; |
|
39 | const qint32 MAGIC_NUMBER = 0x66666666; | |
40 |
|
40 | |||
41 | Engine::Engine(QObject* parent) : |
|
41 | Engine::Engine(QObject* parent) : | |
42 | QObject(parent), m_count(10), m_chart(new QChart()), m_model(0), m_selection(0) |
|
42 | QObject(parent), m_count(10), m_chart(new QChart()), m_model(0), m_selection(0) | |
43 | { |
|
43 | { | |
44 | createModels(); |
|
44 | createModels(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | Engine::~Engine() |
|
47 | Engine::~Engine() | |
48 | { |
|
48 | { | |
49 | delete m_chart; |
|
49 | delete m_chart; | |
50 | delete m_selection; |
|
50 | delete m_selection; | |
51 | delete m_model; |
|
51 | delete m_model; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void Engine::createModels() |
|
54 | void Engine::createModels() | |
55 | { |
|
55 | { | |
56 | m_model = new QStandardItemModel(m_count, m_count); |
|
56 | m_model = new QStandardItemModel(m_count, m_count); | |
57 | m_model->setHorizontalHeaderLabels( |
|
57 | m_model->setHorizontalHeaderLabels( | |
58 | QStringList() << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H" << "I" << "J"); |
|
58 | QStringList() << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H" << "I" << "J"); | |
59 | m_model->setVerticalHeaderLabels( |
|
59 | m_model->setVerticalHeaderLabels( | |
60 | QStringList() << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10"); |
|
60 | QStringList() << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10"); | |
61 | m_selection = new QItemSelectionModel(m_model); |
|
61 | m_selection = new QItemSelectionModel(m_model); | |
62 |
|
62 | |||
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | QList<QAbstractSeries*> Engine::addSeries(QAbstractSeries::SeriesType type) |
|
65 | QList<QAbstractSeries*> Engine::addSeries(QAbstractSeries::SeriesType type) | |
66 | { |
|
66 | { | |
67 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
67 | const QModelIndexList& list = m_selection->selectedIndexes(); | |
68 |
|
68 | |||
69 | QMap<int, QModelIndex> columns; |
|
69 | QMap<int, QModelIndex> columns; | |
70 |
|
70 | |||
71 | foreach (const QModelIndex& index, list) { |
|
71 | foreach (const QModelIndex& index, list) { | |
72 | columns.insertMulti(index.column(), index); |
|
72 | columns.insertMulti(index.column(), index); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QList<int> keys = columns.uniqueKeys(); |
|
75 | QList<int> keys = columns.uniqueKeys(); | |
76 |
|
76 | |||
77 | QModelIndexList rows = columns.values(keys.first()); |
|
77 | QModelIndexList rows = columns.values(keys.first()); | |
78 |
|
78 | |||
79 | int minRow = m_count + 1; |
|
79 | int minRow = m_count + 1; | |
80 | int maxRow = -1; |
|
80 | int maxRow = -1; | |
81 |
|
81 | |||
82 | foreach (const QModelIndex& index, rows) { |
|
82 | foreach (const QModelIndex& index, rows) { | |
83 | minRow = qMin(index.row(), minRow); |
|
83 | minRow = qMin(index.row(), minRow); | |
84 | maxRow = qMax(index.row(), maxRow); |
|
84 | maxRow = qMax(index.row(), maxRow); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | QList<QAbstractSeries*> result; |
|
87 | QList<QAbstractSeries*> result; | |
88 | QColor color; |
|
88 | QColor color; | |
89 |
|
89 | |||
90 | switch (type) { |
|
90 | switch (type) { | |
91 |
|
91 | |||
92 | case QAbstractSeries::SeriesTypeLine: |
|
92 | case QAbstractSeries::SeriesTypeLine: | |
93 | { |
|
93 | { | |
94 | for (int i = 1; i < keys.count(); ++i) { |
|
94 | for (int i = 1; i < keys.count(); ++i) { | |
95 | QLineSeries *line = new QLineSeries(); |
|
95 | QLineSeries *line = new QLineSeries(); | |
96 | setupXYSeries(line, keys, i, minRow, maxRow); |
|
96 | setupXYSeries(line, keys, i, minRow, maxRow); | |
97 | result << line; |
|
97 | result << line; | |
98 | } |
|
98 | } | |
99 | break; |
|
99 | break; | |
100 | } |
|
100 | } | |
101 | case QAbstractSeries::SeriesTypeSpline: |
|
101 | case QAbstractSeries::SeriesTypeSpline: | |
102 | { |
|
102 | { | |
103 | for (int i = 1; i < keys.count(); ++i) { |
|
103 | for (int i = 1; i < keys.count(); ++i) { | |
104 | QSplineSeries *line = new QSplineSeries(); |
|
104 | QSplineSeries *line = new QSplineSeries(); | |
105 | setupXYSeries(line, keys, i, minRow, maxRow); |
|
105 | setupXYSeries(line, keys, i, minRow, maxRow); | |
106 | result << line; |
|
106 | result << line; | |
107 | } |
|
107 | } | |
108 | break; |
|
108 | break; | |
109 | } |
|
109 | } | |
110 | case QAbstractSeries::SeriesTypeScatter: |
|
110 | case QAbstractSeries::SeriesTypeScatter: | |
111 | { |
|
111 | { | |
112 | for (int i = 1; i < keys.count(); ++i) { |
|
112 | for (int i = 1; i < keys.count(); ++i) { | |
113 | QScatterSeries *line = new QScatterSeries(); |
|
113 | QScatterSeries *line = new QScatterSeries(); | |
114 | setupXYSeries(line, keys, i, minRow, maxRow); |
|
114 | setupXYSeries(line, keys, i, minRow, maxRow); | |
115 | result << line; |
|
115 | result << line; | |
116 | } |
|
116 | } | |
117 | break; |
|
117 | break; | |
118 | } |
|
118 | } | |
119 | case QAbstractSeries::SeriesTypeBar: |
|
119 | case QAbstractSeries::SeriesTypeBar: | |
120 | { |
|
120 | { | |
121 | //TODO: fix me |
|
|||
122 | QBarSeries *bar = new QBarSeries(); |
|
121 | QBarSeries *bar = new QBarSeries(); | |
123 | setupBarSeries(bar,keys,minRow,maxRow); |
|
122 | setupBarSeries(bar,keys,minRow,maxRow); | |
124 | result << bar; |
|
123 | result << bar; | |
125 | break; |
|
124 | break; | |
126 | } |
|
125 | } | |
127 | case QAbstractSeries::SeriesTypePercentBar: |
|
126 | case QAbstractSeries::SeriesTypePercentBar: | |
128 | { |
|
127 | { | |
129 | QPercentBarSeries *bar = new QPercentBarSeries(); |
|
128 | QPercentBarSeries *bar = new QPercentBarSeries(); | |
130 | setupBarSeries(bar,keys,minRow,maxRow); |
|
129 | setupBarSeries(bar,keys,minRow,maxRow); | |
131 | result << bar; |
|
130 | result << bar; | |
132 | break; |
|
131 | break; | |
133 | } |
|
132 | } | |
134 | case QAbstractSeries::SeriesTypeStackedBar: |
|
133 | case QAbstractSeries::SeriesTypeStackedBar: | |
135 | { |
|
134 | { | |
136 | QStackedBarSeries *bar = new QStackedBarSeries(); |
|
135 | QStackedBarSeries *bar = new QStackedBarSeries(); | |
137 | setupBarSeries(bar,keys,minRow,maxRow); |
|
136 | setupBarSeries(bar,keys,minRow,maxRow); | |
138 | result << bar; |
|
137 | result << bar; | |
139 | break; |
|
138 | break; | |
140 | } |
|
139 | } | |
141 | case QAbstractSeries::SeriesTypePie: |
|
140 | case QAbstractSeries::SeriesTypePie: | |
142 | { |
|
141 | { | |
143 |
|
142 | |||
144 | QPieSeries *pie = new QPieSeries(); |
|
143 | QPieSeries *pie = new QPieSeries(); | |
145 | setupPieSeries(pie,keys,minRow,maxRow); |
|
144 | setupPieSeries(pie,keys,minRow,maxRow); | |
146 | result << pie; |
|
145 | result << pie; | |
147 | break; |
|
146 | break; | |
148 | } |
|
147 | } | |
149 | case QAbstractSeries::SeriesTypeArea: |
|
148 | case QAbstractSeries::SeriesTypeArea: | |
150 | { |
|
149 | { | |
151 | QAreaSeries *area = new QAreaSeries( new QLineSeries(), new QLineSeries()); |
|
150 | QAreaSeries *area = new QAreaSeries( new QLineSeries(), new QLineSeries()); | |
152 | setupAreaSeries(area,keys,minRow,maxRow); |
|
151 | setupAreaSeries(area,keys,minRow,maxRow); | |
153 | result << area; |
|
152 | result << area; | |
154 | break; |
|
153 | break; | |
155 | } |
|
154 | } | |
156 | } |
|
155 | } | |
157 |
|
156 | |||
158 | m_chart->createDefaultAxes(); |
|
157 | m_chart->createDefaultAxes(); | |
159 | return result; |
|
158 | return result; | |
160 | } |
|
159 | } | |
161 |
|
160 | |||
162 | void Engine::removeSeries(QAbstractSeries* series) |
|
161 | void Engine::removeSeries(QAbstractSeries* series) | |
163 | { |
|
162 | { | |
164 | m_chart->removeSeries(series); |
|
163 | m_chart->removeSeries(series); | |
165 |
|
164 | |||
166 | foreach (const QModelIndex& index, m_seriesModelIndex.value(series)) { |
|
165 | foreach (const QModelIndex& index, m_seriesModelIndex.value(series)) { | |
167 | m_model->setData(index, Qt::white, Qt::BackgroundRole); |
|
166 | m_model->setData(index, Qt::white, Qt::BackgroundRole); | |
168 | } |
|
167 | } | |
169 | } |
|
168 | } | |
170 |
|
169 | |||
171 | void Engine::clearModels() |
|
170 | void Engine::clearModels() | |
172 | { |
|
171 | { | |
173 | delete m_selection; |
|
172 | delete m_selection; | |
174 | m_selection = 0; |
|
173 | m_selection = 0; | |
175 | delete m_model; |
|
174 | delete m_model; | |
176 | m_model = 0; |
|
175 | m_model = 0; | |
177 | createModels(); |
|
176 | createModels(); | |
178 | } |
|
177 | } | |
179 |
|
178 | |||
180 | bool Engine::save(const QString &filename) const |
|
179 | bool Engine::save(const QString &filename) const | |
181 | { |
|
180 | { | |
182 | if (filename.isEmpty()) |
|
181 | if (filename.isEmpty()) | |
183 | return false; |
|
182 | return false; | |
184 |
|
183 | |||
185 | QFile file(filename); |
|
184 | QFile file(filename); | |
186 |
|
185 | |||
187 | if (!file.open(QIODevice::WriteOnly)) { |
|
186 | if (!file.open(QIODevice::WriteOnly)) { | |
188 | return false; |
|
187 | return false; | |
189 | } |
|
188 | } | |
190 |
|
189 | |||
191 | QDataStream out(&file); |
|
190 | QDataStream out(&file); | |
192 | out << MAGIC_NUMBER; |
|
191 | out << MAGIC_NUMBER; | |
193 | out.setVersion(QDataStream::Qt_4_8); |
|
192 | out.setVersion(QDataStream::Qt_4_8); | |
194 | out << m_model->rowCount(); |
|
193 | out << m_model->rowCount(); | |
195 | out << m_model->columnCount(); |
|
194 | out << m_model->columnCount(); | |
196 |
|
195 | |||
197 | for (int row = 0; row < m_model->rowCount(); ++row) { |
|
196 | for (int row = 0; row < m_model->rowCount(); ++row) { | |
198 | for (int column = 0; column < m_model->columnCount(); ++column) { |
|
197 | for (int column = 0; column < m_model->columnCount(); ++column) { | |
199 | QStandardItem *item = m_model->item(row, column); |
|
198 | QStandardItem *item = m_model->item(row, column); | |
200 | if (item) { |
|
199 | if (item) { | |
201 | out << row; |
|
200 | out << row; | |
202 | out << column; |
|
201 | out << column; | |
203 | out << item->data(Qt::EditRole).toString(); |
|
202 | out << item->data(Qt::EditRole).toString(); | |
204 | } |
|
203 | } | |
205 | } |
|
204 | } | |
206 | } |
|
205 | } | |
207 | return true; |
|
206 | return true; | |
208 | } |
|
207 | } | |
209 |
|
208 | |||
210 | bool Engine::load(const QString &filename) |
|
209 | bool Engine::load(const QString &filename) | |
211 | { |
|
210 | { | |
212 | clearModels(); |
|
211 | clearModels(); | |
213 |
|
212 | |||
214 | if (filename.isEmpty()) |
|
213 | if (filename.isEmpty()) | |
215 | return false; |
|
214 | return false; | |
216 |
|
215 | |||
217 | QFile file(filename); |
|
216 | QFile file(filename); | |
218 |
|
217 | |||
219 | if (!file.open(QIODevice::ReadOnly)) { |
|
218 | if (!file.open(QIODevice::ReadOnly)) { | |
220 | return false; |
|
219 | return false; | |
221 | } |
|
220 | } | |
222 |
|
221 | |||
223 | QDataStream in(&file); |
|
222 | QDataStream in(&file); | |
224 |
|
223 | |||
225 | qint32 magicNumber; |
|
224 | qint32 magicNumber; | |
226 | in >> magicNumber; |
|
225 | in >> magicNumber; | |
227 |
|
226 | |||
228 | if (magicNumber != MAGIC_NUMBER) |
|
227 | if (magicNumber != MAGIC_NUMBER) | |
229 | return false; |
|
228 | return false; | |
230 |
|
229 | |||
231 | in.setVersion(QDataStream::Qt_4_8); |
|
230 | in.setVersion(QDataStream::Qt_4_8); | |
232 |
|
231 | |||
233 | int rowCount; |
|
232 | int rowCount; | |
234 | in >> rowCount; |
|
233 | in >> rowCount; | |
235 |
|
234 | |||
236 | int columnCount; |
|
235 | int columnCount; | |
237 | in >> columnCount; |
|
236 | in >> columnCount; | |
238 |
|
237 | |||
239 | while (!in.atEnd()) { |
|
238 | while (!in.atEnd()) { | |
240 | int row; |
|
239 | int row; | |
241 | int column; |
|
240 | int column; | |
242 | QString value; |
|
241 | QString value; | |
243 | in >> row >> column >> value; |
|
242 | in >> row >> column >> value; | |
244 | QStandardItem *item = new QStandardItem(); |
|
243 | QStandardItem *item = new QStandardItem(); | |
245 | bool ok; |
|
244 | bool ok; | |
246 | double result = value.toDouble(&ok); |
|
245 | double result = value.toDouble(&ok); | |
247 | if(ok) |
|
246 | if(ok) | |
248 | item->setData(result, Qt::EditRole); |
|
247 | item->setData(result, Qt::EditRole); | |
249 | else |
|
248 | else | |
250 | item->setData(value, Qt::EditRole); |
|
249 | item->setData(value, Qt::EditRole); | |
251 | m_model->setItem(row, column, item); |
|
250 | m_model->setItem(row, column, item); | |
252 | } |
|
251 | } | |
253 |
|
252 | |||
254 | return true; |
|
253 | return true; | |
255 | } |
|
254 | } | |
256 |
|
255 | |||
257 | void Engine::setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow) |
|
256 | void Engine::setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow) | |
258 | { |
|
257 | { | |
259 | QVXYModelMapper* mapper = new QVXYModelMapper(xyseries); |
|
258 | QVXYModelMapper* mapper = new QVXYModelMapper(xyseries); | |
260 | mapper->setSeries(xyseries); |
|
259 | mapper->setSeries(xyseries); | |
261 | mapper->setModel(m_model); |
|
260 | mapper->setModel(m_model); | |
262 | mapper->setXColumn(columns.first()); |
|
261 | mapper->setXColumn(columns.first()); | |
263 | mapper->setYColumn(columns.at(column)); |
|
262 | mapper->setYColumn(columns.at(column)); | |
264 | mapper->setFirstRow(minRow); |
|
263 | mapper->setFirstRow(minRow); | |
265 | mapper->setRowCount(maxRow - minRow + 1); |
|
264 | mapper->setRowCount(maxRow - minRow + 1); | |
266 | m_chart->addSeries(xyseries); |
|
265 | m_chart->addSeries(xyseries); | |
267 | xyseries->setName(QString("Series %1").arg(m_chart->series().count())); |
|
266 | xyseries->setName(QString("Series %1").arg(m_chart->series().count())); | |
268 | QObject::connect(xyseries,SIGNAL(clicked(QPointF)),this,SIGNAL(selected())); |
|
267 | QObject::connect(xyseries,SIGNAL(clicked(QPointF)),this,SIGNAL(selected())); | |
269 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
268 | const QModelIndexList& list = m_selection->selectedIndexes(); | |
270 | QModelIndexList result; |
|
269 | QModelIndexList result; | |
271 | foreach (const QModelIndex& index, list) { |
|
270 | foreach (const QModelIndex& index, list) { | |
272 | if (index.column() ==columns.at(column)){ |
|
271 | if (index.column() ==columns.at(column)){ | |
273 | m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); |
|
272 | m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); | |
274 | result << index; |
|
273 | result << index; | |
275 | } |
|
274 | } | |
276 | } |
|
275 | } | |
277 | m_seriesModelIndex.insert(xyseries,result); |
|
276 | m_seriesModelIndex.insert(xyseries,result); | |
278 | } |
|
277 | } | |
279 |
|
278 | |||
280 | void Engine::setupBarSeries(QAbstractBarSeries *bar, const QList<int>& columns, int minRow, int maxRow) |
|
279 | void Engine::setupBarSeries(QAbstractBarSeries *bar, const QList<int>& columns, int minRow, int maxRow) | |
281 | { |
|
280 | { | |
282 | QHBarModelMapper* mapper = new QHBarModelMapper(bar); |
|
281 | QHBarModelMapper* mapper = new QHBarModelMapper(bar); | |
283 | mapper->setSeries(bar); |
|
282 | mapper->setSeries(bar); | |
284 | mapper->setModel(m_model); |
|
283 | mapper->setModel(m_model); | |
285 | mapper->setFirstColumn(minRow); |
|
284 | mapper->setFirstColumn(minRow); | |
286 | mapper->setColumnCount(maxRow - minRow + 1); |
|
285 | mapper->setColumnCount(maxRow - minRow + 1); | |
287 | mapper->setFirstBarSetRow(columns.at(1)); |
|
286 | mapper->setFirstBarSetRow(columns.at(1)); | |
288 | mapper->setLastBarSetRow(columns.last()); |
|
287 | mapper->setLastBarSetRow(columns.last()); | |
289 | m_chart->addSeries(bar); |
|
288 | m_chart->addSeries(bar); | |
290 | bar->setName(QString("Series %1").arg(m_chart->series().count())); |
|
289 | bar->setName(QString("Series %1").arg(m_chart->series().count())); | |
291 |
|
290 | |||
292 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
291 | const QModelIndexList& list = m_selection->selectedIndexes(); | |
293 | foreach (const QModelIndex& index, list) { |
|
292 | foreach (const QModelIndex& index, list) { | |
294 | if (index.column() >= columns.at(1) && index.column()<= columns.last()) { |
|
293 | if (index.column() >= columns.at(1) && index.column()<= columns.last()) { | |
295 | //m_model->setData(index, bar->barSets().at(index.column())->brush().color(), Qt::BackgroundRole); |
|
294 | //m_model->setData(index, bar->barSets().at(index.column())->brush().color(), Qt::BackgroundRole); | |
296 | } |
|
295 | } | |
297 | } |
|
296 | } | |
298 | } |
|
297 | } | |
299 |
|
298 | |||
300 | void Engine::setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow) |
|
299 | void Engine::setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow) | |
301 | { |
|
300 | { | |
302 | QVPieModelMapper* mapper = new QVPieModelMapper(pie); |
|
301 | QVPieModelMapper* mapper = new QVPieModelMapper(pie); | |
303 | mapper->setSeries(pie); |
|
302 | mapper->setSeries(pie); | |
304 | mapper->setModel(m_model); |
|
303 | mapper->setModel(m_model); | |
305 | mapper->setValuesColumn(columns.at(1)); |
|
304 | mapper->setValuesColumn(columns.at(1)); | |
306 | mapper->setLabelsColumn(columns.first()); |
|
305 | mapper->setLabelsColumn(columns.first()); | |
307 | mapper->setFirstRow(minRow); |
|
306 | mapper->setFirstRow(minRow); | |
308 | mapper->setRowCount(maxRow - minRow + 1); |
|
307 | mapper->setRowCount(maxRow - minRow + 1); | |
309 | m_chart->addSeries(pie); |
|
308 | m_chart->addSeries(pie); | |
310 | pie->setName(QString("Series %1").arg(m_chart->series().count())); |
|
309 | pie->setName(QString("Series %1").arg(m_chart->series().count())); | |
311 |
|
310 | |||
312 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
311 | const QModelIndexList& list = m_selection->selectedIndexes(); | |
313 | foreach (const QModelIndex& index, list) { |
|
312 | foreach (const QModelIndex& index, list) { | |
314 | // m_model->setData(index, bar->barSets()pen().color(), Qt::BackgroundRole); |
|
313 | // m_model->setData(index, bar->barSets()pen().color(), Qt::BackgroundRole); | |
315 | } |
|
314 | } | |
316 | } |
|
315 | } | |
317 |
|
316 | |||
318 | void Engine::setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow) |
|
317 | void Engine::setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow) | |
319 | { |
|
318 | { | |
320 | QVXYModelMapper* umapper = new QVXYModelMapper(series); |
|
319 | QVXYModelMapper* umapper = new QVXYModelMapper(series); | |
321 | umapper->setSeries(series->upperSeries()); |
|
320 | umapper->setSeries(series->upperSeries()); | |
322 | umapper->setModel(m_model); |
|
321 | umapper->setModel(m_model); | |
323 | umapper->setXColumn(columns.first()); |
|
322 | umapper->setXColumn(columns.first()); | |
324 | umapper->setYColumn(columns.at(1)); |
|
323 | umapper->setYColumn(columns.at(1)); | |
325 | umapper->setFirstRow(minRow); |
|
324 | umapper->setFirstRow(minRow); | |
326 | umapper->setRowCount(maxRow - minRow + 1); |
|
325 | umapper->setRowCount(maxRow - minRow + 1); | |
327 |
|
326 | |||
328 | QVXYModelMapper* lmapper = new QVXYModelMapper(series); |
|
327 | QVXYModelMapper* lmapper = new QVXYModelMapper(series); | |
329 | lmapper->setSeries(series->lowerSeries()); |
|
328 | lmapper->setSeries(series->lowerSeries()); | |
330 | lmapper->setModel(m_model); |
|
329 | lmapper->setModel(m_model); | |
331 | lmapper->setXColumn(columns.first()); |
|
330 | lmapper->setXColumn(columns.first()); | |
332 | lmapper->setYColumn(columns.at(2)); |
|
331 | lmapper->setYColumn(columns.at(2)); | |
333 | lmapper->setFirstRow(minRow); |
|
332 | lmapper->setFirstRow(minRow); | |
334 | lmapper->setRowCount(maxRow - minRow + 1); |
|
333 | lmapper->setRowCount(maxRow - minRow + 1); | |
335 |
|
334 | |||
336 | m_chart->addSeries(series); |
|
335 | m_chart->addSeries(series); | |
337 | series->setName(QString("Series %1").arg(m_chart->series().count())); |
|
336 | series->setName(QString("Series %1").arg(m_chart->series().count())); | |
338 |
|
337 | |||
339 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
338 | const QModelIndexList& list = m_selection->selectedIndexes(); | |
340 | foreach (const QModelIndex& index, list) { |
|
339 | foreach (const QModelIndex& index, list) { | |
341 | //if (index.column() ==columns.at(column)) |
|
340 | //if (index.column() ==columns.at(column)) | |
342 | // m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); |
|
341 | // m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); | |
343 | } |
|
342 | } | |
344 | } |
|
343 | } |
@@ -1,376 +1,375 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "dataseriedialog.h" |
|
22 | #include "dataseriedialog.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include <qareaseries.h> |
|
27 | #include <qareaseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qbarset.h> |
|
29 | #include <qbarset.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 | #include <qpercentbarseries.h> |
|
32 | #include <qpercentbarseries.h> | |
33 | #include <QPushButton> |
|
33 | #include <QPushButton> | |
34 | #include <QComboBox> |
|
34 | #include <QComboBox> | |
35 | #include <QSpinBox> |
|
35 | #include <QSpinBox> | |
36 | #include <QCheckBox> |
|
36 | #include <QCheckBox> | |
37 | #include <QGridLayout> |
|
37 | #include <QGridLayout> | |
38 | #include <QHBoxLayout> |
|
38 | #include <QHBoxLayout> | |
39 | #include <QLabel> |
|
39 | #include <QLabel> | |
40 | #include <QSpacerItem> |
|
40 | #include <QSpacerItem> | |
41 | #include <QMessageBox> |
|
41 | #include <QMessageBox> | |
42 | #include <cmath> |
|
42 | #include <cmath> | |
43 | #include <QDebug> |
|
43 | #include <QDebug> | |
44 | #include <QStandardItemModel> |
|
44 | #include <QStandardItemModel> | |
45 | #include <QBarCategoryAxis> |
|
45 | #include <QBarCategoryAxis> | |
46 | #include <QGLWidget> |
|
46 | #include <QGLWidget> | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | MainWidget::MainWidget(QWidget *parent) : |
|
50 | MainWidget::MainWidget(QWidget *parent) : | |
51 | QWidget(parent), |
|
51 | QWidget(parent), | |
52 | m_addSerieDialog(0), |
|
52 | m_addSerieDialog(0), | |
53 | m_chart(0) |
|
53 | m_chart(0) | |
54 | { |
|
54 | { | |
55 | m_chart = new QChart(); |
|
55 | m_chart = new QChart(); | |
56 |
|
56 | |||
57 | // Grid layout for the controls for configuring the chart widget |
|
57 | // Grid layout for the controls for configuring the chart widget | |
58 | QGridLayout *grid = new QGridLayout(); |
|
58 | QGridLayout *grid = new QGridLayout(); | |
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
61 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | grid->addWidget(addSeriesButton, 0, 1); | |
62 | initBackroundCombo(grid); |
|
62 | initBackroundCombo(grid); | |
63 | initScaleControls(grid); |
|
63 | initScaleControls(grid); | |
64 | initThemeCombo(grid); |
|
64 | initThemeCombo(grid); | |
65 | initCheckboxes(grid); |
|
65 | initCheckboxes(grid); | |
66 |
|
66 | |||
67 | // add row with empty label to make all the other rows static |
|
67 | // add row with empty label to make all the other rows static | |
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
69 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
69 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
70 |
|
70 | |||
71 | // Create chart view with the chart |
|
71 | // Create chart view with the chart | |
72 | m_chartView = new QChartView(m_chart, this); |
|
72 | m_chartView = new QChartView(m_chart, this); | |
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
74 |
|
74 | |||
75 | // Another grid layout as a main layout |
|
75 | // Another grid layout as a main layout | |
76 | QGridLayout *mainLayout = new QGridLayout(); |
|
76 | QGridLayout *mainLayout = new QGridLayout(); | |
77 | mainLayout->addLayout(grid, 0, 0); |
|
77 | mainLayout->addLayout(grid, 0, 0); | |
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
79 | setLayout(mainLayout); |
|
79 | setLayout(mainLayout); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | // Combo box for selecting the chart's background |
|
82 | // Combo box for selecting the chart's background | |
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
84 | { |
|
84 | { | |
85 | QComboBox *backgroundCombo = new QComboBox(this); |
|
85 | QComboBox *backgroundCombo = new QComboBox(this); | |
86 | backgroundCombo->addItem("Color"); |
|
86 | backgroundCombo->addItem("Color"); | |
87 | backgroundCombo->addItem("Gradient"); |
|
87 | backgroundCombo->addItem("Gradient"); | |
88 | backgroundCombo->addItem("Image"); |
|
88 | backgroundCombo->addItem("Image"); | |
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
90 | this, SLOT(backgroundChanged(int))); |
|
90 | this, SLOT(backgroundChanged(int))); | |
91 |
|
91 | |||
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | // Scale related controls (auto-scale vs. manual min-max values) |
|
96 | // Scale related controls (auto-scale vs. manual min-max values) | |
97 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
97 | void MainWidget::initScaleControls(QGridLayout *grid) | |
98 | { |
|
98 | { | |
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
102 | m_xMinSpin = new QSpinBox(); |
|
102 | m_xMinSpin = new QSpinBox(); | |
103 | m_xMinSpin->setMinimum(INT_MIN); |
|
103 | m_xMinSpin->setMinimum(INT_MIN); | |
104 | m_xMinSpin->setMaximum(INT_MAX); |
|
104 | m_xMinSpin->setMaximum(INT_MAX); | |
105 | m_xMinSpin->setValue(0); |
|
105 | m_xMinSpin->setValue(0); | |
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
107 | m_xMaxSpin = new QSpinBox(); |
|
107 | m_xMaxSpin = new QSpinBox(); | |
108 | m_xMaxSpin->setMinimum(INT_MIN); |
|
108 | m_xMaxSpin->setMinimum(INT_MIN); | |
109 | m_xMaxSpin->setMaximum(INT_MAX); |
|
109 | m_xMaxSpin->setMaximum(INT_MAX); | |
110 | m_xMaxSpin->setValue(10); |
|
110 | m_xMaxSpin->setValue(10); | |
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
112 | m_yMinSpin = new QSpinBox(); |
|
112 | m_yMinSpin = new QSpinBox(); | |
113 | m_yMinSpin->setMinimum(INT_MIN); |
|
113 | m_yMinSpin->setMinimum(INT_MIN); | |
114 | m_yMinSpin->setMaximum(INT_MAX); |
|
114 | m_yMinSpin->setMaximum(INT_MAX); | |
115 | m_yMinSpin->setValue(0); |
|
115 | m_yMinSpin->setValue(0); | |
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
117 | m_yMaxSpin = new QSpinBox(); |
|
117 | m_yMaxSpin = new QSpinBox(); | |
118 | m_yMaxSpin->setMinimum(INT_MIN); |
|
118 | m_yMaxSpin->setMinimum(INT_MIN); | |
119 | m_yMaxSpin->setMaximum(INT_MAX); |
|
119 | m_yMaxSpin->setMaximum(INT_MAX); | |
120 | m_yMaxSpin->setValue(10); |
|
120 | m_yMaxSpin->setValue(10); | |
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
122 |
|
122 | |||
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
132 |
|
132 | |||
133 | m_autoScaleCheck->setChecked(true); |
|
133 | m_autoScaleCheck->setChecked(true); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | // Combo box for selecting theme |
|
136 | // Combo box for selecting theme | |
137 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
137 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
138 | { |
|
138 | { | |
139 | QComboBox *chartTheme = new QComboBox(); |
|
139 | QComboBox *chartTheme = new QComboBox(); | |
140 | chartTheme->addItem("Default"); |
|
140 | chartTheme->addItem("Default"); | |
141 | chartTheme->addItem("Light"); |
|
141 | chartTheme->addItem("Light"); | |
142 | chartTheme->addItem("Blue Cerulean"); |
|
142 | chartTheme->addItem("Blue Cerulean"); | |
143 | chartTheme->addItem("Dark"); |
|
143 | chartTheme->addItem("Dark"); | |
144 | chartTheme->addItem("Brown Sand"); |
|
144 | chartTheme->addItem("Brown Sand"); | |
145 | chartTheme->addItem("Blue NCS"); |
|
145 | chartTheme->addItem("Blue NCS"); | |
146 | chartTheme->addItem("High Contrast"); |
|
146 | chartTheme->addItem("High Contrast"); | |
147 | chartTheme->addItem("Blue Icy"); |
|
147 | chartTheme->addItem("Blue Icy"); | |
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
149 | this, SLOT(changeChartTheme(int))); |
|
149 | this, SLOT(changeChartTheme(int))); | |
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
151 | grid->addWidget(chartTheme, 8, 1); |
|
151 | grid->addWidget(chartTheme, 8, 1); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | // Different check boxes for customizing chart |
|
154 | // Different check boxes for customizing chart | |
155 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
155 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
156 | { |
|
156 | { | |
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
160 | zoomCheckBox->setChecked(true); |
|
160 | zoomCheckBox->setChecked(true); | |
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
162 |
|
162 | |||
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
165 | aliasCheckBox->setChecked(false); |
|
165 | aliasCheckBox->setChecked(false); | |
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
167 |
|
167 | |||
168 | QCheckBox *openGLCheckBox = new QCheckBox("Use QGLWidget"); |
|
168 | QCheckBox *openGLCheckBox = new QCheckBox("Use QGLWidget"); | |
169 | connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool))); |
|
169 | connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool))); | |
170 | openGLCheckBox->setChecked(false); |
|
170 | openGLCheckBox->setChecked(false); | |
171 | grid->addWidget(openGLCheckBox, grid->rowCount(), 0); |
|
171 | grid->addWidget(openGLCheckBox, grid->rowCount(), 0); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void MainWidget::antiAliasToggled(bool enabled) |
|
174 | void MainWidget::antiAliasToggled(bool enabled) | |
175 | { |
|
175 | { | |
176 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
176 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void MainWidget::openGLToggled(bool enabled) |
|
179 | void MainWidget::openGLToggled(bool enabled) | |
180 | { |
|
180 | { | |
181 | if (enabled) { |
|
181 | if (enabled) { | |
182 | QGLFormat f = QGLFormat::defaultFormat(); |
|
182 | QGLFormat f = QGLFormat::defaultFormat(); | |
183 | f.setSampleBuffers(true); |
|
183 | f.setSampleBuffers(true); | |
184 | f.setSamples(4); |
|
184 | f.setSamples(4); | |
185 | QGLFormat::setDefaultFormat(f); |
|
185 | QGLFormat::setDefaultFormat(f); | |
186 | QGLWidget *g = new QGLWidget(); |
|
186 | QGLWidget *g = new QGLWidget(); | |
187 | m_chartView->setViewport(g); |
|
187 | m_chartView->setViewport(g); | |
188 | } else { |
|
188 | } else { | |
189 | m_chartView->setViewport(0); |
|
189 | m_chartView->setViewport(0); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | void MainWidget::addSeries() |
|
193 | void MainWidget::addSeries() | |
194 | { |
|
194 | { | |
195 | if (!m_addSerieDialog) { |
|
195 | if (!m_addSerieDialog) { | |
196 | m_addSerieDialog = new DataSerieDialog(this); |
|
196 | m_addSerieDialog = new DataSerieDialog(this); | |
197 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
197 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), | |
198 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
198 | this, SLOT(addSeries(QString,int,int,QString,bool))); | |
199 | } |
|
199 | } | |
200 | m_addSerieDialog->exec(); |
|
200 | m_addSerieDialog->exec(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
203 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
204 | { |
|
204 | { | |
205 | // TODO: dataCharacteristics |
|
|||
206 | QList<RealList> testData; |
|
205 | QList<RealList> testData; | |
207 | for (int j(0); j < columnCount; j++) { |
|
206 | for (int j(0); j < columnCount; j++) { | |
208 | QList <qreal> newColumn; |
|
207 | QList <qreal> newColumn; | |
209 | for (int i(0); i < rowCount; i++) { |
|
208 | for (int i(0); i < rowCount; i++) { | |
210 | if (dataCharacteristics == "Sin") { |
|
209 | if (dataCharacteristics == "Sin") { | |
211 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
210 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
212 | } else if (dataCharacteristics == "Sin + random") { |
|
211 | } else if (dataCharacteristics == "Sin + random") { | |
213 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
212 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
214 | } else if (dataCharacteristics == "Random") { |
|
213 | } else if (dataCharacteristics == "Random") { | |
215 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
214 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
216 | } else if (dataCharacteristics == "Linear") { |
|
215 | } else if (dataCharacteristics == "Linear") { | |
217 | //newColumn.append(i * (j + 1.0)); |
|
216 | //newColumn.append(i * (j + 1.0)); | |
218 | // TODO: temporary hack to make pie work; prevent zero values: |
|
217 | // TODO: temporary hack to make pie work; prevent zero values: | |
219 | newColumn.append(i * (j + 1.0) + 0.1); |
|
218 | newColumn.append(i * (j + 1.0) + 0.1); | |
220 | } else { // "constant" |
|
219 | } else { // "constant" | |
221 | newColumn.append((j + 1.0)); |
|
220 | newColumn.append((j + 1.0)); | |
222 | } |
|
221 | } | |
223 | } |
|
222 | } | |
224 | testData.append(newColumn); |
|
223 | testData.append(newColumn); | |
225 | } |
|
224 | } | |
226 | return testData; |
|
225 | return testData; | |
227 | } |
|
226 | } | |
228 |
|
227 | |||
229 | QStringList MainWidget::generateLabels(int count) |
|
228 | QStringList MainWidget::generateLabels(int count) | |
230 | { |
|
229 | { | |
231 | QStringList result; |
|
230 | QStringList result; | |
232 | for (int i(0); i < count; i++) |
|
231 | for (int i(0); i < count; i++) | |
233 | result.append("label" + QString::number(i)); |
|
232 | result.append("label" + QString::number(i)); | |
234 | return result; |
|
233 | return result; | |
235 | } |
|
234 | } | |
236 |
|
235 | |||
237 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
236 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
238 | { |
|
237 | { | |
239 | qDebug() << "addSeries: " << seriesName |
|
238 | qDebug() << "addSeries: " << seriesName | |
240 | << " columnCount: " << columnCount |
|
239 | << " columnCount: " << columnCount | |
241 | << " rowCount: " << rowCount |
|
240 | << " rowCount: " << rowCount | |
242 | << " dataCharacteristics: " << dataCharacteristics |
|
241 | << " dataCharacteristics: " << dataCharacteristics | |
243 | << " labels enabled: " << labelsEnabled; |
|
242 | << " labels enabled: " << labelsEnabled; | |
244 | m_defaultSeriesName = seriesName; |
|
243 | m_defaultSeriesName = seriesName; | |
245 |
|
244 | |||
246 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
245 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
247 |
|
246 | |||
248 | // Line series and scatter series use similar data |
|
247 | // Line series and scatter series use similar data | |
249 | if (seriesName == "Line") { |
|
248 | if (seriesName == "Line") { | |
250 | for (int j(0); j < data.count(); j ++) { |
|
249 | for (int j(0); j < data.count(); j ++) { | |
251 | QList<qreal> column = data.at(j); |
|
250 | QList<qreal> column = data.at(j); | |
252 | QLineSeries *series = new QLineSeries(); |
|
251 | QLineSeries *series = new QLineSeries(); | |
253 | series->setName("line" + QString::number(j)); |
|
252 | series->setName("line" + QString::number(j)); | |
254 | for (int i(0); i < column.count(); i++) |
|
253 | for (int i(0); i < column.count(); i++) | |
255 | series->append(i, column.at(i)); |
|
254 | series->append(i, column.at(i)); | |
256 | m_chart->addSeries(series); |
|
255 | m_chart->addSeries(series); | |
257 | } |
|
256 | } | |
258 | } else if (seriesName == "Area") { |
|
257 | } else if (seriesName == "Area") { | |
259 | // TODO: lower series for the area? |
|
258 | // TODO: lower series for the area? | |
260 | for (int j(0); j < data.count(); j ++) { |
|
259 | for (int j(0); j < data.count(); j ++) { | |
261 | QList<qreal> column = data.at(j); |
|
260 | QList<qreal> column = data.at(j); | |
262 | QLineSeries *lineSeries = new QLineSeries(); |
|
261 | QLineSeries *lineSeries = new QLineSeries(); | |
263 | for (int i(0); i < column.count(); i++) |
|
262 | for (int i(0); i < column.count(); i++) | |
264 | lineSeries->append(i, column.at(i)); |
|
263 | lineSeries->append(i, column.at(i)); | |
265 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
264 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
266 | areaSeries->setName("area" + QString::number(j)); |
|
265 | areaSeries->setName("area" + QString::number(j)); | |
267 | m_chart->addSeries(areaSeries); |
|
266 | m_chart->addSeries(areaSeries); | |
268 | } |
|
267 | } | |
269 | } else if (seriesName == "Scatter") { |
|
268 | } else if (seriesName == "Scatter") { | |
270 | for (int j(0); j < data.count(); j++) { |
|
269 | for (int j(0); j < data.count(); j++) { | |
271 | QList<qreal> column = data.at(j); |
|
270 | QList<qreal> column = data.at(j); | |
272 | QScatterSeries *series = new QScatterSeries(); |
|
271 | QScatterSeries *series = new QScatterSeries(); | |
273 | series->setName("scatter" + QString::number(j)); |
|
272 | series->setName("scatter" + QString::number(j)); | |
274 | for (int i(0); i < column.count(); i++) |
|
273 | for (int i(0); i < column.count(); i++) | |
275 | series->append(i, column.at(i)); |
|
274 | series->append(i, column.at(i)); | |
276 | m_chart->addSeries(series); |
|
275 | m_chart->addSeries(series); | |
277 | } |
|
276 | } | |
278 | } else if (seriesName == "Pie") { |
|
277 | } else if (seriesName == "Pie") { | |
279 | QStringList labels = generateLabels(rowCount); |
|
278 | QStringList labels = generateLabels(rowCount); | |
280 | for (int j(0); j < data.count(); j++) { |
|
279 | for (int j(0); j < data.count(); j++) { | |
281 | QPieSeries *series = new QPieSeries(); |
|
280 | QPieSeries *series = new QPieSeries(); | |
282 | QList<qreal> column = data.at(j); |
|
281 | QList<qreal> column = data.at(j); | |
283 | for (int i(0); i < column.count(); i++) |
|
282 | for (int i(0); i < column.count(); i++) | |
284 | series->append(labels.at(i), column.at(i)); |
|
283 | series->append(labels.at(i), column.at(i)); | |
285 | m_chart->addSeries(series); |
|
284 | m_chart->addSeries(series); | |
286 | } |
|
285 | } | |
287 | } else if (seriesName == "Bar" |
|
286 | } else if (seriesName == "Bar" | |
288 | || seriesName == "Stacked bar" |
|
287 | || seriesName == "Stacked bar" | |
289 | || seriesName == "Percent bar") { |
|
288 | || seriesName == "Percent bar") { | |
290 | QStringList category; |
|
289 | QStringList category; | |
291 | QStringList labels = generateLabels(rowCount); |
|
290 | QStringList labels = generateLabels(rowCount); | |
292 | foreach (QString label, labels) |
|
291 | foreach (QString label, labels) | |
293 | category << label; |
|
292 | category << label; | |
294 | QAbstractBarSeries* series = 0; |
|
293 | QAbstractBarSeries* series = 0; | |
295 | if (seriesName == "Bar") { |
|
294 | if (seriesName == "Bar") { | |
296 | series = new QBarSeries(this); |
|
295 | series = new QBarSeries(this); | |
297 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
296 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
298 | axis->append(category); |
|
297 | axis->append(category); | |
299 | m_chart->setAxisX(axis,series); |
|
298 | m_chart->setAxisX(axis,series); | |
300 | } else if (seriesName == "Stacked bar") { |
|
299 | } else if (seriesName == "Stacked bar") { | |
301 | series = new QStackedBarSeries(this); |
|
300 | series = new QStackedBarSeries(this); | |
302 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
301 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
303 | axis->append(category); |
|
302 | axis->append(category); | |
304 | m_chart->setAxisX(axis,series); |
|
303 | m_chart->setAxisX(axis,series); | |
305 | } else { |
|
304 | } else { | |
306 | series = new QPercentBarSeries(this); |
|
305 | series = new QPercentBarSeries(this); | |
307 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
306 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
308 | axis->append(category); |
|
307 | axis->append(category); | |
309 | m_chart->setAxisX(axis,series); |
|
308 | m_chart->setAxisX(axis,series); | |
310 | } |
|
309 | } | |
311 |
|
310 | |||
312 | for (int j(0); j < data.count(); j++) { |
|
311 | for (int j(0); j < data.count(); j++) { | |
313 | QList<qreal> column = data.at(j); |
|
312 | QList<qreal> column = data.at(j); | |
314 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
313 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
315 | for (int i(0); i < column.count(); i++) |
|
314 | for (int i(0); i < column.count(); i++) | |
316 | *set << column.at(i); |
|
315 | *set << column.at(i); | |
317 | series->append(set); |
|
316 | series->append(set); | |
318 | } |
|
317 | } | |
319 |
|
318 | |||
320 | m_chart->addSeries(series); |
|
319 | m_chart->addSeries(series); | |
321 | } else if (seriesName == "Spline") { |
|
320 | } else if (seriesName == "Spline") { | |
322 | for (int j(0); j < data.count(); j ++) { |
|
321 | for (int j(0); j < data.count(); j ++) { | |
323 | QList<qreal> column = data.at(j); |
|
322 | QList<qreal> column = data.at(j); | |
324 | QSplineSeries *series = new QSplineSeries(); |
|
323 | QSplineSeries *series = new QSplineSeries(); | |
325 | for (int i(0); i < column.count(); i++) |
|
324 | for (int i(0); i < column.count(); i++) | |
326 | series->append(i, column.at(i)); |
|
325 | series->append(i, column.at(i)); | |
327 | m_chart->addSeries(series); |
|
326 | m_chart->addSeries(series); | |
328 | } |
|
327 | } | |
329 | } |
|
328 | } | |
330 | m_chart->createDefaultAxes(); |
|
329 | m_chart->createDefaultAxes(); | |
331 | } |
|
330 | } | |
332 |
|
331 | |||
333 | void MainWidget::backgroundChanged(int itemIndex) |
|
332 | void MainWidget::backgroundChanged(int itemIndex) | |
334 | { |
|
333 | { | |
335 | qDebug() << "backgroundChanged: " << itemIndex; |
|
334 | qDebug() << "backgroundChanged: " << itemIndex; | |
336 | } |
|
335 | } | |
337 |
|
336 | |||
338 | void MainWidget::autoScaleChanged(int value) |
|
337 | void MainWidget::autoScaleChanged(int value) | |
339 | { |
|
338 | { | |
340 | if (value) { |
|
339 | if (value) { | |
341 | // TODO: enable auto scaling |
|
340 | // TODO: enable auto scaling | |
342 | } else { |
|
341 | } else { | |
343 | // TODO: set scaling manually (and disable auto scaling) |
|
342 | // TODO: set scaling manually (and disable auto scaling) | |
344 | } |
|
343 | } | |
345 |
|
344 | |||
346 | m_xMinSpin->setEnabled(!value); |
|
345 | m_xMinSpin->setEnabled(!value); | |
347 | m_xMaxSpin->setEnabled(!value); |
|
346 | m_xMaxSpin->setEnabled(!value); | |
348 | m_yMinSpin->setEnabled(!value); |
|
347 | m_yMinSpin->setEnabled(!value); | |
349 | m_yMaxSpin->setEnabled(!value); |
|
348 | m_yMaxSpin->setEnabled(!value); | |
350 | } |
|
349 | } | |
351 |
|
350 | |||
352 | void MainWidget::xMinChanged(int value) |
|
351 | void MainWidget::xMinChanged(int value) | |
353 | { |
|
352 | { | |
354 | qDebug() << "xMinChanged: " << value; |
|
353 | qDebug() << "xMinChanged: " << value; | |
355 | } |
|
354 | } | |
356 |
|
355 | |||
357 | void MainWidget::xMaxChanged(int value) |
|
356 | void MainWidget::xMaxChanged(int value) | |
358 | { |
|
357 | { | |
359 | qDebug() << "xMaxChanged: " << value; |
|
358 | qDebug() << "xMaxChanged: " << value; | |
360 | } |
|
359 | } | |
361 |
|
360 | |||
362 | void MainWidget::yMinChanged(int value) |
|
361 | void MainWidget::yMinChanged(int value) | |
363 | { |
|
362 | { | |
364 | qDebug() << "yMinChanged: " << value; |
|
363 | qDebug() << "yMinChanged: " << value; | |
365 | } |
|
364 | } | |
366 |
|
365 | |||
367 | void MainWidget::yMaxChanged(int value) |
|
366 | void MainWidget::yMaxChanged(int value) | |
368 | { |
|
367 | { | |
369 | qDebug() << "yMaxChanged: " << value; |
|
368 | qDebug() << "yMaxChanged: " << value; | |
370 | } |
|
369 | } | |
371 |
|
370 | |||
372 | void MainWidget::changeChartTheme(int themeIndex) |
|
371 | void MainWidget::changeChartTheme(int themeIndex) | |
373 | { |
|
372 | { | |
374 | qDebug() << "changeChartTheme: " << themeIndex; |
|
373 | qDebug() << "changeChartTheme: " << themeIndex; | |
375 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
374 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |
376 | } |
|
375 | } |
General Comments 0
You need to be logged in to leave comments.
Login now