@@ -1,417 +1,535 | |||
|
1 | 1 | #include "SocExplorerPlot.h" |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | SocExplorerPlot::SocExplorerPlot(QWidget *parent) : |
|
6 | QWidget(parent) | |
|
6 | QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) | |
|
7 | 7 | { |
|
8 | 8 |
|
|
9 | 9 |
|
|
10 | 10 |
|
|
11 | 11 |
|
|
12 | 12 |
|
|
13 | 13 |
|
|
14 | 14 |
|
|
15 | 15 |
|
|
16 | 16 |
|
|
17 | 17 |
|
|
18 | 18 |
|
|
19 | 19 |
|
|
20 | 20 |
|
|
21 | 21 |
|
|
22 | 22 |
|
|
23 | 23 |
|
|
24 | } | |
|
24 | 25 | |
|
26 | SocExplorerPlot::~SocExplorerPlot() | |
|
27 | { | |
|
28 | delete mRubberBand; | |
|
25 | 29 | } |
|
26 | 30 | |
|
27 | 31 | void SocExplorerPlot::show() |
|
28 | 32 | { |
|
29 | 33 |
|
|
30 | 34 | } |
|
31 | 35 | |
|
36 | void SocExplorerPlot::replot() | |
|
37 | { | |
|
38 | this->m_plot->replot(); | |
|
39 | } | |
|
40 | ||
|
32 | 41 | void SocExplorerPlot::setTitle(QString title) |
|
33 | 42 | { |
|
34 | 43 |
|
|
35 | 44 |
|
|
36 | 45 | /*! |
|
37 | 46 | @todo Function borcken fixe this! |
|
38 | 47 | */ |
|
39 | 48 |
|
|
40 | 49 | } |
|
41 | 50 | |
|
42 | 51 | void SocExplorerPlot::setXaxisLabel(QString label) |
|
43 | 52 | { |
|
44 | 53 |
|
|
45 | 54 |
|
|
46 | 55 | } |
|
47 | 56 | |
|
48 | 57 | void SocExplorerPlot::setYaxisLabel(QString label) |
|
49 | 58 | { |
|
50 | 59 |
|
|
51 | 60 |
|
|
52 | 61 | } |
|
53 | 62 | |
|
54 | 63 | void SocExplorerPlot::setXaxisRange(double lower, double upper) |
|
55 | 64 | { |
|
56 | 65 |
|
|
57 | 66 | } |
|
58 | 67 | |
|
59 | 68 | void SocExplorerPlot::setYaxisRange(double lower, double upper) |
|
60 | 69 | { |
|
61 | 70 |
|
|
62 | 71 | } |
|
63 | 72 | |
|
64 | 73 | |
|
65 | 74 | void SocExplorerPlot::rescaleAxis() |
|
66 | 75 | { |
|
67 | 76 |
|
|
68 | 77 |
|
|
69 | 78 | } |
|
70 | 79 | |
|
71 | 80 | void SocExplorerPlot::setLegendFont(QFont font) |
|
72 | 81 | { |
|
73 | 82 |
|
|
74 | 83 |
|
|
75 | 84 | } |
|
76 | 85 | |
|
77 | 86 | void SocExplorerPlot::setLegendSelectedFont(QFont font) |
|
78 | 87 | { |
|
79 | 88 |
|
|
80 | 89 |
|
|
81 | 90 | } |
|
82 | 91 | |
|
83 | 92 | void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) |
|
84 | 93 | { |
|
85 | 94 |
|
|
86 | 95 | } |
|
87 | 96 | |
|
88 | 97 | int SocExplorerPlot::addGraph() |
|
89 | 98 | { |
|
90 | 99 |
|
|
91 | 100 |
|
|
92 | 101 | } |
|
93 | 102 | |
|
103 | bool SocExplorerPlot::removeGraph(int graphIndex) | |
|
104 | { | |
|
105 | return this->m_plot->removeGraph(graphIndex); | |
|
106 | } | |
|
107 | ||
|
108 | void SocExplorerPlot::removeAllGraphs() | |
|
109 | { | |
|
110 | int graphCount=this->m_plot->graphCount(); | |
|
111 | for(int i=0;i<graphCount;i++) | |
|
112 | { | |
|
113 | this->m_plot->removeGraph(0); | |
|
114 | } | |
|
115 | } | |
|
116 | ||
|
94 | 117 | |
|
95 | 118 | void SocExplorerPlot::setGraphName(int graphIndex,QString name) |
|
96 | 119 | { |
|
97 | 120 |
|
|
98 | 121 | { |
|
99 | 122 |
|
|
100 | 123 | } |
|
101 | 124 | } |
|
102 | 125 | |
|
103 | 126 | |
|
104 | 127 | void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) |
|
105 | 128 | { |
|
106 | 129 |
|
|
107 | 130 | { |
|
108 | 131 |
|
|
109 | 132 |
|
|
110 | 133 | { |
|
111 | 134 |
|
|
112 | 135 | _y[i] = y.at(i).value<double>();*/ |
|
113 | 136 |
|
|
114 | 137 |
|
|
115 | 138 | } |
|
116 | 139 |
|
|
117 | 140 | } |
|
118 | 141 |
|
|
119 | 142 | } |
|
120 | 143 | |
|
121 | 144 | void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) |
|
122 | 145 | { |
|
123 | 146 |
|
|
124 | 147 | { |
|
125 | 148 |
|
|
126 | 149 |
|
|
127 | 150 | { |
|
128 | 151 |
|
|
129 | 152 | _y[i] = y.at(i).value<double>();*/ |
|
130 | 153 |
|
|
131 | 154 |
|
|
132 | 155 | } |
|
133 | 156 |
|
|
134 | 157 | } |
|
135 | 158 |
|
|
136 | 159 | } |
|
137 | 160 | |
|
138 | 161 | void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) |
|
139 | 162 | { |
|
140 | 163 |
|
|
141 | 164 | { |
|
142 | 165 |
|
|
143 | 166 | } |
|
144 | 167 |
|
|
145 | 168 | } |
|
146 | 169 | |
|
147 | 170 | void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) |
|
148 | 171 | { |
|
149 | 172 |
|
|
150 | 173 | { |
|
151 | 174 |
|
|
152 | 175 | } |
|
153 | 176 | } |
|
154 | 177 | |
|
155 | 178 | QPen SocExplorerPlot::getGraphPen(int graphIndex) |
|
156 | 179 | { |
|
157 | 180 |
|
|
158 | 181 | { |
|
159 | 182 |
|
|
160 | 183 | } |
|
161 | 184 |
|
|
162 | 185 | } |
|
163 | 186 | |
|
164 | 187 | |
|
165 | 188 | |
|
166 | 189 | void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) |
|
167 | 190 | { |
|
168 | 191 |
|
|
169 | 192 | { |
|
170 | 193 |
|
|
171 | 194 | { |
|
172 | 195 |
|
|
173 | 196 |
|
|
174 | 197 | } |
|
175 | 198 |
|
|
176 | 199 | { |
|
177 | 200 |
|
|
178 | 201 |
|
|
179 | 202 | } |
|
180 | 203 |
|
|
181 | 204 | { |
|
182 | 205 |
|
|
183 | 206 |
|
|
184 | 207 | } |
|
185 | 208 |
|
|
186 | 209 | { |
|
187 | 210 |
|
|
188 | 211 |
|
|
189 | 212 | } |
|
190 | 213 |
|
|
191 | 214 | { |
|
192 | 215 |
|
|
193 | 216 |
|
|
194 | 217 | } |
|
195 | 218 |
|
|
196 | 219 | { |
|
197 | 220 |
|
|
198 | 221 |
|
|
199 | 222 | } |
|
200 | 223 | |
|
201 | 224 | |
|
202 | 225 | } |
|
203 | 226 | } |
|
204 | 227 | |
|
205 | 228 | void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) |
|
206 | 229 | { |
|
207 | 230 |
|
|
208 | 231 | { |
|
209 | 232 |
|
|
210 | 233 | { |
|
211 | 234 |
|
|
212 | 235 |
|
|
213 | 236 | } |
|
214 | 237 |
|
|
215 | 238 | { |
|
216 | 239 |
|
|
217 | 240 |
|
|
218 | 241 | } |
|
219 | 242 |
|
|
220 | 243 | { |
|
221 | 244 |
|
|
222 | 245 |
|
|
223 | 246 | } |
|
224 | 247 |
|
|
225 | 248 | { |
|
226 | 249 |
|
|
227 | 250 |
|
|
228 | 251 | } |
|
229 | 252 |
|
|
230 | 253 | { |
|
231 | 254 |
|
|
232 | 255 |
|
|
233 | 256 | } |
|
234 | 257 |
|
|
235 | 258 | { |
|
236 | 259 |
|
|
237 | 260 |
|
|
238 | 261 | } |
|
239 | 262 |
|
|
240 | 263 | { |
|
241 | 264 |
|
|
242 | 265 |
|
|
243 | 266 | } |
|
244 | 267 |
|
|
245 | 268 | { |
|
246 | 269 |
|
|
247 | 270 |
|
|
248 | 271 | } |
|
249 | 272 |
|
|
250 | 273 | { |
|
251 | 274 |
|
|
252 | 275 |
|
|
253 | 276 | } |
|
254 | 277 |
|
|
255 | 278 | { |
|
256 | 279 |
|
|
257 | 280 |
|
|
258 | 281 | } |
|
259 | 282 |
|
|
260 | 283 | { |
|
261 | 284 |
|
|
262 | 285 |
|
|
263 | 286 | } |
|
264 | 287 |
|
|
265 | 288 | { |
|
266 | 289 |
|
|
267 | 290 |
|
|
268 | 291 | } |
|
269 | 292 |
|
|
270 | 293 | { |
|
271 | 294 |
|
|
272 | 295 |
|
|
273 | 296 | } |
|
274 | 297 |
|
|
275 | 298 | { |
|
276 | 299 |
|
|
277 | 300 |
|
|
278 | 301 | } |
|
279 | 302 |
|
|
280 | 303 | { |
|
281 | 304 |
|
|
282 | 305 |
|
|
283 | 306 | } |
|
284 | 307 |
|
|
285 | 308 | { |
|
286 | 309 |
|
|
287 | 310 |
|
|
288 | 311 | } |
|
289 | 312 | |
|
290 | 313 | } |
|
291 | 314 | } |
|
292 | 315 | |
|
316 | void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type) | |
|
317 | { | |
|
318 | this->m_plot->xAxis->setTickLabelType(type); | |
|
319 | } | |
|
320 | ||
|
321 | void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format) | |
|
322 | { | |
|
323 | this->m_plot->xAxis->setDateTimeFormat(format); | |
|
324 | } | |
|
325 | ||
|
293 | 326 | |
|
294 | 327 | |
|
295 | 328 | |
|
296 | 329 | |
|
297 | 330 | void SocExplorerPlot::keyPressEvent(QKeyEvent * event) |
|
298 | 331 | { |
|
299 | 332 |
|
|
300 | 333 | { |
|
301 | 334 | case Qt::Key_Control: |
|
302 | 335 |
|
|
336 | setCursor(Qt::CrossCursor); | |
|
303 | 337 |
|
|
304 | 338 | case Qt::Key_Shift: |
|
305 | 339 |
|
|
306 | 340 |
|
|
307 | 341 | case Qt::Key_M: |
|
308 | 342 |
|
|
309 | 343 |
|
|
344 | case Qt::Key_Left: | |
|
345 | if(!ctrl_hold) | |
|
346 | { | |
|
347 | move(-0.1,Qt::Horizontal); | |
|
348 | } | |
|
349 | else | |
|
350 | { | |
|
351 | zoom(2,this->width()/2,Qt::Horizontal); | |
|
352 | } | |
|
353 | break; | |
|
354 | case Qt::Key_Right: | |
|
355 | if(!ctrl_hold) | |
|
356 | { | |
|
357 | move(0.1,Qt::Horizontal); | |
|
358 | } | |
|
359 | else | |
|
360 | { | |
|
361 | zoom(0.5,this->width()/2,Qt::Horizontal); | |
|
362 | } | |
|
363 | break; | |
|
364 | case Qt::Key_Up: | |
|
365 | if(!ctrl_hold) | |
|
366 | { | |
|
367 | move(0.1,Qt::Vertical); | |
|
368 | } | |
|
369 | else | |
|
370 | { | |
|
371 | zoom(0.5,this->height()/2,Qt::Vertical); | |
|
372 | } | |
|
373 | break; | |
|
374 | case Qt::Key_Down: | |
|
375 | if(!ctrl_hold) | |
|
376 | { | |
|
377 | move(-0.1,Qt::Vertical); | |
|
378 | } | |
|
379 | else | |
|
380 | { | |
|
381 | zoom(2,this->height()/2,Qt::Vertical); | |
|
382 | } | |
|
383 | break; | |
|
310 | 384 | default: |
|
311 | 385 |
|
|
312 | 386 |
|
|
313 | 387 | } |
|
314 | 388 | } |
|
315 | 389 | |
|
316 | 390 | void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) |
|
317 | 391 | { |
|
318 | 392 |
|
|
319 | 393 | { |
|
320 | 394 | case Qt::Key_Control: |
|
321 | 395 |
|
|
322 | 396 |
|
|
323 | 397 |
|
|
324 | 398 | case Qt::Key_Shift: |
|
325 | 399 |
|
|
326 | 400 |
|
|
327 | 401 |
|
|
328 | 402 | default: |
|
329 | 403 |
|
|
330 | 404 |
|
|
331 | 405 | } |
|
406 | setCursor(Qt::ArrowCursor); | |
|
332 | 407 | } |
|
333 | 408 | |
|
334 | 409 | void SocExplorerPlot::wheelEvent(QWheelEvent * event) |
|
335 | 410 | { |
|
336 | 411 |
|
|
337 | 412 |
|
|
338 | 413 |
|
|
339 | 414 | { |
|
340 | 415 |
|
|
341 | 416 | { |
|
417 | setCursor(Qt::SizeVerCursor); | |
|
342 | 418 |
|
|
343 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Vertical); | |
|
344 | axis->scaleRange(factor, axis->pixelToCoord(event->pos().y())); | |
|
419 | zoom(factor,event->pos().y(),Qt::Vertical); | |
|
345 | 420 | } |
|
346 | this->m_plot->replot(); | |
|
347 | 421 |
|
|
348 | 422 |
|
|
349 | 423 | } |
|
350 | 424 |
|
|
351 | 425 | { |
|
352 | 426 |
|
|
353 | 427 | { |
|
428 | setCursor(Qt::SizeHorCursor); | |
|
354 | 429 |
|
|
355 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Horizontal); | |
|
356 | axis->scaleRange(factor, axis->pixelToCoord(event->pos().x())); | |
|
430 | zoom(factor,event->pos().x(),Qt::Horizontal); | |
|
357 | 431 | } |
|
358 | this->m_plot->replot(); | |
|
359 | 432 |
|
|
360 | 433 |
|
|
361 | 434 | } |
|
362 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |
|
363 | double rg = (Haxis->range().upper - Haxis->range().lower)*(wheelSteps/10); | |
|
364 | Haxis->setRange(Haxis->range().lower+(rg), Haxis->range().upper+(rg)); | |
|
365 | this->m_plot->replot(); | |
|
435 | move(wheelSteps/10,Qt::Horizontal); | |
|
366 | 436 |
|
|
367 | 437 | } |
|
368 | 438 | |
|
369 | 439 | |
|
370 | 440 | |
|
371 | 441 | |
|
372 | 442 | void SocExplorerPlot::mousePressEvent(QMouseEvent *event) |
|
373 | 443 | { |
|
374 | 444 |
|
|
375 | 445 | { |
|
446 | if(ctrl_hold) | |
|
447 | { | |
|
448 | setCursor(Qt::CrossCursor); | |
|
449 | mOrigin = event->pos(); | |
|
450 | mRubberBand->setGeometry(QRect(mOrigin, QSize())); | |
|
451 | mRubberBand->show(); | |
|
452 | } | |
|
453 | else | |
|
454 | { | |
|
455 | setCursor(Qt::ClosedHandCursor); | |
|
376 | 456 | mDragStart = event->pos(); |
|
377 | 457 | this->mouse_hold = true; |
|
378 | 458 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); |
|
379 | 459 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); |
|
380 | 460 | } |
|
461 | } | |
|
381 | 462 |
|
|
382 | 463 | } |
|
383 | 464 | |
|
384 | 465 | void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) |
|
385 | 466 | { |
|
386 | 467 |
|
|
387 | 468 | { |
|
388 | 469 |
|
|
389 | 470 | } |
|
471 | if (mRubberBand->isVisible()) | |
|
472 | { | |
|
473 | const QRect & zoomRect = mRubberBand->geometry(); | |
|
474 | int xp1, yp1, xp2, yp2; | |
|
475 | zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); | |
|
476 | double x1 = this->m_plot->xAxis->pixelToCoord(xp1); | |
|
477 | double x2 = this->m_plot->xAxis->pixelToCoord(xp2); | |
|
478 | double y1 = this->m_plot->yAxis->pixelToCoord(yp1); | |
|
479 | double y2 = this->m_plot->yAxis->pixelToCoord(yp2); | |
|
480 | ||
|
481 | this->m_plot->xAxis->setRange(x1, x2); | |
|
482 | this->m_plot->yAxis->setRange(y1, y2); | |
|
483 | ||
|
484 | mRubberBand->hide(); | |
|
485 | this->m_plot->replot(); | |
|
486 | } | |
|
487 | setCursor(Qt::ArrowCursor); | |
|
390 | 488 |
|
|
391 | 489 | } |
|
392 | 490 | |
|
491 | void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) | |
|
492 | { | |
|
493 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); | |
|
494 | axis->scaleRange(factor, axis->pixelToCoord(center)); | |
|
495 | this->m_plot->replot(); | |
|
496 | } | |
|
497 | ||
|
498 | void SocExplorerPlot::move(double factor, Qt::Orientation orientation) | |
|
499 | { | |
|
500 | QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); | |
|
501 | double rg = (axis->range().upper - axis->range().lower)*(factor); | |
|
502 | axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | |
|
503 | this->m_plot->replot(); | |
|
504 | } | |
|
505 | ||
|
506 | ||
|
393 | 507 | void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) |
|
394 | 508 | { |
|
395 | 509 |
|
|
396 | 510 | { |
|
397 | 511 |
|
|
398 | 512 |
|
|
399 | 513 |
|
|
400 | 514 |
|
|
401 | 515 |
|
|
402 | 516 |
|
|
403 | 517 |
|
|
404 | 518 | } |
|
519 | if (mRubberBand->isVisible()) | |
|
520 | { | |
|
521 | mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); | |
|
522 | } | |
|
405 | 523 |
|
|
406 | 524 | } |
|
407 | 525 | |
|
408 | 526 | |
|
409 | 527 | |
|
410 | 528 | |
|
411 | 529 | |
|
412 | 530 | |
|
413 | 531 | |
|
414 | 532 | |
|
415 | 533 | |
|
416 | 534 | |
|
417 | 535 |
@@ -1,56 +1,70 | |||
|
1 | 1 | #ifndef SOCEXPLORERPLOT_H |
|
2 | 2 | #define SOCEXPLORERPLOT_H |
|
3 | 3 | |
|
4 | 4 | #include <QWidget> |
|
5 | 5 | #include <QGridLayout> |
|
6 | 6 | #include <qcustomplot.h> |
|
7 | #include <QRubberBand> | |
|
8 | #include <QPoint> | |
|
7 | 9 | |
|
8 | 10 | class SocExplorerPlot : public QWidget |
|
9 | 11 | { |
|
10 | 12 |
|
|
11 | 13 | public: |
|
12 | 14 |
|
|
15 | ~SocExplorerPlot(); | |
|
13 | 16 |
|
|
14 | 17 |
|
|
15 | 18 |
|
|
16 | 19 |
|
|
17 | 20 |
|
|
18 | 21 |
|
|
19 | 22 |
|
|
20 | 23 |
|
|
21 | 24 |
|
|
22 | 25 |
|
|
26 | bool removeGraph(int graphIndex); | |
|
27 | void removeAllGraphs(); | |
|
23 | 28 |
|
|
24 | 29 |
|
|
30 | void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true); | |
|
25 | 31 |
|
|
26 | 32 |
|
|
27 | 33 |
|
|
28 | 34 |
|
|
29 | 35 |
|
|
30 | 36 |
|
|
37 | void setXaxisTickLabelType(QCPAxis::LabelType type); | |
|
38 | void setXaxisDateTimeFormat(const QString &format); | |
|
31 | 39 |
|
|
40 | void replot(); | |
|
32 | 41 | |
|
33 | 42 | signals: |
|
34 | 43 | |
|
35 | 44 | public slots: |
|
36 | 45 | |
|
37 | 46 | protected: |
|
38 | 47 |
|
|
39 | 48 |
|
|
40 | 49 |
|
|
41 | 50 |
|
|
42 | 51 |
|
|
43 | 52 |
|
|
44 | 53 | |
|
45 | 54 | private: |
|
55 | void zoom(double factor, int center, Qt::Orientation orientation); | |
|
56 | void move(double factor, Qt::Orientation orientation); | |
|
46 | 57 |
|
|
47 | 58 |
|
|
48 | 59 |
|
|
49 | 60 |
|
|
50 | 61 |
|
|
51 | 62 |
|
|
52 | 63 |
|
|
53 | 64 |
|
|
65 | bool mZoomMode; | |
|
66 | QRubberBand * mRubberBand; | |
|
67 | QPoint mOrigin; | |
|
54 | 68 | }; |
|
55 | 69 | |
|
56 | 70 | #endif // SOCEXPLORERPLOT_H |
General Comments 0
You need to be logged in to leave comments.
Login now