Skip to content

Commit

Permalink
Possible workaround for ticket #83. Adds a new toggle to the option
Browse files Browse the repository at this point in the history
dialog that lets the user swap between using a QImage or a QPixmap for
rendering the map. May or may not fix things. Committed so that others
can try it out.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5567 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Jul 7, 2006
1 parent f523c27 commit dd2b966
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 65 deletions.
2 changes: 2 additions & 0 deletions src/gui/qgisapp.cpp
Expand Up @@ -1050,6 +1050,7 @@ void QgisApp::createOverview()
// moved here to set anti aliasing to both map canvas and overview
QSettings mySettings;
mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing",false).toBool());
mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render",false).toBool());
}


Expand Down Expand Up @@ -4048,6 +4049,7 @@ void QgisApp::options()
mAddedLayersVisible = optionsDialog->newVisible();
QSettings mySettings;
mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing").toBool());
mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render").toBool());
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -154,6 +154,11 @@ void QgsMapCanvas::enableAntiAliasing(bool theFlag)
mMapOverview->enableAntiAliasing(theFlag);
} // anti aliasing

void QgsMapCanvas::useQImageToRender(bool theFlag)
{
mMap->useQImageToRender(theFlag);
}

QgsMapCanvasMap* QgsMapCanvas::map()
{
return mMap;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -185,6 +185,9 @@ class QgsMapCanvas : public Q3CanvasView
//! used to determine if anti-aliasing is enabled or not
void enableAntiAliasing(bool theFlag);

//! Select which Qt class to render with
void useQImageToRender(bool theFlag);

// following 2 methods should be moved elsewhere or changed to private
// currently used by pan map tool
//! Ends pan action and redraws the canvas.
Expand Down
41 changes: 29 additions & 12 deletions src/gui/qgsmapcanvasmap.cpp
Expand Up @@ -25,6 +25,7 @@ QgsMapCanvasMap::QgsMapCanvasMap(Q3Canvas *canvas, QgsMapRender* render)
setZ(-10);
move(0,0);
resize(QSize(1,1));
mUseQImageToRender = false;
}


Expand All @@ -42,22 +43,38 @@ void QgsMapCanvasMap::resize(QSize size)

void QgsMapCanvasMap::render()
{
// use temporary image for rendering
QImage image(size(), QImage::Format_RGB32);
// Rendering to a QImage gives incorrectly filled polygons in some
// cases (as at Qt4.1.4), but it is the only renderer that supports
// anti-aliasing, so we provide the means to swap between QImage and
// QPixmap.

if (mUseQImageToRender)
{
// use temporary image for rendering
QImage image(size(), QImage::Format_RGB32);

image.fill(mBgColor.rgb());
image.fill(mBgColor.rgb());

QPainter paint;
paint.begin(&image);
QPainter paint;
paint.begin(&image);

// antialiasing
if (mAntiAliasing)
paint.setRenderHint(QPainter::Antialiasing);
// antialiasing
if (mAntiAliasing)
paint.setRenderHint(QPainter::Antialiasing);

mRender->render(&paint);
mRender->render(&paint);

paint.end();
paint.end();

// convert QImage to QPixmap to acheive faster drawing on screen
mPixmap = QPixmap::fromImage(image);
// convert QImage to QPixmap to acheive faster drawing on screen
mPixmap = QPixmap::fromImage(image);
}
else
{
mPixmap.fill(mBgColor.rgb());
QPainter paint;
paint.begin(&mPixmap);
mRender->render(&paint);
paint.end();
}
}
5 changes: 5 additions & 0 deletions src/gui/qgsmapcanvasmap.h
Expand Up @@ -39,6 +39,8 @@ class QgsMapCanvasMap : public Q3CanvasRectangle

void enableAntiAliasing(bool flag) { mAntiAliasing = flag; }

void useQImageToRender(bool flag) { mUseQImageToRender = flag; }

QPixmap& pixmap() { return mPixmap; }

//! renders map using QgsMapRender to mPixmap
Expand All @@ -61,6 +63,9 @@ class QgsMapCanvasMap : public Q3CanvasRectangle
//! indicates whether antialiasing will be used for rendering
bool mAntiAliasing;

//! Whether to use a QPixmap or a QImage for the rendering
bool mUseQImageToRender;

QgsMapRender* mRender;

QColor mBgColor;
Expand Down
25 changes: 25 additions & 0 deletions src/gui/qgsoptions.cpp
Expand Up @@ -98,6 +98,9 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
cmbTheme->setCurrentText(settings.readEntry("/Themes","default"));
//set teh state of the checkboxes
chkAntiAliasing->setChecked(settings.value("/qgis/enable_anti_aliasing",false).toBool());
// Slightly awkard here at the settings value is true to use QImage,
// but the checkbox is true to use QPixmap
chkUseQPixmap->setChecked(!(settings.value("/qgis/use_qimage_to_render", true).toBool()));
chkAddedVisibility->setChecked(settings.value("/qgis/new_layers_visible",true).toBool());
cbxHideSplash->setChecked(settings.value("/qgis/hideSplash",false).toBool());
//set the colour for selections
Expand Down Expand Up @@ -154,6 +157,7 @@ void QgsOptions::saveOptions()
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
settings.writeEntry("/qgis/new_layers_visible",chkAddedVisibility->isChecked());
settings.writeEntry("/qgis/enable_anti_aliasing",chkAntiAliasing->isChecked());
settings.writeEntry("/qgis/use_qimage_to_render", !(chkUseQPixmap->isChecked()));
settings.setValue("qgis/capitaliseLayerName", capitaliseCheckBox->isChecked());

