[QGIS-trac] [Quantum GIS] #3420: QgsMapCanvas not rendering raster layers in QGIS 1.7

Quantum GIS qgis at qgis.org
Tue Jan 18 04:45:42 EST 2011


#3420: QgsMapCanvas not rendering raster layers in QGIS 1.7
------------------------------------------------+---------------------------
   Reporter:  goocreations                      |              Owner:  nobody       
       Type:  bug                               |             Status:  new          
   Priority:  major: does not work as expected  |          Milestone:  Version 1.7.0
  Component:  MapCanvas                         |            Version:  Trunk        
   Keywords:  QgsMapCanvas, rendering, raster   |   Platform_version:               
   Platform:  Debian                            |           Must_fix:  No           
Status_info:  0                                 |  
------------------------------------------------+---------------------------
 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?

-- 
Ticket URL: <https://trac.osgeo.org/qgis/ticket/3420>
Quantum GIS <http://qgis.org>
Quantum GIS is an Open Source GIS viewer/editor supporting OGR, PostGIS, and GRASS formats


More information about the QGIS-trac mailing list