@@ -3,7 +3,7 | |||
|
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 |
|
@@ -21,7 +21,11 SocExplorerPlot::SocExplorerPlot(QWidget | |||
|
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() |
@@ -29,6 +33,11 void SocExplorerPlot::show() | |||
|
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 |
|
@@ -91,6 +100,20 int SocExplorerPlot::addGraph() | |||
|
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 | { |
@@ -290,6 +313,16 void SocExplorerPlot::setGraphScatterSty | |||
|
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 | |
@@ -300,6 +333,7 void SocExplorerPlot::keyPressEvent(QKey | |||
|
300 | 333 | { |
|
301 | 334 | case Qt::Key_Control: |
|
302 | 335 |
|
|
336 | setCursor(Qt::CrossCursor); | |
|
303 | 337 |
|
|
304 | 338 | case Qt::Key_Shift: |
|
305 | 339 |
|
@@ -307,6 +341,46 void SocExplorerPlot::keyPressEvent(QKey | |||
|
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 |
|
@@ -329,6 +403,7 void SocExplorerPlot::keyReleaseEvent(QK | |||
|
329 | 403 |
|
|
330 | 404 |
|
|
331 | 405 | } |
|
406 | setCursor(Qt::ArrowCursor); | |
|
332 | 407 | } |
|
333 | 408 | |
|
334 | 409 | void SocExplorerPlot::wheelEvent(QWheelEvent * event) |
@@ -339,11 +414,10 void SocExplorerPlot::wheelEvent(QWheelE | |||
|
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 | } |
@@ -351,18 +425,14 void SocExplorerPlot::wheelEvent(QWheelE | |||
|
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 | |
@@ -373,11 +443,22 void SocExplorerPlot::mousePressEvent(QM | |||
|
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 | |
@@ -387,9 +468,42 void SocExplorerPlot::mouseReleaseEvent( | |||
|
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 |
|
@@ -402,6 +516,10 void SocExplorerPlot::mouseMoveEvent(QMo | |||
|
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 |
@@ -4,12 +4,15 | |||
|
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 |
|
@@ -20,15 +23,21 public: | |||
|
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 | |
@@ -43,6 +52,8 protected: | |||
|
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 |
|
@@ -51,6 +62,9 private: | |||
|
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