##// 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 foreach (ChartItem* item ,m_chartItems)
351 foreach (ChartItem* item ,m_chartItems)
352 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
352 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
353 update();
353 update();
354 }else{
354 } else {
355 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
355 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
356 rect.setWidth(rect.width()/2);
356 rect.setWidth(rect.width()/2);
357 rect.setHeight(rect.height()/2);
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 void QChart::setAxisX(const QChartAxis& axis)
383 void QChart::setAxisX(const QChartAxis& axis)
374 {
384 {
375 setAxis(m_axisXItem,axis);
385 setAxis(m_axisXItem,axis);
@@ -66,6 +66,7 public:
66 void zoomInToRect(const QRect& rectangle);
66 void zoomInToRect(const QRect& rectangle);
67 void zoomIn();
67 void zoomIn();
68 void zoomOut();
68 void zoomOut();
69 void zoomReset();
69
70
70 void setAxisX(const QChartAxis& axis);
71 void setAxisX(const QChartAxis& axis);
71 void setAxisY(const QChartAxis& axis);
72 void setAxisY(const QChartAxis& axis);
@@ -8,7 +8,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 QChartWidget::QChartWidget(QWidget *parent) :
9 QChartWidget::QChartWidget(QWidget *parent) :
10 QGraphicsView(parent),
10 QGraphicsView(parent),
11 m_rubberBand(QRubberBand::Rectangle, this)
11 m_rubberBand(QRubberBand::Rectangle, this),
12 m_originX(0)
12 {
13 {
13 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
14 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
14 m_scene = new QGraphicsScene();
15 m_scene = new QGraphicsScene();
@@ -44,10 +45,10 void QChartWidget::mousePressEvent(QMouseEvent *event)
44 if(m_rubberBand.isEnabled() && event->button() == Qt::LeftButton) {
45 if(m_rubberBand.isEnabled() && event->button() == Qt::LeftButton) {
45 int margin = m_chart->margin();
46 int margin = m_chart->margin();
46 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
47 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
47 m_origin = event->pos();
48
48
49 if (rect.contains(m_origin)) {
49 if (rect.contains(event->pos())) {
50 m_rubberBand.setGeometry(QRect(m_origin, QSize()));
50 m_originX = event->pos().x();
51 m_rubberBand.setGeometry(QRect(m_originX, 0, 0, height()));
51 m_rubberBand.show();
52 m_rubberBand.show();
52 event->accept();
53 event->accept();
53 }
54 }
@@ -57,7 +58,8 void QChartWidget::mousePressEvent(QMouseEvent *event)
57 void QChartWidget::mouseMoveEvent(QMouseEvent *event)
58 void QChartWidget::mouseMoveEvent(QMouseEvent *event)
58 {
59 {
59 if(m_rubberBand.isVisible())
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 void QChartWidget::mouseReleaseEvent(QMouseEvent *event)
65 void QChartWidget::mouseReleaseEvent(QMouseEvent *event)
@@ -69,9 +71,8 void QChartWidget::mouseReleaseEvent(QMouseEvent *event)
69 event->accept();
71 event->accept();
70 }
72 }
71
73
72 if(event->button()==Qt::RightButton) {
74 if(event->button()==Qt::RightButton)
73 m_chart->zoomOut();
75 m_chart->zoomReset();
74 }
75 }
76 }
76
77
77 void QChartWidget::addSeries(QChartSeries* series)
78 void QChartWidget::addSeries(QChartSeries* series)
@@ -48,7 +48,7 private:
48 QGraphicsScene *m_scene;
48 QGraphicsScene *m_scene;
49 QChart* m_chart;
49 QChart* m_chart;
50 QRubberBand m_rubberBand;
50 QRubberBand m_rubberBand;
51 QPoint m_origin;
51 int m_originX;
52 };
52 };
53
53
54 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now