Showing with 135 additions and 41 deletions.
  1. +35 −0 src/app/qgsoptions.cpp
  2. +6 −0 src/app/qgsoptions.h
  3. +20 −11 src/core/qgsvectorlayer.cpp
  4. +6 −0 src/core/qgsvectorlayer.h
  5. +28 −8 src/gui/qgsmapcanvas.cpp
  6. +2 −0 src/gui/qgsmapcanvas.h
  7. +38 −22 src/ui/qgsoptionsbase.ui
35 changes: 35 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
connect( spinFontSize, SIGNAL( valueChanged( const QString& ) ), this, SLOT( fontSizeChanged( const QString& ) ) );

connect( chkUseStandardDeviation, SIGNAL( stateChanged( int ) ), this, SLOT( toggleStandardDeviation( int ) ) );
#ifdef Q_WS_X11
connect( chkEnableBackbuffer, SIGNAL( stateChanged( int ) ), this, SLOT( toggleEnableBackbuffer( int ) ) );
#endif

connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );

Expand Down Expand Up @@ -227,6 +230,21 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
if ( index == -1 ) index = 1;
cmbScanZipInBrowser->setCurrentIndex( index );

// Set the enable backbuffer state for X11 (linux) systems only
// TODO: remove this when threading is implemented
#ifdef Q_WS_X11
chkEnableBackbuffer->setChecked( settings.value( "/Map/enableBackbuffer", 1 ).toBool() );
toggleEnableBackbuffer( chkEnableBackbuffer->checkState() );
#elif Q_WS_MAC
chkEnableBackbuffer->setChecked( true );
chkEnableBackbuffer->setEnabled( false );
labelUpdateThreshold->setEnabled( false );
spinBoxUpdateThreshold->setEnabled( false );
#else // Q_WS_WIN32
chkEnableBackbuffer->setChecked( true );
chkEnableBackbuffer->setEnabled( false );
#endif

// set the display update threshold
spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() );
//set the default projection behaviour radio buttongs
Expand Down Expand Up @@ -720,6 +738,22 @@ void QgsOptions::toggleStandardDeviation( int state )
}
}

#ifdef Q_WS_X11
void QgsOptions::toggleEnableBackbuffer( int state )
{
if ( Qt::Checked == state )
{
labelUpdateThreshold->setEnabled( false );
spinBoxUpdateThreshold->setEnabled( false );
}
else
{
labelUpdateThreshold->setEnabled( true );
spinBoxUpdateThreshold->setEnabled( true );
}
}
#endif

