@@ -0,0 +1,13 | |||||
|
1 | INCLUDEPATH += $$PWD | |||
|
2 | DEPENDPATH += $$PWD | |||
|
3 | ||||
|
4 | SOURCES += \ | |||
|
5 | $$PWD/qscatterseries.cpp \ | |||
|
6 | $$PWD/scatterpresenter.cpp | |||
|
7 | ||||
|
8 | PRIVATE_HEADERS += \ | |||
|
9 | $$PWD/scatterpresenter_p.h \ | |||
|
10 | $$PWD/scatterseries_p.h | |||
|
11 | ||||
|
12 | PUBLIC_HEADERS += \ | |||
|
13 | $$PWD/qscatterseries.h |
@@ -1,272 +1,272 | |||||
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 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | //items |
|
13 | //items | |
14 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
15 | #include "bargroup.h" |
|
15 | #include "bargroup.h" | |
16 | #include "stackedbargroup.h" |
|
16 | #include "stackedbargroup.h" | |
17 | #include "linechartitem_p.h" |
|
17 | #include "linechartitem_p.h" | |
18 | #include "percentbargroup.h" |
|
18 | #include "percentbargroup.h" | |
19 | #include "linechartanimationitem_p.h" |
|
19 | #include "linechartanimationitem_p.h" | |
20 | #include "piepresenter.h" |
|
20 | #include "piepresenter.h" | |
21 | #include "scatterpresenter.h" |
|
21 | #include "scatterpresenter_p.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
26 | m_chart(chart), |
|
26 | m_chart(chart), | |
27 | m_dataset(dataset), |
|
27 | m_dataset(dataset), | |
28 | m_chartTheme(0), |
|
28 | m_chartTheme(0), | |
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), |
|
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), | |
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), |
|
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), | |
31 | m_domainIndex(0), |
|
31 | m_domainIndex(0), | |
32 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
34 | { |
|
34 | { | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 | createConnections(); |
|
36 | createConnections(); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
44 | { |
|
44 | { | |
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); | |
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); |
|
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); | |
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); | |
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); |
|
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void ChartPresenter::handleGeometryChanged() |
|
53 | void ChartPresenter::handleGeometryChanged() | |
54 | { |
|
54 | { | |
55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
57 | Q_ASSERT(m_rect.isValid()); |
|
57 | Q_ASSERT(m_rect.isValid()); | |
58 | emit geometryChanged(m_rect); |
|
58 | emit geometryChanged(m_rect); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | int ChartPresenter::margin() const |
|
61 | int ChartPresenter::margin() const | |
62 | { |
|
62 | { | |
63 | return m_marginSize; |
|
63 | return m_marginSize; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void ChartPresenter::setMargin(int margin) |
|
66 | void ChartPresenter::setMargin(int margin) | |
67 | { |
|
67 | { | |
68 | m_marginSize = margin; |
|
68 | m_marginSize = margin; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
72 | { |
|
72 | { | |
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; |
|
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; | |
74 | switch(series->type()) |
|
74 | switch(series->type()) | |
75 | { |
|
75 | { | |
76 | case QChartSeries::SeriesTypeLine: { |
|
76 | case QChartSeries::SeriesTypeLine: { | |
77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); | |
78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
83 | m_chartItems.insert(series,item); |
|
83 | m_chartItems.insert(series,item); | |
84 | break; |
|
84 | break; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | case QChartSeries::SeriesTypeBar: { |
|
87 | case QChartSeries::SeriesTypeBar: { | |
88 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
88 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
89 | BarGroup* item = new BarGroup(barSeries->model(),m_chart); |
|
89 | BarGroup* item = new BarGroup(barSeries->model(),m_chart); | |
90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
94 | m_chartItems.insert(series,item); |
|
94 | m_chartItems.insert(series,item); | |
95 | // m_axisXItem->setVisible(false); |
|
95 | // m_axisXItem->setVisible(false); | |
96 | break; |
|
96 | break; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | case QChartSeries::SeriesTypeStackedBar: { |
|
99 | case QChartSeries::SeriesTypeStackedBar: { | |
100 |
|
100 | |||
101 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
101 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
102 | StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart); |
|
102 | StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart); | |
103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
107 | m_chartItems.insert(series,item); |
|
107 | m_chartItems.insert(series,item); | |
108 | break; |
|
108 | break; | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | case QChartSeries::SeriesTypePercentBar: { |
|
111 | case QChartSeries::SeriesTypePercentBar: { | |
112 |
|
112 | |||
113 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
113 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
114 | PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart); |
|
114 | PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart); | |
115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
119 | m_chartItems.insert(series,item); |
|
119 | m_chartItems.insert(series,item); | |
120 | break; |
|
120 | break; | |
121 | } |
|
121 | } | |
122 | case QChartSeries::SeriesTypeScatter: { |
|
122 | case QChartSeries::SeriesTypeScatter: { | |
123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), |
|
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), | |
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); |
|
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); | |
129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
130 | // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
130 | // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
131 | // scatterSeries->d->setParentItem(this); |
|
131 | // scatterSeries->d->setParentItem(this); | |
132 | // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
132 | // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
133 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
133 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
134 | break; |
|
134 | break; | |
135 | } |
|
135 | } | |
136 | case QChartSeries::SeriesTypePie: { |
|
136 | case QChartSeries::SeriesTypePie: { | |
137 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
137 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
138 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
138 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
139 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
139 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
140 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
140 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
141 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); |
|
141 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); | |
142 | m_chartItems.insert(series, pie); |
|
142 | m_chartItems.insert(series, pie); | |
143 | break; |
|
143 | break; | |
144 | } |
|
144 | } | |
145 | default: { |
|
145 | default: { | |
146 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
146 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
147 | break; |
|
147 | break; | |
148 | } |
|
148 | } | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
151 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
154 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
155 | { |
|
155 | { | |
156 | //TODO: |
|
156 | //TODO: | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
159 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
160 | { |
|
160 | { | |
161 | if(!rect.isValid()) return; |
|
161 | if(!rect.isValid()) return; | |
162 | QRectF r = rect.normalized(); |
|
162 | QRectF r = rect.normalized(); | |
163 | r.translate(-m_marginSize, -m_marginSize); |
|
163 | r.translate(-m_marginSize, -m_marginSize); | |
164 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); |
|
164 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); | |
165 | m_dataset->addDomain(domain); |
|
165 | m_dataset->addDomain(domain); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void ChartPresenter::zoomIn() |
|
168 | void ChartPresenter::zoomIn() | |
169 | { |
|
169 | { | |
170 | if (!m_dataset->nextDomain()) { |
|
170 | if (!m_dataset->nextDomain()) { | |
171 | QRectF rect = m_rect; |
|
171 | QRectF rect = m_rect; | |
172 | rect.setWidth(rect.width()/2); |
|
172 | rect.setWidth(rect.width()/2); | |
173 | rect.setHeight(rect.height()/2); |
|
173 | rect.setHeight(rect.height()/2); | |
174 | rect.moveCenter(m_rect.center()); |
|
174 | rect.moveCenter(m_rect.center()); | |
175 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
175 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
176 | m_dataset->addDomain(domain); |
|
176 | m_dataset->addDomain(domain); | |
177 | } |
|
177 | } | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void ChartPresenter::zoomOut() |
|
180 | void ChartPresenter::zoomOut() | |
181 | { |
|
181 | { | |
182 | m_dataset->previousDomain(); |
|
182 | m_dataset->previousDomain(); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void ChartPresenter::zoomReset() |
|
185 | void ChartPresenter::zoomReset() | |
186 | { |
|
186 | { | |
187 | m_dataset->clearDomains(); |
|
187 | m_dataset->clearDomains(); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
190 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
191 | { |
|
191 | { | |
192 | delete m_chartTheme; |
|
192 | delete m_chartTheme; | |
193 |
|
193 | |||
194 | m_chartTheme = ChartTheme::createTheme(theme); |
|
194 | m_chartTheme = ChartTheme::createTheme(theme); | |
195 |
|
195 | |||
196 | m_chartTheme->decorate(m_chart); |
|
196 | m_chartTheme->decorate(m_chart); | |
197 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
197 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
198 |
|
198 | |||
199 | int index=0; |
|
199 | int index=0; | |
200 | while (i.hasNext()) { |
|
200 | while (i.hasNext()) { | |
201 | i.next(); |
|
201 | i.next(); | |
202 | index++; |
|
202 | index++; | |
203 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
203 | m_chartTheme->decorate(i.value(),i.key(),index); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | m_chartTheme->decorate(m_axisX, m_axisXItem); |
|
206 | m_chartTheme->decorate(m_axisX, m_axisXItem); | |
207 | m_chartTheme->decorate(m_axisY, m_axisYItem); |
|
207 | m_chartTheme->decorate(m_axisY, m_axisYItem); | |
208 |
|
208 | |||
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 |
|
211 | |||
212 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
212 | QChart::ChartTheme ChartPresenter::chartTheme() | |
213 | { |
|
213 | { | |
214 | return m_chartTheme->id(); |
|
214 | return m_chartTheme->id(); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) |
|
217 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) | |
218 | { |
|
218 | { | |
219 | //if(m_axisX != axis) { |
|
219 | //if(m_axisX != axis) { | |
220 | m_axisX = axis; |
|
220 | m_axisX = axis; | |
221 | m_axisXItem->handleAxisChanged(m_axisX); |
|
221 | m_axisXItem->handleAxisChanged(m_axisX); | |
222 | //} |
|
222 | //} | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) |
|
225 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) | |
226 | { |
|
226 | { | |
227 | // if(m_axisY != axis) { |
|
227 | // if(m_axisY != axis) { | |
228 | m_axisY = axis; |
|
228 | m_axisY = axis; | |
229 | m_axisYItem->handleAxisChanged(m_axisY); |
|
229 | m_axisYItem->handleAxisChanged(m_axisY); | |
230 | //} |
|
230 | //} | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | QChartAxis ChartPresenter::defaultAxisX() const |
|
233 | QChartAxis ChartPresenter::defaultAxisX() const | |
234 | { |
|
234 | { | |
235 | return m_axisX; |
|
235 | return m_axisX; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | QChartAxis ChartPresenter::defaultAxisY() const |
|
238 | QChartAxis ChartPresenter::defaultAxisY() const | |
239 | { |
|
239 | { | |
240 | return m_axisY; |
|
240 | return m_axisY; | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | QChartAxis ChartPresenter::axisY(int id) const |
|
243 | QChartAxis ChartPresenter::axisY(int id) const | |
244 | { |
|
244 | { | |
245 | return m_axis.value(id); |
|
245 | return m_axis.value(id); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | int ChartPresenter::addAxisY(const QChartAxis& axis) |
|
248 | int ChartPresenter::addAxisY(const QChartAxis& axis) | |
249 | { |
|
249 | { | |
250 | int key =0 ; |
|
250 | int key =0 ; | |
251 |
|
251 | |||
252 | while(m_axis.contains(key)){ |
|
252 | while(m_axis.contains(key)){ | |
253 | key++; |
|
253 | key++; | |
254 | //TODO overflow |
|
254 | //TODO overflow | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | m_axis.insert(key,axis); |
|
257 | m_axis.insert(key,axis); | |
258 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); |
|
258 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); | |
259 |
|
259 | |||
260 | return key; |
|
260 | return key; | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 |
|
263 | |||
264 | void ChartPresenter::removeAxisY(int id) |
|
264 | void ChartPresenter::removeAxisY(int id) | |
265 | { |
|
265 | { | |
266 | m_axis.remove(id); |
|
266 | m_axis.remove(id); | |
267 | delete m_axisItems.take(id); |
|
267 | delete m_axisItems.take(id); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | #include "moc_chartpresenter_p.cpp" |
|
270 | #include "moc_chartpresenter_p.cpp" | |
271 |
|
271 | |||
272 | QTCOMMERCIALCHART_END_NAMESPACE |
|
272 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,247 +1,247 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 |
|
4 | |||
5 |
|
5 | |||
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 "qscatterseries.h" |
|
11 | #include "qscatterseries.h" | |
12 | #include "qpieseries.h" |
|
12 | #include "qpieseries.h" | |
13 |
|
13 | |||
14 | //items |
|
14 | //items | |
15 | #include "axisitem_p.h" |
|
15 | #include "axisitem_p.h" | |
16 | #include "bargroup.h" |
|
16 | #include "bargroup.h" | |
17 | #include "stackedbargroup.h" |
|
17 | #include "stackedbargroup.h" | |
18 | #include "linechartitem_p.h" |
|
18 | #include "linechartitem_p.h" | |
19 | #include "percentbargroup.h" |
|
19 | #include "percentbargroup.h" | |
20 | #include "scatterpresenter.h" |
|
20 | #include "scatterpresenter_p.h" | |
21 | #include "piepresenter.h" |
|
21 | #include "piepresenter.h" | |
22 |
|
22 | |||
23 | //themes |
|
23 | //themes | |
24 | #include "chartthemevanilla_p.h" |
|
24 | #include "chartthemevanilla_p.h" | |
25 | #include "chartthemeicy_p.h" |
|
25 | #include "chartthemeicy_p.h" | |
26 | #include "chartthemegrayscale_p.h" |
|
26 | #include "chartthemegrayscale_p.h" | |
27 | #include "chartthemescientific_p.h" |
|
27 | #include "chartthemescientific_p.h" | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /* TODO |
|
32 | /* TODO | |
33 | case QChart::ChartThemeUnnamed1: |
|
33 | case QChart::ChartThemeUnnamed1: | |
34 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
34 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
35 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
35 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
39 |
|
39 | |||
40 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
40 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
41 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
41 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
44 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
45 | { |
|
45 | { | |
46 | m_id = id; |
|
46 | m_id = id; | |
47 | m_seriesColor.append(QRgb(0xff000000)); |
|
47 | m_seriesColor.append(QRgb(0xff000000)); | |
48 | m_seriesColor.append(QRgb(0xff707070)); |
|
48 | m_seriesColor.append(QRgb(0xff707070)); | |
49 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
49 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
50 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
50 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
54 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
55 | { |
|
55 | { | |
56 | switch(theme) { |
|
56 | switch(theme) { | |
57 | case QChart::ChartThemeDefault: |
|
57 | case QChart::ChartThemeDefault: | |
58 | return new ChartTheme(); |
|
58 | return new ChartTheme(); | |
59 | case QChart::ChartThemeVanilla: |
|
59 | case QChart::ChartThemeVanilla: | |
60 | return new ChartThemeVanilla(); |
|
60 | return new ChartThemeVanilla(); | |
61 | case QChart::ChartThemeIcy: |
|
61 | case QChart::ChartThemeIcy: | |
62 | return new ChartThemeIcy(); |
|
62 | return new ChartThemeIcy(); | |
63 | case QChart::ChartThemeGrayscale: |
|
63 | case QChart::ChartThemeGrayscale: | |
64 | return new ChartThemeGrayscale(); |
|
64 | return new ChartThemeGrayscale(); | |
65 | case QChart::ChartThemeScientific: |
|
65 | case QChart::ChartThemeScientific: | |
66 | return new ChartThemeScientific(); |
|
66 | return new ChartThemeScientific(); | |
67 | } |
|
67 | } | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void ChartTheme::decorate(QChart* chart) |
|
70 | void ChartTheme::decorate(QChart* chart) | |
71 | { |
|
71 | { | |
72 | QLinearGradient backgroundGradient; |
|
72 | QLinearGradient backgroundGradient; | |
73 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
73 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |
74 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
74 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |
75 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
75 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
76 | chart->setChartBackgroundBrush(backgroundGradient); |
|
76 | chart->setChartBackgroundBrush(backgroundGradient); | |
77 | } |
|
77 | } | |
78 | //TODO helper to by removed later |
|
78 | //TODO helper to by removed later | |
79 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) |
|
79 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) | |
80 | { |
|
80 | { | |
81 | switch(series->type()) |
|
81 | switch(series->type()) | |
82 | { |
|
82 | { | |
83 | case QChartSeries::SeriesTypeLine: { |
|
83 | case QChartSeries::SeriesTypeLine: { | |
84 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); |
|
84 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); | |
85 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
85 | LineChartItem* i = static_cast<LineChartItem*>(item); | |
86 | decorate(i,s,count); |
|
86 | decorate(i,s,count); | |
87 | break; |
|
87 | break; | |
88 | } |
|
88 | } | |
89 | case QChartSeries::SeriesTypeBar: { |
|
89 | case QChartSeries::SeriesTypeBar: { | |
90 | BarChartSeries* b = static_cast<BarChartSeries*>(series); |
|
90 | BarChartSeries* b = static_cast<BarChartSeries*>(series); | |
91 | BarGroup* i = static_cast<BarGroup*>(item); |
|
91 | BarGroup* i = static_cast<BarGroup*>(item); | |
92 | decorate(i,b,count); |
|
92 | decorate(i,b,count); | |
93 | break; |
|
93 | break; | |
94 | } |
|
94 | } | |
95 | case QChartSeries::SeriesTypeStackedBar: { |
|
95 | case QChartSeries::SeriesTypeStackedBar: { | |
96 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); |
|
96 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); | |
97 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); |
|
97 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); | |
98 | decorate(i,s,count); |
|
98 | decorate(i,s,count); | |
99 | break; |
|
99 | break; | |
100 | } |
|
100 | } | |
101 | case QChartSeries::SeriesTypePercentBar: { |
|
101 | case QChartSeries::SeriesTypePercentBar: { | |
102 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); |
|
102 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); | |
103 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); |
|
103 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); | |
104 | decorate(i,s,count); |
|
104 | decorate(i,s,count); | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 | case QChartSeries::SeriesTypePie: { |
|
107 | case QChartSeries::SeriesTypePie: { | |
108 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
108 | QPieSeries* s = static_cast<QPieSeries*>(series); | |
109 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
109 | PiePresenter* i = static_cast<PiePresenter*>(item); | |
110 | decorate(i,s,count); |
|
110 | decorate(i,s,count); | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 | default: |
|
113 | default: | |
114 | qDebug()<<"Wrong item to be decorated by theme"; |
|
114 | qDebug()<<"Wrong item to be decorated by theme"; | |
115 | break; |
|
115 | break; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) |
|
120 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) | |
121 | { |
|
121 | { | |
122 | QPen pen; |
|
122 | QPen pen; | |
123 | if(pen != series->pen()){ |
|
123 | if(pen != series->pen()){ | |
124 | item->setPen(series->pen()); |
|
124 | item->setPen(series->pen()); | |
125 | return; |
|
125 | return; | |
126 | } |
|
126 | } | |
127 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
127 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
128 | pen.setWidthF(2); |
|
128 | pen.setWidthF(2); | |
129 | item->setPen(pen); |
|
129 | item->setPen(pen); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) |
|
132 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) | |
133 | { |
|
133 | { | |
134 | // TODO: better way to descide series color and remove hard coded colors. |
|
134 | // TODO: better way to descide series color and remove hard coded colors. | |
135 | item->resetBrushes(); |
|
135 | item->resetBrushes(); | |
136 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
136 | for (int i=0; i<m_seriesColor.count(); i++) { | |
137 | QBrush brush(m_seriesColor.at(i)); |
|
137 | QBrush brush(m_seriesColor.at(i)); | |
138 | item->addBrush(brush); |
|
138 | item->addBrush(brush); | |
139 | } |
|
139 | } | |
140 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
140 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
141 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
141 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
142 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
142 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
143 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
143 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
144 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
144 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) |
|
147 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) | |
148 | { |
|
148 | { | |
149 | // TODO: better way to descide series color and remove hard coded colors. |
|
149 | // TODO: better way to descide series color and remove hard coded colors. | |
150 | item->resetBrushes(); |
|
150 | item->resetBrushes(); | |
151 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
151 | for (int i=0; i<m_seriesColor.count(); i++) { | |
152 | QBrush brush(m_seriesColor.at(i)); |
|
152 | QBrush brush(m_seriesColor.at(i)); | |
153 | item->addBrush(brush); |
|
153 | item->addBrush(brush); | |
154 | } |
|
154 | } | |
155 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
155 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
156 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
156 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
157 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
157 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
158 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
158 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
159 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
159 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) |
|
162 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) | |
163 | { |
|
163 | { | |
164 | // TODO: better way to descide series color and remove hard coded colors. |
|
164 | // TODO: better way to descide series color and remove hard coded colors. | |
165 | item->resetBrushes(); |
|
165 | item->resetBrushes(); | |
166 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
166 | for (int i=0; i<m_seriesColor.count(); i++) { | |
167 | QBrush brush(m_seriesColor.at(i)); |
|
167 | QBrush brush(m_seriesColor.at(i)); | |
168 | item->addBrush(brush); |
|
168 | item->addBrush(brush); | |
169 | } |
|
169 | } | |
170 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
170 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
171 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
171 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
172 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
172 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
173 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
173 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
174 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
174 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
|
177 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) | |
178 | { |
|
178 | { | |
179 | Q_ASSERT(presenter); |
|
179 | Q_ASSERT(presenter); | |
180 | Q_ASSERT(series); |
|
180 | Q_ASSERT(series); | |
181 |
|
181 | |||
182 | presenter->m_markerPen.setColor(m_seriesColor.at(count % m_seriesColor.size())); |
|
182 | presenter->m_markerPen.setColor(m_seriesColor.at(count % m_seriesColor.size())); | |
183 |
|
183 | |||
184 | // QPen pen; |
|
184 | // QPen pen; | |
185 | // if(pen != series->pen()){ |
|
185 | // if(pen != series->pen()){ | |
186 | // item->setPen(series->pen()); |
|
186 | // item->setPen(series->pen()); | |
187 | // return; |
|
187 | // return; | |
188 | // } |
|
188 | // } | |
189 | // pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
189 | // pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
190 | // pen.setWidthF(2); |
|
190 | // pen.setWidthF(2); | |
191 | // item->setPen(pen); |
|
191 | // item->setPen(pen); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
194 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |
195 | { |
|
195 | { | |
196 | // create a list of slice colors based on current theme |
|
196 | // create a list of slice colors based on current theme | |
197 | int i = 0; |
|
197 | int i = 0; | |
198 | QList<QColor> colors; |
|
198 | QList<QColor> colors; | |
199 | while (colors.count() < series->count()) { |
|
199 | while (colors.count() < series->count()) { | |
200 |
|
200 | |||
201 | // get base color |
|
201 | // get base color | |
202 | QColor c = m_seriesColor[i++]; |
|
202 | QColor c = m_seriesColor[i++]; | |
203 | i = i % m_seriesColor.count(); |
|
203 | i = i % m_seriesColor.count(); | |
204 |
|
204 | |||
205 | // -1 means achromatic color -> cannot manipulate lightness |
|
205 | // -1 means achromatic color -> cannot manipulate lightness | |
206 | // TODO: find a better way to randomize lightness |
|
206 | // TODO: find a better way to randomize lightness | |
207 | if (c.toHsv().hue() == -1) |
|
207 | if (c.toHsv().hue() == -1) | |
208 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; |
|
208 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; | |
209 |
|
209 | |||
210 | // randomize lightness |
|
210 | // randomize lightness | |
211 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter |
|
211 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter | |
212 | c = c.lighter(f); |
|
212 | c = c.lighter(f); | |
213 |
|
213 | |||
214 | // find duplicates |
|
214 | // find duplicates | |
215 | bool isUnique = true; |
|
215 | bool isUnique = true; | |
216 | foreach (QColor color, colors) { |
|
216 | foreach (QColor color, colors) { | |
217 | if (c == color) |
|
217 | if (c == color) | |
218 | isUnique = false; |
|
218 | isUnique = false; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | // add to array if unique |
|
221 | // add to array if unique | |
222 | //if (isUnique) |
|
222 | //if (isUnique) | |
223 | colors << c; |
|
223 | colors << c; | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | // finally update colors |
|
226 | // finally update colors | |
227 | foreach (QPieSliceId id, series->ids()) { |
|
227 | foreach (QPieSliceId id, series->ids()) { | |
228 | QPieSlice s = series->slice(id); |
|
228 | QPieSlice s = series->slice(id); | |
229 | s.setPen(QPen(Qt::black)); // TODO: get from theme |
|
229 | s.setPen(QPen(Qt::black)); // TODO: get from theme | |
230 | s.setBrush(colors.takeFirst()); |
|
230 | s.setBrush(colors.takeFirst()); | |
231 | series->update(s); |
|
231 | series->update(s); | |
232 | } |
|
232 | } | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 |
|
235 | |||
236 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) |
|
236 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) | |
237 | { |
|
237 | { | |
238 | //TODO: dummy defults for now |
|
238 | //TODO: dummy defults for now | |
239 |
|
239 | |||
240 | axis.setLabelsBrush(Qt::black); |
|
240 | axis.setLabelsBrush(Qt::black); | |
241 | axis.setLabelsPen(Qt::NoPen); |
|
241 | axis.setLabelsPen(Qt::NoPen); | |
242 | axis.setShadesPen(Qt::NoPen); |
|
242 | axis.setShadesPen(Qt::NoPen); | |
243 | axis.setShadesOpacity(0.5); |
|
243 | axis.setShadesOpacity(0.5); | |
244 | item->handleAxisChanged(axis); |
|
244 | item->handleAxisChanged(axis); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | QTCOMMERCIALCHART_END_NAMESPACE |
|
247 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,209 +1,209 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qscatterseries.h" |
|
|||
3 | #include "qscatterseries_p.h" |
|
|||
4 | #include "qpieseries.h" |
|
|||
5 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
6 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
7 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
8 |
|
5 | |||
9 | //series |
|
6 | //series | |
10 | #include "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
11 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
12 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
13 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
|
11 | #include "qscatterseries.h" | |||
|
12 | //#include "scatterseries_p.h" | |||
|
13 | #include "qpieseries.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 | QChartSeries *series(0); |
|
39 | QChartSeries *series(0); | |
40 |
|
40 | |||
41 | switch (type) { |
|
41 | switch (type) { | |
42 | case QChartSeries::SeriesTypeLine: { |
|
42 | case QChartSeries::SeriesTypeLine: { | |
43 | series = new QLineChartSeries(this); |
|
43 | series = new QLineChartSeries(this); | |
44 | break; |
|
44 | break; | |
45 | } |
|
45 | } | |
46 | case QChartSeries::SeriesTypeBar: { |
|
46 | case QChartSeries::SeriesTypeBar: { | |
47 | //series = new BarChartSeries(this); |
|
47 | //series = new BarChartSeries(this); | |
48 | break; |
|
48 | break; | |
49 | } |
|
49 | } | |
50 | case QChartSeries::SeriesTypeStackedBar: { |
|
50 | case QChartSeries::SeriesTypeStackedBar: { | |
51 | //series = new StackedBarChartSeries(this); |
|
51 | //series = new StackedBarChartSeries(this); | |
52 | break; |
|
52 | break; | |
53 | } |
|
53 | } | |
54 | case QChartSeries::SeriesTypePercentBar: { |
|
54 | case QChartSeries::SeriesTypePercentBar: { | |
55 | //series = new PercentBarChartSeries(this); |
|
55 | //series = new PercentBarChartSeries(this); | |
56 | break; |
|
56 | break; | |
57 | } |
|
57 | } | |
58 | case QChartSeries::SeriesTypeScatter: { |
|
58 | case QChartSeries::SeriesTypeScatter: { | |
59 | series = new QScatterSeries(this); |
|
59 | series = new QScatterSeries(this); | |
60 | break; |
|
60 | break; | |
61 | } |
|
61 | } | |
62 | case QChartSeries::SeriesTypePie: { |
|
62 | case QChartSeries::SeriesTypePie: { | |
63 | series = new QPieSeries(this); |
|
63 | series = new QPieSeries(this); | |
64 | break; |
|
64 | break; | |
65 | } |
|
65 | } | |
66 | default: |
|
66 | default: | |
67 | Q_ASSERT(false); |
|
67 | Q_ASSERT(false); | |
68 | break; |
|
68 | break; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | addSeries(series); |
|
71 | addSeries(series); | |
72 | return series; |
|
72 | return series; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
76 | { |
|
76 | { | |
77 |
|
77 | |||
78 | if(!m_backgroundItem) { |
|
78 | if(!m_backgroundItem) { | |
79 | m_backgroundItem = new QGraphicsRectItem(this); |
|
79 | m_backgroundItem = new QGraphicsRectItem(this); | |
80 | m_backgroundItem->setZValue(-1); |
|
80 | m_backgroundItem->setZValue(-1); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | m_backgroundItem->setBrush(brush); |
|
83 | m_backgroundItem->setBrush(brush); | |
84 | m_backgroundItem->update(); |
|
84 | m_backgroundItem->update(); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
87 | void QChart::setChartBackgroundPen(const QPen& pen) | |
88 | { |
|
88 | { | |
89 |
|
89 | |||
90 | if(!m_backgroundItem) { |
|
90 | if(!m_backgroundItem) { | |
91 | m_backgroundItem = new QGraphicsRectItem(this); |
|
91 | m_backgroundItem = new QGraphicsRectItem(this); | |
92 | m_backgroundItem->setZValue(-1); |
|
92 | m_backgroundItem->setZValue(-1); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | m_backgroundItem->setPen(pen); |
|
95 | m_backgroundItem->setPen(pen); | |
96 | m_backgroundItem->update(); |
|
96 | m_backgroundItem->update(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QChart::setChartTitle(const QString& title) |
|
99 | void QChart::setChartTitle(const QString& title) | |
100 | { |
|
100 | { | |
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
102 | m_titleItem->setPlainText(title); |
|
102 | m_titleItem->setPlainText(title); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void QChart::setChartTitleFont(const QFont& font) |
|
105 | void QChart::setChartTitleFont(const QFont& font) | |
106 | { |
|
106 | { | |
107 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
107 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
108 | m_titleItem->setFont(font); |
|
108 | m_titleItem->setFont(font); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | int QChart::margin() const |
|
111 | int QChart::margin() const | |
112 | { |
|
112 | { | |
113 | return m_presenter->margin(); |
|
113 | return m_presenter->margin(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void QChart::setMargin(int margin) |
|
116 | void QChart::setMargin(int margin) | |
117 | { |
|
117 | { | |
118 | m_presenter->setMargin(margin); |
|
118 | m_presenter->setMargin(margin); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
121 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
122 | { |
|
122 | { | |
123 | m_presenter->setChartTheme(theme); |
|
123 | m_presenter->setChartTheme(theme); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | QChart::ChartTheme QChart::chartTheme() const |
|
126 | QChart::ChartTheme QChart::chartTheme() const | |
127 | { |
|
127 | { | |
128 | return m_presenter->chartTheme(); |
|
128 | return m_presenter->chartTheme(); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
131 | void QChart::zoomInToRect(const QRectF& rectangle) | |
132 | { |
|
132 | { | |
133 | m_presenter->zoomInToRect(rectangle); |
|
133 | m_presenter->zoomInToRect(rectangle); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void QChart::zoomIn() |
|
136 | void QChart::zoomIn() | |
137 | { |
|
137 | { | |
138 | m_presenter->zoomIn(); |
|
138 | m_presenter->zoomIn(); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void QChart::zoomOut() |
|
141 | void QChart::zoomOut() | |
142 | { |
|
142 | { | |
143 | m_presenter->zoomOut(); |
|
143 | m_presenter->zoomOut(); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void QChart::zoomReset() |
|
146 | void QChart::zoomReset() | |
147 | { |
|
147 | { | |
148 | m_presenter->zoomReset(); |
|
148 | m_presenter->zoomReset(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void QChart::setDefaultAxisX(const QChartAxis& axis) |
|
151 | void QChart::setDefaultAxisX(const QChartAxis& axis) | |
152 | { |
|
152 | { | |
153 | m_presenter->setDefaultAxisX(axis); |
|
153 | m_presenter->setDefaultAxisX(axis); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void QChart::setDefaultAxisY(const QChartAxis& axis) |
|
156 | void QChart::setDefaultAxisY(const QChartAxis& axis) | |
157 | { |
|
157 | { | |
158 | m_presenter->setDefaultAxisY(axis); |
|
158 | m_presenter->setDefaultAxisY(axis); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | QChartAxis QChart::defaultAxisX() const |
|
161 | QChartAxis QChart::defaultAxisX() const | |
162 | { |
|
162 | { | |
163 | return m_presenter->defaultAxisX(); |
|
163 | return m_presenter->defaultAxisX(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QChartAxis QChart::defaultAxisY() const |
|
166 | QChartAxis QChart::defaultAxisY() const | |
167 | { |
|
167 | { | |
168 | return m_presenter->defaultAxisY(); |
|
168 | return m_presenter->defaultAxisY(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | int QChart::addAxisY(const QChartAxis& axis) |
|
171 | int QChart::addAxisY(const QChartAxis& axis) | |
172 | { |
|
172 | { | |
173 | return m_presenter->addAxisY(axis); |
|
173 | return m_presenter->addAxisY(axis); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | QChartAxis QChart::axisY(int id) const |
|
176 | QChartAxis QChart::axisY(int id) const | |
177 | { |
|
177 | { | |
178 | return m_presenter->axisY(id); |
|
178 | return m_presenter->axisY(id); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | void QChart::removeAxisY(int id) |
|
181 | void QChart::removeAxisY(int id) | |
182 | { |
|
182 | { | |
183 | m_presenter->removeAxisY(id); |
|
183 | m_presenter->removeAxisY(id); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
186 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
187 | { |
|
187 | { | |
188 |
|
188 | |||
189 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
189 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
190 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
190 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
191 |
|
191 | |||
192 | // recalculate title position |
|
192 | // recalculate title position | |
193 | if (m_titleItem) { |
|
193 | if (m_titleItem) { | |
194 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
194 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
195 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
195 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | //recalculate background gradient |
|
198 | //recalculate background gradient | |
199 | if (m_backgroundItem) { |
|
199 | if (m_backgroundItem) { | |
200 | m_backgroundItem->setRect(rect); |
|
200 | m_backgroundItem->setRect(rect); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | QGraphicsWidget::resizeEvent(event); |
|
203 | QGraphicsWidget::resizeEvent(event); | |
204 | update(); |
|
204 | update(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | #include "moc_qchart.cpp" |
|
207 | #include "moc_qchart.cpp" | |
208 |
|
208 | |||
209 | QTCOMMERCIALCHART_END_NAMESPACE |
|
209 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,59 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
2 |
#include " |
|
2 | #include "scatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : |
|
7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : | |
8 | m_data(QList<QPointF>()) |
|
8 | m_data(QList<QPointF>()) | |
9 | { |
|
9 | { | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
12 | QScatterSeries::QScatterSeries(QObject *parent) : | |
13 | QChartSeries(parent), |
|
13 | QChartSeries(parent), | |
14 | d(new QScatterSeriesPrivate()) |
|
14 | d(new QScatterSeriesPrivate()) | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | QScatterSeries::~QScatterSeries() |
|
18 | QScatterSeries::~QScatterSeries() | |
19 | { |
|
19 | { | |
20 | delete d; |
|
20 | delete d; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | void QScatterSeries::addData(QPointF value) |
|
23 | void QScatterSeries::addData(QPointF value) | |
24 | { |
|
24 | { | |
25 | d->m_data.append(value); |
|
25 | d->m_data.append(value); | |
26 | emit changed(); |
|
26 | emit changed(); | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) |
|
29 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) | |
30 | { |
|
30 | { | |
31 | d->m_data.append(value); |
|
31 | d->m_data.append(value); | |
32 | emit changed(); |
|
32 | emit changed(); | |
33 | return *this; |
|
33 | return *this; | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void QScatterSeries::setData(QList<QPointF> data) |
|
36 | void QScatterSeries::setData(QList<QPointF> data) | |
37 | { |
|
37 | { | |
38 | d->m_data = data; |
|
38 | d->m_data = data; | |
39 | emit changed(); |
|
39 | emit changed(); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QList<QPointF> QScatterSeries::data() |
|
42 | QList<QPointF> QScatterSeries::data() | |
43 | { |
|
43 | { | |
44 | return d->m_data; |
|
44 | return d->m_data; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void QScatterSeries::setMarkerPen(QPen pen) |
|
47 | void QScatterSeries::setMarkerPen(QPen pen) | |
48 | { |
|
48 | { | |
49 | d->m_markerPen = pen; |
|
49 | d->m_markerPen = pen; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | QPen QScatterSeries::markerPen() |
|
52 | QPen QScatterSeries::markerPen() | |
53 | { |
|
53 | { | |
54 | return d->m_markerPen; |
|
54 | return d->m_markerPen; | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | #include "moc_qscatterseries.cpp" |
|
57 | #include "moc_qscatterseries.cpp" | |
58 |
|
58 | |||
59 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE |
1 | NO CONTENT: file renamed from src/qscatterseries.h to src/scatterseries/qscatterseries.h |
|
NO CONTENT: file renamed from src/qscatterseries.h to src/scatterseries/qscatterseries.h |
@@ -1,94 +1,94 | |||||
1 | #include "scatterpresenter.h" |
|
1 | #include "scatterpresenter_p.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include <QPen> |
|
3 | #include <QPen> | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : |
|
10 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : | |
11 | ChartItem(parent), |
|
11 | ChartItem(parent), | |
12 | m_series(series), |
|
12 | m_series(series), | |
13 | m_boundingRect(), |
|
13 | m_boundingRect(), | |
14 | //m_markerColor(QColor()), |
|
14 | //m_markerColor(QColor()), | |
15 | // m_markerColor(QColor(255, 0, 0)), |
|
15 | // m_markerColor(QColor(255, 0, 0)), | |
16 | m_visibleChartArea() |
|
16 | m_visibleChartArea() | |
17 | { |
|
17 | { | |
18 | if (parent) |
|
18 | if (parent) | |
19 | m_boundingRect = parent->boundingRect(); |
|
19 | m_boundingRect = parent->boundingRect(); | |
20 |
|
20 | |||
21 | if (series) { |
|
21 | if (series) { | |
22 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); |
|
22 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); | |
23 | } |
|
23 | } | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void ScatterPresenter::handleDomainChanged(const Domain& domain) |
|
26 | void ScatterPresenter::handleDomainChanged(const Domain& domain) | |
27 | { |
|
27 | { | |
28 | m_visibleChartArea = domain; |
|
28 | m_visibleChartArea = domain; | |
29 | changeGeometry(); |
|
29 | changeGeometry(); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) |
|
32 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) | |
33 | { |
|
33 | { | |
34 | m_boundingRect = rect; |
|
34 | m_boundingRect = rect; | |
35 | changeGeometry(); |
|
35 | changeGeometry(); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void ScatterPresenter::handleModelChanged() |
|
38 | void ScatterPresenter::handleModelChanged() | |
39 | { |
|
39 | { | |
40 | // TODO: more fine grained modelChanged signaling |
|
40 | // TODO: more fine grained modelChanged signaling | |
41 | changeGeometry(); |
|
41 | changeGeometry(); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
44 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) | |
45 | { |
|
45 | { | |
46 | // TODO: The opacity should be user definable? |
|
46 | // TODO: The opacity should be user definable? | |
47 | //brush.setColor(QColor(255, 82, 0, 100)); |
|
47 | //brush.setColor(QColor(255, 82, 0, 100)); | |
48 | //if (m_series->markerPen().isValid()) { |
|
48 | //if (m_series->markerPen().isValid()) { | |
49 | if (false) { |
|
49 | if (false) { | |
50 | QPen pen = painter->pen(); |
|
50 | QPen pen = painter->pen(); | |
51 | QBrush brush = pen.brush(); |
|
51 | QBrush brush = pen.brush(); | |
52 | brush.setColor(m_series->markerPen().color()); |
|
52 | brush.setColor(m_series->markerPen().color()); | |
53 | pen.setBrush(brush); |
|
53 | pen.setBrush(brush); | |
54 | pen.setWidth(4); |
|
54 | pen.setWidth(4); | |
55 | painter->setPen(pen); |
|
55 | painter->setPen(pen); | |
56 | } |
|
56 | } | |
57 | else { |
|
57 | else { | |
58 | // TODO: fix this |
|
58 | // TODO: fix this | |
59 | QPen pen = painter->pen(); |
|
59 | QPen pen = painter->pen(); | |
60 | QBrush brush = pen.brush(); |
|
60 | QBrush brush = pen.brush(); | |
61 | brush.setColor(m_markerPen.color()); |
|
61 | brush.setColor(m_markerPen.color()); | |
62 | pen.setBrush(brush); |
|
62 | pen.setBrush(brush); | |
63 | pen.setWidth(4); |
|
63 | pen.setWidth(4); | |
64 | painter->setPen(pen); |
|
64 | painter->setPen(pen); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
67 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
68 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
68 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
69 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
|
69 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | |
70 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
70 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void ScatterPresenter::changeGeometry() |
|
74 | void ScatterPresenter::changeGeometry() | |
75 | { |
|
75 | { | |
76 | if (m_boundingRect.isValid()) { |
|
76 | if (m_boundingRect.isValid()) { | |
77 |
|
77 | |||
78 | prepareGeometryChange(); |
|
78 | prepareGeometryChange(); | |
79 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); |
|
79 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); | |
80 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); |
|
80 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); | |
81 | m_scenex.clear(); |
|
81 | m_scenex.clear(); | |
82 | m_sceney.clear(); |
|
82 | m_sceney.clear(); | |
83 |
|
83 | |||
84 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
84 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing | |
85 | foreach (QPointF point, m_series->data()) { |
|
85 | foreach (QPointF point, m_series->data()) { | |
86 | m_scenex.append(m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex); |
|
86 | m_scenex.append(m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex); | |
87 | m_sceney.append(m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley); |
|
87 | m_sceney.append(m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley); | |
88 | } |
|
88 | } | |
89 | } |
|
89 | } | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | #include "moc_scatterpresenter.cpp" |
|
92 | #include "moc_scatterpresenter_p.cpp" | |
93 |
|
93 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
94 | QTCOMMERCIALCHART_END_NAMESPACE |
1 | NO CONTENT: file renamed from src/scatterpresenter.h to src/scatterseries/scatterpresenter_p.h |
|
NO CONTENT: file renamed from src/scatterpresenter.h to src/scatterseries/scatterpresenter_p.h |
1 | NO CONTENT: file renamed from src/qscatterseries_p.h to src/scatterseries/scatterseries_p.h |
|
NO CONTENT: file renamed from src/qscatterseries_p.h to src/scatterseries/scatterseries_p.h |
@@ -1,124 +1,119 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | CONFIG += debug_and_release |
|
7 | CONFIG += debug_and_release | |
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
9 | SOURCES += barchart/barchartseries.cpp \ |
|
9 | SOURCES += barchart/barchartseries.cpp \ | |
10 | barchart/bargroup.cpp \ |
|
10 | barchart/bargroup.cpp \ | |
11 | barchart/bar.cpp \ |
|
11 | barchart/bar.cpp \ | |
12 | barchart/stackedbarchartseries.cpp \ |
|
12 | barchart/stackedbarchartseries.cpp \ | |
13 | barchart/stackedbargroup.cpp \ |
|
13 | barchart/stackedbargroup.cpp \ | |
14 | barchart/percentbarchartseries.cpp \ |
|
14 | barchart/percentbarchartseries.cpp \ | |
15 | barchart/percentbargroup.cpp \ |
|
15 | barchart/percentbargroup.cpp \ | |
16 | barchart/barlabel.cpp \ |
|
16 | barchart/barlabel.cpp \ | |
17 | barchart/barchartmodel.cpp \ |
|
17 | barchart/barchartmodel.cpp \ | |
18 | barchart/separator.cpp \ |
|
18 | barchart/separator.cpp \ | |
19 | barchart/bargroupbase.cpp \ |
|
19 | barchart/bargroupbase.cpp \ | |
20 | barchart/qbarset.cpp \ |
|
20 | barchart/qbarset.cpp \ | |
21 | barchart/qbarcategory.cpp \ |
|
21 | barchart/qbarcategory.cpp \ | |
22 | linechart/linechartanimationitem.cpp \ |
|
22 | linechart/linechartanimationitem.cpp \ | |
23 | linechart/linechartitem.cpp \ |
|
23 | linechart/linechartitem.cpp \ | |
24 | linechart/qlinechartseries.cpp \ |
|
24 | linechart/qlinechartseries.cpp \ | |
25 | qscatterseries.cpp \ |
|
|||
26 | #scatterpresentation.cpp \ |
|
|||
27 | qchart.cpp \ |
|
25 | qchart.cpp \ | |
28 | axisitem.cpp \ |
|
26 | axisitem.cpp \ | |
29 | qchartview.cpp \ |
|
27 | qchartview.cpp \ | |
30 | qchartseries.cpp \ |
|
28 | qchartseries.cpp \ | |
31 | qchartaxis.cpp \ |
|
29 | qchartaxis.cpp \ | |
32 | charttheme.cpp \ |
|
30 | charttheme.cpp \ | |
33 | chartdataset.cpp \ |
|
31 | chartdataset.cpp \ | |
34 | chartpresenter.cpp \ |
|
32 | chartpresenter.cpp \ | |
35 |
domain.cpp |
|
33 | domain.cpp | |
36 | scatterpresenter.cpp |
|
|||
37 | PRIVATE_HEADERS += linechart/linechartitem_p.h \ |
|
34 | PRIVATE_HEADERS += linechart/linechartitem_p.h \ | |
38 | linechart/linechartanimationitem_p.h \ |
|
35 | linechart/linechartanimationitem_p.h \ | |
39 | barchart/barlabel_p.h \ |
|
36 | barchart/barlabel_p.h \ | |
40 | barchart/bar_p.h \ |
|
37 | barchart/bar_p.h \ | |
41 | barchart/separator_p.h \ |
|
38 | barchart/separator_p.h \ | |
42 | barchart/barchartmodel_p.h \ |
|
39 | barchart/barchartmodel_p.h \ | |
43 | qscatterseries_p.h \ |
|
|||
44 | #scatterpresentation.h \ |
|
|||
45 | axisitem_p.h \ |
|
40 | axisitem_p.h \ | |
46 | chartitem_p.h \ |
|
41 | chartitem_p.h \ | |
47 | charttheme_p.h \ |
|
42 | charttheme_p.h \ | |
48 | chartdataset_p.h \ |
|
43 | chartdataset_p.h \ | |
49 | chartpresenter_p.h \ |
|
44 | chartpresenter_p.h \ | |
50 | domain_p.h |
|
45 | domain_p.h | |
51 | PUBLIC_HEADERS += linechart/qlinechartseries.h \ |
|
46 | PUBLIC_HEADERS += linechart/qlinechartseries.h \ | |
52 | barchart/barchartseries.h \ |
|
47 | barchart/barchartseries.h \ | |
53 | barchart/bargroup.h \ |
|
48 | barchart/bargroup.h \ | |
54 | barchart/stackedbarchartseries.h \ |
|
49 | barchart/stackedbarchartseries.h \ | |
55 | barchart/stackedbargroup.h \ |
|
50 | barchart/stackedbargroup.h \ | |
56 | barchart/percentbarchartseries.h \ |
|
51 | barchart/percentbarchartseries.h \ | |
57 | barchart/percentbargroup.h \ |
|
52 | barchart/percentbargroup.h \ | |
58 | barchart/bargroupbase.h \ |
|
53 | barchart/bargroupbase.h \ | |
59 | barchart/qbarset.h \ |
|
54 | barchart/qbarset.h \ | |
60 | barchart/qbarcategory.h \ |
|
55 | barchart/qbarcategory.h \ | |
61 | qchartseries.h \ |
|
56 | qchartseries.h \ | |
62 | qscatterseries.h \ |
|
|||
63 | qchart.h \ |
|
57 | qchart.h \ | |
64 | qchartglobal.h \ |
|
58 | qchartglobal.h \ | |
65 | qchartview.h \ |
|
59 | qchartview.h \ | |
66 | qchartaxis.h |
|
60 | qchartaxis.h | |
67 |
|
61 | |||
68 | include(piechart/piechart.pri) |
|
62 | include(piechart/piechart.pri) | |
|
63 | include(scatterseries/scatter.pri) | |||
69 |
|
64 | |||
70 | THEMES += themes/chartthemeicy_p.h \ |
|
65 | THEMES += themes/chartthemeicy_p.h \ | |
71 | themes/chartthemegrayscale_p.h \ |
|
66 | themes/chartthemegrayscale_p.h \ | |
72 | themes/chartthemescientific_p.h \ |
|
67 | themes/chartthemescientific_p.h \ | |
73 | themes/chartthemevanilla_p.h |
|
68 | themes/chartthemevanilla_p.h | |
74 |
HEADERS += $$PUBLIC_HEADERS |
|
69 | HEADERS += $$PUBLIC_HEADERS | |
75 | scatterpresenter.h |
|
|||
76 | HEADERS += $$PRIVATE_HEADERS |
|
70 | HEADERS += $$PRIVATE_HEADERS | |
77 | HEADERS += $$THEMES |
|
71 | HEADERS += $$THEMES | |
78 | INCLUDEPATH += linechart \ |
|
72 | INCLUDEPATH += linechart \ | |
79 | barchart \ |
|
73 | barchart \ | |
80 | themes \ |
|
74 | themes \ | |
81 | . |
|
75 | . | |
82 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
76 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
83 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
77 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
84 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
78 | UI_DIR = $$CHART_BUILD_DIR/lib | |
85 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
79 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
86 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
80 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
87 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
81 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
88 | public_headers.files = $$PUBLIC_HEADERS |
|
82 | public_headers.files = $$PUBLIC_HEADERS | |
89 | target.path = $$[QT_INSTALL_LIBS] |
|
83 | target.path = $$[QT_INSTALL_LIBS] | |
90 | INSTALLS += target \ |
|
84 | INSTALLS += target \ | |
91 | public_headers |
|
85 | public_headers | |
92 | install_build_public_headers.name = bild_public_headers |
|
86 | install_build_public_headers.name = bild_public_headers | |
93 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
87 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
94 | install_build_public_headers.input = PUBLIC_HEADERS |
|
88 | install_build_public_headers.input = PUBLIC_HEADERS | |
95 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
89 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
96 | ${QMAKE_FILE_NAME} \ |
|
90 | ${QMAKE_FILE_NAME} \ | |
97 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
91 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
98 | install_build_public_headers.CONFIG += target_predeps \ |
|
92 | install_build_public_headers.CONFIG += target_predeps \ | |
99 | no_link |
|
93 | no_link | |
100 | install_build_private_headers.name = bild_private_headers |
|
94 | install_build_private_headers.name = bild_private_headers | |
101 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
95 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
102 | install_build_private_headers.input = PRIVATE_HEADERS |
|
96 | install_build_private_headers.input = PRIVATE_HEADERS | |
103 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
97 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
104 | ${QMAKE_FILE_NAME} \ |
|
98 | ${QMAKE_FILE_NAME} \ | |
105 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
99 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
106 | install_build_private_headers.CONFIG += target_predeps \ |
|
100 | install_build_private_headers.CONFIG += target_predeps \ | |
107 | no_link |
|
101 | no_link | |
108 | QMAKE_EXTRA_COMPILERS += install_build_public_headers install_build_private_headers |
|
102 | QMAKE_EXTRA_COMPILERS += install_build_public_headers install_build_private_headers | |
109 | chartversion.target = qchartversion_p.h |
|
103 | chartversion.target = qchartversion_p.h | |
110 | chartversion.commands = @echo \ |
|
104 | chartversion.commands = @echo \ | |
111 | "build_time" \ |
|
105 | "build_time" \ | |
112 | > \ |
|
106 | > \ | |
113 | $$chartversion.target; |
|
107 | $$chartversion.target; | |
114 | chartversion.depends = $$HEADERS \ |
|
108 | chartversion.depends = $$HEADERS \ | |
115 | $$SOURCES |
|
109 | $$SOURCES | |
116 | PRE_TARGETDEPS += qchartversion_p.h |
|
110 | PRE_TARGETDEPS += qchartversion_p.h | |
117 | QMAKE_CLEAN += qchartversion_p.h |
|
111 | QMAKE_CLEAN += qchartversion_p.h | |
118 | QMAKE_EXTRA_TARGETS += chartversion |
|
112 | QMAKE_EXTRA_TARGETS += chartversion | |
119 | unix:QMAKE_DISTCLEAN += -r \ |
|
113 | unix:QMAKE_DISTCLEAN += -r \ | |
120 | $$CHART_BUILD_HEADER_DIR \ |
|
114 | $$CHART_BUILD_HEADER_DIR \ | |
121 | $$CHART_BUILD_LIB_DIR |
|
115 | $$CHART_BUILD_LIB_DIR | |
122 | win32:QMAKE_DISTCLEAN += /Q \ |
|
116 | win32:QMAKE_DISTCLEAN += /Q \ | |
123 | $$CHART_BUILD_HEADER_DIR \ |
|
117 | $$CHART_BUILD_HEADER_DIR \ | |
124 | $$CHART_BUILD_LIB_DIR |
|
118 | $$CHART_BUILD_LIB_DIR | |
|
119 |
General Comments 0
You need to be logged in to leave comments.
Login now