-
Notifications
You must be signed in to change notification settings - Fork 2
Usage
DataDrivenInputMask adds a menu into QGIS' Vector menu with four submenus:
- Initialize Layer creates the masks for the active layer and adds a layer action showDdForm
- Show Input Form opens the input mask for the selected feature(s) in the active layer; the layer is initialized if needed
- Multi Input Form allows to edit attributes of all selected features in one go.
- Show Search Form opens the search mask for the active layer; the layer is initialized if needed
- Configure Mask lets you edit some dedicated tables stored in public that hold information on the look of the mask (see next section).
Configuration includes:
- choosing your own labels instead of the field name
- creating tabs and assigning fields to them
- arranging the order of fields in the tab (without configuration the fields are ordered according to their creation time)
- skipping (hiding) fields: field is not shown in the mask (e.g. primary keys that get a default value anyways)
- setting a field's min/max values
- (new in version 0.9.0) disable fields: field is shown in the mask but its contents cannot be edited (e.g. primary keys that get a default value anyways)
How to do it: Activate a layer, click Configure mask and add your desired tabs and field specs. If you add only one tab and leave tab_alias empty the default tab will be created. Caution: if you add only some of the fields of the table they will be shown on top because their field_order is specified, whereas the field_order of the rest is not.
See Configuration of masks for details.
Each initialized layer gets a layer action showDdForm (or its local translation if available). If this action is active and any feature in the layer is clicked on, the input mask for this feature is opened. If the layer can be edited it is immediately put into editing mode thus any changes to the feature are directly saved to the layer (no undo).
Any layer where the user has INSERT, UPDATE and DELETE rights is immediately put into editing mode upon opening the mask, the OK button is visible and active. If the user does not have INSERT, UPDATE and DELETE rights the layer is not put into editing mode and the OK button is invisible. This behaviour is identical to the behaviour of QGIS' standard mask (except for putting the layer into editing mode, of course :).
Clicking the OK button in the DataDrivenInputMask commits any changes to the layer (no undo!). If the mask is opened for a layer that already has pending changes, the user is asked to save or discard the changes or abort the opening of the mask (similar to QGIS' default behaviour when toggling the editing status). Thus no previous changes (which might have an undo) are committed. This behaviour can be overridden by passing askForSave = False to DdManager's showFeatureForm when writing your own plugin.
Changes in simple n-to-m relations (DdN2mListWidget, DdN2mTreeWidget) are saved upon clicking on OK, whereas changes in DdN2mTableWidgets are saved immediately.
If a layer is initialized that has been loaded with an authCfgId any additional layer is loaded with auhtCfgId by DataDrivenInputMask, too.
A form identical with the input mask to search for features in the layer. When opening the search mask the last successful search is reloaded automatically. However after restarting QGIS the search form is reset. Therefore the search dialog offers to save the current search into an XML file and reload it at any time.
DdManager has four api methods for this purpose:
-
getInputWidget(), -
addInputWidget(), -
removeInputWidget()and -
replaceInputWidget(),
the latter being the most interesting. It allows running initLayer() and then with getInputWidget() access a widget and its DdAttribute, manipulate the attribute, creat a new widget from it and then replace the original with the newly created (pseudo code):
ddmanager.initLayer(myLayer)
myWidget = ddmananger.getInputWidget(myLayer, "myIntegerField")
myDdAttribute = myWidget.attribute
myDdAttribute.enableWidget = False
myNewWidget = ddui.DdLineEditInt(myDdAttribute)
ddmanager.replaceInputWidget(myLayer, "myIntegerField", myNewWidget)
This disables the widget, which is - of course - easier to achieve by Configuration-of-masks. However this starts getting interesting if - for one reason or another - you want to present only a subset of values to your user in a combo box or a list or tree widget.