Posted by & filed under QGIS.

Currently when you capture vector data in QGIS 1.3, you have some options to control the way attribute data is input. For example you can have a key value list and then the user sees a combo box with a list of possible values for that field. When an item is selected, the key part is saved into the attribute table. There are various other options which make the attribute capture process quite flexible. Fast forward a little now to the recent hackfest we had in Vienna. Juergen Fischer was working on a much more flexible approach for controlling the user interface experience when new attribute data is required. Juergen’s code is in SVN now (the source code repository for QGIS) and this evening I took his new tools for a little test drive.

Getting started

In order to be able to try this out, you need to build the QGIS SVN trunk codebase, or get the nightly build from OSGEO4W. Lets start by creating a simple point layer with two attributes: Name (text) and Age (text).

Screenshot-New Vector Layer

Capture a couple of points to your new layer using the digitising tools so that we have a little data to play with. You should be presented with the default QGIS generated attribute capture form each time you capture a new point.

Default QGIS Attributes Dialog

Creating your customised form

Ok so now we want to create our own custom form for the attribute data capture phase. To do this you need to have Qt4 Designer installed (only needed for the person who creates the forms). Under ubuntu I installed it like this:

sudo apt-get install qt4-designer

Now you can start designer (under Gnome do : Applications -> Programming -> Qt4 Designer). In the dialog that appears create a new dialog. Now drop a lineedit onto the form and set the line edit’s widget name in the property list for the widget to ‘Name’. Next drop a spinbox onto the form and call it ‘Age’. Now any other elements you might want on the form. Finish your form by clicking anywhere on the form and applying a grid layout to it. Lastly save your form remembering its name and where you saved it. I saved my as /tmp/person.ui for the purposes of this blog post but you will likely want to choose somewhere a little more permanent. Here is what my form looked like in designer when I was done:

QGIS Custom Form in Designer

Associating the form to your layer

Ready to have some fun? Jump back to QGIS and double click the layer in the legend to access its properties. Click on ‘General’ in the property list on the left and then specify the path to your ui file.

Setting the ui in Layer Properties

Now save the layer properties and go and start editing and capture a new point. When you do so you should be presented with your custom dialog instead of the generic one that QGIS usually creates. Also if you click on one of your points using the identify tool, you can now bring up the form by right clicking in the identify results window and choosing ‘View Feature Form’ from the context menu. If your layer has editing enabled that context menu will show ‘Edit Feature Form’ rather and you can then adjust the attributes post initial capture.

This is really cool functionality and will be extremely useful in situations where you want to present the form in a very specific way. As a special bonus, if you name a form button after an attribute action, it will cause that action to be launched when the form is presented to the user in QGIS.

From the one more thing dept….

Thats not quite the whole story – with a little python scripting, you can completely customise all the form logic – I will be taking a closer look at that in a future blog post.

  • nimcnaan

    Great tool, will help us greatly in our migration process from ArcView
    I’m new to the QT environment. Can you share a more detailed “step by step” example

    Using the latest version 1.4 trunkbuild 22/11/09 (v 12213) & unable to associate a dynamic form

    • http://linfiniti.com admin

      Hi

      I suggest writing to the QGIS-Devel mailing list if you are encountering specific problems since the tool is still under development.

      Regards

      Tim

  • Pingback: GIS-Lab Blog» Архив блога » Новости вокруг

  • http://gmw.consrv.ca.gov/shmp cgs_bob

    Hi Tim,

    First time posting on your blog. The last part of this article sounds interesting. Looking forward to learning how to customize these dynamic forms with python.

    Regards,
    Bob

  • TimG

    Tim, thanks for the tutorial.

    Any chance of that python follow-up for customising the form logic?

    I would like to link the QT form to predefined dropdown descriptions & values from an XML file, and a directly or indirectly relevant tutorial would be fantastic.

    Thanks.

  • carlozousa

    hello,

    the previous commenter ask, the logic of python code is missing, since it is not possible to replicate the problem. there is another problem, since if the theme is a multipoint theme, how would one navigate back and forth between the field you need to update.

    thanks,

    carlos sousa

  • Pingback: QGIS Tips – Custom feature forms with Python logic « Nathans QGIS and GIS blog