@@ -1,115 +1,115 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 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 "chartview.h" |
|
21 | #include "chartview.h" | |
22 | #include <QLineSeries> |
|
22 | #include <QLineSeries> | |
23 | #include <QScatterSeries> |
|
23 | #include <QScatterSeries> | |
24 | #include <QSplineSeries> |
|
24 | #include <QSplineSeries> | |
25 | #include <QAreaSeries> |
|
25 | #include <QAreaSeries> | |
26 | #include <QTime> |
|
26 | #include <QTime> | |
27 |
|
27 | |||
28 | ChartView::ChartView(QChart* chart,QWidget* parent):QChartView(chart,parent), |
|
28 | ChartView::ChartView(QChart* chart,QWidget* parent):QChartView(chart,parent), | |
29 | m_index(-1),m_chart(chart) |
|
29 | m_index(-1),m_chart(chart) | |
30 | { |
|
30 | { | |
31 | m_chart->setTitle("Charts presenter"); |
|
31 | m_chart->setTitle("Charts presenter"); | |
32 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); |
|
32 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); | |
33 | m_timer.setInterval(3000); |
|
33 | m_timer.setInterval(3000); | |
34 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QLineSeries* series0 = new QLineSeries(this); |
|
36 | QLineSeries* series0 = new QLineSeries(this); | |
37 | QPen blue(Qt::blue); |
|
37 | QPen blue(Qt::blue); | |
38 | blue.setWidth(3); |
|
38 | blue.setWidth(3); | |
39 | series0->setPen(blue); |
|
39 | series0->setPen(blue); | |
40 |
|
40 | |||
41 | QScatterSeries* series1 = new QScatterSeries(this); |
|
41 | QScatterSeries* series1 = new QScatterSeries(this); | |
42 | QPen red(Qt::red); |
|
42 | QPen red(Qt::red); | |
43 | red.setWidth(3); |
|
43 | red.setWidth(3); | |
44 | series1->setPen(red); |
|
44 | series1->setPen(red); | |
45 | series1->setBrush(Qt::white); |
|
45 | series1->setBrush(Qt::white); | |
46 |
|
46 | |||
47 | QSplineSeries* series2 = new QSplineSeries(this); |
|
47 | QSplineSeries* series2 = new QSplineSeries(this); | |
48 | QPen green(Qt::green); |
|
48 | QPen green(Qt::green); | |
49 | green.setWidth(3); |
|
49 | green.setWidth(3); | |
50 | series2->setPen(green); |
|
50 | series2->setPen(green); | |
51 |
|
51 | |||
52 | QAreaSeries* series3 = new QAreaSeries(series0); |
|
52 | QAreaSeries* series3 = new QAreaSeries(series0); | |
53 | QPen yellow(Qt::black); |
|
53 | QPen yellow(Qt::black); | |
54 | yellow.setWidth(3); |
|
54 | yellow.setWidth(3); | |
55 | series3->setPen(yellow); |
|
55 | series3->setPen(yellow); | |
56 | series3->setBrush(Qt::yellow); |
|
56 | series3->setBrush(Qt::yellow); | |
57 | //![1] |
|
57 | //![1] | |
58 |
|
58 | |||
59 | //![2] |
|
59 | //![2] | |
60 | int numPoints = 10; |
|
60 | int numPoints = 10; | |
61 |
|
61 | |||
62 | for (int x = 0; x <= numPoints; ++x) { |
|
62 | for (int x = 0; x <= numPoints; ++x) { | |
63 | qreal y = qrand() % 100; |
|
63 | qreal y = qrand() % 100; | |
64 | series0->append(x,y); |
|
64 | series0->append(x,y); | |
65 | series1->append(x,y); |
|
65 | series1->append(x,y); | |
66 | series2->append(x,y); |
|
66 | series2->append(x,y); | |
67 | } |
|
67 | } | |
68 | //![2] |
|
68 | //![2] | |
69 |
|
69 | |||
70 | //![3] |
|
70 | //![3] | |
71 | m_series<<series0; |
|
71 | m_series<<series0; | |
72 | m_titles<< m_chart->title()+": LineChart"; |
|
72 | m_titles<< m_chart->title()+": LineChart"; | |
73 | m_series<<series1; |
|
73 | m_series<<series1; | |
74 | m_titles<< m_chart->title()+": ScatterChart"; |
|
74 | m_titles<< m_chart->title()+": ScatterChart"; | |
75 | m_series<<series2; |
|
75 | m_series<<series2; | |
76 | m_titles<< m_chart->title()+": SplineChart"; |
|
76 | m_titles<< m_chart->title()+": SplineChart"; | |
77 | m_series<<series3; |
|
77 | m_series<<series3; | |
78 | m_titles<< m_chart->title()+": AreaChart"; |
|
78 | m_titles<< m_chart->title()+": AreaChart"; | |
79 | //![3] |
|
79 | //![3] | |
80 |
|
80 | |||
81 | //![4] |
|
81 | //![4] | |
82 | foreach (QSeries* series, m_series) { |
|
82 | foreach (QSeries* series, m_series) { | |
83 | QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&))); |
|
83 | QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&))); | |
84 | } |
|
84 | } | |
85 | //![4] |
|
85 | //![4] | |
86 | QTimer::singleShot(0,this,SLOT(handleTimeout())); |
|
|||
87 | m_timer.start(); |
|
86 | m_timer.start(); | |
|
87 | handleTimeout(); | |||
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | ChartView::~ChartView() |
|
90 | ChartView::~ChartView() | |
91 | { |
|
91 | { | |
92 | if(m_series.size()==0) return; |
|
92 | if(m_series.size()==0) return; | |
93 | m_chart->removeSeries(m_series.at(m_index)); |
|
93 | m_chart->removeSeries(m_series.at(m_index)); | |
94 | qDeleteAll(m_series); |
|
94 | qDeleteAll(m_series); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | //![5] |
|
97 | //![5] | |
98 | void ChartView::handleTimeout() |
|
98 | void ChartView::handleTimeout() | |
99 | { |
|
99 | { | |
100 | if(m_series.size()==0) return; |
|
100 | if(m_series.size()==0) return; | |
101 | if(m_index>=0) |
|
101 | if(m_index>=0) | |
102 | m_chart->removeSeries(m_series.at(m_index)); |
|
102 | m_chart->removeSeries(m_series.at(m_index)); | |
103 | m_index++; |
|
103 | m_index++; | |
104 | m_index=m_index%m_series.size(); |
|
104 | m_index=m_index%m_series.size(); | |
105 | m_chart->addSeries(m_series.at(m_index)); |
|
105 | m_chart->addSeries(m_series.at(m_index)); | |
106 | m_chart->setTitle(m_titles.at(m_index)); |
|
106 | m_chart->setTitle(m_titles.at(m_index)); | |
107 | } |
|
107 | } | |
108 | //![5] |
|
108 | //![5] | |
109 |
|
109 | |||
110 | //![6] |
|
110 | //![6] | |
111 | void ChartView::handlePointClicked(const QPointF& point) |
|
111 | void ChartView::handlePointClicked(const QPointF& point) | |
112 | { |
|
112 | { | |
113 | m_chart->setTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y())); |
|
113 | m_chart->setTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y())); | |
114 | } |
|
114 | } | |
115 | //![6] |
|
115 | //![6] |
@@ -1,536 +1,529 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 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 "qchartaxis.h" |
|
23 | #include "qchartaxis.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
26 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
27 | #include "chartanimator_p.h" |
|
27 | #include "chartanimator_p.h" | |
28 | //series |
|
28 | //series | |
29 | #include "qbarseries.h" |
|
29 | #include "qbarseries.h" | |
30 | #include "qstackedbarseries.h" |
|
30 | #include "qstackedbarseries.h" | |
31 | #include "qpercentbarseries.h" |
|
31 | #include "qpercentbarseries.h" | |
32 | #include "qlineseries.h" |
|
32 | #include "qlineseries.h" | |
33 | #include "qareaseries.h" |
|
33 | #include "qareaseries.h" | |
34 | #include "qpieseries.h" |
|
34 | #include "qpieseries.h" | |
35 | #include "qscatterseries.h" |
|
35 | #include "qscatterseries.h" | |
36 | #include "qsplineseries.h" |
|
36 | #include "qsplineseries.h" | |
37 | //items |
|
37 | //items | |
38 | #include "axisitem_p.h" |
|
38 | #include "axisitem_p.h" | |
39 | #include "areachartitem_p.h" |
|
39 | #include "areachartitem_p.h" | |
40 | #include "barchartitem_p.h" |
|
40 | #include "barchartitem_p.h" | |
41 | #include "stackedbarchartitem_p.h" |
|
41 | #include "stackedbarchartitem_p.h" | |
42 | #include "percentbarchartitem_p.h" |
|
42 | #include "percentbarchartitem_p.h" | |
43 | #include "linechartitem_p.h" |
|
43 | #include "linechartitem_p.h" | |
44 | #include "piechartitem_p.h" |
|
44 | #include "piechartitem_p.h" | |
45 | #include "scatterchartitem_p.h" |
|
45 | #include "scatterchartitem_p.h" | |
46 | #include "splinechartitem_p.h" |
|
46 | #include "splinechartitem_p.h" | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
49 |
|
49 | |||
50 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
50 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
51 | m_chart(chart), |
|
51 | m_chart(chart), | |
52 | m_animator(0), |
|
52 | m_animator(0), | |
53 | m_dataset(dataset), |
|
53 | m_dataset(dataset), | |
54 | m_chartTheme(0), |
|
54 | m_chartTheme(0), | |
55 | m_chartRect(QRectF(QPoint(0,0),m_chart->size())), |
|
55 | m_chartRect(QRectF(QPoint(0,0),m_chart->size())), | |
56 | m_options(QChart::NoAnimation), |
|
56 | m_options(QChart::NoAnimation), | |
57 | m_themeForce(false), |
|
57 | m_themeForce(false), | |
58 | m_minLeftMargin(0), |
|
58 | m_minLeftMargin(0), | |
59 | m_minBottomMargin(0), |
|
59 | m_minBottomMargin(0), | |
60 | m_backgroundItem(0), |
|
60 | m_backgroundItem(0), | |
61 | m_titleItem(0), |
|
61 | m_titleItem(0), | |
62 | m_marginBig(60), |
|
62 | m_marginBig(60), | |
63 | m_marginSmall(20), |
|
63 | m_marginSmall(20), | |
64 | m_marginTiny(10), |
|
64 | m_marginTiny(10), | |
65 | m_chartMargins(QRect(m_marginBig,m_marginBig,0,0)) |
|
65 | m_chartMargins(QRect(m_marginBig,m_marginBig,0,0)) | |
66 | { |
|
66 | { | |
67 | createConnections(); |
|
|||
68 | } |
|
67 | } | |
69 |
|
68 | |||
70 | ChartPresenter::~ChartPresenter() |
|
69 | ChartPresenter::~ChartPresenter() | |
71 | { |
|
70 | { | |
72 | delete m_chartTheme; |
|
71 | delete m_chartTheme; | |
73 | } |
|
72 | } | |
74 |
|
73 | |||
75 | void ChartPresenter::createConnections() |
|
|||
76 | { |
|
|||
77 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
|||
78 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
|||
79 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
|||
80 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
|||
81 | } |
|
|||
82 |
|
||||
83 | void ChartPresenter::setGeometry(const QRectF& rect) |
|
74 | void ChartPresenter::setGeometry(const QRectF& rect) | |
84 | { |
|
75 | { | |
85 | m_rect = rect; |
|
76 | m_rect = rect; | |
86 | Q_ASSERT(m_rect.isValid()); |
|
77 | Q_ASSERT(m_rect.isValid()); | |
87 | updateLayout(); |
|
78 | updateLayout(); | |
88 | } |
|
79 | } | |
89 |
|
80 | |||
90 | void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width) |
|
81 | void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width) | |
91 | { |
|
82 | { | |
92 | switch(axis->axisType()){ |
|
83 | switch(axis->axisType()){ | |
93 | case Axis::X_AXIS: |
|
84 | case Axis::X_AXIS: | |
94 | { |
|
85 | { | |
95 | if(width>m_chartRect.width()+ m_chartMargins.left()) { |
|
86 | if(width>m_chartRect.width()+ m_chartMargins.left()) { | |
96 | m_minLeftMargin= width - m_chartRect.width(); |
|
87 | m_minLeftMargin= width - m_chartRect.width(); | |
97 | updateLayout(); |
|
88 | updateLayout(); | |
98 | } |
|
89 | } | |
99 | break; |
|
90 | break; | |
100 | } |
|
91 | } | |
101 | case Axis::Y_AXIS: |
|
92 | case Axis::Y_AXIS: | |
102 | { |
|
93 | { | |
103 |
|
94 | |||
104 | if(m_minLeftMargin!=width){ |
|
95 | if(m_minLeftMargin!=width){ | |
105 | m_minLeftMargin= width; |
|
96 | m_minLeftMargin= width; | |
106 | updateLayout(); |
|
97 | updateLayout(); | |
107 | } |
|
98 | } | |
108 | break; |
|
99 | break; | |
109 | } |
|
100 | } | |
110 |
|
101 | |||
111 | } |
|
102 | } | |
112 | } |
|
103 | } | |
113 |
|
104 | |||
114 | void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height) |
|
105 | void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height) | |
115 | { |
|
106 | { | |
116 | switch(axis->axisType()){ |
|
107 | switch(axis->axisType()){ | |
117 | case Axis::X_AXIS: |
|
108 | case Axis::X_AXIS: | |
118 | { |
|
109 | { | |
119 | if(m_minBottomMargin!=height) { |
|
110 | if(m_minBottomMargin!=height) { | |
120 | m_minBottomMargin= height; |
|
111 | m_minBottomMargin= height; | |
121 | updateLayout(); |
|
112 | updateLayout(); | |
122 | } |
|
113 | } | |
123 | break; |
|
114 | break; | |
124 | } |
|
115 | } | |
125 | case Axis::Y_AXIS: |
|
116 | case Axis::Y_AXIS: | |
126 | { |
|
117 | { | |
127 |
|
118 | |||
128 | if(height>m_chartMargins.bottom()+m_chartRect.height()){ |
|
119 | if(height>m_chartMargins.bottom()+m_chartRect.height()){ | |
129 | m_minBottomMargin= height - m_chartRect.height(); |
|
120 | m_minBottomMargin= height - m_chartRect.height(); | |
130 | updateLayout(); |
|
121 | updateLayout(); | |
131 | } |
|
122 | } | |
132 | break; |
|
123 | break; | |
133 | } |
|
124 | } | |
134 |
|
125 | |||
135 | } |
|
126 | } | |
136 | } |
|
127 | } | |
137 |
|
128 | |||
138 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
129 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
139 | { |
|
130 | { | |
140 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); |
|
131 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); | |
141 |
|
132 | |||
142 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
133 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
143 | m_animator->addAnimation(item); |
|
134 | m_animator->addAnimation(item); | |
144 | } |
|
135 | } | |
145 |
|
136 | |||
146 | if(axis==m_dataset->axisX()){ |
|
137 | if(axis==m_dataset->axisX()){ | |
147 | m_chartTheme->decorate(axis,true,m_themeForce); |
|
138 | m_chartTheme->decorate(axis,true,m_themeForce); | |
148 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
139 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
149 | //initialize |
|
140 | //initialize | |
150 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
141 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
151 |
|
142 | |||
152 | } |
|
143 | } | |
153 | else{ |
|
144 | else{ | |
154 | m_chartTheme->decorate(axis,false,m_themeForce); |
|
145 | m_chartTheme->decorate(axis,false,m_themeForce); | |
155 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
146 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
156 | //initialize |
|
147 | //initialize | |
157 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
148 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
158 | } |
|
149 | } | |
159 |
|
150 | |||
160 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
151 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
161 | //initialize |
|
152 | //initialize | |
162 | item->handleGeometryChanged(m_chartRect); |
|
153 | item->handleGeometryChanged(m_chartRect); | |
163 | m_axisItems.insert(axis, item); |
|
154 | m_axisItems.insert(axis, item); | |
164 | } |
|
155 | } | |
165 |
|
156 | |||
166 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
157 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
167 | { |
|
158 | { | |
168 | Axis* item = m_axisItems.take(axis); |
|
159 | Axis* item = m_axisItems.take(axis); | |
169 | Q_ASSERT(item); |
|
160 | Q_ASSERT(item); | |
170 | if(m_animator) m_animator->removeAnimation(item); |
|
161 | if(m_animator) m_animator->removeAnimation(item); | |
171 | delete item; |
|
162 | delete item; | |
172 | } |
|
163 | } | |
173 |
|
164 | |||
174 |
|
165 | |||
175 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
166 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
176 | { |
|
167 | { | |
177 | Chart *item = 0 ; |
|
168 | Chart *item = 0 ; | |
178 |
|
169 | |||
179 | switch(series->type()) |
|
170 | switch(series->type()) | |
180 | { |
|
171 | { | |
181 | case QSeries::SeriesTypeLine: { |
|
172 | case QSeries::SeriesTypeLine: { | |
182 |
|
173 | |||
183 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
174 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
184 | LineChartItem* line = new LineChartItem(lineSeries,this); |
|
175 | LineChartItem* line = new LineChartItem(lineSeries,this); | |
185 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
176 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
186 | m_animator->addAnimation(line); |
|
177 | m_animator->addAnimation(line); | |
187 | } |
|
178 | } | |
188 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
179 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
189 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
180 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); | |
190 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
181 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
191 | item = line; |
|
182 | item = line; | |
192 | break; |
|
183 | break; | |
193 | } |
|
184 | } | |
194 |
|
185 | |||
195 | case QSeries::SeriesTypeArea: { |
|
186 | case QSeries::SeriesTypeArea: { | |
196 |
|
187 | |||
197 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
188 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
198 | AreaChartItem* area = new AreaChartItem(areaSeries,this); |
|
189 | AreaChartItem* area = new AreaChartItem(areaSeries,this); | |
199 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
190 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
200 | m_animator->addAnimation(area->upperLineItem()); |
|
191 | m_animator->addAnimation(area->upperLineItem()); | |
201 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
192 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | |
202 | } |
|
193 | } | |
203 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
194 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); | |
204 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
195 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); | |
205 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
196 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
206 | item=area; |
|
197 | item=area; | |
207 | break; |
|
198 | break; | |
208 | } |
|
199 | } | |
209 |
|
200 | |||
210 | case QSeries::SeriesTypeBar: { |
|
201 | case QSeries::SeriesTypeBar: { | |
211 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
202 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
212 | BarChartItem* bar = new BarChartItem(barSeries,this); |
|
203 | BarChartItem* bar = new BarChartItem(barSeries,this); | |
213 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
204 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
214 | m_animator->addAnimation(bar); |
|
205 | m_animator->addAnimation(bar); | |
215 | } |
|
206 | } | |
216 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); |
|
207 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); | |
217 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
208 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
218 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
209 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
219 | item=bar; |
|
210 | item=bar; | |
220 | break; |
|
211 | break; | |
221 | } |
|
212 | } | |
222 |
|
213 | |||
223 | case QSeries::SeriesTypeStackedBar: { |
|
214 | case QSeries::SeriesTypeStackedBar: { | |
224 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
215 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
225 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this); |
|
216 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this); | |
226 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
217 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
227 | m_animator->addAnimation(bar); |
|
218 | m_animator->addAnimation(bar); | |
228 | } |
|
219 | } | |
229 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); |
|
220 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); | |
230 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
221 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
231 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
222 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
232 | item=bar; |
|
223 | item=bar; | |
233 | break; |
|
224 | break; | |
234 | } |
|
225 | } | |
235 |
|
226 | |||
236 | case QSeries::SeriesTypePercentBar: { |
|
227 | case QSeries::SeriesTypePercentBar: { | |
237 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
228 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
238 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this); |
|
229 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this); | |
239 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
230 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
240 | m_animator->addAnimation(bar); |
|
231 | m_animator->addAnimation(bar); | |
241 | } |
|
232 | } | |
242 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); |
|
233 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); | |
243 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
234 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
244 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
235 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
245 | item=bar; |
|
236 | item=bar; | |
246 | break; |
|
237 | break; | |
247 | } |
|
238 | } | |
248 |
|
239 | |||
249 | case QSeries::SeriesTypeScatter: { |
|
240 | case QSeries::SeriesTypeScatter: { | |
250 |
|
241 | |||
251 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
242 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
252 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this); |
|
243 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this); | |
253 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
244 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
254 | m_animator->addAnimation(scatter); |
|
245 | m_animator->addAnimation(scatter); | |
255 | } |
|
246 | } | |
256 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
247 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); | |
257 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); |
|
248 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); | |
258 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
249 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
259 | item = scatter; |
|
250 | item = scatter; | |
260 | break; |
|
251 | break; | |
261 | } |
|
252 | } | |
262 |
|
253 | |||
263 | case QSeries::SeriesTypePie: { |
|
254 | case QSeries::SeriesTypePie: { | |
264 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
255 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
265 | PieChartItem* pie = new PieChartItem(pieSeries, this); |
|
256 | PieChartItem* pie = new PieChartItem(pieSeries, this); | |
266 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
257 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
267 | m_animator->addAnimation(pie); |
|
258 | m_animator->addAnimation(pie); | |
268 | } |
|
259 | } | |
269 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
260 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); | |
270 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
261 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); | |
271 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
262 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
272 | // Hide all from background when there is only piechart |
|
263 | // Hide all from background when there is only piechart | |
273 | // TODO: refactor this ugly code... should be one setting for this |
|
264 | // TODO: refactor this ugly code... should be one setting for this | |
274 | if (m_chartItems.count() == 0) { |
|
265 | if (m_chartItems.count() == 0) { | |
275 | m_chart->axisX()->hide(); |
|
266 | m_chart->axisX()->hide(); | |
276 | m_chart->axisY()->hide(); |
|
267 | m_chart->axisY()->hide(); | |
277 | } |
|
268 | } | |
278 | item=pie; |
|
269 | item=pie; | |
279 | break; |
|
270 | break; | |
280 | } |
|
271 | } | |
281 |
|
272 | |||
282 | case QSeries::SeriesTypeSpline: { |
|
273 | case QSeries::SeriesTypeSpline: { | |
283 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
274 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
284 | SplineChartItem* spline = new SplineChartItem(splineSeries, this); |
|
275 | SplineChartItem* spline = new SplineChartItem(splineSeries, this); | |
285 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
276 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
286 | m_animator->addAnimation(spline); |
|
277 | m_animator->addAnimation(spline); | |
287 | } |
|
278 | } | |
288 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
279 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
289 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); |
|
280 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); | |
290 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
281 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
291 | item=spline; |
|
282 | item=spline; | |
292 | break; |
|
283 | break; | |
293 | } |
|
284 | } | |
294 | default: { |
|
285 | default: { | |
295 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
286 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
296 | break; |
|
287 | break; | |
297 | } |
|
288 | } | |
298 | } |
|
289 | } | |
299 |
|
290 | |||
300 | //initialize |
|
291 | //initialize | |
301 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
292 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
302 | if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect); |
|
293 | if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect); | |
303 | m_chartItems.insert(series,item); |
|
294 | m_chartItems.insert(series,item); | |
304 | } |
|
295 | } | |
305 |
|
296 | |||
306 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
297 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
307 | { |
|
298 | { | |
308 | Chart* item = m_chartItems.take(series); |
|
299 | Chart* item = m_chartItems.take(series); | |
309 | Q_ASSERT(item); |
|
300 | Q_ASSERT(item); | |
310 | if(m_animator) { |
|
301 | if(m_animator) { | |
311 | //small hack to handle area animations |
|
302 | //small hack to handle area animations | |
312 | if(series->type()==QSeries::SeriesTypeArea){ |
|
303 | if(series->type()==QSeries::SeriesTypeArea){ | |
313 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
304 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
314 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
305 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
315 | m_animator->removeAnimation(area->upperLineItem()); |
|
306 | m_animator->removeAnimation(area->upperLineItem()); | |
316 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); |
|
307 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | |
317 | }else |
|
308 | }else | |
318 | m_animator->removeAnimation(item); |
|
309 | m_animator->removeAnimation(item); | |
319 | } |
|
310 | } | |
320 | delete item; |
|
311 | delete item; | |
321 | } |
|
312 | } | |
322 |
|
313 | |||
323 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
314 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
324 | { |
|
315 | { | |
325 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
316 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
326 | delete m_chartTheme; |
|
317 | delete m_chartTheme; | |
327 | m_themeForce = force; |
|
318 | m_themeForce = force; | |
328 | m_chartTheme = ChartTheme::createTheme(theme); |
|
319 | m_chartTheme = ChartTheme::createTheme(theme); | |
329 | m_chartTheme->decorate(m_chart,m_themeForce); |
|
320 | m_chartTheme->decorate(m_chart,m_themeForce); | |
330 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); |
|
321 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); | |
331 | resetAllElements(); |
|
322 | resetAllElements(); | |
332 | } |
|
323 | } | |
333 |
|
324 | |||
334 | QChart::ChartTheme ChartPresenter::theme() |
|
325 | QChart::ChartTheme ChartPresenter::theme() | |
335 | { |
|
326 | { | |
336 | return m_chartTheme->id(); |
|
327 | return m_chartTheme->id(); | |
337 | } |
|
328 | } | |
338 |
|
329 | |||
339 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
330 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
340 | { |
|
331 | { | |
341 | if(m_options!=options) { |
|
332 | if(m_options!=options) { | |
342 |
|
333 | |||
343 | m_options=options; |
|
334 | m_options=options; | |
344 |
|
335 | |||
345 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
336 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
346 | m_animator= new ChartAnimator(this); |
|
337 | m_animator= new ChartAnimator(this); | |
347 | } |
|
338 | } | |
348 | resetAllElements(); |
|
339 | resetAllElements(); | |
349 | } |
|
340 | } | |
350 |
|
341 | |||
351 | } |
|
342 | } | |
352 |
|
343 | |||
353 | void ChartPresenter::resetAllElements() |
|
344 | void ChartPresenter::resetAllElements() | |
354 | { |
|
345 | { | |
355 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
346 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
356 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
347 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
357 |
|
348 | |||
358 | foreach(QChartAxis* axis, axisList) { |
|
349 | foreach(QChartAxis* axis, axisList) { | |
359 | handleAxisRemoved(axis); |
|
350 | handleAxisRemoved(axis); | |
360 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
351 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
361 | } |
|
352 | } | |
362 | foreach(QSeries* series, seriesList) { |
|
353 | foreach(QSeries* series, seriesList) { | |
363 | handleSeriesRemoved(series); |
|
354 | handleSeriesRemoved(series); | |
364 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
355 | handleSeriesAdded(series,m_dataset->domain(series)); | |
365 | } |
|
356 | } | |
366 | } |
|
357 | } | |
367 |
|
358 | |||
368 | void ChartPresenter::zoomIn() |
|
359 | void ChartPresenter::zoomIn() | |
369 | { |
|
360 | { | |
370 | QRectF rect = chartGeometry(); |
|
361 | QRectF rect = chartGeometry(); | |
371 | rect.setWidth(rect.width()/2); |
|
362 | rect.setWidth(rect.width()/2); | |
372 | rect.setHeight(rect.height()/2); |
|
363 | rect.setHeight(rect.height()/2); | |
373 | rect.moveCenter(chartGeometry().center()); |
|
364 | rect.moveCenter(chartGeometry().center()); | |
374 | zoomIn(rect); |
|
365 | zoomIn(rect); | |
375 | } |
|
366 | } | |
376 |
|
367 | |||
377 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
368 | void ChartPresenter::zoomIn(const QRectF& rect) | |
378 | { |
|
369 | { | |
379 | QRectF r = rect.normalized(); |
|
370 | QRectF r = rect.normalized(); | |
380 | r.translate(-m_chartMargins.topLeft()); |
|
371 | r.translate(-m_chartMargins.topLeft()); | |
381 | if(m_animator) { |
|
372 | if(m_animator) { | |
382 |
|
373 | |||
383 | QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); |
|
374 | QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); | |
384 | m_animator->setState(ChartAnimator::ZoomInState,point); |
|
375 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
385 | } |
|
376 | } | |
386 | m_dataset->zoomInDomain(r,chartGeometry().size()); |
|
377 | m_dataset->zoomInDomain(r,chartGeometry().size()); | |
387 | if(m_animator) { |
|
378 | if(m_animator) { | |
388 | m_animator->setState(ChartAnimator::ShowState); |
|
379 | m_animator->setState(ChartAnimator::ShowState); | |
389 | } |
|
380 | } | |
390 | } |
|
381 | } | |
391 |
|
382 | |||
392 | void ChartPresenter::zoomOut() |
|
383 | void ChartPresenter::zoomOut() | |
393 | { |
|
384 | { | |
394 | if(m_animator) |
|
385 | if(m_animator) | |
395 | { |
|
386 | { | |
396 | m_animator->setState(ChartAnimator::ZoomOutState); |
|
387 | m_animator->setState(ChartAnimator::ZoomOutState); | |
397 | } |
|
388 | } | |
398 |
|
389 | |||
399 | QSizeF size = chartGeometry().size(); |
|
390 | QSizeF size = chartGeometry().size(); | |
400 | QRectF rect = chartGeometry(); |
|
391 | QRectF rect = chartGeometry(); | |
401 | rect.translate(-m_chartMargins.topLeft()); |
|
392 | rect.translate(-m_chartMargins.topLeft()); | |
402 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); |
|
393 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); | |
403 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
394 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
404 |
|
395 | |||
405 | if(m_animator){ |
|
396 | if(m_animator){ | |
406 | m_animator->setState(ChartAnimator::ShowState); |
|
397 | m_animator->setState(ChartAnimator::ShowState); | |
407 | } |
|
398 | } | |
408 | } |
|
399 | } | |
409 |
|
400 | |||
410 | void ChartPresenter::scroll(int dx,int dy) |
|
401 | void ChartPresenter::scroll(int dx,int dy) | |
411 | { |
|
402 | { | |
412 | if(m_animator){ |
|
403 | if(m_animator){ | |
413 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); |
|
404 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
414 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); |
|
405 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
415 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); |
|
406 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
416 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); |
|
407 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
417 | } |
|
408 | } | |
418 |
|
409 | |||
419 | m_dataset->scrollDomain(dx,dy,chartGeometry().size()); |
|
410 | m_dataset->scrollDomain(dx,dy,chartGeometry().size()); | |
420 |
|
411 | |||
421 | if(m_animator){ |
|
412 | if(m_animator){ | |
422 | m_animator->setState(ChartAnimator::ShowState); |
|
413 | m_animator->setState(ChartAnimator::ShowState); | |
423 | } |
|
414 | } | |
424 | } |
|
415 | } | |
425 |
|
416 | |||
426 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
417 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
427 | { |
|
418 | { | |
428 | return m_options; |
|
419 | return m_options; | |
429 | } |
|
420 | } | |
430 |
|
421 | |||
431 | void ChartPresenter::updateLayout() |
|
422 | void ChartPresenter::updateLayout() | |
432 | { |
|
423 | { | |
433 | if (!m_rect.isValid()) return; |
|
424 | if (!m_rect.isValid()) return; | |
434 |
|
425 | |||
435 | // recalculate title size |
|
426 | // recalculate title size | |
436 |
|
427 | |||
437 | QSize titleSize; |
|
428 | QSize titleSize; | |
438 | int titlePadding=0; |
|
429 | int titlePadding=0; | |
439 |
|
430 | |||
440 | if (m_titleItem) { |
|
431 | if (m_titleItem) { | |
441 | titleSize= m_titleItem->boundingRect().size().toSize(); |
|
432 | titleSize= m_titleItem->boundingRect().size().toSize(); | |
442 | } |
|
433 | } | |
443 |
|
434 | |||
444 | //defaults |
|
435 | //defaults | |
445 | m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig)); |
|
436 | m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig)); | |
446 | titlePadding = m_chartMargins.top()/2; |
|
437 | titlePadding = m_chartMargins.top()/2; | |
447 |
|
438 | |||
448 | QLegend* legend = m_chart->d_ptr->m_legend; |
|
439 | QLegend* legend = m_chart->d_ptr->m_legend; | |
449 |
|
440 | |||
450 | // recalculate legend position |
|
441 | // recalculate legend position | |
451 | if (legend->isAttachedToChart() && legend->isEnabled()) { |
|
442 | if (legend->isAttachedToChart() && legend->isEnabled()) { | |
452 |
|
443 | |||
453 | QRect legendRect; |
|
444 | QRect legendRect; | |
454 |
|
445 | |||
455 | // Reserve some space for legend |
|
446 | // Reserve some space for legend | |
456 | switch (legend->alignment()) { |
|
447 | switch (legend->alignment()) { | |
457 |
|
448 | |||
458 | case QLegend::AlignmentTop: { |
|
449 | case QLegend::AlignmentTop: { | |
459 | int ledgendSize = legend->minHeight(); |
|
450 | int ledgendSize = legend->minHeight(); | |
460 | int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; |
|
451 | int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; | |
461 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); |
|
452 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |
462 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny)); |
|
453 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny)); | |
463 | titlePadding = m_marginTiny + m_marginTiny; |
|
454 | titlePadding = m_marginTiny + m_marginTiny; | |
464 | break; |
|
455 | break; | |
465 | } |
|
456 | } | |
466 | case QLegend::AlignmentBottom: { |
|
457 | case QLegend::AlignmentBottom: { | |
467 | int ledgendSize = legend->minHeight(); |
|
458 | int ledgendSize = legend->minHeight(); | |
468 | int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; |
|
459 | int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; | |
469 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); |
|
460 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); | |
470 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall)); |
|
461 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall)); | |
471 | titlePadding = m_chartMargins.top()/2; |
|
462 | titlePadding = m_chartMargins.top()/2; | |
472 | break; |
|
463 | break; | |
473 | } |
|
464 | } | |
474 | case QLegend::AlignmentLeft: { |
|
465 | case QLegend::AlignmentLeft: { | |
475 | int ledgendSize = legend->minWidht(); |
|
466 | int ledgendSize = legend->minWidht(); | |
476 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; |
|
467 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; | |
477 | m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); |
|
468 | m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |
478 | m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom())); |
|
469 | m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom())); | |
479 | titlePadding = m_chartMargins.top()/2; |
|
470 | titlePadding = m_chartMargins.top()/2; | |
480 | break; |
|
471 | break; | |
481 | } |
|
472 | } | |
482 | case QLegend::AlignmentRight: { |
|
473 | case QLegend::AlignmentRight: { | |
483 | int ledgendSize = legend->minWidht(); |
|
474 | int ledgendSize = legend->minWidht(); | |
484 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; |
|
475 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; | |
485 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); |
|
476 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); | |
486 | m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom())); |
|
477 | m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom())); | |
487 | titlePadding = m_chartMargins.top()/2; |
|
478 | titlePadding = m_chartMargins.top()/2; | |
488 | break; |
|
479 | break; | |
489 | } |
|
480 | } | |
490 | default: { |
|
481 | default: { | |
491 | break; |
|
482 | break; | |
492 | } |
|
483 | } | |
493 | } |
|
484 | } | |
494 | } |
|
485 | } | |
495 |
|
486 | |||
496 | // recalculate title position |
|
487 | // recalculate title position | |
497 | if (m_titleItem) { |
|
488 | if (m_titleItem) { | |
498 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
489 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
499 | m_titleItem->setPos(center.x(),titlePadding); |
|
490 | m_titleItem->setPos(center.x(),titlePadding); | |
500 | } |
|
491 | } | |
501 |
|
492 | |||
502 | //recalculate background gradient |
|
493 | //recalculate background gradient | |
503 | if (m_backgroundItem) { |
|
494 | if (m_backgroundItem) { | |
504 | m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny)); |
|
495 | m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny)); | |
505 | } |
|
496 | } | |
506 |
|
497 | |||
507 | QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom()); |
|
498 | QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom()); | |
508 |
|
499 | |||
|
500 | legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); | |||
|
501 | ||||
509 | if(m_chartRect!=chartRect){ |
|
502 | if(m_chartRect!=chartRect){ | |
510 | m_chartRect=chartRect; |
|
503 | m_chartRect=chartRect; | |
511 | emit geometryChanged(m_chartRect); |
|
504 | emit geometryChanged(m_chartRect); | |
512 | } |
|
505 | } | |
513 |
|
506 | |||
514 | legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); |
|
507 | ||
515 | } |
|
508 | } | |
516 |
|
509 | |||
517 | void ChartPresenter::createChartBackgroundItem() |
|
510 | void ChartPresenter::createChartBackgroundItem() | |
518 | { |
|
511 | { | |
519 | if (!m_backgroundItem) { |
|
512 | if (!m_backgroundItem) { | |
520 | m_backgroundItem = new ChartBackground(rootItem()); |
|
513 | m_backgroundItem = new ChartBackground(rootItem()); | |
521 | m_backgroundItem->setPen(Qt::NoPen); |
|
514 | m_backgroundItem->setPen(Qt::NoPen); | |
522 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
515 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
523 | } |
|
516 | } | |
524 | } |
|
517 | } | |
525 |
|
518 | |||
526 | void ChartPresenter::createChartTitleItem() |
|
519 | void ChartPresenter::createChartTitleItem() | |
527 | { |
|
520 | { | |
528 | if (!m_titleItem) { |
|
521 | if (!m_titleItem) { | |
529 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); |
|
522 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); | |
530 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
523 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
531 | } |
|
524 | } | |
532 | } |
|
525 | } | |
533 |
|
526 | |||
534 | #include "moc_chartpresenter_p.cpp" |
|
527 | #include "moc_chartpresenter_p.cpp" | |
535 |
|
528 | |||
536 | QTCOMMERCIALCHART_END_NAMESPACE |
|
529 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,127 +1,126 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 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 CHARTPRESENTER_H_ |
|
21 | #ifndef CHARTPRESENTER_H_ | |
22 | #define CHARTPRESENTER_H_ |
|
22 | #define CHARTPRESENTER_H_ | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "chartbackground_p.h" //TODO fix me |
|
25 | #include "chartbackground_p.h" //TODO fix me | |
26 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
26 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
27 | #include "qchartaxis.h" |
|
27 | #include "qchartaxis.h" | |
28 | #include <QRectF> |
|
28 | #include <QRectF> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class Chart; |
|
32 | class Chart; | |
33 | class QSeries; |
|
33 | class QSeries; | |
34 | class ChartDataSet; |
|
34 | class ChartDataSet; | |
35 | class Domain; |
|
35 | class Domain; | |
36 | class Axis; |
|
36 | class Axis; | |
37 | class ChartTheme; |
|
37 | class ChartTheme; | |
38 | class ChartAnimator; |
|
38 | class ChartAnimator; | |
39 |
|
39 | |||
40 | class ChartPresenter: public QObject |
|
40 | class ChartPresenter: public QObject | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
43 | public: | |
44 | enum ZValues { |
|
44 | enum ZValues { | |
45 | BackgroundZValue = -1, |
|
45 | BackgroundZValue = -1, | |
46 | ShadesZValue, |
|
46 | ShadesZValue, | |
47 | GridZValue, |
|
47 | GridZValue, | |
48 | LineChartZValue, |
|
48 | LineChartZValue, | |
49 | BarSeriesZValue, |
|
49 | BarSeriesZValue, | |
50 | ScatterSeriesZValue, |
|
50 | ScatterSeriesZValue, | |
51 | PieSeriesZValue, |
|
51 | PieSeriesZValue, | |
52 | AxisZValue, |
|
52 | AxisZValue, | |
53 | LegendZValue |
|
53 | LegendZValue | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
56 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
57 | virtual ~ChartPresenter(); |
|
57 | virtual ~ChartPresenter(); | |
58 |
|
58 | |||
59 | ChartAnimator* animator() const { return m_animator; } |
|
59 | ChartAnimator* animator() const { return m_animator; } | |
60 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
60 | ChartTheme *chartTheme() const { return m_chartTheme; } | |
61 | ChartDataSet *dataSet() const { return m_dataset; } |
|
61 | ChartDataSet *dataSet() const { return m_dataset; } | |
62 | QGraphicsItem* rootItem() const { return m_chart; } |
|
62 | QGraphicsItem* rootItem() const { return m_chart; } | |
63 |
|
63 | |||
64 | void setTheme(QChart::ChartTheme theme,bool force = true); |
|
64 | void setTheme(QChart::ChartTheme theme,bool force = true); | |
65 | QChart::ChartTheme theme(); |
|
65 | QChart::ChartTheme theme(); | |
66 |
|
66 | |||
67 | void setAnimationOptions(QChart::AnimationOptions options); |
|
67 | void setAnimationOptions(QChart::AnimationOptions options); | |
68 | QChart::AnimationOptions animationOptions() const; |
|
68 | QChart::AnimationOptions animationOptions() const; | |
69 |
|
69 | |||
70 | void zoomIn(); |
|
70 | void zoomIn(); | |
71 | void zoomIn(const QRectF& rect); |
|
71 | void zoomIn(const QRectF& rect); | |
72 | void zoomOut(); |
|
72 | void zoomOut(); | |
73 | void scroll(int dx,int dy); |
|
73 | void scroll(int dx,int dy); | |
74 |
|
74 | |||
75 | void setGeometry(const QRectF& rect); |
|
75 | void setGeometry(const QRectF& rect); | |
76 | QRectF chartGeometry() const { return m_chartRect; } |
|
76 | QRectF chartGeometry() const { return m_chartRect; } | |
77 |
|
77 | |||
78 | void setMinimumMarginHeight(Axis* axis, qreal height); |
|
78 | void setMinimumMarginHeight(Axis* axis, qreal height); | |
79 | void setMinimumMarginWidth(Axis* axis, qreal width); |
|
79 | void setMinimumMarginWidth(Axis* axis, qreal width); | |
80 | qreal minimumLeftMargin() const { return m_minLeftMargin; } |
|
80 | qreal minimumLeftMargin() const { return m_minLeftMargin; } | |
81 | qreal minimumBottomMargin() const { return m_minBottomMargin; } |
|
81 | qreal minimumBottomMargin() const { return m_minBottomMargin; } | |
82 |
|
82 | |||
83 | public: //TODO: fix me |
|
83 | public: //TODO: fix me | |
84 | void createConnections(); |
|
|||
85 | void resetAllElements(); |
|
84 | void resetAllElements(); | |
86 | void createChartBackgroundItem(); |
|
85 | void createChartBackgroundItem(); | |
87 | void createChartTitleItem(); |
|
86 | void createChartTitleItem(); | |
88 | QRect margins() const { return m_chartMargins;} |
|
87 | QRect margins() const { return m_chartMargins;} | |
89 |
|
88 | |||
90 | public Q_SLOTS: |
|
89 | public Q_SLOTS: | |
91 | void handleSeriesAdded(QSeries* series,Domain* domain); |
|
90 | void handleSeriesAdded(QSeries* series,Domain* domain); | |
92 | void handleSeriesRemoved(QSeries* series); |
|
91 | void handleSeriesRemoved(QSeries* series); | |
93 | void handleAxisAdded(QChartAxis* axis,Domain* domain); |
|
92 | void handleAxisAdded(QChartAxis* axis,Domain* domain); | |
94 | void handleAxisRemoved(QChartAxis* axis); |
|
93 | void handleAxisRemoved(QChartAxis* axis); | |
95 | void updateLayout(); |
|
94 | void updateLayout(); | |
96 |
|
95 | |||
97 | Q_SIGNALS: |
|
96 | Q_SIGNALS: | |
98 | void geometryChanged(const QRectF& rect); |
|
97 | void geometryChanged(const QRectF& rect); | |
99 |
|
98 | |||
100 |
|
99 | |||
101 | private: |
|
100 | private: | |
102 | QChart* m_chart; |
|
101 | QChart* m_chart; | |
103 | ChartAnimator* m_animator; |
|
102 | ChartAnimator* m_animator; | |
104 | ChartDataSet* m_dataset; |
|
103 | ChartDataSet* m_dataset; | |
105 | ChartTheme *m_chartTheme; |
|
104 | ChartTheme *m_chartTheme; | |
106 | QMap<QSeries*,Chart*> m_chartItems; |
|
105 | QMap<QSeries*,Chart*> m_chartItems; | |
107 | QMap<QChartAxis*,Axis*> m_axisItems; |
|
106 | QMap<QChartAxis*,Axis*> m_axisItems; | |
108 | QRectF m_rect; |
|
107 | QRectF m_rect; | |
109 | QRectF m_chartRect; |
|
108 | QRectF m_chartRect; | |
110 | QChart::AnimationOptions m_options; |
|
109 | QChart::AnimationOptions m_options; | |
111 | bool m_themeForce; |
|
110 | bool m_themeForce; | |
112 | qreal m_minLeftMargin; |
|
111 | qreal m_minLeftMargin; | |
113 | qreal m_minBottomMargin; |
|
112 | qreal m_minBottomMargin; | |
114 | public: //TODO: fixme |
|
113 | public: //TODO: fixme | |
115 | ChartBackground* m_backgroundItem; |
|
114 | ChartBackground* m_backgroundItem; | |
116 | QGraphicsSimpleTextItem* m_titleItem; |
|
115 | QGraphicsSimpleTextItem* m_titleItem; | |
117 | int m_marginBig; |
|
116 | int m_marginBig; | |
118 | int m_marginSmall; |
|
117 | int m_marginSmall; | |
119 | int m_marginTiny; |
|
118 | int m_marginTiny; | |
120 | QRect m_chartMargins; |
|
119 | QRect m_chartMargins; | |
121 | QRect m_legendMargins; |
|
120 | QRect m_legendMargins; | |
122 |
|
121 | |||
123 | }; |
|
122 | }; | |
124 |
|
123 | |||
125 | QTCOMMERCIALCHART_END_NAMESPACE |
|
124 | QTCOMMERCIALCHART_END_NAMESPACE | |
126 |
|
125 | |||
127 | #endif /* CHARTPRESENTER_H_ */ |
|
126 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,351 +1,360 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 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 <QGraphicsScene> |
|
23 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
24 | #include <QGraphicsSceneResizeEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChart::ChartTheme |
|
29 | \enum QChart::ChartTheme | |
30 |
|
30 | |||
31 | This enum describes the theme used by the chart. |
|
31 | This enum describes the theme used by the chart. | |
32 |
|
32 | |||
33 | \value ChartThemeLight The default theme |
|
33 | \value ChartThemeLight The default theme | |
34 | \value ChartThemeBlueCerulean |
|
34 | \value ChartThemeBlueCerulean | |
35 | \value ChartThemeDark |
|
35 | \value ChartThemeDark | |
36 | \value ChartThemeBrownSand |
|
36 | \value ChartThemeBrownSand | |
37 | \value ChartThemeBlueNcs |
|
37 | \value ChartThemeBlueNcs | |
38 | \value ChartThemeHighContrast |
|
38 | \value ChartThemeHighContrast | |
39 | \value ChartThemeBlueIcy |
|
39 | \value ChartThemeBlueIcy | |
40 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
40 | \value ChartThemeCount Not really a theme; the total count of themes. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \enum QChart::AnimationOption |
|
44 | \enum QChart::AnimationOption | |
45 |
|
45 | |||
46 | For enabling/disabling animations. Defaults to NoAnimation. |
|
46 | For enabling/disabling animations. Defaults to NoAnimation. | |
47 |
|
47 | |||
48 | \value NoAnimation |
|
48 | \value NoAnimation | |
49 | \value GridAxisAnimations |
|
49 | \value GridAxisAnimations | |
50 | \value SeriesAnimations |
|
50 | \value SeriesAnimations | |
51 | \value AllAnimations |
|
51 | \value AllAnimations | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \class QChart |
|
55 | \class QChart | |
56 | \brief QtCommercial chart API. |
|
56 | \brief QtCommercial chart API. | |
57 |
|
57 | |||
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
59 | representation of different types of QChartSeries and other chart related objects like |
|
59 | representation of different types of QChartSeries and other chart related objects like | |
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
61 | convenience class QChartView instead of QChart. |
|
61 | convenience class QChartView instead of QChart. | |
62 | \sa QChartView |
|
62 | \sa QChartView | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
67 | */ |
|
67 | */ | |
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
69 | d_ptr(new QChartPrivate()) |
|
69 | d_ptr(new QChartPrivate()) | |
70 | { |
|
70 | { | |
71 | d_ptr->m_legend = new ScrolledQLegend(this); |
|
71 | d_ptr->m_legend = new ScrolledQLegend(this); | |
72 | d_ptr->m_dataset = new ChartDataSet(this); |
|
72 | d_ptr->m_dataset = new ChartDataSet(this); | |
73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
74 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
74 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
|
75 | d_ptr->createConnections(); | |||
75 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
76 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |
76 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
|||
77 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
|||
78 | } |
|
77 | } | |
79 |
|
78 | |||
80 | /*! |
|
79 | /*! | |
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
80 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
82 | */ |
|
81 | */ | |
83 | QChart::~QChart() |
|
82 | QChart::~QChart() | |
84 | { |
|
83 | { | |
85 | //delete first presenter , since this is a root of all the graphical items |
|
84 | //delete first presenter , since this is a root of all the graphical items | |
86 | delete d_ptr->m_presenter; |
|
85 | delete d_ptr->m_presenter; | |
87 | d_ptr->m_presenter=0; |
|
86 | d_ptr->m_presenter=0; | |
88 | } |
|
87 | } | |
89 |
|
88 | |||
90 | /*! |
|
89 | /*! | |
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
90 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
91 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
93 | the y axis). |
|
92 | the y axis). | |
94 | */ |
|
93 | */ | |
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
94 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
96 | { |
|
95 | { | |
97 | d_ptr->m_dataset->addSeries(series, axisY); |
|
96 | d_ptr->m_dataset->addSeries(series, axisY); | |
98 | } |
|
97 | } | |
99 |
|
98 | |||
100 | /*! |
|
99 | /*! | |
101 | Removes the \a series specified in a perameter from the QChartView. |
|
100 | Removes the \a series specified in a perameter from the QChartView. | |
102 | It releses its ownership of the specified QChartSeries object. |
|
101 | It releses its ownership of the specified QChartSeries object. | |
103 | It does not delete the pointed QChartSeries data object |
|
102 | It does not delete the pointed QChartSeries data object | |
104 | \sa addSeries(), removeAllSeries() |
|
103 | \sa addSeries(), removeAllSeries() | |
105 | */ |
|
104 | */ | |
106 | void QChart::removeSeries(QSeries* series) |
|
105 | void QChart::removeSeries(QSeries* series) | |
107 | { |
|
106 | { | |
108 | d_ptr->m_dataset->removeSeries(series); |
|
107 | d_ptr->m_dataset->removeSeries(series); | |
109 | } |
|
108 | } | |
110 |
|
109 | |||
111 | /*! |
|
110 | /*! | |
112 | Removes all the QChartSeries that have been added to the QChartView |
|
111 | Removes all the QChartSeries that have been added to the QChartView | |
113 | It also deletes the pointed QChartSeries data objects |
|
112 | It also deletes the pointed QChartSeries data objects | |
114 | \sa addSeries(), removeSeries() |
|
113 | \sa addSeries(), removeSeries() | |
115 | */ |
|
114 | */ | |
116 | void QChart::removeAllSeries() |
|
115 | void QChart::removeAllSeries() | |
117 | { |
|
116 | { | |
118 | d_ptr->m_dataset->removeAllSeries(); |
|
117 | d_ptr->m_dataset->removeAllSeries(); | |
119 | } |
|
118 | } | |
120 |
|
119 | |||
121 | /*! |
|
120 | /*! | |
122 | Sets the \a brush that is used for painting the background of the chart area. |
|
121 | Sets the \a brush that is used for painting the background of the chart area. | |
123 | */ |
|
122 | */ | |
124 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
123 | void QChart::setBackgroundBrush(const QBrush& brush) | |
125 | { |
|
124 | { | |
126 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
125 | d_ptr->m_presenter->createChartBackgroundItem(); | |
127 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
126 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
128 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
127 | d_ptr->m_presenter->m_backgroundItem->update(); | |
129 | } |
|
128 | } | |
130 |
|
129 | |||
131 | QBrush QChart::backgroundBrush() const |
|
130 | QBrush QChart::backgroundBrush() const | |
132 | { |
|
131 | { | |
133 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
132 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
134 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
133 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
135 | } |
|
134 | } | |
136 |
|
135 | |||
137 | /*! |
|
136 | /*! | |
138 | Sets the \a pen that is used for painting the background of the chart area. |
|
137 | Sets the \a pen that is used for painting the background of the chart area. | |
139 | */ |
|
138 | */ | |
140 | void QChart::setBackgroundPen(const QPen& pen) |
|
139 | void QChart::setBackgroundPen(const QPen& pen) | |
141 | { |
|
140 | { | |
142 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
141 | d_ptr->m_presenter->createChartBackgroundItem(); | |
143 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
142 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
144 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
143 | d_ptr->m_presenter->m_backgroundItem->update(); | |
145 | } |
|
144 | } | |
146 |
|
145 | |||
147 | QPen QChart::backgroundPen() const |
|
146 | QPen QChart::backgroundPen() const | |
148 | { |
|
147 | { | |
149 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
148 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
150 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
149 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
151 | } |
|
150 | } | |
152 |
|
151 | |||
153 | /*! |
|
152 | /*! | |
154 | Sets the chart \a title. The description text that is drawn above the chart. |
|
153 | Sets the chart \a title. The description text that is drawn above the chart. | |
155 | */ |
|
154 | */ | |
156 | void QChart::setTitle(const QString& title) |
|
155 | void QChart::setTitle(const QString& title) | |
157 | { |
|
156 | { | |
158 | d_ptr->m_presenter->createChartTitleItem(); |
|
157 | d_ptr->m_presenter->createChartTitleItem(); | |
159 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
158 | d_ptr->m_presenter->m_titleItem->setText(title); | |
160 | d_ptr->m_presenter->updateLayout(); |
|
159 | d_ptr->m_presenter->updateLayout(); | |
161 | } |
|
160 | } | |
162 |
|
161 | |||
163 | /*! |
|
162 | /*! | |
164 | Returns the chart title. The description text that is drawn above the chart. |
|
163 | Returns the chart title. The description text that is drawn above the chart. | |
165 | */ |
|
164 | */ | |
166 | QString QChart::title() const |
|
165 | QString QChart::title() const | |
167 | { |
|
166 | { | |
168 | if (d_ptr->m_presenter->m_titleItem) |
|
167 | if (d_ptr->m_presenter->m_titleItem) | |
169 | return d_ptr->m_presenter->m_titleItem->text(); |
|
168 | return d_ptr->m_presenter->m_titleItem->text(); | |
170 | else |
|
169 | else | |
171 | return QString(); |
|
170 | return QString(); | |
172 | } |
|
171 | } | |
173 |
|
172 | |||
174 | /*! |
|
173 | /*! | |
175 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
174 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
176 | */ |
|
175 | */ | |
177 | void QChart::setTitleFont(const QFont& font) |
|
176 | void QChart::setTitleFont(const QFont& font) | |
178 | { |
|
177 | { | |
179 | d_ptr->m_presenter->createChartTitleItem(); |
|
178 | d_ptr->m_presenter->createChartTitleItem(); | |
180 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
179 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
181 | d_ptr->m_presenter->updateLayout(); |
|
180 | d_ptr->m_presenter->updateLayout(); | |
182 | } |
|
181 | } | |
183 |
|
182 | |||
184 | /*! |
|
183 | /*! | |
185 | Sets the \a brush used for rendering the title text. |
|
184 | Sets the \a brush used for rendering the title text. | |
186 | */ |
|
185 | */ | |
187 | void QChart::setTitleBrush(const QBrush &brush) |
|
186 | void QChart::setTitleBrush(const QBrush &brush) | |
188 | { |
|
187 | { | |
189 | d_ptr->m_presenter->createChartTitleItem(); |
|
188 | d_ptr->m_presenter->createChartTitleItem(); | |
190 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
189 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
191 | d_ptr->m_presenter->updateLayout(); |
|
190 | d_ptr->m_presenter->updateLayout(); | |
192 | } |
|
191 | } | |
193 |
|
192 | |||
194 | /*! |
|
193 | /*! | |
195 | Returns the brush used for rendering the title text. |
|
194 | Returns the brush used for rendering the title text. | |
196 | */ |
|
195 | */ | |
197 | QBrush QChart::titleBrush() const |
|
196 | QBrush QChart::titleBrush() const | |
198 | { |
|
197 | { | |
199 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
198 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
200 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
199 | return d_ptr->m_presenter->m_titleItem->brush(); | |
201 | } |
|
200 | } | |
202 |
|
201 | |||
203 | /*! |
|
202 | /*! | |
204 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
203 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
205 | \sa ChartTheme, chartTheme() |
|
204 | \sa ChartTheme, chartTheme() | |
206 | */ |
|
205 | */ | |
207 | void QChart::setTheme(QChart::ChartTheme theme) |
|
206 | void QChart::setTheme(QChart::ChartTheme theme) | |
208 | { |
|
207 | { | |
209 | d_ptr->m_presenter->setTheme(theme); |
|
208 | d_ptr->m_presenter->setTheme(theme); | |
210 | } |
|
209 | } | |
211 |
|
210 | |||
212 | /*! |
|
211 | /*! | |
213 | Returns the theme enum used by the chart. |
|
212 | Returns the theme enum used by the chart. | |
214 | \sa ChartTheme, setChartTheme() |
|
213 | \sa ChartTheme, setChartTheme() | |
215 | */ |
|
214 | */ | |
216 | QChart::ChartTheme QChart::theme() const |
|
215 | QChart::ChartTheme QChart::theme() const | |
217 | { |
|
216 | { | |
218 | return d_ptr->m_presenter->theme(); |
|
217 | return d_ptr->m_presenter->theme(); | |
219 | } |
|
218 | } | |
220 |
|
219 | |||
221 | /*! |
|
220 | /*! | |
222 | Zooms in the view by a factor of 2 |
|
221 | Zooms in the view by a factor of 2 | |
223 | */ |
|
222 | */ | |
224 | void QChart::zoomIn() |
|
223 | void QChart::zoomIn() | |
225 | { |
|
224 | { | |
226 | d_ptr->m_presenter->zoomIn(); |
|
225 | d_ptr->m_presenter->zoomIn(); | |
227 | } |
|
226 | } | |
228 |
|
227 | |||
229 | /*! |
|
228 | /*! | |
230 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
229 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
231 | */ |
|
230 | */ | |
232 | void QChart::zoomIn(const QRectF& rect) |
|
231 | void QChart::zoomIn(const QRectF& rect) | |
233 | { |
|
232 | { | |
234 | if (!rect.isValid()) return; |
|
233 | if (!rect.isValid()) return; | |
235 | d_ptr->m_presenter->zoomIn(rect); |
|
234 | d_ptr->m_presenter->zoomIn(rect); | |
236 | } |
|
235 | } | |
237 |
|
236 | |||
238 | /*! |
|
237 | /*! | |
239 | Restores the view zoom level to the previous one. |
|
238 | Restores the view zoom level to the previous one. | |
240 | */ |
|
239 | */ | |
241 | void QChart::zoomOut() |
|
240 | void QChart::zoomOut() | |
242 | { |
|
241 | { | |
243 | d_ptr->m_presenter->zoomOut(); |
|
242 | d_ptr->m_presenter->zoomOut(); | |
244 | } |
|
243 | } | |
245 |
|
244 | |||
246 | /*! |
|
245 | /*! | |
247 | Returns the pointer to the x axis object of the chart |
|
246 | Returns the pointer to the x axis object of the chart | |
248 | */ |
|
247 | */ | |
249 | QChartAxis* QChart::axisX() const |
|
248 | QChartAxis* QChart::axisX() const | |
250 | { |
|
249 | { | |
251 | return d_ptr->m_dataset->axisX(); |
|
250 | return d_ptr->m_dataset->axisX(); | |
252 | } |
|
251 | } | |
253 |
|
252 | |||
254 | /*! |
|
253 | /*! | |
255 | Returns the pointer to the y axis object of the chart |
|
254 | Returns the pointer to the y axis object of the chart | |
256 | */ |
|
255 | */ | |
257 | QChartAxis* QChart::axisY() const |
|
256 | QChartAxis* QChart::axisY() const | |
258 | { |
|
257 | { | |
259 | return d_ptr->m_dataset->axisY(); |
|
258 | return d_ptr->m_dataset->axisY(); | |
260 | } |
|
259 | } | |
261 |
|
260 | |||
262 | /*! |
|
261 | /*! | |
263 | Returns the legend object of the chart. Ownership stays in chart. |
|
262 | Returns the legend object of the chart. Ownership stays in chart. | |
264 | */ |
|
263 | */ | |
265 | QLegend* QChart::legend() const |
|
264 | QLegend* QChart::legend() const | |
266 | { |
|
265 | { | |
267 | return d_ptr->m_legend; |
|
266 | return d_ptr->m_legend; | |
268 | } |
|
267 | } | |
269 |
|
268 | |||
270 | QRect QChart::margins() const |
|
269 | QRect QChart::margins() const | |
271 | { |
|
270 | { | |
272 | return d_ptr->m_presenter->margins(); |
|
271 | return d_ptr->m_presenter->margins(); | |
273 | } |
|
272 | } | |
274 |
|
273 | |||
275 |
|
274 | |||
276 | /*! |
|
275 | /*! | |
277 | Resizes and updates the chart area using the \a event data |
|
276 | Resizes and updates the chart area using the \a event data | |
278 | */ |
|
277 | */ | |
279 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
278 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
280 | { |
|
279 | { | |
281 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
280 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
282 | QGraphicsWidget::resizeEvent(event); |
|
281 | QGraphicsWidget::resizeEvent(event); | |
283 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
282 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
284 | } |
|
283 | } | |
285 |
|
284 | |||
286 | /*! |
|
285 | /*! | |
287 | Sets animation \a options for the chart |
|
286 | Sets animation \a options for the chart | |
288 | */ |
|
287 | */ | |
289 | void QChart::setAnimationOptions(AnimationOptions options) |
|
288 | void QChart::setAnimationOptions(AnimationOptions options) | |
290 | { |
|
289 | { | |
291 | d_ptr->m_presenter->setAnimationOptions(options); |
|
290 | d_ptr->m_presenter->setAnimationOptions(options); | |
292 | } |
|
291 | } | |
293 |
|
292 | |||
294 | /*! |
|
293 | /*! | |
295 | Returns animation options for the chart |
|
294 | Returns animation options for the chart | |
296 | */ |
|
295 | */ | |
297 | QChart::AnimationOptions QChart::animationOptions() const |
|
296 | QChart::AnimationOptions QChart::animationOptions() const | |
298 | { |
|
297 | { | |
299 | return d_ptr->m_presenter->animationOptions(); |
|
298 | return d_ptr->m_presenter->animationOptions(); | |
300 | } |
|
299 | } | |
301 |
|
300 | |||
302 | void QChart::scrollLeft() |
|
301 | void QChart::scrollLeft() | |
303 | { |
|
302 | { | |
304 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
303 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
305 | } |
|
304 | } | |
306 |
|
305 | |||
307 | void QChart::scrollRight() |
|
306 | void QChart::scrollRight() | |
308 | { |
|
307 | { | |
309 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
308 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
310 | } |
|
309 | } | |
311 |
|
310 | |||
312 | void QChart::scrollUp() |
|
311 | void QChart::scrollUp() | |
313 | { |
|
312 | { | |
314 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
313 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
315 | } |
|
314 | } | |
316 |
|
315 | |||
317 | void QChart::scrollDown() |
|
316 | void QChart::scrollDown() | |
318 | { |
|
317 | { | |
319 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
318 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
320 | } |
|
319 | } | |
321 |
|
320 | |||
322 | void QChart::setBackgroundVisible(bool visible) |
|
321 | void QChart::setBackgroundVisible(bool visible) | |
323 | { |
|
322 | { | |
324 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
323 | d_ptr->m_presenter->createChartBackgroundItem(); | |
325 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
324 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
326 | } |
|
325 | } | |
327 |
|
326 | |||
328 | bool QChart::isBackgroundVisible() const |
|
327 | bool QChart::isBackgroundVisible() const | |
329 | { |
|
328 | { | |
330 | if (!d_ptr->m_presenter->m_backgroundItem) return false; |
|
329 | if (!d_ptr->m_presenter->m_backgroundItem) return false; | |
331 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
330 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
332 | } |
|
331 | } | |
333 |
|
332 | |||
334 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
333 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
335 |
|
334 | |||
336 | QChartPrivate::QChartPrivate(): |
|
335 | QChartPrivate::QChartPrivate(): | |
337 | m_legend(0), |
|
336 | m_legend(0), | |
338 | m_dataset(0), |
|
337 | m_dataset(0), | |
339 | m_presenter(0) |
|
338 | m_presenter(0) | |
340 | { |
|
339 | { | |
341 |
|
340 | |||
342 | } |
|
341 | } | |
343 |
|
342 | |||
344 | QChartPrivate::~QChartPrivate() |
|
343 | QChartPrivate::~QChartPrivate() | |
345 | { |
|
344 | { | |
346 |
|
345 | |||
347 | } |
|
346 | } | |
348 |
|
347 | |||
|
348 | void QChartPrivate::createConnections() | |||
|
349 | { | |||
|
350 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |||
|
351 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |||
|
352 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |||
|
353 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); | |||
|
354 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |||
|
355 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); | |||
|
356 | } | |||
|
357 | ||||
349 | #include "moc_qchart.cpp" |
|
358 | #include "moc_qchart.cpp" | |
350 |
|
359 | |||
351 | QTCOMMERCIALCHART_END_NAMESPACE |
|
360 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,55 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 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 QCHART_P_H |
|
30 | #ifndef QCHART_P_H | |
31 | #define QCHART_P_H |
|
31 | #define QCHART_P_H | |
32 |
|
32 | |||
33 | #include "qlegend.h" |
|
33 | #include "qlegend.h" | |
34 | #include "chartpresenter_p.h" |
|
34 | #include "chartpresenter_p.h" | |
35 | #include "chartdataset_p.h" |
|
35 | #include "chartdataset_p.h" | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class QChart; |
|
39 | class QChart; | |
40 |
|
40 | |||
41 | struct QChartPrivate |
|
41 | struct QChartPrivate | |
42 | { |
|
42 | { | |
43 | QChartPrivate(); |
|
43 | QChartPrivate(); | |
44 | ~QChartPrivate(); |
|
44 | ~QChartPrivate(); | |
45 | QRectF m_rect; |
|
45 | QRectF m_rect; | |
46 | QLegend* m_legend; |
|
46 | QLegend* m_legend; | |
47 | ChartDataSet *m_dataset; |
|
47 | ChartDataSet *m_dataset; | |
48 | ChartPresenter *m_presenter; |
|
48 | ChartPresenter *m_presenter; | |
49 |
|
49 | |||
|
50 | void createConnections(); | |||
|
51 | ||||
50 | }; |
|
52 | }; | |
51 |
|
53 | |||
52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
53 | #endif |
|
55 | #endif |
@@ -1,529 +1,523 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 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 "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qseries.h" |
|
23 | #include "qseries.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 | #include "qxyseries.h" |
|
25 | #include "qxyseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include "qareaseries.h" |
|
27 | #include "qareaseries.h" | |
28 | #include "qscatterseries.h" |
|
28 | #include "qscatterseries.h" | |
29 | #include "qsplineseries.h" |
|
29 | #include "qsplineseries.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 "qbarset.h" |
|
33 | #include "qbarset.h" | |
34 | #include "qpieseries.h" |
|
34 | #include "qpieseries.h" | |
35 | #include "qpieslice.h" |
|
35 | #include "qpieslice.h" | |
36 | #include "chartpresenter_p.h" |
|
36 | #include "chartpresenter_p.h" | |
37 | #include <QPainter> |
|
37 | #include <QPainter> | |
38 | #include <QPen> |
|
38 | #include <QPen> | |
39 | #include <QTimer> |
|
39 | #include <QTimer> | |
40 |
|
40 | |||
41 | #include <QGraphicsSceneEvent> |
|
41 | #include <QGraphicsSceneEvent> | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \class QLegend |
|
46 | \class QLegend | |
47 | \brief part of QtCommercial chart API. |
|
47 | \brief part of QtCommercial chart API. | |
48 |
|
48 | |||
49 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
49 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
50 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
50 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
51 | handle the drawing manually. |
|
51 | handle the drawing manually. | |
52 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
52 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
53 |
|
53 | |||
54 | \mainclass |
|
54 | \mainclass | |
55 |
|
55 | |||
56 | \sa QChart, QSeries |
|
56 | \sa QChart, QSeries | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \enum QLegend::Layout |
|
60 | \enum QLegend::Layout | |
61 |
|
61 | |||
62 | This enum describes the possible position for legend inside chart. |
|
62 | This enum describes the possible position for legend inside chart. | |
63 |
|
63 | |||
64 | \value LayoutTop |
|
64 | \value LayoutTop | |
65 | \value LayoutBottom |
|
65 | \value LayoutBottom | |
66 | \value LayoutLeft |
|
66 | \value LayoutLeft | |
67 | \value LayoutRight |
|
67 | \value LayoutRight | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \fn void QLegend::clicked(QSeries* series, Qt::MouseButton button) |
|
72 | \fn void QLegend::clicked(QSeries* series, Qt::MouseButton button) | |
73 | \brief Notifies when series has been clicked on legend \a series \a button |
|
73 | \brief Notifies when series has been clicked on legend \a series \a button | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \fn void QLegend::clicked(QBarSet* barset, Qt::MouseButton button) |
|
77 | \fn void QLegend::clicked(QBarSet* barset, Qt::MouseButton button) | |
78 | \brief Notifies when barset has been clicked on legend \a barset \a button |
|
78 | \brief Notifies when barset has been clicked on legend \a barset \a button | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | \fn void QLegend::clicked(QPieSlice* slice, Qt::MouseButton button) |
|
82 | \fn void QLegend::clicked(QPieSlice* slice, Qt::MouseButton button) | |
83 | \brief Notifies when pie slice has been clicked on legend \a slice \a button |
|
83 | \brief Notifies when pie slice has been clicked on legend \a slice \a button | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | Constructs the legend object and sets the parent to \a parent |
|
87 | Constructs the legend object and sets the parent to \a parent | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
90 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
91 | m_margin(5), |
|
91 | m_margin(5), | |
92 | m_offsetX(0), |
|
92 | m_offsetX(0), | |
93 | m_offsetY(0), |
|
93 | m_offsetY(0), | |
94 | m_brush(Qt::darkGray), // TODO: default should come from theme |
|
94 | m_brush(Qt::darkGray), // TODO: default should come from theme | |
95 | m_alignment(QLegend::AlignmentTop), |
|
95 | m_alignment(QLegend::AlignmentTop), | |
96 | m_markers(new QGraphicsItemGroup(this)), |
|
96 | m_markers(new QGraphicsItemGroup(this)), | |
97 | m_attachedToChart(true), |
|
97 | m_attachedToChart(true), | |
98 | m_chart(chart), |
|
98 | m_chart(chart), | |
99 | m_minWidth(0), |
|
99 | m_minWidth(0), | |
100 | m_minHeight(0), |
|
100 | m_minHeight(0), | |
101 | m_width(0), |
|
101 | m_width(0), | |
102 | m_height(0), |
|
102 | m_height(0), | |
103 |
m_visible(false) |
|
103 | m_visible(false) | |
104 | m_dirty(false) |
|
|||
105 | { |
|
104 | { | |
106 | setZValue(ChartPresenter::LegendZValue); |
|
105 | setZValue(ChartPresenter::LegendZValue); | |
107 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
106 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
108 | } |
|
107 | } | |
109 |
|
108 | |||
110 | /*! |
|
109 | /*! | |
111 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. |
|
110 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. | |
112 | */ |
|
111 | */ | |
113 |
|
112 | |||
114 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
113 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
115 | { |
|
114 | { | |
116 | Q_UNUSED(option) |
|
115 | Q_UNUSED(option) | |
117 | Q_UNUSED(widget) |
|
116 | Q_UNUSED(widget) | |
118 | if(!m_visible) return; |
|
117 | if(!m_visible) return; | |
119 |
|
118 | |||
120 | painter->setOpacity(opacity()); |
|
119 | painter->setOpacity(opacity()); | |
121 | painter->setPen(m_pen); |
|
120 | painter->setPen(m_pen); | |
122 | painter->setBrush(m_brush); |
|
121 | painter->setBrush(m_brush); | |
123 | painter->drawRect(boundingRect()); |
|
122 | painter->drawRect(boundingRect()); | |
124 | } |
|
123 | } | |
125 |
|
124 | |||
126 | /*! |
|
125 | /*! | |
127 | Bounding rect of legend. |
|
126 | Bounding rect of legend. | |
128 | */ |
|
127 | */ | |
129 |
|
128 | |||
130 | QRectF QLegend::boundingRect() const |
|
129 | QRectF QLegend::boundingRect() const | |
131 | { |
|
130 | { | |
132 | return m_rect; |
|
131 | return m_rect; | |
133 | } |
|
132 | } | |
134 |
|
133 | |||
135 | /*! |
|
134 | /*! | |
136 | Sets the \a brush of legend. Brush affects the background of legend. |
|
135 | Sets the \a brush of legend. Brush affects the background of legend. | |
137 | */ |
|
136 | */ | |
138 | void QLegend::setBrush(const QBrush &brush) |
|
137 | void QLegend::setBrush(const QBrush &brush) | |
139 | { |
|
138 | { | |
140 | if (m_brush != brush) { |
|
139 | if (m_brush != brush) { | |
141 | m_brush = brush; |
|
140 | m_brush = brush; | |
142 | update(); |
|
141 | update(); | |
143 | } |
|
142 | } | |
144 | } |
|
143 | } | |
145 |
|
144 | |||
146 | /*! |
|
145 | /*! | |
147 | Returns the brush used by legend. |
|
146 | Returns the brush used by legend. | |
148 | */ |
|
147 | */ | |
149 | QBrush QLegend::brush() const |
|
148 | QBrush QLegend::brush() const | |
150 | { |
|
149 | { | |
151 | return m_brush; |
|
150 | return m_brush; | |
152 | } |
|
151 | } | |
153 |
|
152 | |||
154 | /*! |
|
153 | /*! | |
155 | Sets the \a pen of legend. Pen affects the legend borders. |
|
154 | Sets the \a pen of legend. Pen affects the legend borders. | |
156 | */ |
|
155 | */ | |
157 | void QLegend::setPen(const QPen &pen) |
|
156 | void QLegend::setPen(const QPen &pen) | |
158 | { |
|
157 | { | |
159 | if (m_pen != pen) { |
|
158 | if (m_pen != pen) { | |
160 | m_pen = pen; |
|
159 | m_pen = pen; | |
161 | update(); |
|
160 | update(); | |
162 | } |
|
161 | } | |
163 | } |
|
162 | } | |
164 |
|
163 | |||
165 | /*! |
|
164 | /*! | |
166 | Returns the pen used by legend |
|
165 | Returns the pen used by legend | |
167 | */ |
|
166 | */ | |
168 |
|
167 | |||
169 | QPen QLegend::pen() const |
|
168 | QPen QLegend::pen() const | |
170 | { |
|
169 | { | |
171 | return m_pen; |
|
170 | return m_pen; | |
172 | } |
|
171 | } | |
173 |
|
172 | |||
174 | /*! |
|
173 | /*! | |
175 | Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart. |
|
174 | Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart. | |
176 | \sa QLegend::Layout |
|
175 | \sa QLegend::Layout | |
177 | */ |
|
176 | */ | |
178 | void QLegend::setAlignmnent(QLegend::Alignments alignment) |
|
177 | void QLegend::setAlignmnent(QLegend::Alignments alignment) | |
179 | { |
|
178 | { | |
180 | if(m_alignment!=alignment && m_attachedToChart) { |
|
179 | if(m_alignment!=alignment && m_attachedToChart) { | |
181 | m_alignment = alignment; |
|
180 | m_alignment = alignment; | |
182 | updateLayout(); |
|
181 | updateLayout(); | |
183 | } |
|
182 | } | |
184 | } |
|
183 | } | |
185 |
|
184 | |||
186 | /*! |
|
185 | /*! | |
187 | Returns the preferred layout for legend |
|
186 | Returns the preferred layout for legend | |
188 | */ |
|
187 | */ | |
189 | QLegend::Alignments QLegend::alignment() const |
|
188 | QLegend::Alignments QLegend::alignment() const | |
190 | { |
|
189 | { | |
191 | return m_alignment; |
|
190 | return m_alignment; | |
192 | } |
|
191 | } | |
193 |
|
192 | |||
194 | /*! |
|
193 | /*! | |
195 | \internal \a series \a domain Should be called when series is added to chart. |
|
194 | \internal \a series \a domain Should be called when series is added to chart. | |
196 | */ |
|
195 | */ | |
197 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) |
|
196 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) | |
198 | { |
|
197 | { | |
199 | Q_UNUSED(domain) |
|
198 | Q_UNUSED(domain) | |
200 |
|
199 | |||
201 | switch (series->type()) |
|
200 | switch (series->type()) | |
202 | { |
|
201 | { | |
203 | case QSeries::SeriesTypeLine: { |
|
202 | case QSeries::SeriesTypeLine: { | |
204 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); |
|
203 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); | |
205 | appendMarkers(lineSeries); |
|
204 | appendMarkers(lineSeries); | |
206 | break; |
|
205 | break; | |
207 | } |
|
206 | } | |
208 | case QSeries::SeriesTypeArea: { |
|
207 | case QSeries::SeriesTypeArea: { | |
209 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
208 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); | |
210 | appendMarkers(areaSeries); |
|
209 | appendMarkers(areaSeries); | |
211 | break; |
|
210 | break; | |
212 | } |
|
211 | } | |
213 | case QSeries::SeriesTypeBar: { |
|
212 | case QSeries::SeriesTypeBar: { | |
214 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); |
|
213 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); | |
215 | appendMarkers(barSeries); |
|
214 | appendMarkers(barSeries); | |
216 | break; |
|
215 | break; | |
217 | } |
|
216 | } | |
218 | case QSeries::SeriesTypeStackedBar: { |
|
217 | case QSeries::SeriesTypeStackedBar: { | |
219 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); |
|
218 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); | |
220 | appendMarkers(stackedBarSeries); |
|
219 | appendMarkers(stackedBarSeries); | |
221 | break; |
|
220 | break; | |
222 | } |
|
221 | } | |
223 | case QSeries::SeriesTypePercentBar: { |
|
222 | case QSeries::SeriesTypePercentBar: { | |
224 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); |
|
223 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); | |
225 | appendMarkers(percentBarSeries); |
|
224 | appendMarkers(percentBarSeries); | |
226 | break; |
|
225 | break; | |
227 | } |
|
226 | } | |
228 | case QSeries::SeriesTypeScatter: { |
|
227 | case QSeries::SeriesTypeScatter: { | |
229 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
228 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
230 | appendMarkers(scatterSeries); |
|
229 | appendMarkers(scatterSeries); | |
231 | break; |
|
230 | break; | |
232 | } |
|
231 | } | |
233 | case QSeries::SeriesTypePie: { |
|
232 | case QSeries::SeriesTypePie: { | |
234 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
233 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
235 | appendMarkers(pieSeries); |
|
234 | appendMarkers(pieSeries); | |
236 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); |
|
235 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); | |
237 | break; |
|
236 | break; | |
238 | } |
|
237 | } | |
239 | case QSeries::SeriesTypeSpline: { |
|
238 | case QSeries::SeriesTypeSpline: { | |
240 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); |
|
239 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); | |
241 | appendMarkers(splineSeries); |
|
240 | appendMarkers(splineSeries); | |
242 | break; |
|
241 | break; | |
243 | } |
|
242 | } | |
244 | default: { |
|
243 | default: { | |
245 | qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type."; |
|
244 | qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type."; | |
246 | break; |
|
245 | break; | |
247 | } |
|
246 | } | |
248 | } |
|
247 | } | |
249 |
|
248 | |||
250 | // wait for all series added |
|
249 | updateLayout(); | |
251 | if(!m_dirty){ |
|
|||
252 | QTimer::singleShot(0,this,SLOT(updateLayout())); |
|
|||
253 | m_dirty=true; |
|
|||
254 | } |
|
|||
255 | } |
|
250 | } | |
256 |
|
251 | |||
257 | /*! |
|
252 | /*! | |
258 | \internal \a series Should be called when series is removed from chart. |
|
253 | \internal \a series Should be called when series is removed from chart. | |
259 | */ |
|
254 | */ | |
260 | void QLegend::handleSeriesRemoved(QSeries *series) |
|
255 | void QLegend::handleSeriesRemoved(QSeries *series) | |
261 | { |
|
256 | { | |
262 | switch (series->type()) |
|
257 | switch (series->type()) | |
263 | { |
|
258 | { | |
264 | case QSeries::SeriesTypeArea: { |
|
259 | case QSeries::SeriesTypeArea: { | |
265 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
260 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); | |
266 | deleteMarkers(areaSeries); |
|
261 | deleteMarkers(areaSeries); | |
267 | break; |
|
262 | break; | |
268 | } |
|
263 | } | |
269 | case QSeries::SeriesTypePie: { |
|
264 | case QSeries::SeriesTypePie: { | |
270 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
265 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
271 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); |
|
266 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); | |
272 | deleteMarkers(series); |
|
267 | deleteMarkers(series); | |
273 | break; |
|
268 | break; | |
274 | } |
|
269 | } | |
275 | default: { |
|
270 | default: { | |
276 | // All other types |
|
271 | // All other types | |
277 | deleteMarkers(series); |
|
272 | deleteMarkers(series); | |
278 | break; |
|
273 | break; | |
279 | } |
|
274 | } | |
280 | } |
|
275 | } | |
281 |
|
276 | |||
282 | updateLayout(); |
|
277 | updateLayout(); | |
283 | } |
|
278 | } | |
284 |
|
279 | |||
285 | /*! |
|
280 | /*! | |
286 | \internal \a slices Should be called when slices are added to pie chart. |
|
281 | \internal \a slices Should be called when slices are added to pie chart. | |
287 | */ |
|
282 | */ | |
288 | void QLegend::handleAdded(QList<QPieSlice *> slices) |
|
283 | void QLegend::handleAdded(QList<QPieSlice *> slices) | |
289 | { |
|
284 | { | |
290 | QPieSeries* series = static_cast<QPieSeries *> (sender()); |
|
285 | QPieSeries* series = static_cast<QPieSeries *> (sender()); | |
291 | foreach(QPieSlice* slice, slices) { |
|
286 | foreach(QPieSlice* slice, slices) { | |
292 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); |
|
287 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); | |
293 | m_markers->addToGroup(marker); |
|
288 | m_markers->addToGroup(marker); | |
294 | } |
|
289 | } | |
295 | updateLayout(); |
|
290 | updateLayout(); | |
296 | } |
|
291 | } | |
297 |
|
292 | |||
298 | /*! |
|
293 | /*! | |
299 | \internal \a slices Should be called when slices are removed from pie chart. Currently unused, |
|
294 | \internal \a slices Should be called when slices are removed from pie chart. Currently unused, | |
300 | because removed slices are also deleted and we listen destroyed signal |
|
295 | because removed slices are also deleted and we listen destroyed signal | |
301 | */ |
|
296 | */ | |
302 | void QLegend::handleRemoved(QList<QPieSlice *> slices) |
|
297 | void QLegend::handleRemoved(QList<QPieSlice *> slices) | |
303 | { |
|
298 | { | |
304 | Q_UNUSED(slices) |
|
299 | Q_UNUSED(slices) | |
305 | } |
|
300 | } | |
306 |
|
301 | |||
307 | /*! |
|
302 | /*! | |
308 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
303 | Detaches the legend from chart. Chart won't change layout of the legend. | |
309 | */ |
|
304 | */ | |
310 | void QLegend::detachFromChart() |
|
305 | void QLegend::detachFromChart() | |
311 | { |
|
306 | { | |
312 | m_attachedToChart = false; |
|
307 | m_attachedToChart = false; | |
313 | } |
|
308 | } | |
314 |
|
309 | |||
315 | /*! |
|
310 | /*! | |
316 | Attaches the legend to chart. Chart may change layout of the legend. |
|
311 | Attaches the legend to chart. Chart may change layout of the legend. | |
317 | */ |
|
312 | */ | |
318 | void QLegend::attachToChart() |
|
313 | void QLegend::attachToChart() | |
319 | { |
|
314 | { | |
320 | m_attachedToChart = true; |
|
315 | m_attachedToChart = true; | |
321 | } |
|
316 | } | |
322 |
|
317 | |||
323 | /*! |
|
318 | /*! | |
324 | Returns true, if legend is attached to chart. |
|
319 | Returns true, if legend is attached to chart. | |
325 | */ |
|
320 | */ | |
326 | bool QLegend::isAttachedToChart() |
|
321 | bool QLegend::isAttachedToChart() | |
327 | { |
|
322 | { | |
328 | return m_attachedToChart; |
|
323 | return m_attachedToChart; | |
329 | } |
|
324 | } | |
330 |
|
325 | |||
331 | /*! |
|
326 | /*! | |
332 | \internal Helper function. Appends markers from \a series to legend. |
|
327 | \internal Helper function. Appends markers from \a series to legend. | |
333 | */ |
|
328 | */ | |
334 | void QLegend::appendMarkers(QAreaSeries* series) |
|
329 | void QLegend::appendMarkers(QAreaSeries* series) | |
335 | { |
|
330 | { | |
336 | AreaLegendMarker* marker = new AreaLegendMarker(series,this); |
|
331 | AreaLegendMarker* marker = new AreaLegendMarker(series,this); | |
337 | m_markers->addToGroup(marker); |
|
332 | m_markers->addToGroup(marker); | |
338 | } |
|
333 | } | |
339 |
|
334 | |||
340 | /*! |
|
335 | /*! | |
341 | \internal Helper function. Appends markers from \a series to legend. |
|
336 | \internal Helper function. Appends markers from \a series to legend. | |
342 | */ |
|
337 | */ | |
343 | void QLegend::appendMarkers(QXYSeries* series) |
|
338 | void QLegend::appendMarkers(QXYSeries* series) | |
344 | { |
|
339 | { | |
345 | XYLegendMarker* marker = new XYLegendMarker(series,this); |
|
340 | XYLegendMarker* marker = new XYLegendMarker(series,this); | |
346 | m_markers->addToGroup(marker); |
|
341 | m_markers->addToGroup(marker); | |
347 | } |
|
342 | } | |
348 |
|
343 | |||
349 | /*! |
|
344 | /*! | |
350 | \internal Helper function. Appends markers from \a series to legend. |
|
345 | \internal Helper function. Appends markers from \a series to legend. | |
351 | */ |
|
346 | */ | |
352 | void QLegend::appendMarkers(QBarSeries *series) |
|
347 | void QLegend::appendMarkers(QBarSeries *series) | |
353 | { |
|
348 | { | |
354 | foreach(QBarSet* set, series->barSets()) { |
|
349 | foreach(QBarSet* set, series->barSets()) { | |
355 | BarLegendMarker* marker = new BarLegendMarker(series,set, this); |
|
350 | BarLegendMarker* marker = new BarLegendMarker(series,set, this); | |
356 | m_markers->addToGroup(marker); |
|
351 | m_markers->addToGroup(marker); | |
357 | } |
|
352 | } | |
358 | } |
|
353 | } | |
359 |
|
354 | |||
360 | /*! |
|
355 | /*! | |
361 | \internal Helper function. Appends markers from \a series to legend. |
|
356 | \internal Helper function. Appends markers from \a series to legend. | |
362 | */ |
|
357 | */ | |
363 | void QLegend::appendMarkers(QPieSeries *series) |
|
358 | void QLegend::appendMarkers(QPieSeries *series) | |
364 | { |
|
359 | { | |
365 | foreach(QPieSlice* slice, series->slices()) { |
|
360 | foreach(QPieSlice* slice, series->slices()) { | |
366 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); |
|
361 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); | |
367 | m_markers->addToGroup(marker); |
|
362 | m_markers->addToGroup(marker); | |
368 | } |
|
363 | } | |
369 | } |
|
364 | } | |
370 |
|
365 | |||
371 | /*! |
|
366 | /*! | |
372 | \internal Deletes all markers that are created from \a series |
|
367 | \internal Deletes all markers that are created from \a series | |
373 | */ |
|
368 | */ | |
374 | void QLegend::deleteMarkers(QSeries *series) |
|
369 | void QLegend::deleteMarkers(QSeries *series) | |
375 | { |
|
370 | { | |
376 | // Search all markers that belong to given series and delete them. |
|
371 | // Search all markers that belong to given series and delete them. | |
377 |
|
372 | |||
378 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
373 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
379 |
|
374 | |||
380 | foreach (QGraphicsItem *markers, items) { |
|
375 | foreach (QGraphicsItem *markers, items) { | |
381 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
376 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
382 | if (marker->series() == series) { |
|
377 | if (marker->series() == series) { | |
383 | delete marker; |
|
378 | delete marker; | |
384 | } |
|
379 | } | |
385 | } |
|
380 | } | |
386 | } |
|
381 | } | |
387 |
|
382 | |||
388 | /*! |
|
383 | /*! | |
389 | \internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend. |
|
384 | \internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend. | |
390 | If items don't fit, sets the visibility of scroll buttons accordingly. |
|
385 | If items don't fit, sets the visibility of scroll buttons accordingly. | |
391 | Causes legend to be resized. |
|
386 | Causes legend to be resized. | |
392 | */ |
|
387 | */ | |
393 |
|
388 | |||
394 | void QLegend::setOffset(const QPointF& point) |
|
389 | void QLegend::setOffset(const QPointF& point) | |
395 | { |
|
390 | { | |
396 |
|
391 | |||
397 | switch(m_alignment) { |
|
392 | switch(m_alignment) { | |
398 |
|
393 | |||
399 | case AlignmentTop: |
|
394 | case AlignmentTop: | |
400 | case AlignmentBottom: { |
|
395 | case AlignmentBottom: { | |
401 | if(m_width<=m_rect.width()) return; |
|
396 | if(m_width<=m_rect.width()) return; | |
402 |
|
397 | |||
403 | if (point.x() != m_offsetX) { |
|
398 | if (point.x() != m_offsetX) { | |
404 | m_offsetX = qBound(0.0, point.x(), m_width - m_rect.width()); |
|
399 | m_offsetX = qBound(0.0, point.x(), m_width - m_rect.width()); | |
405 | m_markers->setPos(-m_offsetX,m_rect.top()); |
|
400 | m_markers->setPos(-m_offsetX,m_rect.top()); | |
406 | } |
|
401 | } | |
407 | break; |
|
402 | break; | |
408 | } |
|
403 | } | |
409 | case AlignmentLeft: |
|
404 | case AlignmentLeft: | |
410 | case AlignmentRight: { |
|
405 | case AlignmentRight: { | |
411 |
|
406 | |||
412 | if(m_height<=m_rect.height()) return; |
|
407 | if(m_height<=m_rect.height()) return; | |
413 |
|
408 | |||
414 | if (point.y() != m_offsetY) { |
|
409 | if (point.y() != m_offsetY) { | |
415 | m_offsetY = qBound(0.0, point.y(), m_height - m_rect.height()); |
|
410 | m_offsetY = qBound(0.0, point.y(), m_height - m_rect.height()); | |
416 | m_markers->setPos(m_rect.left(),-m_offsetY); |
|
411 | m_markers->setPos(m_rect.left(),-m_offsetY); | |
417 | } |
|
412 | } | |
418 | break; |
|
413 | break; | |
419 | } |
|
414 | } | |
420 | } |
|
415 | } | |
421 | } |
|
416 | } | |
422 |
|
417 | |||
423 | QPointF QLegend::offset() const |
|
418 | QPointF QLegend::offset() const | |
424 | { |
|
419 | { | |
425 | return QPointF(m_offsetX,m_offsetY); |
|
420 | return QPointF(m_offsetX,m_offsetY); | |
426 | } |
|
421 | } | |
427 |
|
422 | |||
428 | // this function runs first to set min max values |
|
423 | // this function runs first to set min max values | |
429 | void QLegend::updateLayout() |
|
424 | void QLegend::updateLayout() | |
430 | { |
|
425 | { | |
431 | m_dirty=false; |
|
|||
432 | m_offsetX=0; |
|
426 | m_offsetX=0; | |
433 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
427 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
434 |
|
428 | |||
435 | if(items.isEmpty()) return; |
|
429 | if(items.isEmpty()) return; | |
436 |
|
430 | |||
437 | m_minWidth=0; |
|
431 | m_minWidth=0; | |
438 | m_minHeight=0; |
|
432 | m_minHeight=0; | |
439 |
|
433 | |||
440 | switch(m_alignment) { |
|
434 | switch(m_alignment) { | |
441 |
|
435 | |||
442 | case AlignmentTop: |
|
436 | case AlignmentTop: | |
443 | case AlignmentBottom: { |
|
437 | case AlignmentBottom: { | |
444 | QPointF point = m_rect.topLeft(); |
|
438 | QPointF point = m_rect.topLeft(); | |
445 | m_width = 0; |
|
439 | m_width = 0; | |
446 | foreach (QGraphicsItem *item, items) { |
|
440 | foreach (QGraphicsItem *item, items) { | |
447 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); |
|
441 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); | |
448 | const QRectF& rect = item->boundingRect(); |
|
442 | const QRectF& rect = item->boundingRect(); | |
449 | qreal w = rect.width(); |
|
443 | qreal w = rect.width(); | |
450 | m_minWidth=qMax(m_minWidth,w); |
|
444 | m_minWidth=qMax(m_minWidth,w); | |
451 | m_minHeight=qMax(m_minHeight,rect.height()); |
|
445 | m_minHeight=qMax(m_minHeight,rect.height()); | |
452 | m_width+=w; |
|
446 | m_width+=w; | |
453 | point.setX(point.x() + w); |
|
447 | point.setX(point.x() + w); | |
454 | } |
|
448 | } | |
455 | if(m_width<m_rect.width()){ |
|
449 | if(m_width<m_rect.width()){ | |
456 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); |
|
450 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); | |
457 | }else{ |
|
451 | }else{ | |
458 | m_markers->setPos(m_rect.topLeft()); |
|
452 | m_markers->setPos(m_rect.topLeft()); | |
459 | } |
|
453 | } | |
460 | m_height=m_minHeight; |
|
454 | m_height=m_minHeight; | |
461 | } |
|
455 | } | |
462 | break; |
|
456 | break; | |
463 | case AlignmentLeft: |
|
457 | case AlignmentLeft: | |
464 | case AlignmentRight:{ |
|
458 | case AlignmentRight:{ | |
465 | QPointF point = m_rect.topLeft(); |
|
459 | QPointF point = m_rect.topLeft(); | |
466 | m_height = 0; |
|
460 | m_height = 0; | |
467 | foreach (QGraphicsItem *item, items) { |
|
461 | foreach (QGraphicsItem *item, items) { | |
468 | item->setPos(point); |
|
462 | item->setPos(point); | |
469 | const QRectF& rect = item->boundingRect(); |
|
463 | const QRectF& rect = item->boundingRect(); | |
470 | qreal h = rect.height(); |
|
464 | qreal h = rect.height(); | |
471 | m_minWidth=qMax(m_minWidth,rect.width()); |
|
465 | m_minWidth=qMax(m_minWidth,rect.width()); | |
472 | m_minHeight=qMax(m_minHeight,h); |
|
466 | m_minHeight=qMax(m_minHeight,h); | |
473 | m_height+=h; |
|
467 | m_height+=h; | |
474 | point.setY(point.y() + h); |
|
468 | point.setY(point.y() + h); | |
475 | } |
|
469 | } | |
476 | if(m_height<m_rect.height()){ |
|
470 | if(m_height<m_rect.height()){ | |
477 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); |
|
471 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); | |
478 | }else{ |
|
472 | }else{ | |
479 | m_markers->setPos(m_rect.topLeft()); |
|
473 | m_markers->setPos(m_rect.topLeft()); | |
480 | } |
|
474 | } | |
481 | m_width=m_minWidth; |
|
475 | m_width=m_minWidth; | |
482 | } |
|
476 | } | |
483 | break; |
|
477 | break; | |
484 | } |
|
478 | } | |
485 |
|
479 | |||
486 | m_chart->d_ptr->m_presenter->updateLayout(); //TODO fixme; |
|
480 | m_chart->d_ptr->m_presenter->updateLayout(); //TODO fixme; | |
487 | } |
|
481 | } | |
488 |
|
482 | |||
489 | void QLegend::setBackgroundVisible(bool visible) |
|
483 | void QLegend::setBackgroundVisible(bool visible) | |
490 | { |
|
484 | { | |
491 | if(m_visible!=visible) |
|
485 | if(m_visible!=visible) | |
492 | { |
|
486 | { | |
493 | m_visible=visible; |
|
487 | m_visible=visible; | |
494 | update(); |
|
488 | update(); | |
495 | } |
|
489 | } | |
496 | } |
|
490 | } | |
497 |
|
491 | |||
498 | bool QLegend::isBackgroundVisible() const |
|
492 | bool QLegend::isBackgroundVisible() const | |
499 | { |
|
493 | { | |
500 | return m_visible; |
|
494 | return m_visible; | |
501 | } |
|
495 | } | |
502 |
|
496 | |||
503 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
497 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) | |
504 | { |
|
498 | { | |
505 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); |
|
499 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); | |
506 | QGraphicsWidget::resizeEvent(event); |
|
500 | QGraphicsWidget::resizeEvent(event); | |
507 | if(m_rect != rect){ |
|
501 | if(m_rect != rect){ | |
508 | m_rect = rect; |
|
502 | m_rect = rect; | |
509 | updateLayout(); |
|
503 | updateLayout(); | |
510 | } |
|
504 | } | |
511 | } |
|
505 | } | |
512 |
|
506 | |||
513 | void QLegend::hideEvent(QHideEvent *event) |
|
507 | void QLegend::hideEvent(QHideEvent *event) | |
514 | { |
|
508 | { | |
515 | QGraphicsWidget::hideEvent(event); |
|
509 | QGraphicsWidget::hideEvent(event); | |
516 | setEnabled(false); |
|
510 | setEnabled(false); | |
517 | updateLayout(); |
|
511 | updateLayout(); | |
518 | } |
|
512 | } | |
519 |
|
513 | |||
520 | void QLegend::showEvent(QShowEvent *event) |
|
514 | void QLegend::showEvent(QShowEvent *event) | |
521 | { |
|
515 | { | |
522 | QGraphicsWidget::showEvent(event); |
|
516 | QGraphicsWidget::showEvent(event); | |
523 | setEnabled(true); |
|
517 | setEnabled(true); | |
524 | updateLayout(); |
|
518 | updateLayout(); | |
525 | } |
|
519 | } | |
526 |
|
520 | |||
527 | #include "moc_qlegend.cpp" |
|
521 | #include "moc_qlegend.cpp" | |
528 |
|
522 | |||
529 | QTCOMMERCIALCHART_END_NAMESPACE |
|
523 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,177 +1,171 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 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 QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 | #include "private/scroller_p.h" //TODO fixme |
|
28 | #include "private/scroller_p.h" //TODO fixme | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class Domain; |
|
32 | class Domain; | |
33 | class LegendMarker; |
|
33 | class LegendMarker; | |
34 | class QPieSlice; |
|
34 | class QPieSlice; | |
35 | class QXYSeries; |
|
35 | class QXYSeries; | |
36 | class QBarSet; |
|
36 | class QBarSet; | |
37 | class QBarSeries; |
|
37 | class QBarSeries; | |
38 | class QPieSeries; |
|
38 | class QPieSeries; | |
39 | class QAreaSeries; |
|
39 | class QAreaSeries; | |
40 | class LegendScrollButton; |
|
40 | class LegendScrollButton; | |
41 | class QSeries; |
|
41 | class QSeries; | |
42 | class QChart; |
|
42 | class QChart; | |
43 |
|
43 | |||
44 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
44 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 |
|
48 | |||
49 | // We only support these alignments (for now) |
|
49 | // We only support these alignments (for now) | |
50 | enum Alignment { |
|
50 | enum Alignment { | |
51 | AlignmentTop = Qt::AlignTop, |
|
51 | AlignmentTop = Qt::AlignTop, | |
52 | AlignmentBottom = Qt::AlignBottom, |
|
52 | AlignmentBottom = Qt::AlignBottom, | |
53 | AlignmentLeft = Qt::AlignLeft, |
|
53 | AlignmentLeft = Qt::AlignLeft, | |
54 | AlignmentRight = Qt::AlignRight |
|
54 | AlignmentRight = Qt::AlignRight | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | Q_DECLARE_FLAGS(Alignments, Alignment) |
|
57 | Q_DECLARE_FLAGS(Alignments, Alignment) | |
58 |
|
58 | |||
59 | private: |
|
59 | private: | |
60 | explicit QLegend(QChart *chart); |
|
60 | explicit QLegend(QChart *chart); | |
61 |
|
61 | |||
62 | public: |
|
62 | public: | |
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
64 | QRectF boundingRect() const; |
|
64 | QRectF boundingRect() const; | |
65 |
|
65 | |||
66 | void setBrush(const QBrush &brush); |
|
66 | void setBrush(const QBrush &brush); | |
67 | QBrush brush() const; |
|
67 | QBrush brush() const; | |
68 |
|
68 | |||
69 | void setPen(const QPen &pen); |
|
69 | void setPen(const QPen &pen); | |
70 | QPen pen() const; |
|
70 | QPen pen() const; | |
71 |
|
71 | |||
72 | void setAlignmnent(QLegend::Alignments alignment); |
|
72 | void setAlignmnent(QLegend::Alignments alignment); | |
73 | QLegend::Alignments alignment() const; |
|
73 | QLegend::Alignments alignment() const; | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | void detachFromChart(); |
|
76 | void detachFromChart(); | |
77 | void attachToChart(); |
|
77 | void attachToChart(); | |
78 | bool isAttachedToChart(); |
|
78 | bool isAttachedToChart(); | |
79 |
|
79 | |||
80 | qreal minWidht() const { return m_minWidth;} |
|
80 | qreal minWidht() const { return m_minWidth;} | |
81 | qreal minHeight() const { return m_minHeight;} |
|
81 | qreal minHeight() const { return m_minHeight;} | |
82 |
|
82 | |||
83 | void setBackgroundVisible(bool visible); |
|
83 | void setBackgroundVisible(bool visible); | |
84 | bool isBackgroundVisible() const; |
|
84 | bool isBackgroundVisible() const; | |
85 |
|
85 | |||
86 | void setOffset(const QPointF& point); |
|
86 | void setOffset(const QPointF& point); | |
87 | QPointF offset() const; |
|
87 | QPointF offset() const; | |
88 |
|
88 | |||
89 | protected: |
|
89 | protected: | |
90 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
90 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
91 | void hideEvent(QHideEvent *event); |
|
91 | void hideEvent(QHideEvent *event); | |
92 | void showEvent(QShowEvent *event); |
|
92 | void showEvent(QShowEvent *event); | |
93 |
|
93 | |||
94 | public Q_SLOTS: |
|
94 | public Q_SLOTS: | |
95 | // PIMPL ---> |
|
95 | // PIMPL ---> | |
96 | void handleSeriesAdded(QSeries *series, Domain *domain); |
|
96 | void handleSeriesAdded(QSeries *series, Domain *domain); | |
97 | void handleSeriesRemoved(QSeries *series); |
|
97 | void handleSeriesRemoved(QSeries *series); | |
98 | void handleAdded(QList<QPieSlice *> slices); |
|
98 | void handleAdded(QList<QPieSlice *> slices); | |
99 | void handleRemoved(QList<QPieSlice *> slices); |
|
99 | void handleRemoved(QList<QPieSlice *> slices); | |
100 | // PIMPL <--- |
|
100 | // PIMPL <--- | |
101 |
|
101 | |||
102 | private: |
|
102 | private: | |
103 | // PIMPL ---> |
|
103 | // PIMPL ---> | |
104 | void appendMarkers(QAreaSeries *series); |
|
104 | void appendMarkers(QAreaSeries *series); | |
105 | void appendMarkers(QXYSeries *series); |
|
105 | void appendMarkers(QXYSeries *series); | |
106 | void appendMarkers(QBarSeries *series); |
|
106 | void appendMarkers(QBarSeries *series); | |
107 | void appendMarkers(QPieSeries *series); |
|
107 | void appendMarkers(QPieSeries *series); | |
108 | void deleteMarkers(QSeries *series); |
|
108 | void deleteMarkers(QSeries *series); | |
109 |
|
||||
110 |
|
||||
111 |
|
||||
112 |
|
||||
113 | private Q_SLOTS: |
|
|||
114 | void updateLayout(); |
|
109 | void updateLayout(); | |
115 |
|
110 | |||
116 | private: |
|
111 | private: | |
117 | qreal m_margin; |
|
112 | qreal m_margin; | |
118 |
|
113 | |||
119 | QRectF m_rect; |
|
114 | QRectF m_rect; | |
120 | qreal m_offsetX; |
|
115 | qreal m_offsetX; | |
121 | qreal m_offsetY; |
|
116 | qreal m_offsetY; | |
122 |
|
117 | |||
123 | //QList<LegendMarker *> m_markers; |
|
118 | //QList<LegendMarker *> m_markers; | |
124 |
|
119 | |||
125 | QBrush m_brush; |
|
120 | QBrush m_brush; | |
126 | QPen m_pen; |
|
121 | QPen m_pen; | |
127 | QLegend::Alignments m_alignment; |
|
122 | QLegend::Alignments m_alignment; | |
128 | QGraphicsItemGroup* m_markers; |
|
123 | QGraphicsItemGroup* m_markers; | |
129 |
|
124 | |||
130 |
|
125 | |||
131 | bool m_attachedToChart; |
|
126 | bool m_attachedToChart; | |
132 |
|
127 | |||
133 | QChart *m_chart; |
|
128 | QChart *m_chart; | |
134 | qreal m_minWidth; |
|
129 | qreal m_minWidth; | |
135 | qreal m_minHeight; |
|
130 | qreal m_minHeight; | |
136 | qreal m_width; |
|
131 | qreal m_width; | |
137 | qreal m_height; |
|
132 | qreal m_height; | |
138 | bool m_visible; |
|
133 | bool m_visible; | |
139 | bool m_dirty; |
|
|||
140 | friend class ScrolledQLegend; |
|
134 | friend class ScrolledQLegend; | |
141 | // <--- PIMPL |
|
135 | // <--- PIMPL | |
142 | }; |
|
136 | }; | |
143 |
|
137 | |||
144 | class ScrolledQLegend: public QLegend, public Scroller |
|
138 | class ScrolledQLegend: public QLegend, public Scroller | |
145 | { |
|
139 | { | |
146 |
|
140 | |||
147 | public: |
|
141 | public: | |
148 | ScrolledQLegend(QChart *chart):QLegend(chart) |
|
142 | ScrolledQLegend(QChart *chart):QLegend(chart) | |
149 | { |
|
143 | { | |
150 | } |
|
144 | } | |
151 |
|
145 | |||
152 | void setOffset(const QPointF& point) |
|
146 | void setOffset(const QPointF& point) | |
153 | { |
|
147 | { | |
154 | QLegend::setOffset(point); |
|
148 | QLegend::setOffset(point); | |
155 | } |
|
149 | } | |
156 | QPointF offset() const |
|
150 | QPointF offset() const | |
157 | { |
|
151 | { | |
158 | return QLegend::offset(); |
|
152 | return QLegend::offset(); | |
159 | } |
|
153 | } | |
160 |
|
154 | |||
161 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ |
|
155 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ | |
162 | Scroller::mousePressEvent(event); |
|
156 | Scroller::mousePressEvent(event); | |
163 | //QLegend::mousePressEvent(event); |
|
157 | //QLegend::mousePressEvent(event); | |
164 | } |
|
158 | } | |
165 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ |
|
159 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ | |
166 | Scroller::mouseMoveEvent(event); |
|
160 | Scroller::mouseMoveEvent(event); | |
167 | //QLegend::mouseMoveEvent(event); |
|
161 | //QLegend::mouseMoveEvent(event); | |
168 | } |
|
162 | } | |
169 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ |
|
163 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ | |
170 | Scroller::mouseReleaseEvent(event); |
|
164 | Scroller::mouseReleaseEvent(event); | |
171 | //QLegend::mouseReleaseEvent(event); |
|
165 | //QLegend::mouseReleaseEvent(event); | |
172 | } |
|
166 | } | |
173 | }; |
|
167 | }; | |
174 |
|
168 | |||
175 | QTCOMMERCIALCHART_END_NAMESPACE |
|
169 | QTCOMMERCIALCHART_END_NAMESPACE | |
176 |
|
170 | |||
177 | #endif // QLEGEND_H |
|
171 | #endif // QLEGEND_H |
General Comments 0
You need to be logged in to leave comments.
Login now