[Qgis-developer] QgsAttributeDialog() working example

Andrew McClure andrew at southweb.co.nz
Thu Oct 16 15:51:14 PDT 2014


Alexandre

I wanted to give an update on this.

Use case 1:
	- Store a reference to the feature in the data portion of a QWidget
	- On a callback, make the layer editable and pass the stored feature to the openFeatureForm

This works and enabled the feature to be edited.  HOWEVER, the feature may already have been changed so could be in a stale state.

Use case 2:
	- On the same call back, look up the new feature using layer.getFeatures()
	- Make the layer editable and pass the "returned" feature to the openFeatureForm

This fails.  Feature form opens as non editable.

Use case 3:
	- Use the original feature.
	- Copy the attributes  from layer.getFeatures() to ensure the old feature is in sync.
	- Make the layer editable and pass the "updated" feature to the openFeatureForm

This appears to work ok. See issue raised here:

https://hub.qgis.org/issues/11395

Telemetry Layer has been updated to support the working scenario:
	
http://plugins.qgis.org/plugins/TelemetryLayer/


Andrew

	



> Hello,
> 
> even calling startEditing() programmatically, I don't seem to be able to open the Form in editable mode.
> 
> Any help with this will be appreciated
> 
> Thanks,
> 
> Alexandre Neto
> 
> On Thu, Oct 2, 2014 at 6:33 AM, Andrew McClure <andrew at southweb.co.nz> wrote:
> I found this thread very helpful.  It seems to be that to the dialog into edit mode this has to be done programmatically by calling startEditing() - not by simply having the layer in edit mode.   Can anyone else verify that?   Regardless, thanks for the pointers and suggestions in the thread. Much appreciated.
> 
> On 30/09/2014, at 8:12 pm, Alexandre Neto <senhor.neto at gmail.com> wrote:
> 
>> Hi
>> 
>> On Tue, Sep 30, 2014 at 6:42 AM, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
>> 
>> 
>> If you want to open a feature form like doing it from QGIS, just run:
>> 
>> iface.openFeatureForm(layer, feature, false, true/false) 
>> 
>> http://qgis.org/api/classQgisInterface.html#a11b90f38afd09ac5e9f363933ee4a509
>> 
>> Cheers,
>> 
>> Denis
>> 
>> 
>> Actually this how my plugin worked back in QGIS 2.2. But in the latest versions the iface.openFeatureForm() is always in add mode (like setIsAddDialog). That is, after accepting the dialog, it adds a new feature, and does not update my temporary feature. This leaves no room for any changes before the feature commit. I described my problem in the following bug report, and Matthias Kuhn adviced me to create my own Dialog, so that's what I'm trying to do. I would be glad to use iface.openFeatureForm() only
>> 
>> https://hub.qgis.org/issues/11099
>> 
>> Thanks for your help
>> 
>> Alexandre
>> 
>> 
>> 
>> 
>> 
>>  
>> 
>> 
>> On 29.09.2014 18:19, Alexandre Neto wrote:
>>> Hello Salvatore,
>>> 
>>> You were right, I just needed to import the class first, this have opened the form for me:
>>> 
>>> from qgis.gui import QgsAttributeDialog
>>> mc = iface.mapCanvas()
>>> layer = mc.currentLayer()
>>> temp_feature.setAttributes(attributes)
>>> dialog = QgsAttributeDialog(layer, temp_feature, True)
>>> dialog.show()
>>> 
>>> But now I can't make it editable.
>>> 
>>> All I can do is cancel the dialog.
>>> 
>>> Thanks for your help,
>>> 
>>> Alexandre Neto
>>> 
>>> 
>>> 
>>> On Mon, Sep 29, 2014 at 4:21 PM, Salvatore Larosa <lrssvtml at gmail.com> wrote:
>>> Hi,
>>> 
>>> On Mon, Sep 29, 2014 at 4:56 PM, Alexandre Neto <senhor.neto at gmail.com> wrote:
>>> > Hello,
>>> >
>>> > I'm trying to open an attribute dialog for a temporary feature using
>>> > QgsAttributeDialog(). but with no luck. Can anyone point me to working
>>> > example?
>>> > I'm trying something like this:
>>> >
>>> >>
>>> >> mc = iface.mapCanvas()
>>> >> layer = mc.currentLayer()
>>> >> dialog = QgsAttributeDialog(layer, temp_feature)
>>> >> dialog.show()
>>> 
>>> I think you should to import the class before and setting the feature
>>> owner bool parameter.
>>> after this changes the snippet should work fine for you!
>>> 
>>> Regards,
>>> -SL
>>> 
>>> --
>>> Salvatore Larosa
>>> linkedIn: http://linkedin.com/in/larosasalvatore
>>> twitter: @lrssvt
>>> skype: s.larosa
>>> IRC: lrssvt on freenode
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>> 
>> 
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> 

_______________________________________________
Qgis-developer mailing list
Qgis-developer at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141017/cc8f63a8/attachment.html>


More information about the Qgis-developer mailing list