@@ -1,261 +1,292 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
9 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | //items |
|
12 | //items | |
13 | #include "axisitem_p.h" |
|
13 | #include "axisitem_p.h" | |
14 | #include "bargroup.h" |
|
14 | #include "bargroup.h" | |
15 | #include "stackedbargroup.h" |
|
15 | #include "stackedbargroup.h" | |
16 | #include "linechartitem_p.h" |
|
16 | #include "linechartitem_p.h" | |
17 | #include "percentbargroup.h" |
|
17 | #include "percentbargroup.h" | |
18 | #include "linechartanimationitem_p.h" |
|
18 | #include "linechartanimationitem_p.h" | |
19 | #include "piepresenter.h" |
|
19 | #include "piepresenter.h" | |
20 |
|
20 | |||
21 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
21 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
22 |
|
22 | |||
23 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
23 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
24 | m_chart(chart), |
|
24 | m_chart(chart), | |
25 | m_dataset(dataset), |
|
25 | m_dataset(dataset), | |
26 | m_chartTheme(0), |
|
26 | m_chartTheme(0), | |
27 | m_domainIndex(0), |
|
27 | m_domainIndex(0), | |
28 | m_marginSize(0), |
|
28 | m_marginSize(0), | |
|
29 | m_axisX(new QChartAxis(this)), | |||
|
30 | m_axisY(new QChartAxis(this)), | |||
29 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
30 | { |
|
32 | { | |
31 | setChartTheme(QChart::ChartThemeDefault); |
|
33 | setChartTheme(QChart::ChartThemeDefault); | |
|
34 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); | |||
|
35 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); | |||
32 | createConnections(); |
|
36 | createConnections(); | |
33 | createDeafultAxis(); |
|
|||
34 | } |
|
37 | } | |
35 |
|
38 | |||
36 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
37 | { |
|
40 | { | |
38 | } |
|
41 | } | |
39 |
|
42 | |||
40 | void ChartPresenter::createDeafultAxis() |
|
|||
41 | { |
|
|||
42 | //default axis |
|
|||
43 | QChartAxis* axisX = new QChartAxis(this); |
|
|||
44 | QChartAxis* axisY = new QChartAxis(this); |
|
|||
45 |
|
||||
46 | m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart); |
|
|||
47 | m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart); |
|
|||
48 |
|
||||
49 | foreach(AxisItem* item, m_axis) { |
|
|||
50 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
|||
51 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
|||
52 | } |
|
|||
53 | } |
|
|||
54 |
|
||||
55 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
56 | { |
|
44 | { | |
57 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
58 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
|
47 | ||||
|
48 | QMapIterator<QChartAxis*,AxisItem*> i(m_axisItems); | |||
|
49 | ||||
|
50 | while (i.hasNext()) { | |||
|
51 | i.next(); | |||
|
52 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),i.value(),SLOT(handleGeometryChanged(const QRectF&))); | |||
|
53 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),i.value(),SLOT(handleDomainChanged(const Domain&))); | |||
|
54 | } | |||
59 | } |
|
55 | } | |
60 |
|
56 | |||
61 | void ChartPresenter::handleGeometryChanged() |
|
57 | void ChartPresenter::handleGeometryChanged() | |
62 | { |
|
58 | { | |
63 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
59 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
64 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
60 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
65 | Q_ASSERT(m_rect.isValid()); |
|
61 | Q_ASSERT(m_rect.isValid()); | |
66 | emit geometryChanged(m_rect); |
|
62 | emit geometryChanged(m_rect); | |
67 | } |
|
63 | } | |
68 |
|
64 | |||
69 | int ChartPresenter::margin() const |
|
65 | int ChartPresenter::margin() const | |
70 | { |
|
66 | { | |
71 | return m_marginSize; |
|
67 | return m_marginSize; | |
72 | } |
|
68 | } | |
73 |
|
69 | |||
74 | void ChartPresenter::setMargin(int margin) |
|
70 | void ChartPresenter::setMargin(int margin) | |
75 | { |
|
71 | { | |
76 | m_marginSize = margin; |
|
72 | m_marginSize = margin; | |
77 | } |
|
73 | } | |
78 |
|
74 | |||
79 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
75 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
80 | { |
|
76 | { | |
81 | switch(series->type()) |
|
77 | switch(series->type()) | |
82 | { |
|
78 | { | |
83 | case QChartSeries::SeriesTypeLine: { |
|
79 | case QChartSeries::SeriesTypeLine: { | |
84 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
80 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); | |
85 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
81 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
86 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
82 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
87 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
83 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
88 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
84 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
89 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
85 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
90 | m_chartItems.insert(series,item); |
|
86 | m_chartItems.insert(series,item); | |
91 | break; |
|
87 | break; | |
92 | } |
|
88 | } | |
93 |
|
89 | |||
94 | case QChartSeries::SeriesTypeBar: { |
|
90 | case QChartSeries::SeriesTypeBar: { | |
95 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
91 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
96 | BarGroup* item = new BarGroup(*barSeries,m_chart); |
|
92 | BarGroup* item = new BarGroup(*barSeries,m_chart); | |
97 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
93 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
98 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
94 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
99 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
95 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
100 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
96 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
101 | m_chartItems.insert(series,item); |
|
97 | m_chartItems.insert(series,item); | |
102 | // m_axisXItem->setVisible(false); |
|
98 | // m_axisXItem->setVisible(false); | |
103 | break; |
|
99 | break; | |
104 | } |
|
100 | } | |
105 |
|
101 | |||
106 | case QChartSeries::SeriesTypeStackedBar: { |
|
102 | case QChartSeries::SeriesTypeStackedBar: { | |
107 |
|
103 | |||
108 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
104 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
109 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); |
|
105 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); | |
110 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
106 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
111 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
107 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
112 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
108 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
113 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
109 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
114 | m_chartItems.insert(series,item); |
|
110 | m_chartItems.insert(series,item); | |
115 | break; |
|
111 | break; | |
116 | } |
|
112 | } | |
117 |
|
113 | |||
118 | case QChartSeries::SeriesTypePercentBar: { |
|
114 | case QChartSeries::SeriesTypePercentBar: { | |
119 |
|
115 | |||
120 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
116 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
121 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); |
|
117 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); | |
122 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
118 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
123 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
119 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
124 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
120 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
125 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
121 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
126 | m_chartItems.insert(series,item); |
|
122 | m_chartItems.insert(series,item); | |
127 | break; |
|
123 | break; | |
128 | } |
|
124 | } | |
129 | /* |
|
125 | /* | |
130 | case QChartSeries::SeriesTypeScatter: { |
|
126 | case QChartSeries::SeriesTypeScatter: { | |
131 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
127 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
132 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
128 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
133 | scatterSeries->d->setParentItem(this); |
|
129 | scatterSeries->d->setParentItem(this); | |
134 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
130 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
135 | m_chartItems << scatterSeries->d; |
|
131 | m_chartItems << scatterSeries->d; | |
136 | m_chartTheme->addObserver(scatterSeries->d); |
|
132 | m_chartTheme->addObserver(scatterSeries->d); | |
137 |
|
133 | |||
138 | foreach (qreal x, scatterSeries->d->m_x) { |
|
134 | foreach (qreal x, scatterSeries->d->m_x) { | |
139 | domain.m_minX = qMin(domain.m_minX, x); |
|
135 | domain.m_minX = qMin(domain.m_minX, x); | |
140 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
136 | domain.m_maxX = qMax(domain.m_maxX, x); | |
141 | } |
|
137 | } | |
142 | foreach (qreal y, scatterSeries->d->m_y) { |
|
138 | foreach (qreal y, scatterSeries->d->m_y) { | |
143 | domain.m_minY = qMin(domain.m_minY, y); |
|
139 | domain.m_minY = qMin(domain.m_minY, y); | |
144 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
140 | domain.m_maxY = qMax(domain.m_maxY, y); | |
145 | } |
|
141 | } | |
146 |
|
142 | |||
147 | break; |
|
143 | break; | |
148 | } |
|
144 | } | |
149 | */ |
|
145 | */ | |
150 |
|
146 | |||
151 | case QChartSeries::SeriesTypePie: { |
|
147 | case QChartSeries::SeriesTypePie: { | |
152 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
148 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
153 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); |
|
149 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); | |
154 | pieSeries->m_piePresenter = pie; // TODO: remove this pointer passing use signals&slots |
|
150 | pieSeries->m_piePresenter = pie; // TODO: remove this pointer passing use signals&slots | |
155 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
151 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
156 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); |
|
152 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); | |
157 | m_chartItems.insert(series, pie); |
|
153 | m_chartItems.insert(series, pie); | |
158 | break; |
|
154 | break; | |
159 | } |
|
155 | } | |
160 |
|
156 | |||
161 | default: { |
|
157 | default: { | |
162 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
158 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
163 | break; |
|
159 | break; | |
164 | } |
|
160 | } | |
165 | } |
|
161 | } | |
166 |
|
162 | |||
167 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
163 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
168 | } |
|
164 | } | |
169 |
|
165 | |||
170 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
166 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
171 | { |
|
167 | { | |
172 | //TODO: |
|
168 | //TODO: | |
173 | } |
|
169 | } | |
174 |
|
170 | |||
175 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
171 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
176 | { |
|
172 | { | |
177 | if(!rect.isValid()) return; |
|
173 | if(!rect.isValid()) return; | |
178 | QRectF r = rect.normalized(); |
|
174 | QRectF r = rect.normalized(); | |
179 | r.translate(-m_marginSize, -m_marginSize); |
|
175 | r.translate(-m_marginSize, -m_marginSize); | |
180 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); |
|
176 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); | |
181 | m_dataset->addDomain(domain); |
|
177 | m_dataset->addDomain(domain); | |
182 | } |
|
178 | } | |
183 |
|
179 | |||
184 | void ChartPresenter::zoomIn() |
|
180 | void ChartPresenter::zoomIn() | |
185 | { |
|
181 | { | |
186 | if (!m_dataset->nextDomain()) { |
|
182 | if (!m_dataset->nextDomain()) { | |
187 | QRectF rect = m_rect; |
|
183 | QRectF rect = m_rect; | |
188 | rect.setWidth(rect.width()/2); |
|
184 | rect.setWidth(rect.width()/2); | |
189 | rect.setHeight(rect.height()/2); |
|
185 | rect.setHeight(rect.height()/2); | |
190 | rect.moveCenter(m_rect.center()); |
|
186 | rect.moveCenter(m_rect.center()); | |
191 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
187 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
192 | m_dataset->addDomain(domain); |
|
188 | m_dataset->addDomain(domain); | |
193 | } |
|
189 | } | |
194 | } |
|
190 | } | |
195 |
|
191 | |||
196 | void ChartPresenter::zoomOut() |
|
192 | void ChartPresenter::zoomOut() | |
197 | { |
|
193 | { | |
198 | m_dataset->previousDomain(); |
|
194 | m_dataset->previousDomain(); | |
199 | } |
|
195 | } | |
200 |
|
196 | |||
201 | void ChartPresenter::zoomReset() |
|
197 | void ChartPresenter::zoomReset() | |
202 | { |
|
198 | { | |
203 | m_dataset->clearDomains(); |
|
199 | m_dataset->clearDomains(); | |
204 | } |
|
200 | } | |
205 |
|
201 | |||
206 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
202 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
207 | { |
|
203 | { | |
208 | delete m_chartTheme; |
|
204 | delete m_chartTheme; | |
209 |
|
205 | |||
210 | m_chartTheme = ChartTheme::createTheme(theme); |
|
206 | m_chartTheme = ChartTheme::createTheme(theme); | |
211 |
|
207 | |||
212 | m_chartTheme->decorate(m_chart); |
|
208 | m_chartTheme->decorate(m_chart); | |
213 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
209 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
214 |
|
210 | |||
215 | int index=0; |
|
211 | int index=0; | |
216 | while (i.hasNext()) { |
|
212 | while (i.hasNext()) { | |
217 | i.next(); |
|
213 | i.next(); | |
218 | index++; |
|
214 | index++; | |
219 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
215 | m_chartTheme->decorate(i.value(),i.key(),index); | |
220 | } |
|
216 | } | |
221 | } |
|
217 | } | |
222 |
|
218 | |||
223 |
|
219 | |||
224 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
220 | QChart::ChartTheme ChartPresenter::chartTheme() | |
225 | { |
|
221 | { | |
226 | return m_chartTheme->id(); |
|
222 | return m_chartTheme->id(); | |
227 | } |
|
223 | } | |
228 |
|
224 | |||
229 | void ChartPresenter::setAxisX(QChartAxis* axis) |
|
225 | QChartAxis* ChartPresenter::axisX() | |
230 | { |
|
226 | { | |
|
227 | return m_axisX; | |||
|
228 | } | |||
231 |
|
229 | |||
|
230 | QChartAxis* ChartPresenter::axisY() | |||
|
231 | { | |||
|
232 | return m_axisY; | |||
232 | } |
|
233 | } | |
233 |
|
234 | |||
234 |
|
|
235 | QChartAxis* ChartPresenter::addAxisX() | |
235 | { |
|
236 | { | |
|
237 | //only one axis | |||
|
238 | if(m_axisX==0){ | |||
|
239 | m_axisX = new QChartAxis(this); | |||
|
240 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); | |||
|
241 | } | |||
|
242 | return m_axisX; | |||
|
243 | } | |||
236 |
|
244 | |||
|
245 | QChartAxis* ChartPresenter::addAxisY() | |||
|
246 | { | |||
|
247 | if(m_axisY==0){ | |||
|
248 | m_axisY = new QChartAxis(this); | |||
|
249 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); | |||
|
250 | return m_axisY; | |||
|
251 | } | |||
|
252 | ||||
|
253 | QChartAxis* axis = new QChartAxis(this); | |||
|
254 | m_axisItems[axis] = new AxisItem(axis,AxisItem::Y_AXIS,m_chart); | |||
|
255 | return axis; | |||
|
256 | } | |||
|
257 | ||||
|
258 | void ChartPresenter::removeAxis(QChartAxis* axis) | |||
|
259 | { | |||
|
260 | AxisItem* item = m_axisItems.take(axis); | |||
|
261 | if(item){ | |||
|
262 | delete item; | |||
|
263 | delete axis; | |||
|
264 | } | |||
|
265 | //reset pointers to default ones | |||
|
266 | if(axis == m_axisX) m_axisX=0; | |||
|
267 | else if(axis == m_axisY) m_axisY=0; | |||
237 | } |
|
268 | } | |
238 |
|
269 | |||
239 | /* |
|
270 | /* | |
240 | void ChartPresenter::setAxisX(const QChartAxis& axis) |
|
271 | void ChartPresenter::setAxisX(const QChartAxis& axis) | |
241 | { |
|
272 | { | |
242 | setAxis(m_axisXItem,axis); |
|
273 | setAxis(m_axisXItem,axis); | |
243 | } |
|
274 | } | |
244 | void ChartPresenter::setAxisY(const QChartAxis& axis) |
|
275 | void ChartPresenter::setAxisY(const QChartAxis& axis) | |
245 | { |
|
276 | { | |
246 | setAxis(m_axisYItem.at(0),axis); |
|
277 | setAxis(m_axisYItem.at(0),axis); | |
247 | } |
|
278 | } | |
248 |
|
279 | |||
249 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) |
|
280 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) | |
250 | { |
|
281 | { | |
251 | //TODO not implemented |
|
282 | //TODO not implemented | |
252 | } |
|
283 | } | |
253 |
|
284 | |||
254 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) |
|
285 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) | |
255 | { |
|
286 | { | |
256 | item->setVisible(axis.isAxisVisible()); |
|
287 | item->setVisible(axis.isAxisVisible()); | |
257 | } |
|
288 | } | |
258 | */ |
|
289 | */ | |
259 | #include "moc_chartpresenter_p.cpp" |
|
290 | #include "moc_chartpresenter_p.cpp" | |
260 |
|
291 | |||
261 | QTCOMMERCIALCHART_END_NAMESPACE |
|
292 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,72 | |||||
1 | #ifndef CHARTPRESENTER_H_ |
|
1 | #ifndef CHARTPRESENTER_H_ | |
2 | #define CHARTPRESENTER_H_ |
|
2 | #define CHARTPRESENTER_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
6 | #include <QRectF> |
|
6 | #include <QRectF> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartItem; |
|
10 | class ChartItem; | |
11 | class QChartSeries; |
|
11 | class QChartSeries; | |
12 | class ChartDataSet; |
|
12 | class ChartDataSet; | |
13 | //class QChart; |
|
13 | //class QChart; | |
14 | class Domain; |
|
14 | class Domain; | |
15 | class AxisItem; |
|
15 | class AxisItem; | |
16 | class ChartTheme; |
|
16 | class ChartTheme; | |
17 |
|
17 | |||
18 | class ChartPresenter: public QObject |
|
18 | class ChartPresenter: public QObject | |
19 | { |
|
19 | { | |
20 | Q_OBJECT |
|
20 | Q_OBJECT | |
21 | public: |
|
21 | public: | |
22 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
22 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
23 | virtual ~ChartPresenter(); |
|
23 | virtual ~ChartPresenter(); | |
24 |
|
24 | |||
25 | void setMargin(int margin); |
|
25 | void setMargin(int margin); | |
26 | int margin() const; |
|
26 | int margin() const; | |
27 |
|
27 | |||
28 | void zoomInToRect(const QRectF& rectangle); |
|
28 | void zoomInToRect(const QRectF& rectangle); | |
29 | void zoomIn(); |
|
29 | void zoomIn(); | |
30 | void zoomOut(); |
|
30 | void zoomOut(); | |
31 | void zoomReset(); |
|
31 | void zoomReset(); | |
32 |
|
32 | |||
33 | void setChartTheme(QChart::ChartTheme theme); |
|
33 | void setChartTheme(QChart::ChartTheme theme); | |
34 | QChart::ChartTheme chartTheme(); |
|
34 | QChart::ChartTheme chartTheme(); | |
35 |
|
35 | |||
36 |
|
|
36 | QChartAxis* axisX(); | |
37 |
|
|
37 | QChartAxis* axisY(); | |
|
38 | QChartAxis* addAxisX(); | |||
|
39 | QChartAxis* addAxisY(); | |||
|
40 | void removeAxis(QChartAxis* axis); | |||
|
41 | ||||
38 | private: |
|
42 | private: | |
39 | void createConnections(); |
|
43 | void createConnections(); | |
40 | void createDeafultAxis(); |
|
|||
41 |
|
44 | |||
42 | public slots: |
|
45 | public slots: | |
43 | void handleSeriesAdded(QChartSeries* series); |
|
46 | void handleSeriesAdded(QChartSeries* series); | |
44 | void handleSeriesRemoved(QChartSeries* series){}; |
|
47 | void handleSeriesRemoved(QChartSeries* series){}; | |
45 | void handleSeriesChanged(QChartSeries* series); |
|
48 | void handleSeriesChanged(QChartSeries* series); | |
46 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); |
|
49 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); | |
47 | void handleGeometryChanged(); |
|
50 | void handleGeometryChanged(); | |
48 |
|
51 | |||
49 | signals: |
|
52 | signals: | |
50 | void geometryChanged(const QRectF& rect); |
|
53 | void geometryChanged(const QRectF& rect); | |
51 |
|
54 | |||
52 | private: |
|
55 | private: | |
53 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
56 | QMap<QChartSeries*,ChartItem*> m_chartItems; | |
|
57 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |||
54 | QChart* m_chart; |
|
58 | QChart* m_chart; | |
55 | ChartDataSet* m_dataset; |
|
59 | ChartDataSet* m_dataset; | |
56 | QVector<Domain> m_domains; |
|
60 | QVector<Domain> m_domains; | |
57 | QList<AxisItem*> m_axis; |
|
|||
58 | ChartTheme *m_chartTheme; |
|
61 | ChartTheme *m_chartTheme; | |
|
62 | QChartAxis* m_axisX; | |||
|
63 | QChartAxis* m_axisY; | |||
59 | int m_domainIndex; |
|
64 | int m_domainIndex; | |
60 | int m_marginSize; |
|
65 | int m_marginSize; | |
61 | QRectF m_rect; |
|
66 | QRectF m_rect; | |
62 |
|
67 | |||
63 | }; |
|
68 | }; | |
64 |
|
69 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
71 | |||
67 | #endif /* CHARTPRESENTER_H_ */ |
|
72 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,180 +1,196 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include "qscatterseries_p.h" |
|
3 | #include "qscatterseries_p.h" | |
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include "qchartaxis.h" |
|
5 | #include "qchartaxis.h" | |
6 | #include "chartpresenter_p.h" |
|
6 | #include "chartpresenter_p.h" | |
7 | #include "chartdataset_p.h" |
|
7 | #include "chartdataset_p.h" | |
8 |
|
8 | |||
9 | //series |
|
9 | //series | |
10 | #include "barchartseries.h" |
|
10 | #include "barchartseries.h" | |
11 | #include "stackedbarchartseries.h" |
|
11 | #include "stackedbarchartseries.h" | |
12 | #include "percentbarchartseries.h" |
|
12 | #include "percentbarchartseries.h" | |
13 | #include "qlinechartseries.h" |
|
13 | #include "qlinechartseries.h" | |
14 |
|
14 | |||
15 | #include <QGraphicsScene> |
|
15 | #include <QGraphicsScene> | |
16 | #include <QGraphicsSceneResizeEvent> |
|
16 | #include <QGraphicsSceneResizeEvent> | |
17 | #include <QDebug> |
|
17 | #include <QDebug> | |
18 |
|
18 | |||
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
20 |
|
20 | |||
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
22 | m_backgroundItem(0), |
|
22 | m_backgroundItem(0), | |
23 | m_titleItem(0), |
|
23 | m_titleItem(0), | |
24 | m_dataset(new ChartDataSet(this)), |
|
24 | m_dataset(new ChartDataSet(this)), | |
25 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
25 | m_presenter(new ChartPresenter(this,m_dataset)) | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | QChart::~QChart() {} |
|
29 | QChart::~QChart() {} | |
30 |
|
30 | |||
31 | void QChart::addSeries(QChartSeries* series) |
|
31 | void QChart::addSeries(QChartSeries* series) | |
32 | { |
|
32 | { | |
33 | m_dataset->addSeries(series); |
|
33 | m_dataset->addSeries(series); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | //TODO on review, is it really needed ?? |
|
36 | //TODO on review, is it really needed ?? | |
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
38 | { |
|
38 | { | |
39 | // TODO: support also other types; not only scatter and pie |
|
39 | // TODO: support also other types; not only scatter and pie | |
40 |
|
40 | |||
41 | QChartSeries *series(0); |
|
41 | QChartSeries *series(0); | |
42 |
|
42 | |||
43 | switch (type) { |
|
43 | switch (type) { | |
44 | case QChartSeries::SeriesTypeLine: { |
|
44 | case QChartSeries::SeriesTypeLine: { | |
45 | series = QLineChartSeries::create(); |
|
45 | series = QLineChartSeries::create(); | |
46 | break; |
|
46 | break; | |
47 | } |
|
47 | } | |
48 | case QChartSeries::SeriesTypeBar: { |
|
48 | case QChartSeries::SeriesTypeBar: { | |
49 | series = new BarChartSeries(this); |
|
49 | series = new BarChartSeries(this); | |
50 | break; |
|
50 | break; | |
51 | } |
|
51 | } | |
52 | case QChartSeries::SeriesTypeStackedBar: { |
|
52 | case QChartSeries::SeriesTypeStackedBar: { | |
53 | series = new StackedBarChartSeries(this); |
|
53 | series = new StackedBarChartSeries(this); | |
54 | break; |
|
54 | break; | |
55 | } |
|
55 | } | |
56 | case QChartSeries::SeriesTypePercentBar: { |
|
56 | case QChartSeries::SeriesTypePercentBar: { | |
57 | series = new PercentBarChartSeries(this); |
|
57 | series = new PercentBarChartSeries(this); | |
58 | break; |
|
58 | break; | |
59 | } |
|
59 | } | |
60 | case QChartSeries::SeriesTypeScatter: { |
|
60 | case QChartSeries::SeriesTypeScatter: { | |
61 | series = new QScatterSeries(this); |
|
61 | series = new QScatterSeries(this); | |
62 | break; |
|
62 | break; | |
63 | } |
|
63 | } | |
64 | case QChartSeries::SeriesTypePie: { |
|
64 | case QChartSeries::SeriesTypePie: { | |
65 | series = new QPieSeries(this); |
|
65 | series = new QPieSeries(this); | |
66 | break; |
|
66 | break; | |
67 | } |
|
67 | } | |
68 | default: |
|
68 | default: | |
69 | Q_ASSERT(false); |
|
69 | Q_ASSERT(false); | |
70 | break; |
|
70 | break; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | addSeries(series); |
|
73 | addSeries(series); | |
74 | return series; |
|
74 | return series; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
77 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
78 | { |
|
78 | { | |
79 |
|
79 | |||
80 | if(!m_backgroundItem) { |
|
80 | if(!m_backgroundItem) { | |
81 | m_backgroundItem = new QGraphicsRectItem(this); |
|
81 | m_backgroundItem = new QGraphicsRectItem(this); | |
82 | m_backgroundItem->setZValue(-1); |
|
82 | m_backgroundItem->setZValue(-1); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | m_backgroundItem->setBrush(brush); |
|
85 | m_backgroundItem->setBrush(brush); | |
86 | m_backgroundItem->update(); |
|
86 | m_backgroundItem->update(); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
89 | void QChart::setChartBackgroundPen(const QPen& pen) | |
90 | { |
|
90 | { | |
91 |
|
91 | |||
92 | if(!m_backgroundItem) { |
|
92 | if(!m_backgroundItem) { | |
93 | m_backgroundItem = new QGraphicsRectItem(this); |
|
93 | m_backgroundItem = new QGraphicsRectItem(this); | |
94 | m_backgroundItem->setZValue(-1); |
|
94 | m_backgroundItem->setZValue(-1); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | m_backgroundItem->setPen(pen); |
|
97 | m_backgroundItem->setPen(pen); | |
98 | m_backgroundItem->update(); |
|
98 | m_backgroundItem->update(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void QChart::setTitle(const QString& title,const QFont& font) |
|
101 | void QChart::setTitle(const QString& title,const QFont& font) | |
102 | { |
|
102 | { | |
103 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
103 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
104 | m_titleItem->setPlainText(title); |
|
104 | m_titleItem->setPlainText(title); | |
105 | m_titleItem->setFont(font); |
|
105 | m_titleItem->setFont(font); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | int QChart::margin() const |
|
108 | int QChart::margin() const | |
109 | { |
|
109 | { | |
110 | return m_presenter->margin(); |
|
110 | return m_presenter->margin(); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void QChart::setMargin(int margin) |
|
113 | void QChart::setMargin(int margin) | |
114 | { |
|
114 | { | |
115 | m_presenter->setMargin(margin); |
|
115 | m_presenter->setMargin(margin); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
118 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
119 | { |
|
119 | { | |
120 | m_presenter->setChartTheme(theme); |
|
120 | m_presenter->setChartTheme(theme); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | QChart::ChartTheme QChart::chartTheme() const |
|
123 | QChart::ChartTheme QChart::chartTheme() const | |
124 | { |
|
124 | { | |
125 | return m_presenter->chartTheme(); |
|
125 | return m_presenter->chartTheme(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
128 | void QChart::zoomInToRect(const QRectF& rectangle) | |
129 | { |
|
129 | { | |
130 | m_presenter->zoomInToRect(rectangle); |
|
130 | m_presenter->zoomInToRect(rectangle); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void QChart::zoomIn() |
|
133 | void QChart::zoomIn() | |
134 | { |
|
134 | { | |
135 | m_presenter->zoomIn(); |
|
135 | m_presenter->zoomIn(); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void QChart::zoomOut() |
|
138 | void QChart::zoomOut() | |
139 | { |
|
139 | { | |
140 | m_presenter->zoomOut(); |
|
140 | m_presenter->zoomOut(); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void QChart::zoomReset() |
|
143 | void QChart::zoomReset() | |
144 | { |
|
144 | { | |
145 | m_presenter->zoomReset(); |
|
145 | m_presenter->zoomReset(); | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void QChart::setAxisX(QChartAxis* axis) |
|
148 | QChartAxis* QChart::axisX() | |
149 | { |
|
149 | { | |
150 |
m_presenter-> |
|
150 | return m_presenter->axisX(); | |
151 | } |
|
151 | } | |
152 | void QChart::addAxisY(QChartAxis* axis) |
|
152 | ||
|
153 | QChartAxis* QChart::axisY() | |||
|
154 | { | |||
|
155 | return m_presenter->axisY(); | |||
|
156 | } | |||
|
157 | ||||
|
158 | QChartAxis* QChart::addAxisX() | |||
|
159 | { | |||
|
160 | return m_presenter->addAxisX(); | |||
|
161 | } | |||
|
162 | ||||
|
163 | QChartAxis* QChart::addAxisY() | |||
|
164 | { | |||
|
165 | return m_presenter->addAxisY(); | |||
|
166 | } | |||
|
167 | ||||
|
168 | void QChart::removeAxis(QChartAxis* axis) | |||
153 | { |
|
169 | { | |
154 |
m_presenter-> |
|
170 | m_presenter->removeAxis(axis); | |
155 | } |
|
171 | } | |
156 |
|
172 | |||
157 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
173 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
158 | { |
|
174 | { | |
159 |
|
175 | |||
160 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
176 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
161 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
177 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
162 |
|
178 | |||
163 | // recalculate title position |
|
179 | // recalculate title position | |
164 | if (m_titleItem) { |
|
180 | if (m_titleItem) { | |
165 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
181 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
166 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
182 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
167 | } |
|
183 | } | |
168 |
|
184 | |||
169 | //recalculate background gradient |
|
185 | //recalculate background gradient | |
170 | if (m_backgroundItem) { |
|
186 | if (m_backgroundItem) { | |
171 | m_backgroundItem->setRect(rect); |
|
187 | m_backgroundItem->setRect(rect); | |
172 | } |
|
188 | } | |
173 |
|
189 | |||
174 | QGraphicsWidget::resizeEvent(event); |
|
190 | QGraphicsWidget::resizeEvent(event); | |
175 | update(); |
|
191 | update(); | |
176 | } |
|
192 | } | |
177 |
|
193 | |||
178 | #include "moc_qchart.cpp" |
|
194 | #include "moc_qchart.cpp" | |
179 |
|
195 | |||
180 | QTCOMMERCIALCHART_END_NAMESPACE |
|
196 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,90 +1,90 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarGroup; |
|
17 | class BarGroup; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
25 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
25 | //class QTCOMMERCIALCHART_EXPORT QChart | |
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
27 | // public: QChartGraphicsItem(QChart &chart); |
|
27 | // public: QChartGraphicsItem(QChart &chart); | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | * TODO: define the responsibilities |
|
30 | * TODO: define the responsibilities | |
31 | */ |
|
31 | */ | |
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | enum ChartTheme { |
|
36 | enum ChartTheme { | |
37 | /*! The default theme follows the GUI style of the Operating System */ |
|
37 | /*! The default theme follows the GUI style of the Operating System */ | |
38 | ChartThemeDefault, |
|
38 | ChartThemeDefault, | |
39 | ChartThemeVanilla, |
|
39 | ChartThemeVanilla, | |
40 | ChartThemeIcy, |
|
40 | ChartThemeIcy, | |
41 | ChartThemeGrayscale, |
|
41 | ChartThemeGrayscale, | |
42 | ChartThemeScientific, |
|
42 | ChartThemeScientific, | |
43 | //ChartThemeUnnamed1 |
|
43 | //ChartThemeUnnamed1 | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
48 | ~QChart(); |
|
48 | ~QChart(); | |
49 |
|
49 | |||
50 | void addSeries(QChartSeries* series); |
|
50 | void addSeries(QChartSeries* series); | |
51 |
|
51 | |||
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
55 |
|
55 | |||
56 | void setMargin(int margin); |
|
56 | void setMargin(int margin); | |
57 | int margin() const; |
|
57 | int margin() const; | |
58 | void setChartTheme(QChart::ChartTheme theme); |
|
58 | void setChartTheme(QChart::ChartTheme theme); | |
59 | QChart::ChartTheme chartTheme() const; |
|
59 | QChart::ChartTheme chartTheme() const; | |
60 |
|
60 | |||
61 | void setTitle(const QString& title,const QFont& font = QFont()); |
|
61 | void setTitle(const QString& title,const QFont& font = QFont()); | |
62 | void setChartBackgroundBrush(const QBrush& brush); |
|
62 | void setChartBackgroundBrush(const QBrush& brush); | |
63 | void setChartBackgroundPen(const QPen& pen); |
|
63 | void setChartBackgroundPen(const QPen& pen); | |
64 |
|
64 | |||
65 | void zoomInToRect(const QRectF& rectangle); |
|
65 | void zoomInToRect(const QRectF& rectangle); | |
66 | void zoomIn(); |
|
66 | void zoomIn(); | |
67 | void zoomOut(); |
|
67 | void zoomOut(); | |
68 | void zoomReset(); |
|
68 | void zoomReset(); | |
69 |
|
69 | |||
70 |
|
|
70 | QChartAxis* axisX(); | |
71 |
|
|
71 | QChartAxis* axisY(); | |
|
72 | QChartAxis* addAxisX(); | |||
|
73 | QChartAxis* addAxisY(); | |||
|
74 | void removeAxis(QChartAxis* axis); | |||
72 |
|
75 | |||
73 | protected: |
|
76 | protected: | |
74 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
77 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
75 |
|
78 | |||
76 | private: |
|
79 | private: | |
77 | void setAxis(AxisItem *item, const QChartAxis& axis); |
|
|||
78 |
|
||||
79 | private: |
|
|||
80 | Q_DISABLE_COPY(QChart) |
|
80 | Q_DISABLE_COPY(QChart) | |
81 | QGraphicsRectItem* m_backgroundItem; |
|
81 | QGraphicsRectItem* m_backgroundItem; | |
82 | QGraphicsTextItem* m_titleItem; |
|
82 | QGraphicsTextItem* m_titleItem; | |
83 | QRectF m_rect; |
|
83 | QRectF m_rect; | |
84 | ChartDataSet *m_dataset; |
|
84 | ChartDataSet *m_dataset; | |
85 | ChartPresenter *m_presenter; |
|
85 | ChartPresenter *m_presenter; | |
86 | }; |
|
86 | }; | |
87 |
|
87 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE | |
89 |
|
89 | |||
90 | #endif |
|
90 | #endif |
@@ -1,75 +1,76 | |||||
1 | #ifndef QCHARTAXIS_H_ |
|
1 | #ifndef QCHARTAXIS_H_ | |
2 | #define QCHARTAXIS_H_ |
|
2 | #define QCHARTAXIS_H_ | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartAxis : public QObject |
|
10 | class QChartAxis : public QObject | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 |
|
13 | |||
14 | Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); |
|
14 | Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); | |
15 | Q_PROPERTY(QPen axisPen READ axisPen WRITE setAxisPen NOTIFY axisPenChanged); |
|
15 | Q_PROPERTY(QPen axisPen READ axisPen WRITE setAxisPen NOTIFY axisPenChanged); | |
16 | Q_PROPERTY(QBrush axisBrush READ axisBrush WRITE setAxisBrush NOTIFY axisBurshChanged); |
|
16 | Q_PROPERTY(QBrush axisBrush READ axisBrush WRITE setAxisBrush NOTIFY axisBurshChanged); | |
17 |
|
17 | |||
18 | // Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); |
|
18 | // Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); | |
19 | public: |
|
19 | public: | |
20 | enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE }; |
|
20 | enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE }; | |
21 |
|
21 | |||
22 | QChartAxis(QObject* parent = 0); |
|
22 | QChartAxis(QObject* parent = 0); | |
23 | virtual ~QChartAxis(); |
|
23 | virtual ~QChartAxis(); | |
24 |
|
24 | |||
25 | //axis |
|
25 | //axis | |
26 | bool isAxisVisible() const { return m_axisVisible;}; |
|
26 | bool isAxisVisible() const { return m_axisVisible;}; | |
27 | void setAxisVisible(bool visible); |
|
27 | void setAxisVisible(bool visible); | |
28 | void setAxisPen(const QPen& pen); |
|
28 | void setAxisPen(const QPen& pen); | |
29 | const QPen& axisPen() const { return m_axisPen;}; |
|
29 | const QPen& axisPen() const { return m_axisPen;}; | |
30 | void setAxisBrush(const QBrush& brush); |
|
30 | void setAxisBrush(const QBrush& brush); | |
31 | const QBrush& axisBrush() const { return m_axisBrush;}; |
|
31 | const QBrush& axisBrush() const { return m_axisBrush;}; | |
32 |
|
32 | |||
33 | //grid |
|
33 | //grid | |
34 | bool isGridVisible() const { return m_girdVisible;}; |
|
34 | bool isGridVisible() const { return m_girdVisible;}; | |
35 | void setGridVisible(bool visible); |
|
35 | void setGridVisible(bool visible); | |
36 |
|
36 | |||
37 | bool isLabelsVisible() const { return m_labelsVisible;}; |
|
37 | bool isLabelsVisible() const { return m_labelsVisible;}; | |
38 | void setLabelsVisible(bool visible); |
|
38 | void setLabelsVisible(bool visible); | |
39 |
|
39 | |||
40 | bool isRowShadesVisible() const { return m_rowShadesVisible;}; |
|
40 | bool isRowShadesVisible() const { return m_rowShadesVisible;}; | |
41 | void setRowShadesVisible(bool visible); |
|
41 | void setRowShadesVisible(bool visible); | |
42 |
|
42 | |||
43 | /* |
|
43 | /* | |
44 | void setLabelFont(const QFont& font); |
|
44 | void setLabelFont(const QFont& font); | |
45 | const QFont& labelFont(); |
|
45 | const QFont& labelFont(); | |
46 |
|
46 | |||
47 | void setLabelPen(const QPen& pen); |
|
47 | void setLabelPen(const QPen& pen); | |
48 | const QPen& labelPen(); |
|
48 | const QPen& labelPen(); | |
49 |
|
49 | |||
50 | void setGridPen(const QPen& pen); |
|
50 | void setGridPen(const QPen& pen); | |
51 | const QPen& gridPen(); |
|
51 | const QPen& gridPen(); | |
52 |
|
52 | |||
53 | void setGridBrush(const QBrush& brush); |
|
53 | void setGridBrush(const QBrush& brush); | |
54 | const QBrush& gridBrush(); |
|
54 | const QBrush& gridBrush(); | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
|
57 | ||||
57 | signals: |
|
58 | signals: | |
58 | void axisVisibilityChanged(); |
|
59 | void axisVisibilityChanged(); | |
59 | void axisPenChanged(); |
|
60 | void axisPenChanged(); | |
60 | void axisBurshChanged(); |
|
61 | void axisBurshChanged(); | |
61 |
|
62 | |||
62 |
|
63 | |||
63 | private: |
|
64 | private: | |
64 |
|
65 | |||
65 | bool m_axisVisible; |
|
66 | bool m_axisVisible; | |
66 | QPen m_axisPen; |
|
67 | QPen m_axisPen; | |
67 | QBrush m_axisBrush; |
|
68 | QBrush m_axisBrush; | |
68 |
|
69 | |||
69 | bool m_girdVisible; |
|
70 | bool m_girdVisible; | |
70 | bool m_labelsVisible; |
|
71 | bool m_labelsVisible; | |
71 | bool m_rowShadesVisible; |
|
72 | bool m_rowShadesVisible; | |
72 | }; |
|
73 | }; | |
73 |
|
74 | |||
74 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
75 | #endif /* QCHARTAXIS_H_ */ |
|
76 | #endif /* QCHARTAXIS_H_ */ |
@@ -1,202 +1,227 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
5 | #include <QRubberBand> |
|
5 | #include <QRubberBand> | |
6 | #include <QResizeEvent> |
|
6 | #include <QResizeEvent> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | QChartView::QChartView(QWidget *parent) : |
|
11 | QChartView::QChartView(QWidget *parent) : | |
12 | QGraphicsView(parent), |
|
12 | QGraphicsView(parent), | |
13 | m_scene(new QGraphicsScene()), |
|
13 | m_scene(new QGraphicsScene()), | |
14 | m_chart(new QChart()), |
|
14 | m_chart(new QChart()), | |
15 | m_rubberBand(0), |
|
15 | m_rubberBand(0), | |
16 | m_verticalRubberBand(false), |
|
16 | m_verticalRubberBand(false), | |
17 | m_horizonalRubberBand(false) |
|
17 | m_horizonalRubberBand(false) | |
18 | { |
|
18 | { | |
19 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
19 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
20 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
20 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
21 | setScene(m_scene); |
|
21 | setScene(m_scene); | |
22 | m_chart->setMargin(50); |
|
22 | m_chart->setMargin(50); | |
23 | m_scene->addItem(m_chart); |
|
23 | m_scene->addItem(m_chart); | |
24 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
24 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | QChartView::~QChartView() |
|
27 | QChartView::~QChartView() | |
28 | { |
|
28 | { | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | void QChartView::resizeEvent(QResizeEvent *event) |
|
31 | void QChartView::resizeEvent(QResizeEvent *event) | |
32 | { |
|
32 | { | |
33 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
33 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
34 | m_chart->resize(size()); |
|
34 | m_chart->resize(size()); | |
35 | QWidget::resizeEvent(event); |
|
35 | QWidget::resizeEvent(event); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | void QChartView::addSeries(QChartSeries* series) |
|
39 | void QChartView::addSeries(QChartSeries* series) | |
40 | { |
|
40 | { | |
41 | m_chart->addSeries(series); |
|
41 | m_chart->addSeries(series); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) |
|
44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) | |
45 | { |
|
45 | { | |
46 |
|
46 | |||
47 | return m_chart->createSeries(type); |
|
47 | return m_chart->createSeries(type); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void QChartView::zoomInToRect(const QRect& rectangle) |
|
50 | void QChartView::zoomInToRect(const QRect& rectangle) | |
51 | { |
|
51 | { | |
52 | m_chart->zoomInToRect(rectangle); |
|
52 | m_chart->zoomInToRect(rectangle); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void QChartView::zoomIn() |
|
55 | void QChartView::zoomIn() | |
56 | { |
|
56 | { | |
57 | m_chart->zoomIn(); |
|
57 | m_chart->zoomIn(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void QChartView::zoomOut() |
|
60 | void QChartView::zoomOut() | |
61 | { |
|
61 | { | |
62 | m_chart->zoomOut(); |
|
62 | m_chart->zoomOut(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | int QChartView::margin() const |
|
65 | int QChartView::margin() const | |
66 | { |
|
66 | { | |
67 | return m_chart->margin(); |
|
67 | return m_chart->margin(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void QChartView::setTitle(const QString& title) |
|
70 | void QChartView::setTitle(const QString& title) | |
71 | { |
|
71 | { | |
72 | m_chart->setTitle(title); |
|
72 | m_chart->setTitle(title); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
75 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
76 | { |
|
76 | { | |
77 | m_chart->setChartBackgroundBrush(brush); |
|
77 | m_chart->setChartBackgroundBrush(brush); | |
78 | } |
|
78 | } | |
79 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
79 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
80 | { |
|
80 | { | |
81 | m_chart->setChartBackgroundPen(pen); |
|
81 | m_chart->setChartBackgroundPen(pen); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 |
|
84 | |||
85 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
85 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
86 | { |
|
86 | { | |
87 | switch(policy){ |
|
87 | switch(policy){ | |
88 | case VerticalRubberBand: |
|
88 | case VerticalRubberBand: | |
89 | m_verticalRubberBand = true; |
|
89 | m_verticalRubberBand = true; | |
90 | m_horizonalRubberBand = false; |
|
90 | m_horizonalRubberBand = false; | |
91 | break; |
|
91 | break; | |
92 | case HorizonalRubberBand: |
|
92 | case HorizonalRubberBand: | |
93 | m_verticalRubberBand = false; |
|
93 | m_verticalRubberBand = false; | |
94 | m_horizonalRubberBand = true; |
|
94 | m_horizonalRubberBand = true; | |
95 | break; |
|
95 | break; | |
96 | case RectangleRubberBand: |
|
96 | case RectangleRubberBand: | |
97 | m_verticalRubberBand = true; |
|
97 | m_verticalRubberBand = true; | |
98 | m_horizonalRubberBand = true; |
|
98 | m_horizonalRubberBand = true; | |
99 | break; |
|
99 | break; | |
100 | case NoRubberBand: |
|
100 | case NoRubberBand: | |
101 | default: |
|
101 | default: | |
102 | delete m_rubberBand; |
|
102 | delete m_rubberBand; | |
103 | m_rubberBand=0; |
|
103 | m_rubberBand=0; | |
104 | m_horizonalRubberBand = false; |
|
104 | m_horizonalRubberBand = false; | |
105 | m_verticalRubberBand = false; |
|
105 | m_verticalRubberBand = false; | |
106 | return; |
|
106 | return; | |
107 | } |
|
107 | } | |
108 | if(!m_rubberBand){ |
|
108 | if(!m_rubberBand){ | |
109 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
109 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
110 | m_rubberBand->setEnabled(true); |
|
110 | m_rubberBand->setEnabled(true); | |
111 | } |
|
111 | } | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
114 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |
115 | { |
|
115 | { | |
116 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
116 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |
117 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
117 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |
118 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
118 | if(m_verticalRubberBand) return VerticalRubberBand; | |
119 | return NoRubberBand; |
|
119 | return NoRubberBand; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
123 | void QChartView::mousePressEvent(QMouseEvent *event) | |
124 | { |
|
124 | { | |
125 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
125 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
126 |
|
126 | |||
127 | int margin = m_chart->margin(); |
|
127 | int margin = m_chart->margin(); | |
128 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
128 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
129 |
|
129 | |||
130 | if (rect.contains(event->pos())) { |
|
130 | if (rect.contains(event->pos())) { | |
131 | m_rubberBandOrigin = event->pos(); |
|
131 | m_rubberBandOrigin = event->pos(); | |
132 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
132 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |
133 | m_rubberBand->show(); |
|
133 | m_rubberBand->show(); | |
134 | event->accept(); |
|
134 | event->accept(); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
139 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
140 | { |
|
140 | { | |
141 | if(m_rubberBand && m_rubberBand->isVisible()){ |
|
141 | if(m_rubberBand && m_rubberBand->isVisible()){ | |
142 | int margin = m_chart->margin(); |
|
142 | int margin = m_chart->margin(); | |
143 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
143 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
144 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
144 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
145 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
145 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
146 | if(!m_verticalRubberBand) { |
|
146 | if(!m_verticalRubberBand) { | |
147 | m_rubberBandOrigin.setY(rect.top()); |
|
147 | m_rubberBandOrigin.setY(rect.top()); | |
148 | height = rect.height(); |
|
148 | height = rect.height(); | |
149 | } |
|
149 | } | |
150 | if(!m_horizonalRubberBand) { |
|
150 | if(!m_horizonalRubberBand) { | |
151 | m_rubberBandOrigin.setX(rect.left()); |
|
151 | m_rubberBandOrigin.setX(rect.left()); | |
152 | width= rect.width(); |
|
152 | width= rect.width(); | |
153 | } |
|
153 | } | |
154 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
154 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
155 | } else { |
|
155 | } else { | |
156 | QGraphicsView::mouseMoveEvent(event); |
|
156 | QGraphicsView::mouseMoveEvent(event); | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
160 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
161 | { |
|
161 | { | |
162 | if(m_rubberBand){ |
|
162 | if(m_rubberBand){ | |
163 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
163 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |
164 | m_rubberBand->hide(); |
|
164 | m_rubberBand->hide(); | |
165 | QRect rect = m_rubberBand->geometry(); |
|
165 | QRect rect = m_rubberBand->geometry(); | |
166 | m_chart->zoomInToRect(rect); |
|
166 | m_chart->zoomInToRect(rect); | |
167 | event->accept(); |
|
167 | event->accept(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | if(event->button()==Qt::RightButton) |
|
170 | if(event->button()==Qt::RightButton) | |
171 | m_chart->zoomReset(); |
|
171 | m_chart->zoomReset(); | |
172 | }else{ |
|
172 | }else{ | |
173 | QGraphicsView::mouseReleaseEvent(event); |
|
173 | QGraphicsView::mouseReleaseEvent(event); | |
174 | } |
|
174 | } | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
177 | void QChartView::keyPressEvent(QKeyEvent *event) | |
178 | { |
|
178 | { | |
179 | switch (event->key()) { |
|
179 | switch (event->key()) { | |
180 | case Qt::Key_Plus: |
|
180 | case Qt::Key_Plus: | |
181 | zoomIn(); |
|
181 | zoomIn(); | |
182 | break; |
|
182 | break; | |
183 | case Qt::Key_Minus: |
|
183 | case Qt::Key_Minus: | |
184 | zoomOut(); |
|
184 | zoomOut(); | |
185 | break; |
|
185 | break; | |
186 | default: |
|
186 | default: | |
187 | QGraphicsView::keyPressEvent(event); |
|
187 | QGraphicsView::keyPressEvent(event); | |
188 | break; |
|
188 | break; | |
189 | } |
|
189 | } | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
192 | void QChartView::setChartTheme(QChart::ChartTheme theme) | |
193 | { |
|
193 | { | |
194 | m_chart->setChartTheme(theme); |
|
194 | m_chart->setChartTheme(theme); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QChart::ChartTheme QChartView::chartTheme() const |
|
197 | QChart::ChartTheme QChartView::chartTheme() const | |
198 | { |
|
198 | { | |
199 | return m_chart->chartTheme(); |
|
199 | return m_chart->chartTheme(); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
|
202 | QChartAxis* QChartView::axisX() | |||
|
203 | { | |||
|
204 | return m_chart->axisX(); | |||
|
205 | } | |||
|
206 | ||||
|
207 | QChartAxis* QChartView::axisY() | |||
|
208 | { | |||
|
209 | return m_chart->axisY(); | |||
|
210 | } | |||
|
211 | ||||
|
212 | QChartAxis* QChartView::addAxisX() | |||
|
213 | { | |||
|
214 | return m_chart->addAxisX(); | |||
|
215 | } | |||
|
216 | ||||
|
217 | QChartAxis* QChartView::addAxisY() | |||
|
218 | { | |||
|
219 | return m_chart->addAxisY(); | |||
|
220 | } | |||
|
221 | ||||
|
222 | void QChartView::removeAxis(QChartAxis* axis) | |||
|
223 | { | |||
|
224 | m_chart->removeAxis(axis); | |||
|
225 | } | |||
|
226 | ||||
202 | QTCOMMERCIALCHART_END_NAMESPACE |
|
227 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,69 +1,75 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
10 | class QRubberBand; |
|
10 | class QRubberBand; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class QChart; |
|
14 | class QChart; | |
15 |
|
15 | |||
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
17 | { |
|
17 | { | |
18 | public: |
|
18 | public: | |
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |
20 |
|
20 | |||
21 | explicit QChartView(QWidget *parent = 0); |
|
21 | explicit QChartView(QWidget *parent = 0); | |
22 | ~QChartView(); |
|
22 | ~QChartView(); | |
23 |
|
23 | |||
24 | //implement from QWidget |
|
24 | //implement from QWidget | |
25 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
26 |
|
26 | |||
27 | void addSeries(QChartSeries* series); |
|
27 | void addSeries(QChartSeries* series); | |
28 |
|
28 | |||
29 | // Convenience function |
|
29 | // Convenience function | |
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
31 |
|
31 | |||
32 | int margin() const; |
|
32 | int margin() const; | |
33 |
|
33 | |||
34 | void setTitle(const QString& title); |
|
34 | void setTitle(const QString& title); | |
35 | void setChartBackgroundBrush(const QBrush& brush); |
|
35 | void setChartBackgroundBrush(const QBrush& brush); | |
36 | void setChartBackgroundPen(const QPen& pen); |
|
36 | void setChartBackgroundPen(const QPen& pen); | |
37 |
|
37 | |||
38 | void zoomInToRect(const QRect& rectangle); |
|
38 | void zoomInToRect(const QRect& rectangle); | |
39 | void zoomIn(); |
|
39 | void zoomIn(); | |
40 | void zoomOut(); |
|
40 | void zoomOut(); | |
41 |
|
41 | |||
42 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
42 | void setRubberBandPolicy(const RubberBandPolicy ); | |
43 | RubberBandPolicy rubberBandPolicy() const; |
|
43 | RubberBandPolicy rubberBandPolicy() const; | |
44 |
|
44 | |||
45 | void setChartTheme(QChart::ChartTheme theme); |
|
45 | void setChartTheme(QChart::ChartTheme theme); | |
46 | QChart::ChartTheme chartTheme() const; |
|
46 | QChart::ChartTheme chartTheme() const; | |
47 |
|
47 | |||
|
48 | QChartAxis* axisX(); | |||
|
49 | QChartAxis* axisY(); | |||
|
50 | QChartAxis* addAxisX(); | |||
|
51 | QChartAxis* addAxisY(); | |||
|
52 | void removeAxis(QChartAxis* axis); | |||
|
53 | ||||
48 | protected: |
|
54 | protected: | |
49 | void mousePressEvent(QMouseEvent *event); |
|
55 | void mousePressEvent(QMouseEvent *event); | |
50 | void mouseMoveEvent(QMouseEvent *event); |
|
56 | void mouseMoveEvent(QMouseEvent *event); | |
51 | void mouseReleaseEvent(QMouseEvent *event); |
|
57 | void mouseReleaseEvent(QMouseEvent *event); | |
52 | void keyPressEvent(QKeyEvent *event); |
|
58 | void keyPressEvent(QKeyEvent *event); | |
53 |
|
59 | |||
54 |
|
60 | |||
55 | private: |
|
61 | private: | |
56 | QGraphicsScene *m_scene; |
|
62 | QGraphicsScene *m_scene; | |
57 | QChart* m_chart; |
|
63 | QChart* m_chart; | |
58 | QPoint m_rubberBandOrigin; |
|
64 | QPoint m_rubberBandOrigin; | |
59 | QRubberBand* m_rubberBand; |
|
65 | QRubberBand* m_rubberBand; | |
60 | bool m_verticalRubberBand; |
|
66 | bool m_verticalRubberBand; | |
61 | bool m_horizonalRubberBand; |
|
67 | bool m_horizonalRubberBand; | |
62 | Q_DISABLE_COPY(QChartView) |
|
68 | Q_DISABLE_COPY(QChartView) | |
63 |
|
69 | |||
64 |
|
70 | |||
65 | }; |
|
71 | }; | |
66 |
|
72 | |||
67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE | |
68 |
|
74 | |||
69 | #endif // QCHARTWIDGET_H |
|
75 | #endif // QCHARTWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now