@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef AXISANIMATION |
|
|
22 |
#define AXISANIMATION |
|
|
21 | #ifndef AXISANIMATION_H | |
|
22 | #define AXISANIMATION_H | |
|
23 | 23 | |
|
24 | 24 | #include "axis_p.h" |
|
25 | 25 | #include "chartanimation_p.h" |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef BARANIMATION_P_H |
|
|
22 |
#define BARANIMATION_P_H |
|
|
21 | #ifndef BARANIMATION_P_H | |
|
22 | #define BARANIMATION_P_H | |
|
23 | 23 | |
|
24 | 24 | #include "chartanimation_p.h" |
|
25 | 25 | #include "barchartitem_p.h" |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTANIMATION_H |
|
|
22 |
#define CHARTANIMATION_H |
|
|
21 | #ifndef CHARTANIMATION_H | |
|
22 | #define CHARTANIMATION_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include <QVariantAnimation> |
@@ -18,8 +18,9 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTANIMATOR_P_H |
|
|
22 |
#define CHARTANIMATOR_P_H |
|
|
21 | #ifndef CHARTANIMATOR_P_H | |
|
22 | #define CHARTANIMATOR_P_H | |
|
23 | ||
|
23 | 24 | #include "qchartglobal.h" |
|
24 | 25 | #include "chartanimation_p.h" |
|
25 | 26 | #include "piechartitem_p.h" |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef PIEANIMATION_P_H |
|
|
22 |
#define PIEANIMATION_P_H |
|
|
21 | #ifndef PIEANIMATION_P_H | |
|
22 | #define PIEANIMATION_P_H | |
|
23 | 23 | |
|
24 | 24 | #include "chartanimation_p.h" |
|
25 | 25 | #include "piechartitem_p.h" |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef PIESLICEANIMATION_P_H |
|
|
22 |
#define PIESLICEANIMATION_P_H |
|
|
21 | #ifndef PIESLICEANIMATION_P_H | |
|
22 | #define PIESLICEANIMATION_P_H | |
|
23 | 23 | |
|
24 | 24 | #include "piechartitem_p.h" |
|
25 | 25 | #include <QVariantAnimation> |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef SPLINEANIMATION_P_H |
|
|
22 |
#define SPLINEANIMATION_P_H |
|
|
21 | #ifndef SPLINEANIMATION_P_H | |
|
22 | #define SPLINEANIMATION_P_H | |
|
23 | 23 | #include "chartanimation_p.h" |
|
24 | 24 | #include <QPointF> |
|
25 | 25 |
@@ -18,8 +18,9 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef XY |
|
|
22 |
#define XY |
|
|
21 | #ifndef XYANIMATION_P_H | |
|
22 | #define XYANIMATION_P_H | |
|
23 | ||
|
23 | 24 | #include "chartanimation_p.h" |
|
24 | 25 | #include <QPointF> |
|
25 | 26 |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef QAREASERIES_H |
|
|
22 |
#define QAREASERIES_H |
|
|
21 | #ifndef QAREASERIES_H | |
|
22 | #define QAREASERIES_H | |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qseries.h> |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QAREASERIES_P_H |
|
|
31 |
#define QAREASERIES_P_H |
|
|
30 | #ifndef QAREASERIES_P_H | |
|
31 | #define QAREASERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qseries_p.h" |
|
34 | 34 |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef AXIS |
|
|
22 |
#define AXIS |
|
|
21 | #ifndef AXIS_H | |
|
22 | #define AXIS_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "chart_p.h" |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef QCHARTAXIS_H |
|
|
22 |
#define QCHARTAXIS_H |
|
|
21 | #ifndef QCHARTAXIS_H | |
|
22 | #define QCHARTAXIS_H | |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qchartaxiscategories.h> |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QCHARTAXIS_P_H |
|
|
31 |
#define QCHARTAXIS_P_H |
|
|
30 | #ifndef QCHARTAXIS_P_H | |
|
31 | #define QCHARTAXIS_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qchartaxis.h" |
|
34 | 34 |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef QCHARTAXISCATEGORIES_H |
|
|
22 |
#define QCHARTAXISCATEGORIES_H |
|
|
21 | #ifndef QCHARTAXISCATEGORIES_H | |
|
22 | #define QCHARTAXISCATEGORIES_H | |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qbarseries.h> |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QCHARTAXISCATEGORIES_P_H |
|
|
31 |
#define QCHARTAXISCATEGORIES_P_H |
|
|
30 | #ifndef QCHARTAXISCATEGORIES_P_H | |
|
31 | #define QCHARTAXISCATEGORIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qchartaxiscategories.h" |
|
34 | 34 |
@@ -18,11 +18,11 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | #include "barchartmodel_p.h" | |
|
22 | #include "qbarset.h" | |
|
21 | 23 | #include <limits.h> |
|
22 | 24 | #include <QVector> |
|
23 | 25 | #include <QDebug> |
|
24 | #include "barchartmodel_p.h" | |
|
25 | #include "qbarset.h" | |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
@@ -195,4 +195,4 QString BarChartModel::categoryName(int category) | |||
|
195 | 195 | |
|
196 | 196 | #include "moc_barchartmodel_p.cpp" |
|
197 | 197 | |
|
198 |
QTCOMMERCIALCHART_END_NAMESPACE |
|
|
198 | QTCOMMERCIALCHART_END_NAMESPACE No newline at end of file |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QPERCENTBARSERIES_P_H |
|
|
31 |
#define QPERCENTBARSERIES_P_H |
|
|
30 | #ifndef QPERCENTBARSERIES_P_H | |
|
31 | #define QPERCENTBARSERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QSTACKEDBARSERIES_P_H |
|
|
31 |
#define QSTACKEDBARSERIES_P_H |
|
|
30 | #ifndef QSTACKEDBARSERIES_P_H | |
|
31 | #define QSTACKEDBARSERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHART_H |
|
|
22 |
#define CHART_H |
|
|
21 | #ifndef CHART_H | |
|
22 | #define CHART_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include <QRect> |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTBACKGROUND_H |
|
|
22 |
#define CHARTBACKGROUND_H |
|
|
21 | #ifndef CHARTBACKGROUND_H | |
|
22 | #define CHARTBACKGROUND_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include <QGraphicsRectItem> |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTCONFIG_H |
|
|
22 |
#define CHARTCONFIG_H |
|
|
21 | #ifndef CHARTCONFIG_H | |
|
22 | #define CHARTCONFIG_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #ifdef Q_CC_MSVC |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef CHARTDATASET_P_H |
|
|
31 |
#define CHARTDATASET_P_H |
|
|
30 | #ifndef CHARTDATASET_P_H | |
|
31 | #define CHARTDATASET_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qseries.h" |
|
34 | 34 | #include "domain_p.h" |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTITEM_H |
|
|
22 |
#define CHARTITEM_H |
|
|
21 | #ifndef CHARTITEM_H | |
|
22 | #define CHARTITEM_H | |
|
23 | 23 | |
|
24 | 24 | #include "chart_p.h" |
|
25 | 25 | #include "chartpresenter_p.h" |
@@ -1,27 +1,26 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | #include "chartpresenter_p.h" | |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "qchartaxis.h" |
|
24 | #include "chartpresenter_p.h" | |
|
25 | 24 | #include "chartdataset_p.h" |
|
26 | 25 | #include "charttheme_p.h" |
|
27 | 26 | #include "chartanimator_p.h" |
@@ -33,26 +32,26 | |||
|
33 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 33 | |
|
35 | 34 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
35 | m_chart(chart), | |
|
36 | m_animator(0), | |
|
37 | m_dataset(dataset), | |
|
38 | m_chartTheme(0), | |
|
39 | m_chartRect(QRectF(QPoint(0,0),m_chart->size())), | |
|
40 | m_options(QChart::NoAnimation), | |
|
41 | m_minLeftMargin(0), | |
|
42 | m_minBottomMargin(0), | |
|
43 | m_backgroundItem(0), | |
|
44 | m_titleItem(0), | |
|
45 | m_marginBig(60), | |
|
46 | m_marginSmall(20), | |
|
47 | m_marginTiny(10), | |
|
48 | m_chartMargins(QRect(m_marginBig,m_marginBig,0,0)) | |
|
50 | 49 | { |
|
51 | 50 | } |
|
52 | 51 | |
|
53 | 52 | ChartPresenter::~ChartPresenter() |
|
54 | 53 | { |
|
55 |
|
|
|
54 | delete m_chartTheme; | |
|
56 | 55 | } |
|
57 | 56 | |
|
58 | 57 | void ChartPresenter::setGeometry(const QRectF& rect) |
@@ -65,23 +64,23 void ChartPresenter::setGeometry(const QRectF& rect) | |||
|
65 | 64 | void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width) |
|
66 | 65 | { |
|
67 | 66 | switch(axis->axisType()){ |
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 | } | |
|
74 | break; | |
|
67 | case Axis::X_AXIS: | |
|
68 | { | |
|
69 | if(width>m_chartRect.width()+ m_chartMargins.left()) { | |
|
70 | m_minLeftMargin= width - m_chartRect.width(); | |
|
71 | updateLayout(); | |
|
75 | 72 | } |
|
76 | case Axis::Y_AXIS: | |
|
77 | { | |
|
73 | break; | |
|
74 | } | |
|
75 | case Axis::Y_AXIS: | |
|
76 | { | |
|
78 | 77 | |
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 | } | |
|
83 | break; | |
|
78 | if(m_minLeftMargin!=width){ | |
|
79 | m_minLeftMargin= width; | |
|
80 | updateLayout(); | |
|
84 | 81 | } |
|
82 | break; | |
|
83 | } | |
|
85 | 84 | |
|
86 | 85 | } |
|
87 | 86 | } |
@@ -89,23 +88,23 void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width) | |||
|
89 | 88 | void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height) |
|
90 | 89 | { |
|
91 | 90 | switch(axis->axisType()){ |
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 | } | |
|
98 | break; | |
|
91 | case Axis::X_AXIS: | |
|
92 | { | |
|
93 | if(m_minBottomMargin!=height) { | |
|
94 | m_minBottomMargin= height; | |
|
95 | updateLayout(); | |
|
99 | 96 | } |
|
100 | case Axis::Y_AXIS: | |
|
101 | { | |
|
97 | break; | |
|
98 | } | |
|
99 | case Axis::Y_AXIS: | |
|
100 | { | |
|
102 | 101 | |
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 | } | |
|
107 | break; | |
|
102 | if(height>m_chartMargins.bottom()+m_chartRect.height()){ | |
|
103 | m_minBottomMargin= height - m_chartRect.height(); | |
|
104 | updateLayout(); | |
|
108 | 105 | } |
|
106 | break; | |
|
107 | } | |
|
109 | 108 | |
|
110 | 109 | } |
|
111 | 110 | } |
@@ -149,14 +148,14 void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |||
|
149 | 148 | |
|
150 | 149 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
151 | 150 | { |
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
151 | Chart *item = series->d_ptr->createGraphics(this); | |
|
152 | Q_ASSERT(item); | |
|
153 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
|
154 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
|
155 | //initialize | |
|
156 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
|
157 | if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect); | |
|
158 | m_chartItems.insert(series,item); | |
|
160 | 159 | } |
|
161 | 160 | |
|
162 | 161 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
@@ -166,19 +165,19 void ChartPresenter::handleSeriesRemoved(QSeries* series) | |||
|
166 | 165 | if(m_animator) { |
|
167 | 166 | //small hack to handle area animations |
|
168 | 167 | if(series->type()==QSeries::SeriesTypeArea){ |
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
168 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
|
169 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
|
170 | m_animator->removeAnimation(area->upperLineItem()); | |
|
171 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | |
|
173 | 172 | }else |
|
174 | m_animator->removeAnimation(item); | |
|
173 | m_animator->removeAnimation(item); | |
|
175 | 174 | } |
|
176 | 175 | delete item; |
|
177 | 176 | } |
|
178 | 177 | |
|
179 | 178 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
180 | 179 | { |
|
181 |
|
|
|
180 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
|
182 | 181 | delete m_chartTheme; |
|
183 | 182 | m_chartTheme = ChartTheme::createTheme(theme); |
|
184 | 183 | m_chartTheme->setForced(force); |
@@ -208,75 +207,75 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |||
|
208 | 207 | |
|
209 | 208 | void ChartPresenter::resetAllElements() |
|
210 | 209 | { |
|
211 |
|
|
|
212 |
|
|
|
213 | ||
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
210 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
|
211 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
|
212 | ||
|
213 | foreach(QChartAxis* axis, axisList) { | |
|
214 | handleAxisRemoved(axis); | |
|
215 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
|
216 | } | |
|
217 | foreach(QSeries* series, seriesList) { | |
|
218 | handleSeriesRemoved(series); | |
|
219 | handleSeriesAdded(series,m_dataset->domain(series)); | |
|
220 | } | |
|
222 | 221 | } |
|
223 | 222 | |
|
224 | 223 | void ChartPresenter::zoomIn() |
|
225 | 224 | { |
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
225 | QRectF rect = chartGeometry(); | |
|
226 | rect.setWidth(rect.width()/2); | |
|
227 | rect.setHeight(rect.height()/2); | |
|
228 | rect.moveCenter(chartGeometry().center()); | |
|
229 | zoomIn(rect); | |
|
231 | 230 | } |
|
232 | 231 | |
|
233 | 232 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
234 | 233 | { |
|
235 |
|
|
|
234 | QRectF r = rect.normalized(); | |
|
236 | 235 | r.translate(-m_chartMargins.topLeft()); |
|
237 |
|
|
|
238 | ||
|
239 |
|
|
|
240 |
|
|
|
241 | } | |
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 | } | |
|
236 | if(m_animator) { | |
|
237 | ||
|
238 | QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); | |
|
239 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
|
240 | } | |
|
241 | m_dataset->zoomInDomain(r,chartGeometry().size()); | |
|
242 | if(m_animator) { | |
|
243 | m_animator->setState(ChartAnimator::ShowState); | |
|
244 | } | |
|
246 | 245 | } |
|
247 | 246 | |
|
248 | 247 | void ChartPresenter::zoomOut() |
|
249 | 248 | { |
|
250 |
|
|
|
251 | { | |
|
252 |
|
|
|
253 | } | |
|
249 | if(m_animator) | |
|
250 | { | |
|
251 | m_animator->setState(ChartAnimator::ZoomOutState); | |
|
252 | } | |
|
254 | 253 | |
|
255 |
|
|
|
256 |
|
|
|
254 | QSizeF size = chartGeometry().size(); | |
|
255 | QRectF rect = chartGeometry(); | |
|
257 | 256 | rect.translate(-m_chartMargins.topLeft()); |
|
258 | 257 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); |
|
259 | 258 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
260 | 259 | |
|
261 |
|
|
|
262 |
|
|
|
263 | } | |
|
260 | if(m_animator){ | |
|
261 | m_animator->setState(ChartAnimator::ShowState); | |
|
262 | } | |
|
264 | 263 | } |
|
265 | 264 | |
|
266 | 265 | void ChartPresenter::scroll(int dx,int dy) |
|
267 | 266 | { |
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
|
273 | } | |
|
267 | if(m_animator){ | |
|
268 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
|
269 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
|
270 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
|
271 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
|
272 | } | |
|
274 | 273 | |
|
275 |
|
|
|
274 | m_dataset->scrollDomain(dx,dy,chartGeometry().size()); | |
|
276 | 275 | |
|
277 | 276 | if(m_animator){ |
|
278 |
|
|
|
279 | } | |
|
277 | m_animator->setState(ChartAnimator::ShowState); | |
|
278 | } | |
|
280 | 279 | } |
|
281 | 280 | |
|
282 | 281 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
@@ -311,41 +310,41 void ChartPresenter::updateLayout() | |||
|
311 | 310 | // Reserve some space for legend |
|
312 | 311 | switch (legend->alignment()) { |
|
313 | 312 | |
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
|
313 | case QLegend::AlignmentTop: { | |
|
314 | int ledgendSize = legend->minHeight(); | |
|
315 | int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; | |
|
316 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |
|
317 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny)); | |
|
318 | titlePadding = m_marginTiny + m_marginTiny; | |
|
319 | break; | |
|
320 | } | |
|
321 | case QLegend::AlignmentBottom: { | |
|
322 | int ledgendSize = legend->minHeight(); | |
|
323 | int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; | |
|
324 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); | |
|
325 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall)); | |
|
326 | titlePadding = m_chartMargins.top()/2; | |
|
327 | break; | |
|
328 | } | |
|
329 | case QLegend::AlignmentLeft: { | |
|
330 | int ledgendSize = legend->minWidth(); | |
|
331 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; | |
|
332 | m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |
|
333 | m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom())); | |
|
334 | titlePadding = m_chartMargins.top()/2; | |
|
335 | break; | |
|
336 | } | |
|
337 | case QLegend::AlignmentRight: { | |
|
338 | int ledgendSize = legend->minWidth(); | |
|
339 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; | |
|
340 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); | |
|
341 | m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom())); | |
|
342 | titlePadding = m_chartMargins.top()/2; | |
|
343 | break; | |
|
344 | } | |
|
345 | default: { | |
|
346 | break; | |
|
347 | } | |
|
349 | 348 | } |
|
350 | 349 | } |
|
351 | 350 | |
@@ -372,10 +371,10 void ChartPresenter::updateLayout() | |||
|
372 | 371 | |
|
373 | 372 | legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); |
|
374 | 373 | |
|
375 | if(m_chartRect!=chartRect){ | |
|
376 | m_chartRect=chartRect; | |
|
377 | emit geometryChanged(m_chartRect); | |
|
378 | } | |
|
374 | if(m_chartRect!=chartRect){ | |
|
375 | m_chartRect=chartRect; | |
|
376 | emit geometryChanged(m_chartRect); | |
|
377 | } | |
|
379 | 378 | |
|
380 | 379 | |
|
381 | 380 | } |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTPRESENTER_H |
|
|
22 |
#define CHARTPRESENTER_H |
|
|
21 | #ifndef CHARTPRESENTER_H | |
|
22 | #define CHARTPRESENTER_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "chartbackground_p.h" //TODO fix me |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef DOMAIN_H |
|
|
22 |
#define DOMAIN_H |
|
|
21 | #ifndef DOMAIN_H | |
|
22 | #define DOMAIN_H | |
|
23 | 23 | #include "qchartglobal.h" |
|
24 | 24 | #include <QRectF> |
|
25 | 25 | #include <QSizeF> |
@@ -28,8 +28,8 | |||
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | |
|
31 |
#ifndef LEGENDSCROLLER_P_H |
|
|
32 |
#define LEGENDSCROLLER_P_H |
|
|
31 | #ifndef LEGENDSCROLLER_P_H | |
|
32 | #define LEGENDSCROLLER_P_H | |
|
33 | 33 | |
|
34 | 34 | #include "qlegend.h" |
|
35 | 35 | #include "scroller_p.h" |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QLEGEND_P_H |
|
|
31 |
#define QLEGEND_P_H |
|
|
30 | #ifndef QLEGEND_P_H | |
|
31 | #define QLEGEND_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qlegend.h" |
|
34 | 34 |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef QLINESERIES_H |
|
|
22 |
#define QLINESERIES_H |
|
|
21 | #ifndef QLINESERIES_H | |
|
22 | #define QLINESERIES_H | |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qxyseries.h> |
@@ -33,12 +33,12 class QTCOMMERCIALCHART_EXPORT QLineSeries : public QXYSeries | |||
|
33 | 33 | { |
|
34 | 34 | public: |
|
35 | 35 | explicit QLineSeries(QObject *parent=0); |
|
36 |
|
|
|
36 | ~QLineSeries(); | |
|
37 | 37 | |
|
38 |
|
|
|
38 | QSeries::QSeriesType type() const; | |
|
39 | 39 | |
|
40 | 40 | protected: |
|
41 |
|
|
|
41 | QLineSeries(QLineSeriesPrivate &d,QObject *parent = 0); | |
|
42 | 42 | |
|
43 | 43 | private: |
|
44 | 44 | Q_DECLARE_PRIVATE(QLineSeries); |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QLINESERIES_P_H |
|
|
31 |
#define QLINESERIES_P_H |
|
|
30 | #ifndef QLINESERIES_P_H | |
|
31 | #define QLINESERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qxyseries_p.h" |
|
34 | 34 |
@@ -1,219 +1,218 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "qchartview.h" | |
|
22 | #include "qchart_p.h" | |
|
23 |
#include "qchart |
|
|
24 | #include <QGraphicsScene> | |
|
25 | #include <QRubberBand> | |
|
26 | ||
|
27 | ||
|
28 | /*! | |
|
29 | \enum QChartView::RubberBand | |
|
30 | ||
|
31 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
|
32 | ||
|
33 |
\value |
|
|
34 |
\value |
|
|
35 |
\value |
|
|
36 | \value RectangleRubberBand | |
|
37 | */ | |
|
38 | ||
|
39 | /*! | |
|
40 | \class QChartView | |
|
41 | \brief Standalone charting widget. | |
|
42 | ||
|
43 | QChartView is a standalone widget that can display charts. It does not require separate | |
|
44 | QGraphicsScene to work. It manages the graphical representation of different types of | |
|
45 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to | |
|
46 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |
|
47 | ||
|
48 | \sa QChart | |
|
49 | */ | |
|
50 | ||
|
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
52 | ||
|
53 | /*! | |
|
54 | Constructs a chartView object which is a child of a\a parent. | |
|
55 | */ | |
|
56 | QChartView::QChartView(QChart *chart,QWidget *parent) : | |
|
57 | QGraphicsView(parent), | |
|
58 | d_ptr(new QChartViewPrivate()) | |
|
59 | { | |
|
60 | Q_ASSERT(chart); | |
|
61 | d_ptr->m_scene = new QGraphicsScene(this); | |
|
62 | d_ptr->m_chart = chart; | |
|
63 | setFrameShape(QFrame::NoFrame); | |
|
64 | setBackgroundRole(QPalette::Window); | |
|
65 |
set |
|
|
66 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
|
67 |
|
|
|
68 | d_ptr->m_scene->addItem(chart); | |
|
69 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
|
70 | } | |
|
71 | ||
|
72 | ||
|
73 | /*! | |
|
74 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
|
75 | */ | |
|
76 | QChartView::~QChartView() | |
|
77 | { | |
|
78 | } | |
|
79 | ||
|
80 | /*! | |
|
81 | Returns the pointer to the associated chart | |
|
82 | */ | |
|
83 | QChart* QChartView::chart() const | |
|
84 | { | |
|
85 | return d_ptr->m_chart; | |
|
86 | } | |
|
87 | ||
|
88 | /*! | |
|
89 | Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed. | |
|
90 | */ | |
|
91 | void QChartView::setRubberBand(const RubberBands& rubberBand) | |
|
92 | { | |
|
93 | d_ptr->m_rubberBandFlags=rubberBand; | |
|
94 | ||
|
95 |
|
|
|
96 |
|
|
|
97 | d_ptr->m_rubberBand=0; | |
|
98 | return; | |
|
99 | } | |
|
100 | ||
|
101 | if (!d_ptr->m_rubberBand) { | |
|
102 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
|
103 | d_ptr->m_rubberBand->setEnabled(true); | |
|
104 | } | |
|
105 | } | |
|
106 | ||
|
107 | /*! | |
|
108 | Returns the RubberBandPolicy that is currently being used by the widget. | |
|
109 | */ | |
|
110 | QChartView::RubberBands QChartView::rubberBand() const | |
|
111 | { | |
|
112 | return d_ptr->m_rubberBandFlags; | |
|
113 | } | |
|
114 | ||
|
115 | /*! | |
|
116 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
|
117 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. | |
|
118 | */ | |
|
119 | void QChartView::mousePressEvent(QMouseEvent *event) | |
|
120 | { | |
|
121 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
|
122 | ||
|
123 | int padding = d_ptr->m_chart->margins().top(); | |
|
124 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
|
125 | ||
|
126 | if (rect.contains(event->pos())) { | |
|
127 | d_ptr->m_rubberBandOrigin = event->pos(); | |
|
128 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
|
129 | d_ptr->m_rubberBand->show(); | |
|
130 | event->accept(); | |
|
131 |
|
|
|
132 | } | |
|
133 | else { | |
|
134 | QGraphicsView::mousePressEvent(event); | |
|
135 | } | |
|
136 | } | |
|
137 | ||
|
138 | /*! | |
|
139 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
|
140 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
|
141 | */ | |
|
142 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
|
143 | { | |
|
144 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
|
145 |
QRectF |
|
|
146 | QRectF geometry = d_ptr->m_chart->geometry(); | |
|
147 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); | |
|
148 |
int |
|
|
149 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
|
150 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
|
151 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
|
152 | height = rect.height(); | |
|
153 | } | |
|
154 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
|
155 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
|
156 | width= rect.width(); | |
|
157 | } | |
|
158 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); | |
|
159 | } | |
|
160 | else { | |
|
161 | QGraphicsView::mouseMoveEvent(event); | |
|
162 | } | |
|
163 | } | |
|
164 | ||
|
165 | /*! | |
|
166 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand | |
|
167 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
|
168 | */ | |
|
169 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
|
170 | { | |
|
171 | if(d_ptr->m_rubberBand) { | |
|
172 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
|
173 |
d_ptr->m_rubberBand-> |
|
|
174 |
|
|
|
175 | d_ptr->m_chart->zoomIn(rect); | |
|
176 | event->accept(); | |
|
177 | } | |
|
178 | ||
|
179 | if(event->button()==Qt::RightButton){ | |
|
180 | d_ptr->m_chart->zoomOut(); | |
|
181 | event->accept(); | |
|
182 |
|
|
|
183 | } | |
|
184 | else { | |
|
185 | QGraphicsView::mouseReleaseEvent(event); | |
|
186 | } | |
|
187 | } | |
|
188 | ||
|
189 | /*! | |
|
190 | Resizes and updates the chart area using the \a event data | |
|
191 | */ | |
|
192 | void QChartView::resizeEvent(QResizeEvent *event) | |
|
193 | { | |
|
194 | QGraphicsView::resizeEvent(event); | |
|
195 |
d_ptr->m_chart-> |
|
|
196 |
set |
|
|
197 | setSceneRect(d_ptr->m_chart->geometry()); | |
|
198 | } | |
|
199 | ||
|
200 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
201 | ||
|
202 | QChartViewPrivate::QChartViewPrivate(): | |
|
203 |
m_ |
|
|
204 |
m_ |
|
|
205 | m_presenter(0), | |
|
206 | m_rubberBand(0), | |
|
207 | m_rubberBandFlags(QChartView::NoRubberBand) | |
|
208 | { | |
|
209 | ||
|
210 | } | |
|
211 | ||
|
212 | QChartViewPrivate::~QChartViewPrivate() | |
|
213 | { | |
|
214 | ||
|
215 | } | |
|
216 | ||
|
217 | #include "moc_qchartview.cpp" | |
|
218 | ||
|
219 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "qchartview.h" | |
|
22 | #include "qchartview_p.h" | |
|
23 | #include "qchart_p.h" | |
|
24 | #include <QGraphicsScene> | |
|
25 | #include <QRubberBand> | |
|
26 | ||
|
27 | /*! | |
|
28 | \enum QChartView::RubberBand | |
|
29 | ||
|
30 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
|
31 | ||
|
32 | \value NoRubberBand | |
|
33 | \value VerticalRubberBand | |
|
34 | \value HorizonalRubberBand | |
|
35 | \value RectangleRubberBand | |
|
36 | */ | |
|
37 | ||
|
38 | /*! | |
|
39 | \class QChartView | |
|
40 | \brief Standalone charting widget. | |
|
41 | ||
|
42 | QChartView is a standalone widget that can display charts. It does not require separate | |
|
43 | QGraphicsScene to work. It manages the graphical representation of different types of | |
|
44 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to | |
|
45 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |
|
46 | ||
|
47 | \sa QChart | |
|
48 | */ | |
|
49 | ||
|
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
51 | ||
|
52 | /*! | |
|
53 | Constructs a chartView object which is a child of a\a parent. | |
|
54 | */ | |
|
55 | QChartView::QChartView(QChart *chart,QWidget *parent) : | |
|
56 | QGraphicsView(parent), | |
|
57 | d_ptr(new QChartViewPrivate()) | |
|
58 | { | |
|
59 | Q_ASSERT(chart); | |
|
60 | d_ptr->m_scene = new QGraphicsScene(this); | |
|
61 | d_ptr->m_chart = chart; | |
|
62 | setFrameShape(QFrame::NoFrame); | |
|
63 | setBackgroundRole(QPalette::Window); | |
|
64 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
|
65 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
|
66 | setScene(d_ptr->m_scene); | |
|
67 | d_ptr->m_scene->addItem(chart); | |
|
68 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
|
69 | } | |
|
70 | ||
|
71 | ||
|
72 | /*! | |
|
73 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
|
74 | */ | |
|
75 | QChartView::~QChartView() | |
|
76 | { | |
|
77 | } | |
|
78 | ||
|
79 | /*! | |
|
80 | Returns the pointer to the associated chart | |
|
81 | */ | |
|
82 | QChart* QChartView::chart() const | |
|
83 | { | |
|
84 | return d_ptr->m_chart; | |
|
85 | } | |
|
86 | ||
|
87 | /*! | |
|
88 | Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed. | |
|
89 | */ | |
|
90 | void QChartView::setRubberBand(const RubberBands& rubberBand) | |
|
91 | { | |
|
92 | d_ptr->m_rubberBandFlags=rubberBand; | |
|
93 | ||
|
94 | if (!d_ptr->m_rubberBandFlags) { | |
|
95 | delete d_ptr->m_rubberBand; | |
|
96 | d_ptr->m_rubberBand=0; | |
|
97 | return; | |
|
98 | } | |
|
99 | ||
|
100 | if (!d_ptr->m_rubberBand) { | |
|
101 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
|
102 | d_ptr->m_rubberBand->setEnabled(true); | |
|
103 | } | |
|
104 | } | |
|
105 | ||
|
106 | /*! | |
|
107 | Returns the RubberBandPolicy that is currently being used by the widget. | |
|
108 | */ | |
|
109 | QChartView::RubberBands QChartView::rubberBand() const | |
|
110 | { | |
|
111 | return d_ptr->m_rubberBandFlags; | |
|
112 | } | |
|
113 | ||
|
114 | /*! | |
|
115 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
|
116 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. | |
|
117 | */ | |
|
118 | void QChartView::mousePressEvent(QMouseEvent *event) | |
|
119 | { | |
|
120 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
|
121 | ||
|
122 | int padding = d_ptr->m_chart->margins().top(); | |
|
123 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
|
124 | ||
|
125 | if (rect.contains(event->pos())) { | |
|
126 | d_ptr->m_rubberBandOrigin = event->pos(); | |
|
127 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
|
128 | d_ptr->m_rubberBand->show(); | |
|
129 | event->accept(); | |
|
130 | } | |
|
131 | } | |
|
132 | else { | |
|
133 | QGraphicsView::mousePressEvent(event); | |
|
134 | } | |
|
135 | } | |
|
136 | ||
|
137 | /*! | |
|
138 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
|
139 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
|
140 | */ | |
|
141 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
|
142 | { | |
|
143 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
|
144 | QRectF margins = d_ptr->m_chart->margins(); | |
|
145 | QRectF geometry = d_ptr->m_chart->geometry(); | |
|
146 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); | |
|
147 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
|
148 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
|
149 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
|
150 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
|
151 | height = rect.height(); | |
|
152 | } | |
|
153 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
|
154 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
|
155 | width= rect.width(); | |
|
156 | } | |
|
157 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); | |
|
158 | } | |
|
159 | else { | |
|
160 | QGraphicsView::mouseMoveEvent(event); | |
|
161 | } | |
|
162 | } | |
|
163 | ||
|
164 | /*! | |
|
165 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand | |
|
166 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
|
167 | */ | |
|
168 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
|
169 | { | |
|
170 | if(d_ptr->m_rubberBand) { | |
|
171 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
|
172 | d_ptr->m_rubberBand->hide(); | |
|
173 | QRect rect = d_ptr->m_rubberBand->geometry(); | |
|
174 | d_ptr->m_chart->zoomIn(rect); | |
|
175 | event->accept(); | |
|
176 | } | |
|
177 | ||
|
178 | if(event->button()==Qt::RightButton){ | |
|
179 | d_ptr->m_chart->zoomOut(); | |
|
180 | event->accept(); | |
|
181 | } | |
|
182 | } | |
|
183 | else { | |
|
184 | QGraphicsView::mouseReleaseEvent(event); | |
|
185 | } | |
|
186 | } | |
|
187 | ||
|
188 | /*! | |
|
189 | Resizes and updates the chart area using the \a event data | |
|
190 | */ | |
|
191 | void QChartView::resizeEvent(QResizeEvent *event) | |
|
192 | { | |
|
193 | QGraphicsView::resizeEvent(event); | |
|
194 | d_ptr->m_chart->resize(size()); | |
|
195 | setMinimumSize(d_ptr->m_chart->minimumSize().toSize()); | |
|
196 | setSceneRect(d_ptr->m_chart->geometry()); | |
|
197 | } | |
|
198 | ||
|
199 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
200 | ||
|
201 | QChartViewPrivate::QChartViewPrivate(): | |
|
202 | m_scene(0), | |
|
203 | m_chart(0), | |
|
204 | m_presenter(0), | |
|
205 | m_rubberBand(0), | |
|
206 | m_rubberBandFlags(QChartView::NoRubberBand) | |
|
207 | { | |
|
208 | ||
|
209 | } | |
|
210 | ||
|
211 | QChartViewPrivate::~QChartViewPrivate() | |
|
212 | { | |
|
213 | ||
|
214 | } | |
|
215 | ||
|
216 | #include "moc_qchartview.cpp" | |
|
217 | ||
|
218 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -33,6 +33,7 | |||
|
33 | 33 | #include "qchartview.h" |
|
34 | 34 | |
|
35 | 35 | class QGraphicsScene; |
|
36 | class ChartPresenter; | |
|
36 | 37 | |
|
37 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 39 |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QSERIES_P_H |
|
|
31 |
#define QSERIES_P_H |
|
|
30 | #ifndef QSERIES_P_H | |
|
31 | #define QSERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qseries.h" |
|
34 | 34 |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QSCATTERSERIES_P_H |
|
|
31 |
#define QSCATTERSERIES_P_H |
|
|
30 | #ifndef QSCATTERSERIES_P_H | |
|
31 | #define QSCATTERSERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qxyseries_p.h" |
|
34 | 34 |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef SCATTER |
|
|
22 |
#define SCATTER |
|
|
21 | #ifndef SCATTERCHARTITEM_H | |
|
22 | #define SCATTERCHARTITEM_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "xychartitem_p.h" |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef SCROLLER_P_H |
|
|
31 |
#define SCROLLER_P_H |
|
|
30 | #ifndef SCROLLER_P_H | |
|
31 | #define SCROLLER_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include <QBasicTimer> |
@@ -27,8 +27,8 | |||
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef QSPLINESERIES_P_H |
|
|
31 |
#define QSPLINESERIES_P_H |
|
|
30 | #ifndef QSPLINESERIES_P_H | |
|
31 | #define QSPLINESERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qlineseries_p.h" |
|
34 | 34 |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTTHEMEBLUE |
|
|
22 |
#define CHARTTHEMEBLUE |
|
|
21 | #ifndef CHARTTHEMEBLUEICY_P_H | |
|
22 | #define CHARTTHEMEBLUEICY_P_H | |
|
23 | 23 | |
|
24 | 24 | #include "charttheme_p.h" |
|
25 | 25 |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef CHARTTHEME |
|
|
22 |
#define CHARTTHEME |
|
|
21 | #ifndef CHARTTHEMELIGHT_P_H | |
|
22 | #define CHARTTHEMELIGHT_P_H | |
|
23 | 23 | |
|
24 | 24 | #include "charttheme_p.h" |
|
25 | 25 |
General Comments 0
You need to be logged in to leave comments.
Login now