Skip to content

Commit d4fcc6d

Browse files
committed
Add option to show canvas refresh event in Log Message panel
- In Options at bottom of Rendering tab - Useful for debugging excessive refreshes from userspace without having to build with debug and filter logs - Records time taken for refresh and any resolvable sender class
1 parent 92cbf8f commit d4fcc6d

File tree

3 files changed

+92
-22
lines changed

3 files changed

+92
-22
lines changed

src/app/qgsoptions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
358358

359359
// set the display update threshold
360360
spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() );
361+
362+
// log rendering events, for userspace debugging
363+
mLogCanvasRefreshChkBx->setChecked( settings.value( "/Map/logCanvasRefreshEvent", false ).toBool() );
364+
361365
//set the default projection behaviour radio buttongs
362366
if ( settings.value( "/Projections/defaultBehaviour", "prompt" ).toString() == "prompt" )
363367
{
@@ -1140,6 +1144,10 @@ void QgsOptions::saveOptions()
11401144

11411145
settings.setValue( "/Map/enableBackbuffer", chkEnableBackbuffer->isChecked() );
11421146
settings.setValue( "/Map/updateThreshold", spinBoxUpdateThreshold->value() );
1147+
1148+
// log rendering events, for userspace debugging
1149+
settings.setValue( "/Map/logCanvasRefreshEvent", mLogCanvasRefreshChkBx->isChecked() );
1150+
11431151
//check behaviour so default projection when new layer is added with no
11441152
//projection defined...
11451153
if ( radPromptForProjection->isChecked() )

src/gui/qgsmapcanvas.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ email : sherman at mrcc.com
4747
#include "qgsmaptopixel.h"
4848
#include "qgsmapoverviewcanvas.h"
4949
#include "qgsmaprenderer.h"
50+
#include "qgsmessagelog.h"
5051
#include "qgsmessageviewer.h"
5152
#include "qgsproject.h"
5253
#include "qgsrubberband.h"
@@ -368,6 +369,13 @@ void QgsMapCanvas::refresh()
368369
return;
369370

370371
QSettings settings;
372+
bool logRefresh = settings.value( "/Map/logCanvasRefreshEvent", false ).toBool();
373+
QTime t;
374+
if ( logRefresh )
375+
{
376+
t.start();
377+
}
378+
371379
#ifdef Q_WS_X11
372380
bool enableBackbufferSetting = settings.value( "/Map/enableBackbuffer", 1 ).toBool();
373381
#endif
@@ -428,6 +436,17 @@ void QgsMapCanvas::refresh()
428436
// Done refreshing
429437
emit mapCanvasRefreshed();
430438

439+
if ( logRefresh )
440+
{
441+
QString logMsg = tr( "Canvas refresh: %1 ms" ).arg( t.elapsed() );
442+
QObject* senderObj = QObject::sender();
443+
if ( senderObj )
444+
{
445+
logMsg += tr( ", sender '%1'" ).arg( senderObj->metaObject()->className() );
446+
}
447+
QgsMessageLog::logMessage( logMsg, tr( "Rendering" ) );
448+
}
449+
431450
} // refresh
432451

433452
void QgsMapCanvas::updateMap()

