Skip to content

Commit 6abc64b

Browse files
author
g_j_m
committedJul 7, 2006
Possible workaround for ticket #83. Adds a new toggle to the option
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@5567 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4dd9a2b commit 6abc64b

File tree

8 files changed

+137
-65
lines changed

8 files changed

+137
-65
lines changed
 

‎src/gui/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ void QgisApp::createOverview()
10501050
// moved here to set anti aliasing to both map canvas and overview
10511051
QSettings mySettings;
10521052
mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing",false).toBool());
1053+
mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render",false).toBool());
10531054
}
10541055

10551056

@@ -4048,6 +4049,7 @@ void QgisApp::options()
40484049
mAddedLayersVisible = optionsDialog->newVisible();
40494050
QSettings mySettings;
40504051
mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing").toBool());
4052+
mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render").toBool());
40514053
}
40524054
}
40534055

‎src/gui/qgsmapcanvas.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ void QgsMapCanvas::enableAntiAliasing(bool theFlag)
154154
mMapOverview->enableAntiAliasing(theFlag);
155155
} // anti aliasing
156156

157+
void QgsMapCanvas::useQImageToRender(bool theFlag)
158+
{
159+
mMap->useQImageToRender(theFlag);
160+
}
161+
157162
QgsMapCanvasMap* QgsMapCanvas::map()
158163
{
159164
return mMap;

‎src/gui/qgsmapcanvas.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ class QgsMapCanvas : public Q3CanvasView
185185
//! used to determine if anti-aliasing is enabled or not
186186
void enableAntiAliasing(bool theFlag);
187187

188+
//! Select which Qt class to render with
189+
void useQImageToRender(bool theFlag);
190+
188191
// following 2 methods should be moved elsewhere or changed to private
189192
// currently used by pan map tool
190193
//! Ends pan action and redraws the canvas.

‎src/gui/qgsmapcanvasmap.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ QgsMapCanvasMap::QgsMapCanvasMap(Q3Canvas *canvas, QgsMapRender* render)
2525
setZ(-10);
2626
move(0,0);
2727
resize(QSize(1,1));
28+
mUseQImageToRender = false;
2829
}
2930

3031

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

4344
void QgsMapCanvasMap::render()
4445
{
45-
// use temporary image for rendering
46-
QImage image(size(), QImage::Format_RGB32);
46+
// Rendering to a QImage gives incorrectly filled polygons in some
47+
// cases (as at Qt4.1.4), but it is the only renderer that supports
48+
// anti-aliasing, so we provide the means to swap between QImage and
49+
// QPixmap.
50+
51+
if (mUseQImageToRender)
52+
{
53+
// use temporary image for rendering
54+
QImage image(size(), QImage::Format_RGB32);
4755

48-
image.fill(mBgColor.rgb());
56+
image.fill(mBgColor.rgb());
4957

50-
QPainter paint;
51-
paint.begin(&image);
58+
QPainter paint;
59+
paint.begin(&image);
5260

53-
// antialiasing
54-
if (mAntiAliasing)
55-
paint.setRenderHint(QPainter::Antialiasing);
61+
// antialiasing
62+
if (mAntiAliasing)
63+
paint.setRenderHint(QPainter::Antialiasing);
5664

57-
mRender->render(&paint);
65+
mRender->render(&paint);
5866

59-
paint.end();
67+
paint.end();
6068

61-
// convert QImage to QPixmap to acheive faster drawing on screen
62-
mPixmap = QPixmap::fromImage(image);
69+
// convert QImage to QPixmap to acheive faster drawing on screen
70+
mPixmap = QPixmap::fromImage(image);
71+
}
72+
else
73+
{
74+
mPixmap.fill(mBgColor.rgb());
75+
QPainter paint;
76+
paint.begin(&mPixmap);
77+
mRender->render(&paint);
78+
paint.end();
79+
}
6380
}

‎src/gui/qgsmapcanvasmap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class QgsMapCanvasMap : public Q3CanvasRectangle
3939

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

42+
void useQImageToRender(bool flag) { mUseQImageToRender = flag; }
43+
4244
QPixmap& pixmap() { return mPixmap; }
4345

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

66+
//! Whether to use a QPixmap or a QImage for the rendering
67+
bool mUseQImageToRender;
68+
6469
QgsMapRender* mRender;
6570

6671
QColor mBgColor;

