[Qgis-developer] Built-in attribute form validation
bernhard.stroebl at jena.de
bernhard.stroebl at jena.de
Tue Dec 20 09:15:15 EST 2011
Am 20.12.2011 13:58, schrieb Nathan Woodrow:
> Maybe it would be good to have a merge of the two ideas. Have a set of
> pre-built rules (non-python) that you can supply in the fields tab with the
> ability to also supply a Python file which has more complex rules e.g
>
> if field1 == "Hello WOrld" and field2< field3 then error
>
> etc
>
> Thoughts?
I was thinking of that, too so the majority of cases is probably covered
by the built-in functions
>
> P.S
>>> I cannot be sure that anyone loading my qml file has the python file
> available in the same path as I do
> Normally I would store the python file in the same folder as the project
> file and ship it with the project but I get what you mean.
that is not feasible because the project file stores the DB user's
username and password. So I advice my users to not exchange project
files but qmls. That is why I think it should be placed in there.
Bernhard
>
> - Nathan
>
> On Tue, Dec 20, 2011 at 10:10 PM,<bernhard.stroebl at jena.de> wrote:
>
>> Nathan,
>>
>> I do like your idea, it in fact would reduce the need for custom Uis. How
>> about saving the check as part of the project or qml file similar to the
>> edit-widget option in the layer properties. Because for my feeling that
>> would be the place where it belongs and I cannot be sure that anyone
>> loading my qml file has the python file available in the same path as I do.
>> Probably there is only a limited number of checks which cover the majority
>> of use cases e.g.
>> - NOT NULL
>> - range (for Numbers)
>> - range (for dates)
>> - max length (for strings)
>> - contains regex/string (for strings)
>> Multiple rules could be applied to any field in the fields tab of the
>> layer properties. For special cases you would still need a custom Ui,
>> though.
>>
>> just my two cents
>>
>> Bernhard
>>
>>
>>
>> Am 20.12.2011 12:41, schrieb Nathan Woodrow:
>>
>>> Hi all,
>>>
>>> I have been working on this idea over the last couple days which I think
>>> would be cool/handy to have in QGIS and I would be interested to get some
>>> feedback with what people think.
>>>
>>> The general idea is to add a form of field validation to the built-in
>>> attribute forms. The use case for this is pretty clear I think, being
>>> able
>>> to let the user/admin of any layer define validation rules to check
>>> against
>>> the data entered on the attribute form when the user presses OK providing
>>> instant feedback. I normally do this on my PostGIS tables but you don't
>>> get errors until you try and commit the data and even then it's a simple
>>> "there is a error", if you have added more then 1 item you have to check
>>> each one to work out what is wrong, and this method only applies to a
>>> PostGIS layer. The idea I have been drafting would work on any layer, as
>>> it's at the QGIS level vs at the datasource level.
>>>
>>> My idea is to use simple a simple Python file with basic functions that
>>> will be called for each field in the attribute form that is editable. I'm
>>> a big fan of convention over configuration so my idea uses conventions to
>>> define what functions are used to validate what fields. The function will
>>> return False and an error message that can be shown to the user if
>>> something is wrong.
>>>
>>> The functions use the following syntax: validate{FieldName} or
>>> validate{FieldIndex} for naming (plus some other styles) e.g
>>>
>>> def validateName():
>>> if value == "":
>>> return (False,"Name can't be NULL")
>>> return True
>>>
>>> You would place the function in a python file e.g PeopleRules.py and then
>>> tell QGIS to use this file to look for validation rules, pretty much the
>>> same as we do now for having custom Python forms.
>>>
>>> Overview of logic:
>>>
>>> 1. Define Python file with rules
>>> 2. Tell QGIS to use the rules file for the layer.
>>> 3. Open attribute form
>>> 4. Edit some values
>>> 5. Press OK
>>> 6. QGIS calls each function in the rules file to validate each field
>>>
>>> that is defined with a rule
>>> 7. If there are errors: cancel the accept() action and show the errors.
>>>
>>> If there are no errors go though like normal.
>>>
>>> My thoughts for using Python are:
>>>
>>> - Easy to read and write
>>> - Not limited to what we have in QgsExpression and easier to expand.
>>> - Can add documentation to validation rules.
>>> - Can add more complex validation rules e.g. regex, parsing, database
>>>
>>> checks etc
>>>
>>> My overall goal with this is to reduce the need to create custom Python Qt
>>> forms when doing data entry, and doing validation is one of the reasons I
>>> tend to make custom Python Qt forms but then you loose the ease of QGIS
>>> doing most of the form work for you.
>>>
>>> I have attached two files which have a example of what the idea is.
>>> fieldChecks.py is an example rules file with comments to explain each
>>> section, runMe.py has the logic for reading and executing the rules for
>>> each field. Run: python runMe.py to see the running logic and output.
>>>
>>> What love to get peoples thoughts about this, users and devs a like.
>>>
>>> - Nathan
>>>
>>>
>>> ________ Information from NOD32 ________
>>> This message was checked by NOD32 Antivirus System for Linux Mail Server.
>>> http://www.nod32.com
>>>
>>>
>>>
>>>
>>> ______________________________**_________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/**mailman/listinfo/qgis-**developer<http://lists.osgeo.org/mailman/listinfo/qgis-developer>
>>>
>>>
>>> ________ Information from NOD32 ________
>>> This message was checked by NOD32 Antivirus System for Linux Mail Server.
>>> http://www.nod32.com
>>>
>>
>>
>>
>>
>> ________ Information from NOD32 ________
>> This message was checked by NOD32 Antivirus System for Linux Mail Server.
>> http://www.nod32.com
>>
>
>
> ________ Information from NOD32 ________
> This message was checked by NOD32 Antivirus System for Linux Mail Server.
> http://www.nod32.com
>
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com
More information about the Qgis-developer
mailing list