QString QgsOptions::theme()
{
// returns the current theme (as selected in the cmbTheme combo box)
Expand Down Expand Up @@ -891,6 +925,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/Raster/cumulativeCutLower", mRasterCumulativeCutLowerDoubleSpinBox->value() / 100.0 );
settings.setValue( "/Raster/cumulativeCutUpper", mRasterCumulativeCutUpperDoubleSpinBox->value() / 100.0 );

settings.setValue( "/Map/enableBackbuffer", chkEnableBackbuffer->isChecked() );
settings.setValue( "/Map/updateThreshold", spinBoxUpdateThreshold->value() );
//check behaviour so default projection when new layer is added with no
//projection defined...
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase

void toggleStandardDeviation( int );

#ifdef Q_WS_X11
//! Slot to change backbuffering. This is handled when the user changes
// the value of the checkbox
void toggleEnableBackbuffer( int );
#endif

/**
* Return the desired state of newly added layers. If a layer
* is to be drawn when added to the map, this function returns
Expand Down
31 changes: 20 additions & 11 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,20 +733,26 @@ void QgsVectorLayer::drawRendererV2( QgsRenderContext& rendererContext, bool lab
{
break;
}

#ifndef Q_WS_MAC //MH: disable this on Mac for now to avoid problems with resizing
if ( mUpdateThreshold > 0 && 0 == featureCount % mUpdateThreshold )
{
emit screenUpdateRequested();
// emit drawingProgress( featureCount, totalFeatures );
qApp->processEvents();
}
else if ( featureCount % 1000 == 0 )
#ifdef Q_WS_X11
if ( !mEnableBackbuffer ) // do not handle events, as we're already inside a paint event
{
// emit drawingProgress( featureCount, totalFeatures );
qApp->processEvents();
#endif // Q_WS_X11
if ( mUpdateThreshold > 0 && 0 == featureCount % mUpdateThreshold )
{
emit screenUpdateRequested();
// emit drawingProgress( featureCount, totalFeatures );
qApp->processEvents();
}
else if ( featureCount % 1000 == 0 )
{
// emit drawingProgress( featureCount, totalFeatures );
qApp->processEvents();
}
#ifdef Q_WS_X11
}
#endif //Q_WS_MAC
#endif // Q_WS_X11
#endif // Q_WS_MAC

bool sel = mSelectedFeatureIds.contains( fet.id() );
bool drawMarker = ( mEditable && ( !vertexMarkerOnlyForSelection || sel ) );
Expand Down Expand Up @@ -955,6 +961,9 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
//set update threshold before each draw to make sure the current setting is picked up
QSettings settings;
mUpdateThreshold = settings.value( "Map/updateThreshold", 0 ).toInt();
#ifdef Q_WS_X11
mEnableBackbuffer = settings.value( "/Map/enableBackbuffer", 1 ).toBool();
#endif

if ( mUsingRendererV2 )
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
int mUpdateThreshold;

/** Enables backbuffering for the map window. This improves graphics performance,
* but the possibility to cancel rendering and incremental feature drawing will be lost.
*
*/
bool mEnableBackbuffer;

/** Pointer to data provider derived from the abastract base class QgsDataProvider */
QgsVectorDataProvider *mDataProvider;

Expand Down
36 changes: 28 additions & 8 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
, mAntiAliasing( false )
{
setObjectName( name );
//disable the update that leads to the resize crash
if ( viewport() )
{
#ifndef ANDROID
viewport()->setAttribute( Qt::WA_PaintOnScreen, true );
#endif //ANDROID
}

mScene = new QGraphicsScene();
setScene( mScene );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
Expand All @@ -102,6 +94,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
mMapTool = NULL;
mLastNonZoomMapTool = NULL;

mBackbufferEnabled = true;
mDrawing = false;
mFrozen = false;
mDirty = true;
Expand Down Expand Up @@ -377,6 +370,33 @@ void QgsMapCanvas::refresh()
if ( mDrawing )
return;

QSettings settings;
#ifdef Q_WS_X11
bool enableBackbufferSetting = settings.value( "/Map/enableBackbuffer", 1 ).toBool();
#endif

#ifdef Q_WS_X11
#ifndef ANDROID
// disable the update that leads to the resize crash on X11 systems
if ( viewport() )
{
if ( enableBackbufferSetting != mBackbufferEnabled )
{
qDebug() << "Enable back buffering: " << enableBackbufferSetting;
if ( enableBackbufferSetting )
{
viewport()->setAttribute( Qt::WA_PaintOnScreen, false );
}
else
{
viewport()->setAttribute( Qt::WA_PaintOnScreen, true );
}
mBackbufferEnabled = enableBackbufferSetting;
}
}
#endif // ANDROID
#endif // Q_WS_X11

mDrawing = true;

if ( mRenderFlag && !mFrozen )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmapcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! map overview widget - it's controlled by QgsMapCanvas
QgsMapOverviewCanvas* mMapOverview;

//! If backbuffering is currently enabled
bool mBackbufferEnabled;
//! Flag indicating a map refresh is in progress
bool mDrawing;

Expand Down
60 changes: 38 additions & 22 deletions src/ui/qgsoptionsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>526</height>
<width>1107</width>
<height>843</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -33,7 +33,7 @@
<item row="2" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -953,46 +953,63 @@
<string>Rendering behavior</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<item row="1" column="0">
<widget class="QCheckBox" name="chkAddedVisibility">
<property name="text">
<string>By default new la&amp;yers added to the map should be displayed</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="4" column="0" colspan="3">
<widget class="QLabel" name="textLabel3">
<property name="text">
<string>&lt;b&gt;Note:&lt;/b&gt; Use zero to prevent display updates until all features have been rendered</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="chkUseRenderCaching">
<property name="text">
<string>Use render caching where possible to speed up redraws</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel1_6">
<item row="2" column="0">
<widget class="QCheckBox" name="chkEnableBackbuffer">
<property name="text">
<string>Number of features to draw before updating the display</string>
<string>Enable back buffer (Better graphics performance at the cost of loosing the possibility to cancel rendering and incremental feature drawing)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxUpdateThreshold">
<property name="toolTip">
<string>Map display will be updated (drawn) after this many features have been read from the data source</string>
</property>
<property name="maximum">
<number>1000000</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QLabel" name="labelUpdateThreshold">
<property name="text">
<string>Number of features to draw before updating the display</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxUpdateThreshold">
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Map display will be updated (drawn) after this many features have been read from the data source</string>
</property>
<property name="maximum">
<number>1000000</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -2693,7 +2710,6 @@
<tabstop>buttonBox</tabstop>
<tabstop>scrollArea_3</tabstop>
<tabstop>chkAddedVisibility</tabstop>
<tabstop>spinBoxUpdateThreshold</tabstop>
<tabstop>chkUseRenderCaching</tabstop>
<tabstop>chkAntiAliasing</tabstop>
<tabstop>chkUseQPixmap</tabstop>
Expand Down