‎src/gui/qgsoptions.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
9898
cmbTheme->setCurrentText(settings.readEntry("/Themes","default"));
9999
//set teh state of the checkboxes
100100
chkAntiAliasing->setChecked(settings.value("/qgis/enable_anti_aliasing",false).toBool());
101+
// Slightly awkard here at the settings value is true to use QImage,
102+
// but the checkbox is true to use QPixmap
103+
chkUseQPixmap->setChecked(!(settings.value("/qgis/use_qimage_to_render", true).toBool()));
101104
chkAddedVisibility->setChecked(settings.value("/qgis/new_layers_visible",true).toBool());
102105
cbxHideSplash->setChecked(settings.value("/qgis/hideSplash",false).toBool());
103106
//set the colour for selections
@@ -154,6 +157,7 @@ void QgsOptions::saveOptions()
154157
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
155158
settings.writeEntry("/qgis/new_layers_visible",chkAddedVisibility->isChecked());
156159
settings.writeEntry("/qgis/enable_anti_aliasing",chkAntiAliasing->isChecked());
160+
settings.writeEntry("/qgis/use_qimage_to_render", !(chkUseQPixmap->isChecked()));
157161
settings.setValue("qgis/capitaliseLayerName", capitaliseCheckBox->isChecked());
158162

159163
if(cmbTheme->currentText().length() == 0)
@@ -250,6 +254,27 @@ void QgsOptions::on_pbnSelectProjection_clicked()
250254
}
251255

252256
}
257+
258+
void QgsOptions::on_chkAntiAliasing_stateChanged()
259+
{
260+
// We can't have the anti-aliasing turned on when QPixmap is being
261+
// used (we we can. but it then doesn't do anti-aliasing, and this
262+
// will confuse people).
263+
if (chkAntiAliasing->isChecked())
264+
chkUseQPixmap->setChecked(false);
265+
266+
}
267+
268+
void QgsOptions::on_chkUseQPixmap_stateChanged()
269+
{
270+
// We can't have the anti-aliasing turned on when QPixmap is being
271+
// used (we we can. but it then doesn't do anti-aliasing, and this
272+
// will confuse people).
273+
if (chkUseQPixmap->isChecked())
274+
chkAntiAliasing->setChecked(false);
275+
276+
}
277+
253278
// Return state of the visibility flag for newly added layers. If
254279

255280
bool QgsOptions::newVisible()

‎src/gui/qgsoptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class QgsOptions :public QDialog, private Ui::QgsOptionsBase
4747
//! Slot called when user chooses to change the project wide projection.
4848
void on_pbnSelectProjection_clicked();
4949
void on_btnFindBrowser_clicked();
50+
void on_chkAntiAliasing_stateChanged();
51+
void on_chkUseQPixmap_stateChanged();
5052
void saveOptions();
5153
//! Slot to change the theme this is handled when the user
5254
// activates or highlights a theme name in the drop-down list

