Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QgsMapCanvas not rendering raster layers in QGIS 1.7 #13480

Closed
qgib opened this issue Jan 18, 2011 · 2 comments
Closed

QgsMapCanvas not rendering raster layers in QGIS 1.7 #13480

qgib opened this issue Jan 18, 2011 · 2 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Map and Legend Related to map or legend rendering
Milestone

Comments

@qgib
Copy link
Contributor

qgib commented Jan 18, 2011

Author Name: goocreations - (goocreations -)
Original Redmine Issue: 3420

Redmine category:map_canvas
Assignee: Martin Dobias


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?


@qgib
Copy link
Contributor Author

qgib commented Jan 24, 2011

Author Name: goocreations - (goocreations -)


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


  • resolution was configured as fixed
  • status_id was changed from Open to Closed

@qgib
Copy link
Contributor Author

qgib commented Jan 24, 2011

Author Name: Tim Sutton (Tim Sutton)


Applied with 43aff11 (SVN r15076).

Regards

Tim

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Map and Legend Related to map or legend rendering labels May 24, 2019
@qgib qgib added this to the Version 1.7.0 milestone May 24, 2019
@qgib qgib closed this as completed May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Map and Legend Related to map or legend rendering
Projects
None yet
Development

No branches or pull requests

1 participant