Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#3420 closed bug (fixed)

QgsMapCanvas not rendering raster layers in QGIS 1.7

Reported by: goocreations Owned by: wonder
Priority: major: does not work as expected Milestone: Version 1.7.0
Component: MapCanvas Version: Trunk
Keywords: QgsMapCanvas, rendering, raster Cc:
Must Fix for Release: No Platform: Debian
Platform Version: Awaiting user input: no

Description

I've found a problem when using the QgsMapCanvas in new version of QGIS(1.7) which is not present in the previous version.

When using QgsMapCanvas in Python like this:

layer = QgsRasterLayer(filePath, fileInfo.completeBaseName())
mapRegistry = QgsMapLayerRegistry.instance().addMapLayer(layer, False)
layerSet = []
mapCanvasLayer = QgsMapCanvasLayer(layer, True)
layerSet.append(mapCanvasLayer)
self.canvas.setExtent(layer.extent())
self.canvas.enableAntiAliasing(True)
self.canvas.freeze(False)
self.canvas.setLayerSet(layerSet)
self.canvas.setVisible(True)
self.canvas.refresh()

The debug console says the raster was render without issues, the extent was set correctly, but the raster is not showing on the canvas (MirrorMap python plugin has the problem too).

After working through the C++ source code of QgsMapCanvas, I've noticed that most of the resizeEvent's code is now in the paintEvent. For some reason repaint is not called once the canvas resizes, hence the code (previously in the resiveEvent) is never executed. The important part of the code is:

mMap->resize( QSize( width, height ) );

which when called renders the raster correctly. I've adapted the python code of my plug-in as follows:

layer = QgsRasterLayer(filePath, fileInfo.completeBaseName())
mapRegistry = QgsMapLayerRegistry.instance().addMapLayer(layer, False)
layerSet = []
mapCanvasLayer = QgsMapCanvasLayer(layer, True)
layerSet.append(mapCanvasLayer)
self.canvas.setExtent(layer.extent())
self.canvas.enableAntiAliasing(True)
self.canvas.freeze(False)
self.canvas.setLayerSet(layerSet)
width = self.canvas.size().width() #NEW CODE
height = self.canvas.size().height() #NEW CODE
self.canvas.map().resize( QSize( width, height ) ) #NEW CODE
self.canvas.setVisible(True)
self.canvas.refresh()

Every time I add a raster layer to the canvas, I have to manually resize the map of the canvas. I'm not sure if this is a bug, or if it has to be this way. Is there any other or better way doing this?

Attachments (1)

mapcanvaspatch.diff (453 bytes ) - added by goocreations 13 years ago.
the possible solution

Download all attachments as: .zip

Change History (4)

comment:1 by timlinux, 13 years ago

Owner: changed from nobody to wonder

comment:2 by goocreations, 13 years ago

Resolution: fixed
Status: newclosed

Hey here is a solution to this problem (hopefully). Just added the paintEvent to the Python bindings. I've attached a patch.

by goocreations, 13 years ago

Attachment: mapcanvaspatch.diff added

the possible solution

comment:3 by timlinux, 13 years ago

Applied with r15075.

Regards

Tim

Note: See TracTickets for help on using tickets.