Skip to content
Permalink
Browse files

Optionally draw little rendering stats (switch on/off with S key)

  • Loading branch information
wonder-sk committed Dec 11, 2013
1 parent d3b5fb0 commit 1074312f6d1bb84ad9924b8573afd7741550a219
Showing with 46 additions and 0 deletions.
  1. +13 −0 src/core/qgsmaprendererjob.cpp
  2. +7 −0 src/core/qgsmaprendererjob.h
  3. +23 −0 src/gui/qgsmapcanvas.cpp
  4. +3 −0 src/gui/qgsmapcanvas.h
@@ -2,6 +2,7 @@
#include "qgsmaprendererjob.h"

#include <QPainter>
#include <QTime>
#include <QTimer>
#include <QtConcurrentMap>

@@ -18,6 +19,7 @@
QgsMapRendererJob::QgsMapRendererJob( const QgsMapSettings& settings )
: mSettings(settings)
, mCache( 0 )
, mRenderingTime( 0 )
{
}

@@ -71,6 +73,8 @@ void QgsMapRendererSequentialJob::start()
if ( isActive() )
return; // do nothing if we are already running

mRenderingStart.start();

mErrors.clear();

qDebug("SEQUENTIAL START");
@@ -148,6 +152,8 @@ void QgsMapRendererSequentialJob::internalFinished()
mInternalJob->deleteLater();
mInternalJob = 0;

mRenderingTime = mRenderingStart.elapsed();

emit finished();
}

@@ -180,6 +186,8 @@ void QgsMapRendererCustomPainterJob::start()
if ( isActive() )
return;

mRenderingStart.start();

mActive = true;

mErrors.clear();
@@ -291,6 +299,7 @@ QgsLabelingResults* QgsMapRendererCustomPainterJob::takeLabelingResults()
void QgsMapRendererCustomPainterJob::futureFinished()
{
mActive = false;
mRenderingTime = mRenderingStart.elapsed();
qDebug("QPAINTER futureFinished");
emit finished();
}
@@ -693,6 +702,8 @@ void QgsMapRendererParallelJob::start()
if ( isActive() )
return;

mRenderingStart.start();

mStatus = RenderingLayers;

delete mLabelingEngine;
@@ -837,6 +848,8 @@ void QgsMapRendererParallelJob::renderingFinished()

mStatus = Idle;

mRenderingTime = mRenderingStart.elapsed();

emit finished();
}

@@ -6,6 +6,7 @@
#include <QImage>
#include <QPainter>
#include <QObject>
#include <QTime>

#include "qgsrendercontext.h"

@@ -77,6 +78,9 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
void setCache( QgsMapRendererCache* cache );


//! Find out how log it took to finish the job (in miliseconds)
int renderingTime() const { return mRenderingTime; }

signals:

//! emitted when asynchronous rendering is finished (or canceled).
@@ -108,6 +112,9 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
Errors mErrors;

QgsMapRendererCache* mCache;

QTime mRenderingStart;
int mRenderingTime;
};


@@ -158,6 +158,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
, mJobCancelled( false )
, mLabelingResults( 0 )
, mUseParallelRendering( false )
, mDrawRenderingStats( false )
, mCache( 0 )
{
setObjectName( name );
@@ -688,6 +689,23 @@ void QgsMapCanvas::rendererJobFinished()
// emit renderComplete to get our decorations drawn
QPainter p( &img );
emit renderComplete( &p );

if ( mDrawRenderingStats )
{
int w = img.width(), h = img.height();
QFont fnt = p.font();
fnt.setBold( true );
p.setFont( fnt );
int lh = p.fontMetrics().height()*2;
QRect r( 0, h - lh, w, lh );
p.setPen( Qt::NoPen );
p.setBrush( QColor( 0, 0, 0, 110 ) );
p.drawRect( r );
p.setPen( Qt::white );
QString msg = QString("%1 :: %2 ms").arg( mUseParallelRendering ? "PARALLEL" : "SEQUENTIAL" ).arg( mJob->renderingTime() );
p.drawText( r, msg, QTextOption( Qt::AlignCenter ) );
}

p.end();

mMap->setContent( img, mSettings.visibleExtent() );
@@ -1069,6 +1087,11 @@ void QgsMapCanvas::keyPressEvent( QKeyEvent * e )
refresh();
break;

case Qt::Key_S:
mDrawRenderingStats = !mDrawRenderingStats;
refresh();
break;

default:
// Pass it on
if ( mMapTool )
@@ -577,6 +577,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Whether layers are rendered sequentially or in parallel
bool mUseParallelRendering;

//! Whether to add rendering stats to the rendered image
bool mDrawRenderingStats;

//! Optionally use cache with rendered map layers for the current map settings
QgsMapRendererCache* mCache;

0 comments on commit 1074312

Please sign in to comment.
You can’t perform that action at this time.