##// END OF EJS Templates
QChartWidget now zooms only x axis and zoom is reset with right click
Tero Ahola -
r93:264fcc5c2ce8
parent child
Show More
@@ -351,7 +351,7 void QChart::zoomIn()
351 351 foreach (ChartItem* item ,m_chartItems)
352 352 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
353 353 update();
354 }else{
354 } else {
355 355 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
356 356 rect.setWidth(rect.width()/2);
357 357 rect.setHeight(rect.height()/2);
@@ -370,6 +370,16 void QChart::zoomOut()
370 370 }
371 371 }
372 372
373 void QChart::zoomReset()
374 {
375 if (m_plotDataIndex > 0) {
376 m_plotDataIndex = 0;
377 foreach (ChartItem* item ,m_chartItems)
378 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
379 update();
380 }
381 }
382
373 383 void QChart::setAxisX(const QChartAxis& axis)
374 384 {
375 385 setAxis(m_axisXItem,axis);
@@ -66,6 +66,7 public:
66 66 void zoomInToRect(const QRect& rectangle);
67 67 void zoomIn();
68 68 void zoomOut();
69 void zoomReset();
69 70
70 71 void setAxisX(const QChartAxis& axis);
71 72 void setAxisY(const QChartAxis& axis);
@@ -8,7 +8,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 QChartWidget::QChartWidget(QWidget *parent) :
10 10 QGraphicsView(parent),
11 m_rubberBand(QRubberBand::Rectangle, this)
11 m_rubberBand(QRubberBand::Rectangle, this),
12 m_originX(0)
12 13 {
13 14 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
14 15 m_scene = new QGraphicsScene();
@@ -44,10 +45,10 void QChartWidget::mousePressEvent(QMouseEvent *event)
44 45 if(m_rubberBand.isEnabled() && event->button() == Qt::LeftButton) {
45 46 int margin = m_chart->margin();
46 47 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
47 m_origin = event->pos();
48 48
49 if (rect.contains(m_origin)) {
50 m_rubberBand.setGeometry(QRect(m_origin, QSize()));
49 if (rect.contains(event->pos())) {
50 m_originX = event->pos().x();
51 m_rubberBand.setGeometry(QRect(m_originX, 0, 0, height()));
51 52 m_rubberBand.show();
52 53 event->accept();
53 54 }
@@ -57,7 +58,8 void QChartWidget::mousePressEvent(QMouseEvent *event)
57 58 void QChartWidget::mouseMoveEvent(QMouseEvent *event)
58 59 {
59 60 if(m_rubberBand.isVisible())
60 m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized());
61 m_rubberBand.setGeometry(QRect(m_originX, 0,
62 event->pos().x() - m_originX, height()).normalized());
61 63 }
62 64
63 65 void QChartWidget::mouseReleaseEvent(QMouseEvent *event)
@@ -69,9 +71,8 void QChartWidget::mouseReleaseEvent(QMouseEvent *event)
69 71 event->accept();
70 72 }
71 73
72 if(event->button()==Qt::RightButton) {
73 m_chart->zoomOut();
74 }
74 if(event->button()==Qt::RightButton)
75 m_chart->zoomReset();
75 76 }
76 77
77 78 void QChartWidget::addSeries(QChartSeries* series)
@@ -48,7 +48,7 private:
48 48 QGraphicsScene *m_scene;
49 49 QChart* m_chart;
50 50 QRubberBand m_rubberBand;
51 QPoint m_origin;
51 int m_originX;
52 52 };
53 53
54 54 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now