if(cmbTheme->currentText().length() == 0)
Expand Down Expand Up @@ -250,6 +254,27 @@ void QgsOptions::on_pbnSelectProjection_clicked()
}

}

void QgsOptions::on_chkAntiAliasing_stateChanged()
{
// We can't have the anti-aliasing turned on when QPixmap is being
// used (we we can. but it then doesn't do anti-aliasing, and this
// will confuse people).
if (chkAntiAliasing->isChecked())
chkUseQPixmap->setChecked(false);

}

void QgsOptions::on_chkUseQPixmap_stateChanged()
{
// We can't have the anti-aliasing turned on when QPixmap is being
// used (we we can. but it then doesn't do anti-aliasing, and this
// will confuse people).
if (chkUseQPixmap->isChecked())
chkAntiAliasing->setChecked(false);

}

// Return state of the visibility flag for newly added layers. If

bool QgsOptions::newVisible()
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsoptions.h
Expand Up @@ -47,6 +47,8 @@ class QgsOptions :public QDialog, private Ui::QgsOptionsBase
//! Slot called when user chooses to change the project wide projection.
void on_pbnSelectProjection_clicked();
void on_btnFindBrowser_clicked();
void on_chkAntiAliasing_stateChanged();
void on_chkUseQPixmap_stateChanged();
void saveOptions();
//! Slot to change the theme this is handled when the user
// activates or highlights a theme name in the drop-down list
Expand Down
119 changes: 66 additions & 53 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -21,15 +21,18 @@
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QVBoxLayout" >
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<item row="0" column="0" >
<widget class="QTabWidget" name="tabWidget" >
<property name="currentIndex" >
<number>1</number>
</property>
<widget class="QWidget" name="tabAppearance" >
<attribute name="title" >
<string>&amp;Appearance</string>
Expand Down Expand Up @@ -227,30 +230,17 @@
<attribute name="title" >
<string>&amp;Rendering</string>
</attribute>
<layout class="QGridLayout" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="3" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" >
<widget class="QGroupBox" name="groupBox_8" >
<item>
<widget class="QGroupBox" name="groupBox_5" >
<property name="title" >
<string>Anti-aliasing</string>
<string>&amp;Update during drawing</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
Expand All @@ -259,17 +249,47 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="2" >
<widget class="QLabel" name="textLabel2_2" >
<property name="text" >
<string>features</string>
</property>
</widget>
</item>
<item row="0" 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>
<item row="0" column="0" >
<widget class="QCheckBox" name="chkAntiAliasing" >
<widget class="QLabel" name="textLabel1_6" >
<property name="text" >
<string>Make lines appear less jagged at the expense of some drawing performance</string>
<string>Update display after reading</string>
</property>
<property name="buddy" >
<cstring>spinBoxUpdateThreshold</cstring>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3" >
<widget class="QLabel" name="textLabel3" >
<property name="text" >
<string>(Set to 0 to not update the display until all features have been read)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" >
<item>
<widget class="QGroupBox" name="groupBox_4" >
<property name="title" >
<string>Initial Visibility</string>
Expand All @@ -291,10 +311,10 @@
</layout>
</widget>
</item>
<item row="0" column="0" >
<widget class="QGroupBox" name="groupBox_5" >
<item>
<widget class="QGroupBox" name="groupBox_8" >
<property name="title" >
<string>&amp;Update during drawing</string>
<string>Rendering</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
Expand All @@ -303,46 +323,39 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="2" >
<widget class="QLabel" name="textLabel2_2" >
<property name="text" >
<string>features</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QSpinBox" name="spinBoxUpdateThreshold" >
<item row="1" column="0" >
<widget class="QCheckBox" name="chkUseQPixmap" >
<property name="toolTip" >
<string>Map display will be updated (drawn) after this many features have been read from the data source</string>
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:Sans Serif; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Selecting this will unselect the 'make lines less' jagged toggle&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="maximum" >
<number>1000000</number>
</property>
<property name="value" >
<number>1000</number>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel1_6" >
<property name="text" >
<string>Update display after reading</string>
</property>
<property name="buddy" >
<cstring>spinBoxUpdateThreshold</cstring>
<string>Fix problems with incorrectly filled polygons</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3" >
<widget class="QLabel" name="textLabel3" >
<item row="0" column="0" >
<widget class="QCheckBox" name="chkAntiAliasing" >
<property name="text" >
<string>(Set to 0 to not update the display until all features have been read)</string>
<string>Make lines appear less jagged at the expense of some drawing performance</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabMap" >
Expand Down Expand Up @@ -631,7 +644,7 @@ identifying features without zooming in very close.
</widget>
</widget>
</item>
<item>
<item row="1" column="0" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
Expand Down

0 comments on commit dd2b966

Please sign in to comment.