‎src/ui/qgsoptionsbase.ui

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
<property name="sizeGripEnabled" >
2222
<bool>true</bool>
2323
</property>
24-
<layout class="QVBoxLayout" >
24+
<layout class="QGridLayout" >
2525
<property name="margin" >
2626
<number>9</number>
2727
</property>
2828
<property name="spacing" >
2929
<number>6</number>
3030
</property>
31-
<item>
31+
<item row="0" column="0" >
3232
<widget class="QTabWidget" name="tabWidget" >
33+
<property name="currentIndex" >
34+
<number>1</number>
35+
</property>
3336
<widget class="QWidget" name="tabAppearance" >
3437
<attribute name="title" >
3538
<string>&amp;Appearance</string>
@@ -227,30 +230,17 @@
227230
<attribute name="title" >
228231
<string>&amp;Rendering</string>
229232
</attribute>
230-
<layout class="QGridLayout" >
233+
<layout class="QVBoxLayout" >
231234
<property name="margin" >
232235
<number>9</number>
233236
</property>
234237
<property name="spacing" >
235238
<number>6</number>
236239
</property>
237-
<item row="3" column="0" >
238-
<spacer>
239-
<property name="orientation" >
240-
<enum>Qt::Vertical</enum>
241-
</property>
242-
<property name="sizeHint" >
243-
<size>
244-
<width>20</width>
245-
<height>40</height>
246-
</size>
247-
</property>
248-
</spacer>
249-
</item>
250-
<item row="2" column="0" >
251-
<widget class="QGroupBox" name="groupBox_8" >
240+
<item>
241+
<widget class="QGroupBox" name="groupBox_5" >
252242
<property name="title" >
253-
<string>Anti-aliasing</string>
243+
<string>&amp;Update during drawing</string>
254244
</property>
255245
<layout class="QGridLayout" >
256246
<property name="margin" >
@@ -259,17 +249,47 @@
259249
<property name="spacing" >
260250
<number>6</number>
261251
</property>
252+
<item row="0" column="2" >
253+
<widget class="QLabel" name="textLabel2_2" >
254+
<property name="text" >
255+
<string>features</string>
256+
</property>
257+
</widget>
258+
</item>
259+
<item row="0" column="1" >
260+
<widget class="QSpinBox" name="spinBoxUpdateThreshold" >
261+
<property name="toolTip" >
262+
<string>Map display will be updated (drawn) after this many features have been read from the data source</string>
263+
</property>
264+
<property name="maximum" >
265+
<number>1000000</number>
266+
</property>
267+
<property name="value" >
268+
<number>1000</number>
269+
</property>
270+
</widget>
271+
</item>
262272
<item row="0" column="0" >
263-
<widget class="QCheckBox" name="chkAntiAliasing" >
273+
<widget class="QLabel" name="textLabel1_6" >
264274
<property name="text" >
265-
<string>Make lines appear less jagged at the expense of some drawing performance</string>
275+
<string>Update display after reading</string>
276+
</property>
277+
<property name="buddy" >
278+
<cstring>spinBoxUpdateThreshold</cstring>
279+
</property>
280+
</widget>
281+
</item>
282+
<item row="1" column="0" colspan="3" >
283+
<widget class="QLabel" name="textLabel3" >
284+
<property name="text" >
285+
<string>(Set to 0 to not update the display until all features have been read)</string>
266286
</property>
267287
</widget>
268288
</item>
269289
</layout>
270290
</widget>
271291
</item>
272-
<item row="1" column="0" >
292+
<item>
273293
<widget class="QGroupBox" name="groupBox_4" >
274294
<property name="title" >
275295
<string>Initial Visibility</string>
@@ -291,10 +311,10 @@
291311
</layout>
292312
</widget>
293313
</item>
294-
<item row="0" column="0" >
295-
<widget class="QGroupBox" name="groupBox_5" >
314+
<item>
315+
<widget class="QGroupBox" name="groupBox_8" >
296316
<property name="title" >
297-
<string>&amp;Update during drawing</string>
317+
<string>Rendering</string>
298318
</property>
299319
<layout class="QGridLayout" >
300320
<property name="margin" >
@@ -303,46 +323,39 @@
303323
<property name="spacing" >
304324
<number>6</number>
305325
</property>
306-
<item row="0" column="2" >
307-
<widget class="QLabel" name="textLabel2_2" >
308-
<property name="text" >
309-
<string>features</string>
310-
</property>
311-
</widget>
312-
</item>
313-
<item row="0" column="1" >
314-
<widget class="QSpinBox" name="spinBoxUpdateThreshold" >
326+
<item row="1" column="0" >
327+
<widget class="QCheckBox" name="chkUseQPixmap" >
315328
<property name="toolTip" >
316-
<string>Map display will be updated (drawn) after this many features have been read from the data source</string>
329+
<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>
317330
</property>
318-
<property name="maximum" >
319-
<number>1000000</number>
320-
</property>
321-
<property name="value" >
322-
<number>1000</number>
323-
</property>
324-
</widget>
325-
</item>
326-
<item row="0" column="0" >
327-
<widget class="QLabel" name="textLabel1_6" >
328331
<property name="text" >
329-
<string>Update display after reading</string>
330-
</property>
331-
<property name="buddy" >
332-
<cstring>spinBoxUpdateThreshold</cstring>
332+
<string>Fix problems with incorrectly filled polygons</string>
333333
</property>
334334
</widget>
335335
</item>
336-
<item row="1" column="0" colspan="3" >
337-
<widget class="QLabel" name="textLabel3" >
336+
<item row="0" column="0" >
337+
<widget class="QCheckBox" name="chkAntiAliasing" >
338338
<property name="text" >
339-
<string>(Set to 0 to not update the display until all features have been read)</string>
339+
<string>Make lines appear less jagged at the expense of some drawing performance</string>
340340
</property>
341341
</widget>
342342
</item>
343343
</layout>
344344
</widget>
345345
</item>
346+
<item>
347+
<spacer>
348+
<property name="orientation" >
349+
<enum>Qt::Vertical</enum>
350+
</property>
351+
<property name="sizeHint" >
352+
<size>
353+
<width>20</width>
354+
<height>40</height>
355+
</size>
356+
</property>
357+
</spacer>
358+
</item>
346359
</layout>
347360
</widget>
348361
<widget class="QWidget" name="tabMap" >
@@ -631,7 +644,7 @@ identifying features without zooming in very close.
631644
</widget>
632645
</widget>
633646
</item>
634-
<item>
647+
<item row="1" column="0" >
635648
<layout class="QHBoxLayout" >
636649
<property name="margin" >
637650
<number>0</number>

0 commit comments

Comments
 (0)
Please sign in to comment.