diff --git a/src/context/applets/analyzer/plugin/AnalyzerBase.cpp b/src/context/applets/analyzer/plugin/AnalyzerBase.cpp --- a/src/context/applets/analyzer/plugin/AnalyzerBase.cpp +++ b/src/context/applets/analyzer/plugin/AnalyzerBase.cpp @@ -68,8 +68,12 @@ { DEBUG_BLOCK - m_worker->deleteLater(); - m_worker = Q_NULLPTR; + if( m_worker ) + { + m_worker->deleteLater(); + m_worker = nullptr; + } + m_workerThread.quit(); m_workerThread.wait(); } diff --git a/src/context/applets/analyzer/plugin/BlockAnalyzer.cpp b/src/context/applets/analyzer/plugin/BlockAnalyzer.cpp --- a/src/context/applets/analyzer/plugin/BlockAnalyzer.cpp +++ b/src/context/applets/analyzer/plugin/BlockAnalyzer.cpp @@ -20,8 +20,8 @@ #include "AnalyzerWorker.h" #include "BlockRenderer.h" #include "BlockWorker.h" - #include "PaletteHandler.h" +#include "core/support/Debug.h" #include diff --git a/src/context/applets/analyzer/plugin/BlockRenderer.h b/src/context/applets/analyzer/plugin/BlockRenderer.h --- a/src/context/applets/analyzer/plugin/BlockRenderer.h +++ b/src/context/applets/analyzer/plugin/BlockRenderer.h @@ -26,21 +26,20 @@ #include "BlockAnalyzer.h" #include "BlockWorker.h" -#include "core/support/Debug.h" #include #include #include +#include #include -#include -#include + class BlockRenderer : public QQuickFramebufferObject::Renderer { public: static const int BLOCK_HEIGHT = BlockAnalyzer::BLOCK_HEIGHT; - BlockRenderer() {} + BlockRenderer() : m_worker( nullptr ) {} protected: QOpenGLFramebufferObject* createFramebufferObject(const QSize &size) override @@ -52,29 +51,38 @@ void render() override { + // Synchronize worker data + if (!m_worker) + return; + + m_worker->m_mutex.lock(); + const QVector store = m_worker->m_store; + const QVector > fadebars = m_worker->m_fadebars; + m_worker->m_mutex.unlock(); + QOpenGLPaintDevice d; d.setSize(framebufferObject()->size()); QPainter p(&d); // Draw the background p.drawPixmap(QRect(QPoint(0, 0), framebufferObject()->size()), m_backgroundPixmap); - for( uint x = 0; x < (uint)m_store.size(); ++x ) + for(uint x = 0; x < (uint)store.size(); ++x) { // Draw fade bars - for( const auto &fadebar : m_fadebars.at(x) ) + for(const auto &fadebar : qAsConst(fadebars.at(x))) { - if( fadebar.intensity > 0 ) + if(fadebar.intensity > 0) { const uint offset = fadebar.intensity; const int fadeHeight = fadebar.y * (BLOCK_HEIGHT + 1); - if( fadeHeight > 0 ) - p.drawPixmap(x * ( m_columnWidth + 1 ), 0, m_fadeBarsPixmaps.value(offset), 0, 0, m_columnWidth, fadeHeight); + if(fadeHeight > 0) + p.drawPixmap(x * (m_columnWidth + 1), 0, m_fadeBarsPixmaps.value(offset), 0, 0, m_columnWidth, fadeHeight); } } // Draw bars - const int height = m_store.at(x) * (BLOCK_HEIGHT + 1); + const int height = store.at(x) * (BLOCK_HEIGHT + 1); if (height > 0) p.drawPixmap(x * (m_columnWidth + 1), 0, m_barPixmap, 0, 0, m_columnWidth, height); @@ -92,14 +100,8 @@ m_rows = analyzer->m_rows; m_columnWidth = analyzer->m_columnWidth; - auto worker = qobject_cast(analyzer->worker()); - if (worker) - { - worker->m_mutex.lock(); - m_store = worker->m_store; - m_fadebars = worker->m_fadebars; - worker->m_mutex.unlock(); - } + if (!m_worker) + m_worker = qobject_cast(analyzer->worker()); if (analyzer->m_pixmapsChanged) { @@ -113,8 +115,8 @@ } private: - QVector m_store; - QVector > m_fadebars; + QPointer m_worker; + int m_rows; int m_columnWidth; diff --git a/src/context/applets/analyzer/plugin/BlockWorker.cpp b/src/context/applets/analyzer/plugin/BlockWorker.cpp --- a/src/context/applets/analyzer/plugin/BlockWorker.cpp +++ b/src/context/applets/analyzer/plugin/BlockWorker.cpp @@ -61,7 +61,7 @@ m_mutex.unlock(); } -void BlockWorker::setColumns(int columns) +void BlockWorker::setColumns( int columns ) { if( m_columns == columns ) return; @@ -85,8 +85,8 @@ const qreal step = m_step * timeElapsed / 1000.0; const qreal fadeStep = (qreal)timeElapsed / 20.0; - // block m_store and m_fadebars - QMutexLocker locker(&m_mutex); + // lock m_store and m_fadebars + QMutexLocker locker( &m_mutex ); m_store.resize( scopeSize ); m_fadebars.resize( scopeSize ); @@ -102,7 +102,7 @@ auto &store = m_store[x]; // remove obscured fadebars - while( !fadebars.isEmpty() && fadebars.last().y >= y ) + while( !fadebars.isEmpty() && fadebars.last().y <= y ) fadebars.removeLast(); // remove completely faded fadebars