Bug report #7283

Updated by Giovanni Manghi over 5 years ago

I have a plugin for exporting maps as PNG images. I believe this code was working correctly within 1.6 (but I cannot guarantee I haven't made another change that would have broken it there, too).



Basically, I load a set of base map features and then loop through a set of point layers that get applied and the whole thing is exported as an image. I'm not getting the full canvas at all, but only a single attribute loaded from the base map and nothing from the point layers. (bad result, expected result)



In the process of debugging this, I discovered a curious fact. If I include a QMessageBox.information right before I do the export, it works correctly!



Doesn't work:



self.mapCanvas.resize(QSize(394,350))

self.mapCanvas.zoomToFullExtent()

currentImagePath = theExportPath + folder

currentImageName = attribute.replace(' ', '_') + ".png"

self.mapCanvas.saveAsImage(currentImagePath + "/" + currentImageName)

Does work:



self.mapCanvas.resize(QSize(394,350))

self.mapCanvas.zoomToFullExtent()

QMessageBox.information(self.iface.mainWindow(),"Debug","Break")

currentImagePath = theExportPath + folder

currentImageName = attribute.replace(' ', '_') + ".png"

self.mapCanvas.saveAsImage(currentImagePath + "/" + currentImageName)



I tried to add a simple self.iface.mainWindow() in place of the message box but that didn't do the trick. I'm thinking there is some kind of refresh I could do, too, but I tried mapCanvas.refresh() and mapCanvas.updateMap() and these in combination with mainWindow() but could get nothing to work.



Did this change in 1.8? Any suggestions to make it work? Including the QMessageBox call will get me going but I have to press "OK" for each map to be exported. With all the export combinations, I'd be doing this more than 1000 times!



Thanks!



B



Reported as question at: http://gis.stackexchange.com/questions/52563/mapcanvas-saveasimage-not-functioning-as-expected-in-qgis-1-8

Back