src/ui/qgsoptionsbase.ui

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@
901901
<rect>
902902
<x>0</x>
903903
<y>0</y>
904-
<width>611</width>
904+
<width>654</width>
905905
<height>808</height>
906906
</rect>
907907
</property>
@@ -1231,8 +1231,8 @@
12311231
<rect>
12321232
<x>0</x>
12331233
<y>0</y>
1234-
<width>559</width>
1235-
<height>417</height>
1234+
<width>669</width>
1235+
<height>490</height>
12361236
</rect>
12371237
</property>
12381238
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -1549,9 +1549,9 @@
15491549
<property name="geometry">
15501550
<rect>
15511551
<x>0</x>
1552-
<y>0</y>
1553-
<width>615</width>
1554-
<height>681</height>
1552+
<y>-291</y>
1553+
<width>654</width>
1554+
<height>781</height>
15551555
</rect>
15561556
</property>
15571557
<layout class="QVBoxLayout" name="verticalLayout_29">
@@ -1561,7 +1561,7 @@
15611561
<string>Rendering behavior</string>
15621562
</property>
15631563
<layout class="QGridLayout" name="_4">
1564-
<item row="2" column="0">
1564+
<item row="1" column="0">
15651565
<widget class="QCheckBox" name="chkEnableBackbuffer">
15661566
<property name="toolTip">
15671567
<string>Better graphics performance at the cost of loosing the possibility to cancel rendering and incremental feature drawing</string>
@@ -1571,21 +1571,21 @@
15711571
</property>
15721572
</widget>
15731573
</item>
1574-
<item row="1" column="0">
1574+
<item row="0" column="0">
15751575
<widget class="QCheckBox" name="chkAddedVisibility">
15761576
<property name="text">
15771577
<string>By default new la&amp;yers added to the map should be displayed</string>
15781578
</property>
15791579
</widget>
15801580
</item>
1581-
<item row="5" column="0" colspan="3">
1581+
<item row="4" column="0" colspan="2">
15821582
<widget class="QCheckBox" name="chkUseRenderCaching">
15831583
<property name="text">
15841584
<string>Use render caching where possible to speed up redraws</string>
15851585
</property>
15861586
</widget>
15871587
</item>
1588-
<item row="3" column="0">
1588+
<item row="2" column="0">
15891589
<layout class="QHBoxLayout" name="horizontalLayout_26">
15901590
<item>
15911591
<widget class="QLabel" name="labelUpdateThreshold">
@@ -1615,7 +1615,7 @@
16151615
</item>
16161616
</layout>
16171617
</item>
1618-
<item row="4" column="0" colspan="3">
1618+
<item row="3" column="0" colspan="2">
16191619
<widget class="QLabel" name="textLabel3">
16201620
<property name="text">
16211621
<string>&lt;b&gt;Note:&lt;/b&gt; Use zero to prevent display updates until all features have been rendered</string>
@@ -1991,6 +1991,49 @@
19911991
</layout>
19921992
</widget>
19931993
</item>
1994+
<item>
1995+
<widget class="QGroupBox" name="groupBox_22">
1996+
<property name="title">
1997+
<string>Debugging</string>
1998+
</property>
1999+
<layout class="QVBoxLayout" name="verticalLayout_35">
2000+
<item>
2001+
<widget class="QLabel" name="label_55">
2002+
<property name="text">
2003+
<string>Show these events in the Log Message panel (under Rendering tab)</string>
2004+
</property>
2005+
</widget>
2006+
</item>
2007+
<item>
2008+
<layout class="QGridLayout" name="gridLayout_6">
2009+
<item row="0" column="0">
2010+
<spacer name="horizontalSpacer_37">
2011+
<property name="orientation">
2012+
<enum>Qt::Horizontal</enum>
2013+
</property>
2014+
<property name="sizeType">
2015+
<enum>QSizePolicy::Fixed</enum>
2016+
</property>
2017+
<property name="sizeHint" stdset="0">
2018+
<size>
2019+
<width>8</width>
2020+
<height>20</height>
2021+
</size>
2022+
</property>
2023+
</spacer>
2024+
</item>
2025+
<item row="0" column="1">
2026+
<widget class="QCheckBox" name="mLogCanvasRefreshChkBx">
2027+
<property name="text">
2028+
<string>Map canvas refresh</string>
2029+
</property>
2030+
</widget>
2031+
</item>
2032+
</layout>
2033+
</item>
2034+
</layout>
2035+
</widget>
2036+
</item>
19942037
<item>
19952038
<spacer name="verticalSpacer_6">
19962039
<property name="orientation">
@@ -2038,8 +2081,8 @@
20382081
<rect>
20392082
<x>0</x>
20402083
<y>0</y>
2041-
<width>498</width>
2042-
<height>396</height>
2084+
<width>669</width>
2085+
<height>490</height>
20432086
</rect>
20442087
</property>
20452088
<layout class="QVBoxLayout" name="verticalLayout_25">
@@ -2349,7 +2392,7 @@
23492392
<rect>
23502393
<x>0</x>
23512394
<y>0</y>
2352-
<width>556</width>
2395+
<width>654</width>
23532396
<height>718</height>
23542397
</rect>
23552398
</property>
@@ -2729,7 +2772,7 @@
27292772
<rect>
27302773
<x>0</x>
27312774
<y>0</y>
2732-
<width>517</width>
2775+
<width>654</width>
27332776
<height>643</height>
27342777
</rect>
27352778
</property>
@@ -3218,8 +3261,8 @@
32183261
<rect>
32193262
<x>0</x>
32203263
<y>0</y>
3221-
<width>537</width>
3222-
<height>361</height>
3264+
<width>669</width>
3265+
<height>490</height>
32233266
</rect>
32243267
</property>
32253268
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -3358,8 +3401,8 @@
33583401
<rect>
33593402
<x>0</x>
33603403
<y>0</y>
3361-
<width>614</width>
3362-
<height>393</height>
3404+
<width>669</width>
3405+
<height>490</height>
33633406
</rect>
33643407
</property>
33653408
<layout class="QGridLayout" name="gridLayout_15">
@@ -3539,8 +3582,8 @@
35393582
<rect>
35403583
<x>0</x>
35413584
<y>0</y>
3542-
<width>300</width>
3543-
<height>248</height>
3585+
<width>669</width>
3586+
<height>490</height>
35443587
</rect>
35453588
</property>
35463589
<layout class="QVBoxLayout" name="verticalLayout_32">
@@ -3639,7 +3682,7 @@
36393682
<rect>
36403683
<x>0</x>
36413684
<y>0</y>
3642-
<width>521</width>
3685+
<width>654</width>
36433686
<height>650</height>
36443687
</rect>
36453688
</property>

0 commit comments

Comments
 (0)