@@ -46,6 +46,7 | |||
|
46 | 46 | #include <QGraphicsSceneHoverEvent> |
|
47 | 47 | #include <QApplication> |
|
48 | 48 | #include <QTimer> |
|
49 | #include <QThread> | |
|
49 | 50 | #endif |
|
50 | 51 | |
|
51 | 52 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -265,6 +266,8 void DeclarativeChart::initChart(QChart::ChartType type) | |||
|
265 | 266 | { |
|
266 | 267 | #ifdef CHARTS_FOR_QUICK2 |
|
267 | 268 | m_currentSceneImage = 0; |
|
269 | m_guiThreadId = QThread::currentThreadId(); | |
|
270 | m_paintThreadId = 0; | |
|
268 | 271 | |
|
269 | 272 | if (type == QChart::ChartTypePolar) |
|
270 | 273 | m_chart = new QPolarChart(); |
@@ -429,10 +432,16 void DeclarativeChart::sceneChanged(QList<QRectF> region) | |||
|
429 | 432 | { |
|
430 | 433 | Q_UNUSED(region); |
|
431 | 434 | |
|
432 | if (!m_updatePending) { | |
|
433 | m_updatePending = true; | |
|
434 | // Do async render to avoid some unnecessary renders. | |
|
435 | QTimer::singleShot(0, this, SLOT(renderScene())); | |
|
435 | if (m_guiThreadId == m_paintThreadId) { | |
|
436 | // Rendering in gui thread, no need for shenannigans, just update | |
|
437 | update(); | |
|
438 | } else { | |
|
439 | // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread | |
|
440 | if (!m_updatePending) { | |
|
441 | m_updatePending = true; | |
|
442 | // Do async render to avoid some unnecessary renders. | |
|
443 | QTimer::singleShot(0, this, SLOT(renderScene())); | |
|
444 | } | |
|
436 | 445 | } |
|
437 | 446 | } |
|
438 | 447 | |
@@ -444,6 +453,8 void DeclarativeChart::renderScene() | |||
|
444 | 453 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); |
|
445 | 454 | m_currentSceneImage->fill(Qt::transparent); |
|
446 | 455 | QPainter painter(m_currentSceneImage); |
|
456 | if (antialiasing()) | |
|
457 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); | |
|
447 | 458 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); |
|
448 | 459 | m_scene->render(&painter, renderRect, renderRect); |
|
449 | 460 | m_sceneImageLock.unlock(); |
@@ -453,13 +464,29 void DeclarativeChart::renderScene() | |||
|
453 | 464 | |
|
454 | 465 | void DeclarativeChart::paint(QPainter *painter) |
|
455 | 466 | { |
|
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); | |
|
467 | if (!m_paintThreadId) { | |
|
468 | m_paintThreadId = QThread::currentThreadId(); | |
|
469 | if (m_guiThreadId == m_paintThreadId) { | |
|
470 | // No need for scene image in single threaded rendering, so delete | |
|
471 | // the one that got made by default before the rendering type was | |
|
472 | // detected. | |
|
473 | delete m_currentSceneImage; | |
|
474 | m_currentSceneImage = 0; | |
|
475 | } | |
|
476 | } | |
|
477 | ||
|
478 | if (m_guiThreadId == m_paintThreadId) { | |
|
479 | QRectF renderRect(QPointF(0, 0), m_chart->size()); | |
|
480 | m_scene->render(painter, renderRect, renderRect); | |
|
481 | } else { | |
|
482 | m_sceneImageLock.lock(); | |
|
483 | if (m_currentSceneImage) { | |
|
484 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); | |
|
485 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); | |
|
486 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); | |
|
487 | } | |
|
488 | m_sceneImageLock.unlock(); | |
|
461 | 489 | } |
|
462 | m_sceneImageLock.unlock(); | |
|
463 | 490 | } |
|
464 | 491 | |
|
465 | 492 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
General Comments 0
You need to be logged in to leave comments.
Login now