@@ -21,8 +21,7 | |||||
21 | \note Since QtCommercial Charts utilizes Qt Graphics View Framework for drawing, it works best |
|
21 | \note Since QtCommercial Charts utilizes Qt Graphics View Framework for drawing, it works best | |
22 | with QtQuick 1, which is based on the same framework. |
|
22 | with QtQuick 1, which is based on the same framework. | |
23 | As of release 1.3.0, QtCommercial Charts is also usable with QtQuick 2, though the performance |
|
23 | As of release 1.3.0, QtCommercial Charts is also usable with QtQuick 2, though the performance | |
24 | is slightly worse than with QtQuick 1. Also, hovered and clicked signals of series do not work |
|
24 | is slightly worse than with QtQuick 1 due to additional rendering step that is required. | |
25 | with QtQuick 2. |
|
|||
26 |
|
25 | |||
27 | \raw HTML |
|
26 | \raw HTML | |
28 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
27 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
@@ -41,6 +41,12 | |||||
41 | #include "qdatetimeaxis.h" |
|
41 | #include "qdatetimeaxis.h" | |
42 | #endif |
|
42 | #endif | |
43 |
|
43 | |||
|
44 | #ifdef CHARTS_FOR_QUICK2 | |||
|
45 | #include <QGraphicsSceneMouseEvent> | |||
|
46 | #include <QGraphicsSceneHoverEvent> | |||
|
47 | #include <QApplication> | |||
|
48 | #endif | |||
|
49 | ||||
44 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
45 |
|
51 | |||
46 | /*! |
|
52 | /*! | |
@@ -261,6 +267,9 void DeclarativeChart::initChart(QChart::ChartType type) | |||||
261 | setAntialiasing(QQuickItem::antialiasing()); |
|
267 | setAntialiasing(QQuickItem::antialiasing()); | |
262 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(update())); |
|
268 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(update())); | |
263 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
269 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); | |
|
270 | ||||
|
271 | setAcceptedMouseButtons(Qt::AllButtons); | |||
|
272 | setAcceptHoverEvents(true); | |||
264 | #else |
|
273 | #else | |
265 | if (type == QChart::ChartTypePolar) |
|
274 | if (type == QChart::ChartTypePolar) | |
266 | m_chart = new QPolarChart(this); |
|
275 | m_chart = new QPolarChart(this); | |
@@ -386,7 +395,6 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) | |||||
386 |
|
395 | |||
387 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
396 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
388 | { |
|
397 | { | |
389 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
|||
390 | if (newGeometry.isValid()) { |
|
398 | if (newGeometry.isValid()) { | |
391 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
399 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
392 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
400 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
@@ -407,6 +415,78 void DeclarativeChart::paint(QPainter *painter) | |||||
407 | m_scene->render(painter, renderRect, renderRect); |
|
415 | m_scene->render(painter, renderRect, renderRect); | |
408 | } |
|
416 | } | |
409 |
|
417 | |||
|
418 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) | |||
|
419 | { | |||
|
420 | m_mousePressScenePoint = event->pos(); | |||
|
421 | m_mousePressScreenPoint = event->globalPos(); | |||
|
422 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; | |||
|
423 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; | |||
|
424 | m_mousePressButton = event->button(); | |||
|
425 | m_mousePressButtons = event->buttons(); | |||
|
426 | ||||
|
427 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); | |||
|
428 | mouseEvent.setWidget(0); | |||
|
429 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |||
|
430 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |||
|
431 | mouseEvent.setScenePos(m_mousePressScenePoint); | |||
|
432 | mouseEvent.setScreenPos(m_mousePressScreenPoint); | |||
|
433 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |||
|
434 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |||
|
435 | mouseEvent.setButtons(m_mousePressButtons); | |||
|
436 | mouseEvent.setButton(m_mousePressButton); | |||
|
437 | mouseEvent.setModifiers(event->modifiers()); | |||
|
438 | mouseEvent.setAccepted(false); | |||
|
439 | ||||
|
440 | QApplication::sendEvent(m_scene, &mouseEvent); | |||
|
441 | } | |||
|
442 | ||||
|
443 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) | |||
|
444 | { | |||
|
445 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); | |||
|
446 | mouseEvent.setWidget(0); | |||
|
447 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |||
|
448 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |||
|
449 | mouseEvent.setScenePos(event->pos()); | |||
|
450 | mouseEvent.setScreenPos(event->globalPos()); | |||
|
451 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |||
|
452 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |||
|
453 | mouseEvent.setButtons(event->buttons()); | |||
|
454 | mouseEvent.setButton(event->button()); | |||
|
455 | mouseEvent.setModifiers(event->modifiers()); | |||
|
456 | mouseEvent.setAccepted(false); | |||
|
457 | ||||
|
458 | QApplication::sendEvent(m_scene, &mouseEvent); | |||
|
459 | ||||
|
460 | m_mousePressButtons = event->buttons(); | |||
|
461 | m_mousePressButton = Qt::NoButton; | |||
|
462 | } | |||
|
463 | ||||
|
464 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) | |||
|
465 | { | |||
|
466 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. | |||
|
467 | // QGraphicsScene generates hover events from mouse move events, so we don't need | |||
|
468 | // to pass hover events there. | |||
|
469 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); | |||
|
470 | mouseEvent.setWidget(0); | |||
|
471 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |||
|
472 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |||
|
473 | mouseEvent.setScenePos(event->pos()); | |||
|
474 | // Hover events do not have global pos in them, and the screen position doesn't seem to | |||
|
475 | // matter anyway in this use case, so just pass event pos instead of trying to | |||
|
476 | // calculate the real screen position. | |||
|
477 | mouseEvent.setScreenPos(event->pos()); | |||
|
478 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |||
|
479 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |||
|
480 | mouseEvent.setButtons(m_mousePressButtons); | |||
|
481 | mouseEvent.setButton(m_mousePressButton); | |||
|
482 | mouseEvent.setModifiers(event->modifiers()); | |||
|
483 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); | |||
|
484 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); | |||
|
485 | mouseEvent.setAccepted(false); | |||
|
486 | ||||
|
487 | QApplication::sendEvent(m_scene, &mouseEvent); | |||
|
488 | } | |||
|
489 | ||||
410 | void DeclarativeChart::handleAntialiasingChanged(bool enable) |
|
490 | void DeclarativeChart::handleAntialiasingChanged(bool enable) | |
411 | { |
|
491 | { | |
412 | setAntialiasing(enable); |
|
492 | setAntialiasing(enable); |
@@ -111,6 +111,10 public: // From parent classes | |||||
111 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
111 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
112 | #ifdef CHARTS_FOR_QUICK2 |
|
112 | #ifdef CHARTS_FOR_QUICK2 | |
113 | void paint(QPainter *painter); |
|
113 | void paint(QPainter *painter); | |
|
114 | protected: | |||
|
115 | void mousePressEvent(QMouseEvent *event); | |||
|
116 | void mouseReleaseEvent(QMouseEvent *event); | |||
|
117 | void hoverMoveEvent(QHoverEvent *event); | |||
114 | private Q_SLOTS: |
|
118 | private Q_SLOTS: | |
115 | void handleAntialiasingChanged(bool enable); |
|
119 | void handleAntialiasingChanged(bool enable); | |
116 | #endif |
|
120 | #endif | |
@@ -198,6 +202,12 private: | |||||
198 | QChart *m_chart; |
|
202 | QChart *m_chart; | |
199 | #ifdef CHARTS_FOR_QUICK2 |
|
203 | #ifdef CHARTS_FOR_QUICK2 | |
200 | QGraphicsScene *m_scene; |
|
204 | QGraphicsScene *m_scene; | |
|
205 | QPointF m_mousePressScenePoint; | |||
|
206 | QPoint m_mousePressScreenPoint; | |||
|
207 | QPointF m_lastMouseMoveScenePoint; | |||
|
208 | QPoint m_lastMouseMoveScreenPoint; | |||
|
209 | Qt::MouseButton m_mousePressButton; | |||
|
210 | Qt::MouseButtons m_mousePressButtons; | |||
201 | #endif |
|
211 | #endif | |
202 | DeclarativeMargins *m_margins; |
|
212 | DeclarativeMargins *m_margins; | |
203 | }; |
|
213 | }; |
@@ -63,5 +63,6 ChartView { | |||||
63 | XYPoint { x: 3.4; y: 2.0 } |
|
63 | XYPoint { x: 3.4; y: 2.0 } | |
64 | XYPoint { x: 4.1; y: 2.3 } |
|
64 | XYPoint { x: 4.1; y: 2.3 } | |
65 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
65 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
|
66 | onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); | |||
66 | } |
|
67 | } | |
67 | } |
|
68 | } |
@@ -41,6 +41,7 ChartView { | |||||
41 | onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); |
|
41 | onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); | |
42 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); |
|
42 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); | |
43 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
43 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
|
44 | onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); | |||
44 | onPointReplaced: console.log("scatterSeries.onPointReplaced: " + index); |
|
45 | onPointReplaced: console.log("scatterSeries.onPointReplaced: " + index); | |
45 | onPointRemoved: console.log("scatterSeries.onPointRemoved: " + index); |
|
46 | onPointRemoved: console.log("scatterSeries.onPointRemoved: " + index); | |
46 | onPointAdded: console.log("scatterSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); |
|
47 | onPointAdded: console.log("scatterSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); | |
@@ -59,5 +60,6 ChartView { | |||||
59 | XYPoint { x: 2.4; y: 2.7 } |
|
60 | XYPoint { x: 2.4; y: 2.7 } | |
60 | XYPoint { x: 2.67; y: 2.65 } |
|
61 | XYPoint { x: 2.67; y: 2.65 } | |
61 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
62 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
|
63 | onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); | |||
62 | } |
|
64 | } | |
63 | } |
|
65 | } |
@@ -42,6 +42,7 ChartView { | |||||
42 | onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible); |
|
42 | onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible); | |
43 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); |
|
43 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); | |
44 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
44 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
|
45 | onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); | |||
45 | onPointReplaced: console.log("splineSeries.onPointReplaced: " + index); |
|
46 | onPointReplaced: console.log("splineSeries.onPointReplaced: " + index); | |
46 | onPointRemoved: console.log("splineSeries.onPointRemoved: " + index); |
|
47 | onPointRemoved: console.log("splineSeries.onPointRemoved: " + index); | |
47 | onPointAdded: console.log("splineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); |
|
48 | onPointAdded: console.log("splineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); | |
@@ -61,5 +62,6 ChartView { | |||||
61 | XYPoint { x: 3.4; y: 2.0 } |
|
62 | XYPoint { x: 3.4; y: 2.0 } | |
62 | XYPoint { x: 4.1; y: 2.3 } |
|
63 | XYPoint { x: 4.1; y: 2.3 } | |
63 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
64 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
|
65 | onHovered: console.log(name + ".onHovered: " + point.x + ", " + point.y); | |||
64 | } |
|
66 | } | |
65 | } |
|
67 | } |
General Comments 0
You need to be logged in to leave comments.
Login now