@@ -45,6 +45,7 | |||
|
45 | 45 | #include <QGraphicsSceneMouseEvent> |
|
46 | 46 | #include <QGraphicsSceneHoverEvent> |
|
47 | 47 | #include <QApplication> |
|
48 | #include <QTimer> | |
|
48 | 49 | #endif |
|
49 | 50 | |
|
50 | 51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -263,6 +264,8 DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *pa | |||
|
263 | 264 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
264 | 265 | { |
|
265 | 266 | #ifdef CHARTS_FOR_QUICK2 |
|
267 | m_currentSceneImage = 0; | |
|
268 | ||
|
266 | 269 | if (type == QChart::ChartTypePolar) |
|
267 | 270 | m_chart = new QPolarChart(); |
|
268 | 271 | else |
@@ -272,7 +275,7 void DeclarativeChart::initChart(QChart::ChartType type) | |||
|
272 | 275 | m_scene->addItem(m_chart); |
|
273 | 276 | |
|
274 | 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 | 279 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
277 | 280 | |
|
278 | 281 | setAcceptedMouseButtons(Qt::AllButtons); |
@@ -314,6 +317,12 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int r | |||
|
314 | 317 | DeclarativeChart::~DeclarativeChart() |
|
315 | 318 | { |
|
316 | 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 | 328 | void DeclarativeChart::childEvent(QChildEvent *event) |
@@ -416,10 +425,41 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF & | |||
|
416 | 425 | } |
|
417 | 426 | |
|
418 | 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 | 454 | void DeclarativeChart::paint(QPainter *painter) |
|
420 | 455 | { |
|
421 | QRectF renderRect(QPointF(0, 0), m_chart->size()); | |
|
422 | m_scene->render(painter, renderRect, renderRect); | |
|
456 | m_sceneImageLock.lock(); | |
|
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 | 465 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
@@ -28,6 +28,7 | |||
|
28 | 28 | #include <QtQuick/QQuickItem> |
|
29 | 29 | #include <QtQuick/QQuickPaintedItem> |
|
30 | 30 | #include <QtWidgets/QGraphicsScene> |
|
31 | #include <QtCore/QMutex> | |
|
31 | 32 | #else |
|
32 | 33 | #include <QtDeclarative/QDeclarativeItem> |
|
33 | 34 | #endif |
@@ -118,6 +119,8 protected: | |||
|
118 | 119 | void hoverMoveEvent(QHoverEvent *event); |
|
119 | 120 | private Q_SLOTS: |
|
120 | 121 | void handleAntialiasingChanged(bool enable); |
|
122 | void sceneChanged(QList<QRectF> region); | |
|
123 | void renderScene(); | |
|
121 | 124 | #endif |
|
122 | 125 | |
|
123 | 126 | public: |
@@ -212,6 +215,9 private: | |||
|
212 | 215 | QPoint m_lastMouseMoveScreenPoint; |
|
213 | 216 | Qt::MouseButton m_mousePressButton; |
|
214 | 217 | Qt::MouseButtons m_mousePressButtons; |
|
218 | QMutex m_sceneImageLock; | |
|
219 | QImage *m_currentSceneImage; | |
|
220 | bool m_updatePending; | |
|
215 | 221 | #endif |
|
216 | 222 | DeclarativeMargins *m_margins; |
|
217 | 223 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now