[Qgis-developer] Python init script

Bernhard Ströbl bernhard.stroebl at jena.de
Thu Jul 10 01:09:10 PDT 2014


Hallo Andreas,


Am 10.07.2014 09:53, schrieb Andreas Neumann:
> Hi Bernhard,
>
> I am able to change the attribute value in the feature record, but the
> attribute dialog does not update the value. Probably because "feature"
> is not live-linked but a copy of the record?

works for me:
myFeature = myLayer.selectedFeatures()[0] # access the feature
myFeature[myLayer.fieldNameIndex("fieldxy")] = "blabla" # change value
if iface.openFeatureForm(myLayer, myFeature): # show dialog
   # change feature values for myFeature in myLayer

Bernhard

>
> The other bad thing is that there is no way to address widgets by
> objectName. They don't seem to have object names in drag-and-drop mode
> or in the standard feature form mode. So no way to use
> dialog.findChild() or dialog findChildren(). Only if you use qtdesigner
> forms you can set the objectname.
>
> I think that the widgets in the feature form should be addressable by
> objectName in the future. Will open a feature request.
>
> Andreas
>
> Am 2014-07-10 09:04, schrieb Bernhard Ströbl:
>> Hi Andreas,
>>
>> I doubt you can access the QLineEdit (though I do not know for sure).
>> Why don't you change the attribute data of the feature before opening
>> the form (keeping the "real" value in memory and redoing the change if
>> the user did not change the value in the form)?
>>
>> Bernhard
>>
>> Am 09.07.2014 16:09, schrieb Andreas Neumann:
>>> Hi,
>>>
>>> I am trying to do a python init script that executes upon opening a form
>>> (the standard-form, not a custom form).
>>>
>>> The script should take a value of a feature, round the value (without
>>> modifying the data) and display it in the form instead of the unrounded
>>> value.
>>>
>>> I can get access to the attribute data, but don't know how to access the
>>> QLineEdit to change the value in the form.
>>>
>>> Here is what I did so far:
>>>
>>> ---------------------------------------------------------------
>>>
>>> # -*- coding: utf-8 -*-
>>> # Import the PyQt and QGIS librariesfrom qgis.core import *
>>> from PyQt4.QtCore import *
>>> from PyQt4.QtGui import *
>>> from qgis.core import *
>>> from qgis.gui import *
>>>
>>> def featureFormInit(dialog,layer,feature):
>>>     area_rounded = round(feature.attribute("f_area"))
>>>     feature.setAttribute("f_area",area_rounded)
>>>
>>> ---------------------------------------------------------------
>>>
>>> The above code works fine so far and I checked by logging the rounded
>>> value. How can I now get access to the correct widget and replace the
>>> unrounded value with the rounded one?
>>>
>>> Thanks for any hint,
>>> Andreas
>>
>>
>> __________ Information from ESET Mail Security, version of virus
>> signature database 10073 (20140710) __________
>>
>> The message was checked by ESET Mail Security.
>> http://www.eset.com
>>
>>
>> _______________________________________________
>> 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

-- 
Bernhard Ströbl
Anwendungsbetreuer GIS

Kommunale Immobilien Jena
Am Anger 26
07743 Jena

Tel.: 03641 49- 5190
E-Mail: bernhard.stroebl at jena.de
Internet: www.kij.de


Kommunale Immobilien Jena
Eigenbetrieb der Stadt Jena
Werkleiter: Dr. Götz Blankenburg


__________ Information from ESET Mail Security, version of virus signature database 10073 (20140710) __________

The message was checked by ESET Mail Security.
http://www.eset.com




More information about the Qgis-developer mailing list