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