You're right Carson. I used it only with a WFS layer, and in fact I see that WFS is the only providers that implements it.<div>There would be the setDataProvider method on the vector layer but it's private...</div>
<div><br></div><div>You've raised an important point, that I took for granted :(</div><div>I fear that in this moment the only solution is remove it and reload it.
</div><div>giovanni<br><div><br><br><div class="gmail_quote">2012/5/17 Carson Farmer <span dir="ltr"><<a href="mailto:carson.farmer@gmail.com" target="_blank">carson.farmer@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Giovanni,<br>
<br>
Thanks for the tip. To answer your question: I am trying to<br>
synchronise the layer with the datasource. Having said that, I don't<br>
seem to be able to get 'reload' to work. It looks like reload is<br>
reimplemented in QgsVectorLayer, which in turns calls the<br>
dataProvider's reloadData method, so this may vary by provider type? I<br>
tried it with a shapefile and a spatialite layer, and it did not seem<br>
to do anything: I deleted several fields from the shapefile and added<br>
a field to the spatialite layer in an external program, and these<br>
changes were not reflected when I 'reloaded' the layers. Am I missing<br>
something here? Perhaps there is something else needed to get the<br>
changes to 'show up'?<br>
<br>
Cheers,<br>
<br>
Carson<br>
<br>
On Wed, May 16, 2012 at 4:36 PM, G. Allegri <<a href="mailto:giohappy@gmail.com">giohappy@gmail.com</a>> wrote:<br>
> Do you mean refresh the rendering or synchronizing the layer with the data<br>
> source?<br>
> I usually use QgsMapLayer::reload() for the latter, and<br>
> QgsMapCanvas::refresh() for the first.<br>
><br>
> giovanni<br>
><br>
> 2012/5/16 Carson Farmer <<a href="mailto:carson.farmer@gmail.com">carson.farmer@gmail.com</a>><br>
>><br>
>> Hi list, does anyone know of a clever way to (programmatically) reload<br>
>> a layer without actually removing it and re-adding it to the layer<br>
>> list. Some context: I have a layer that sometimes gets updated by an<br>
>> external application, and I want to be able to 'refresh' the layer<br>
>> from the Python console to reflect these changes (new features,<br>
>> deleted features, new attributes, etc.). I *could* simply load the<br>
>> layer again, but I'm hoping there is a more efficient way to do this<br>
>> (also I want to keep the current styling, layer order, unique layer<br>
>> id, etc).<br>
>><br>
>> Any thoughts/ideas? Note: assume we are working with a spatialite layer<br>
>> for now.<br>
>><br>
>> Carson<br>
>><br>
>> --<br>
>> Dr. Carson J. Q. Farmer<br>
>> Centre for GeoInformatics (CGI)<br>
>> School of Geography and Geosciences<br>
>> Irvine Building, University of St Andrews<br>
>> St Andrews, Fife, KY16 9AL<br>
>> Scotland, UK<br>
>> _______________________________________________<br>
>> Qgis-developer mailing list<br>
>> <a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
>> <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Dr. Carson J. Q. Farmer<br>
Centre for GeoInformatics (CGI)<br>
School of Geography and Geosciences<br>
Irvine Building, University of St Andrews<br>
St Andrews, Fife, KY16 9AL<br>
Scotland, UK<br>
</font></span></blockquote></div><br></div></div>