@@ -45,6 +45,7 | |||||
45 | #include <QGraphicsSceneMouseEvent> |
|
45 | #include <QGraphicsSceneMouseEvent> | |
46 | #include <QGraphicsSceneHoverEvent> |
|
46 | #include <QGraphicsSceneHoverEvent> | |
47 | #include <QApplication> |
|
47 | #include <QApplication> | |
|
48 | #include <QTimer> | |||
48 | #endif |
|
49 | #endif | |
49 |
|
50 | |||
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -263,6 +264,8 DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *pa | |||||
263 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
264 | void DeclarativeChart::initChart(QChart::ChartType type) | |
264 | { |
|
265 | { | |
265 | #ifdef CHARTS_FOR_QUICK2 |
|
266 | #ifdef CHARTS_FOR_QUICK2 | |
|
267 | m_currentSceneImage = 0; | |||
|
268 | ||||
266 | if (type == QChart::ChartTypePolar) |
|
269 | if (type == QChart::ChartTypePolar) | |
267 | m_chart = new QPolarChart(); |
|
270 | m_chart = new QPolarChart(); | |
268 | else |
|
271 | else | |
@@ -272,7 +275,7 void DeclarativeChart::initChart(QChart::ChartType type) | |||||
272 | m_scene->addItem(m_chart); |
|
275 | m_scene->addItem(m_chart); | |
273 |
|
276 | |||
274 | setAntialiasing(QQuickItem::antialiasing()); |
|
277 | setAntialiasing(QQuickItem::antialiasing()); | |
275 |
connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT( |
|
278 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>))); | |
276 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
279 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); | |
277 |
|
280 | |||
278 | setAcceptedMouseButtons(Qt::AllButtons); |
|
281 | setAcceptedMouseButtons(Qt::AllButtons); | |
@@ -314,6 +317,12 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int r | |||||
314 | DeclarativeChart::~DeclarativeChart() |
|
317 | DeclarativeChart::~DeclarativeChart() | |
315 | { |
|
318 | { | |
316 | delete m_chart; |
|
319 | delete m_chart; | |
|
320 | #ifdef CHARTS_FOR_QUICK2 | |||
|
321 | m_sceneImageLock.lock(); | |||
|
322 | delete m_currentSceneImage; | |||
|
323 | m_currentSceneImage = 0; | |||
|
324 | m_sceneImageLock.unlock(); | |||
|
325 | #endif | |||
317 | } |
|
326 | } | |
318 |
|
327 | |||
319 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
328 | void DeclarativeChart::childEvent(QChildEvent *event) | |
@@ -416,10 +425,41 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF & | |||||
416 | } |
|
425 | } | |
417 |
|
426 | |||
418 | #ifdef CHARTS_FOR_QUICK2 |
|
427 | #ifdef CHARTS_FOR_QUICK2 | |
|
428 | void DeclarativeChart::sceneChanged(QList<QRectF> region) | |||
|
429 | { | |||
|
430 | Q_UNUSED(region); | |||
|
431 | ||||
|
432 | if (!m_updatePending) { | |||
|
433 | m_updatePending = true; | |||
|
434 | // Do async render to avoid some unnecessary renders. | |||
|
435 | QTimer::singleShot(0, this, SLOT(renderScene())); | |||
|
436 | } | |||
|
437 | } | |||
|
438 | ||||
|
439 | void DeclarativeChart::renderScene() | |||
|
440 | { | |||
|
441 | m_updatePending = false; | |||
|
442 | m_sceneImageLock.lock(); | |||
|
443 | delete m_currentSceneImage; | |||
|
444 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); | |||
|
445 | m_currentSceneImage->fill(Qt::transparent); | |||
|
446 | QPainter painter(m_currentSceneImage); | |||
|
447 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); | |||
|
448 | m_scene->render(&painter, renderRect, renderRect); | |||
|
449 | m_sceneImageLock.unlock(); | |||
|
450 | ||||
|
451 | update(); | |||
|
452 | } | |||
|
453 | ||||
419 | void DeclarativeChart::paint(QPainter *painter) |
|
454 | void DeclarativeChart::paint(QPainter *painter) | |
420 | { |
|
455 | { | |
421 | QRectF renderRect(QPointF(0, 0), m_chart->size()); |
|
456 | m_sceneImageLock.lock(); | |
422 | m_scene->render(painter, renderRect, renderRect); |
|
457 | if (m_currentSceneImage) { | |
|
458 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); | |||
|
459 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); | |||
|
460 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); | |||
|
461 | } | |||
|
462 | m_sceneImageLock.unlock(); | |||
423 | } |
|
463 | } | |
424 |
|
464 | |||
425 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
465 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
@@ -28,6 +28,7 | |||||
28 | #include <QtQuick/QQuickItem> |
|
28 | #include <QtQuick/QQuickItem> | |
29 | #include <QtQuick/QQuickPaintedItem> |
|
29 | #include <QtQuick/QQuickPaintedItem> | |
30 | #include <QtWidgets/QGraphicsScene> |
|
30 | #include <QtWidgets/QGraphicsScene> | |
|
31 | #include <QtCore/QMutex> | |||
31 | #else |
|
32 | #else | |
32 | #include <QtDeclarative/QDeclarativeItem> |
|
33 | #include <QtDeclarative/QDeclarativeItem> | |
33 | #endif |
|
34 | #endif | |
@@ -118,6 +119,8 protected: | |||||
118 | void hoverMoveEvent(QHoverEvent *event); |
|
119 | void hoverMoveEvent(QHoverEvent *event); | |
119 | private Q_SLOTS: |
|
120 | private Q_SLOTS: | |
120 | void handleAntialiasingChanged(bool enable); |
|
121 | void handleAntialiasingChanged(bool enable); | |
|
122 | void sceneChanged(QList<QRectF> region); | |||
|
123 | void renderScene(); | |||
121 | #endif |
|
124 | #endif | |
122 |
|
125 | |||
123 | public: |
|
126 | public: | |
@@ -212,6 +215,9 private: | |||||
212 | QPoint m_lastMouseMoveScreenPoint; |
|
215 | QPoint m_lastMouseMoveScreenPoint; | |
213 | Qt::MouseButton m_mousePressButton; |
|
216 | Qt::MouseButton m_mousePressButton; | |
214 | Qt::MouseButtons m_mousePressButtons; |
|
217 | Qt::MouseButtons m_mousePressButtons; | |
|
218 | QMutex m_sceneImageLock; | |||
|
219 | QImage *m_currentSceneImage; | |||
|
220 | bool m_updatePending; | |||
215 | #endif |
|
221 | #endif | |
216 | DeclarativeMargins *m_margins; |
|
222 | DeclarativeMargins *m_margins; | |
217 | }; |
|
223 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now