@@ -46,6 +46,7 | |||||
46 | #include <QGraphicsSceneHoverEvent> |
|
46 | #include <QGraphicsSceneHoverEvent> | |
47 | #include <QApplication> |
|
47 | #include <QApplication> | |
48 | #include <QTimer> |
|
48 | #include <QTimer> | |
|
49 | #include <QThread> | |||
49 | #endif |
|
50 | #endif | |
50 |
|
51 | |||
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
52 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -265,6 +266,8 void DeclarativeChart::initChart(QChart::ChartType type) | |||||
265 | { |
|
266 | { | |
266 | #ifdef CHARTS_FOR_QUICK2 |
|
267 | #ifdef CHARTS_FOR_QUICK2 | |
267 | m_currentSceneImage = 0; |
|
268 | m_currentSceneImage = 0; | |
|
269 | m_guiThreadId = QThread::currentThreadId(); | |||
|
270 | m_paintThreadId = 0; | |||
268 |
|
271 | |||
269 | if (type == QChart::ChartTypePolar) |
|
272 | if (type == QChart::ChartTypePolar) | |
270 | m_chart = new QPolarChart(); |
|
273 | m_chart = new QPolarChart(); | |
@@ -429,12 +432,18 void DeclarativeChart::sceneChanged(QList<QRectF> region) | |||||
429 | { |
|
432 | { | |
430 | Q_UNUSED(region); |
|
433 | Q_UNUSED(region); | |
431 |
|
434 | |||
|
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 | |||
432 | if (!m_updatePending) { |
|
440 | if (!m_updatePending) { | |
433 | m_updatePending = true; |
|
441 | m_updatePending = true; | |
434 | // Do async render to avoid some unnecessary renders. |
|
442 | // Do async render to avoid some unnecessary renders. | |
435 | QTimer::singleShot(0, this, SLOT(renderScene())); |
|
443 | QTimer::singleShot(0, this, SLOT(renderScene())); | |
436 | } |
|
444 | } | |
437 | } |
|
445 | } | |
|
446 | } | |||
438 |
|
447 | |||
439 | void DeclarativeChart::renderScene() |
|
448 | void DeclarativeChart::renderScene() | |
440 | { |
|
449 | { | |
@@ -444,6 +453,8 void DeclarativeChart::renderScene() | |||||
444 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); |
|
453 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); | |
445 | m_currentSceneImage->fill(Qt::transparent); |
|
454 | m_currentSceneImage->fill(Qt::transparent); | |
446 | QPainter painter(m_currentSceneImage); |
|
455 | QPainter painter(m_currentSceneImage); | |
|
456 | if (antialiasing()) | |||
|
457 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); | |||
447 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); |
|
458 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); | |
448 | m_scene->render(&painter, renderRect, renderRect); |
|
459 | m_scene->render(&painter, renderRect, renderRect); | |
449 | m_sceneImageLock.unlock(); |
|
460 | m_sceneImageLock.unlock(); | |
@@ -453,6 +464,21 void DeclarativeChart::renderScene() | |||||
453 |
|
464 | |||
454 | void DeclarativeChart::paint(QPainter *painter) |
|
465 | void DeclarativeChart::paint(QPainter *painter) | |
455 | { |
|
466 | { | |
|
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 { | |||
456 | m_sceneImageLock.lock(); |
|
482 | m_sceneImageLock.lock(); | |
457 | if (m_currentSceneImage) { |
|
483 | if (m_currentSceneImage) { | |
458 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); |
|
484 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); | |
@@ -461,6 +487,7 void DeclarativeChart::paint(QPainter *painter) | |||||
461 | } |
|
487 | } | |
462 | m_sceneImageLock.unlock(); |
|
488 | m_sceneImageLock.unlock(); | |
463 | } |
|
489 | } | |
|
490 | } | |||
464 |
|
491 | |||
465 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
492 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) | |
466 | { |
|
493 | { |
@@ -218,6 +218,8 private: | |||||
218 | QMutex m_sceneImageLock; |
|
218 | QMutex m_sceneImageLock; | |
219 | QImage *m_currentSceneImage; |
|
219 | QImage *m_currentSceneImage; | |
220 | bool m_updatePending; |
|
220 | bool m_updatePending; | |
|
221 | Qt::HANDLE m_paintThreadId; | |||
|
222 | Qt::HANDLE m_guiThreadId; | |||
221 | #endif |
|
223 | #endif | |
222 | DeclarativeMargins *m_margins; |
|
224 | DeclarativeMargins *m_margins; | |
223 | }; |
|
225 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now