Discussion:
QgsAttributeDialog() working example
Alexandre Neto
2014-09-29 14:56:33 UTC
Permalink
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?
mc = iface.mapCanvas()
layer = mc.currentLayer()
dialog = QgsAttributeDialog(layer, temp_feature)
dialog.show()
that gives me the following error on the 3rd line:

NameError: name 'QgsAttributeDialog' is not defined


Thanks,

Alexandre
Salvatore Larosa
2014-09-29 15:21:38 UTC
Permalink
Hi,
Post by Alexandre Neto
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?
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
Alexandre Neto
2014-09-29 16:19:58 UTC
Permalink
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
Hi,
Post by Alexandre Neto
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?
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
skype: s.larosa
IRC: lrssvt on freenode
Salvatore Larosa
2014-09-29 19:38:28 UTC
Permalink
Hi,
Post by Alexandre Neto
Hello Salvatore,
You were right, I just needed to import the class first, this have opened
Post by Alexandre Neto
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.
is your layer editable? you need to call startEditing() method in
order to get the form in edit mode.

Best Regards,
-SL
--
Salvatore Larosa
linkedIn: http://linkedin.com/in/larosasalvatore
twitter: @lrssvt
skype: s.larosa
IRC: lrssvt on freenode
Denis Rouzaud
2014-09-30 05:42:06 UTC
Permalink
Hi Alexandre,

What you did is just the building of the form, you don't have all the
stuff around to make editable/uneditable and update the layer.

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
Post by Alexandre Neto
Hello Salvatore,
You were right, I just needed to import the class first, this have
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
Hi,
On Mon, Sep 29, 2014 at 4:56 PM, Alexandre Neto
Post by Alexandre Neto
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
Post by Alexandre Neto
example?
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
skype: s.larosa
IRC: lrssvt on freenode
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Alexandre Neto
2014-09-30 07:12:27 UTC
Permalink
Hi
Post by Denis Rouzaud
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
<http://qgis.org/api/classQgsAttributeDialog.html#a2fbbff1c23be058caa26cc5aaf7040e8>).
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
Post by Denis Rouzaud
Hello Salvatore,
You were right, I just needed to import the class first, this have
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
Hi,
Post by Alexandre Neto
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?
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
skype: s.larosa
IRC: lrssvt on freenode
_______________________________________________
Andrew McClure
2014-10-02 05:33:40 UTC
Permalink
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.
Post by Denis Rouzaud
Hi
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
Post by Alexandre Neto
Hello Salvatore,
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
Hi,
Post by Alexandre Neto
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?
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
skype: s.larosa
IRC: lrssvt on freenode
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Alexandre Neto
2014-10-02 16:26:58 UTC
Permalink
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
Post by Andrew McClure
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.
Hi
Post by Denis Rouzaud
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
<http://qgis.org/api/classQgsAttributeDialog.html#a2fbbff1c23be058caa26cc5aaf7040e8>).
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
Post by Denis Rouzaud
Hello Salvatore,
You were right, I just needed to import the class first, this have
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
Hi,
Post by Alexandre Neto
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?
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
skype: s.larosa
IRC: lrssvt on freenode
_______________________________________________
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Andrew McClure
2014-10-02 18:01:00 UTC
Permalink
I found that I had to invoke the feature form myself to get the form into edit mode.

layer.startEditing()
self.iface.openFeatureForm(layer, feature, True)

It was not enough to invoke startEditing from within the feature form init method.

Am not sure if this is by design.
Post by Alexandre Neto
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
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.
Post by Denis Rouzaud
Hi
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
Post by Alexandre Neto
Hello Salvatore,
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
Hi,
Post by Alexandre Neto
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?
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
skype: s.larosa
IRC: lrssvt on freenode
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Andrew McClure
2014-10-03 05:41:54 UTC
Permalink
Here's a crude PHP script to login and upload your <plugin>.zip file when it's been updated.

Requires libcurl

https://github.com/nzfarmer1/qgisplugintools/blob/master/upload.php


p.s. have just made a new release of TelemetryLayer - starting to get down to a short list issues that could use a more experienced plugin developer if anyone's keen ... ? :)


Andrew
Paolo Cavallini
2014-10-03 08:16:27 UTC
Permalink
Post by Andrew McClure
Here's a crude PHP script to login and upload your <plugin>.zip
file when it's been updated.
Requires libcurl
https://github.com/nzfarmer1/qgisplugintools/blob/master/upload.php
There
is already a make option for this: perhaps it is not easy enough
to find?

All the best.
- --
Paolo Cavallini - www.faunalia.eu
QGIS & PostGIS courses: http://www.faunalia.eu/training.html
Alessandro Pasotti
2014-10-03 09:52:57 UTC
Permalink
The python uploader code is here:

https://github.com/qgis/QGIS-Django/blob/master/qgis-app/plugins/utils/plugin_upload.py
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Andrew McClure
Here's a crude PHP script to login and upload your <plugin>.zip
file when it's been updated.
Requires libcurl
https://github.com/nzfarmer1/qgisplugintools/blob/master/upload.php
There
is already a make option for this: perhaps it is not easy enough
to find?
All the best.
- --
Paolo Cavallini - www.faunalia.eu
QGIS & PostGIS courses: http://www.faunalia.eu/training.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iEYEARECAAYFAlQuW1oACgkQ/NedwLUzIr53nQCfYRHjkY9qVqXiNIOYDrp7YC4s
eKoAnA47lYsGhdIwDkEnNi0tEJQcvgsr
=NLLD
-----END PGP SIGNATURE-----
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
Alessandro Pasotti
w3: www.itopen.it
Andrew McClure
2014-10-03 11:44:11 UTC
Permalink
Alexandre

Feel free to see a working example in the latest release of TelemetryLayer

https://github.com/nzfarmer1/telemetrylayer/blob/master/tlbrokerconfig.py (Line : 143)

If you install the plugin you can see it working by double clicking a group in the legend.

There's also an example showing how to wrap the dialog init within a class with state and to reflect dynamic changes made to the features while the dialog is open

https://github.com/nzfarmer1/telemetrylayer/blob/master/featureforms/editformfactory.py
https://github.com/nzfarmer1/telemetrylayer/blob/master/tltopicmanager.py

(Code's a bit rough as this is a work in progress)
Post by Alexandre Neto
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
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.
Post by Denis Rouzaud
Hi
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
Post by Alexandre Neto
Hello Salvatore,
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
Hi,
Post by Alexandre Neto
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?
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
skype: s.larosa
IRC: lrssvt on freenode
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Andrew McClure
2014-10-16 22:51:14 UTC
Permalink
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
Post by Alexandre Neto
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
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.
Post by Denis Rouzaud
Hi
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
Post by Alexandre Neto
Hello Salvatore,
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
Hi,
Post by Alexandre Neto
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?
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
skype: s.larosa
IRC: lrssvt on freenode
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Loading...