Full Documentation¶
Modules¶
datadriveninputmask¶
-
class
datadriveninputmask.
DataDrivenInputMask
(iface)[source]¶ Main class for the QGIS plugin
-
configureMask
()[source]¶ SLOT: configure the mask for the active layer using the config tables in the db
-
getConfigFeature
(configLayer, ddTable)[source]¶ returns the QgsFeature for this ddTable in configLayer (public.dd_table)
-
ddmanager¶
Class that steers the DataDrivenUI
-
class
ddmanager.
DdManager
(iface)[source]¶ DdManager manages all masks in the current project
-
addAction
(layer, actionName=u'showDdForm', ddManagerName='ddManager')[source]¶ api method to add an action to the layer with a self defined name
-
addInputWidget
(layer, inputWidget, ddFormWidgetIndex=None, beforeWidget=None, toUi=True, toSearchUi=True)[source]¶ api method to add a DdWidget into the ui of a layer
-
addInputWidgetAfter
(layer, inputWidget, afterAttributeName, toUi=True, toSearchUi=True)[source]¶ api method to add a DdWidget into the ui of a layer after the widget of attribute with afterAttributeName. Will be placed in the same form
-
addInputWidgetBefore
(layer, inputWidget, beforeAttributeName, toUi=True, toSearchUi=True)[source]¶ api method to add a DdWidget into the ui of a layer before the widget of attribute with beforeAttributeName. Will be placed in the same form
-
createDdTable
(db, schemaName, tableName, withOid=True, withComment=True)[source]¶ create a DdTable object from the passed in variables
-
enableInputWidget
(layer, attributeName, doEnable)[source]¶ api method to enable a DdWidget, i.e. set its Ddattribute to enableWidget
-
getInputWidget
(layer, attributeName)[source]¶ api method returning the DdWidget for a certain attribute
-
initLayer
(layer, skip=[], labels={}, fieldOrder=[], fieldGroups={}, minMax={}, noSearchFields=[], showParents=True, createAction=True, db=None, inputMask=True, searchMask=True, inputUi=None, searchUi=None, helpText='', fieldDisable=[])[source]¶ api method initLayer: initialize this layer with a data-driven input mask. In case there is configuration for this layer in the database read this configuration and apply what is provided there. Returns a Boolean stating the success of the initialization Parameters: WARNING: if config tables are used, the parameters’ objects survive and are thus applied to the next layer, too. Be sure to also pass ALL optional paramerters when calling initLayer()
- layer [QgsVectorLayer]
- skip [array [string]]: field names to not show
- labels [dict] with entries: “fieldname”: “label”
- fieldOrder [array[string]]: containing the field names in the order they should be shown
- fieldGroups [dict] with entries: fieldName: [tabTitle, tabTooltip] for each group a tab is created and the fields from fieldName onwards (refers to fieldOrder) are grouped in this tab; tabTooltip is optional
- minMax [dict] with entries: “fieldname”: [min, max] - strings; use for numerical or date fields only!
- noSearchFields [array[string]] with fields not to be shown in the search form, if empty all fields are shown. Skipped fields are never shown in the search form, no matter if they are included here
- showParents [Boolean] show tabs for 1-to-1 relations (parents)
- createAction [Boolean]: add an action to the layer’s list of actions
- db [QtSql.QSqlDatabase]
- inputMask [Boolean]: create a data-edit mask
- searchMask [Boolean]: create a data-search mask
- inputUi [ddui.DdDialogWidget]: apply this inputUi
- searchUi [ddui.DdDialogWidget]: apply this as search ui
- helpText [string] help text for this mask, may be html formatted
- fieldDisable [array[string]]: field names whose DdInputWidget shall be disabled in the inputMask
-
loadPostGISLayer
(db, ddTable, displayName=None, geomColumn=None, whereClause=None, keyColumn=None, intoDdGroup=True)[source]¶
-
makeDdTable
(layer, db=None)[source]¶ make a DdTable object from the passed in layer, returns None, if layer is not suitable
-
removeInputWidget
(layer, attributeName, fromUi=True, fromSearchUi=True)[source]¶ api method to remove the DdWidget for a certain attribute
-
replaceInputWidget
(layer, attributeName, newWidget, toUi=True, toSearchUi=True)[source]¶ api method to replace a DdWidget in the ui of a layer with another one
-
setUi
(layer, ui, searchUi=None, showParents=None, thisSize=None)[source]¶ api method to exchange the default ui with a custom ui
-
showFeatureForm
(layer, feature, showParents=True, title=None, askForSave=True, multiEdit=False)[source]¶ api method showFeatureForm: show the data-driven input mask for a layer and a feature if the data provider allows editing the layer is turned into editing mode if the user clicks OK all changes to the feature are committed (no undo!) if askForSave is true and the layer has pending changes the user is asked if the changes shall be commited before the mask is opened if multiEdit is True then the changes are applied to all selected Features in the layer returns 1 if user clicked OK, 0 if CANCEL
-
ddattribute¶
Each DdAttribute corresponds to an input widget in the mask or each input widget is based on exactly one DdAttribute.
General rules:¶
- every field has an input widget suitable for its type
- no ARRAY typees are supported
- supported types are: int4, int8, float, date, boolean, char, varchar, text
- foreign keys are represented as comboboxes and are only supported if based on one field (exactly one fk field in the table references exactly one pk field in the referenced table)
- the table referenced by a foreign key should have at least one field wit a notNull constraint apart from the primary key. This field will be used as display field in the combobox
- if a varchar field is present in a table referenced by a foreign key it is used as display field in the combobox, if there are several the one defined earlier is used
- if no varchar field is present any char field is used
- if no varchar or char fields are available the pk field is used for display
- table inheritance is not covered
- if a table’s pk is a fk to another table’s pk the other table’s mask is shown in a second tab
-
class
ddattribute.
DdAttribute
(table, type, notNull, name, comment, label, min=None, max=None, enableWidget=True)[source]¶ abstract super class for all DdAttributes
-
class
ddattribute.
DdCheckableTableAttribute
(relationTable, relatedTable, comment, label, relationFeatureIdField, relationRelatedIdField, relatedIdField, relatedDisplayField, attributes, catalogTable=None, relatedCatalogIdField=None, catalogIdField=None, catalogDisplayField=None, catalogLabel=None, enableWidget=True)[source]¶
-
class
ddattribute.
DdDateLayerAttribute
(table, type, notNull, name, comment, attNum, isPK, isFK, default, hasDefault, length, label=None, min=None, max=None, dateFormat='yyyy-MM-dd', enableWidget=True, isArray=False, arrayDelim='')[source]¶ a DdAttribute for a date field in a QGIS layer if you want to specify today as min or max, simply pass “today”
-
class
ddattribute.
DdFkLayerAttribute
(table, type, notNull, name, comment, attNum, isPK, default, hasDefault, queryForCbx, label=None, enableWidget=True)[source]¶ a DdAttribute for field in a QGIS layer that represents a foreign key
-
class
ddattribute.
DdGeometryAttribute
(table, type, name, comment, attNum)[source]¶ a DdAttribute for a geometry field in a QGIS layer
-
class
ddattribute.
DdLayerAttribute
(table, type, notNull, name, comment, attNum, isPK, isFK, default, hasDefault, length, label=None, min=None, max=None, enableWidget=True, isArray=False, arrayDelim='')[source]¶ a DdAttribute for a field in a QGIS layer
-
class
ddattribute.
DdManyToManyAttribute
(relationTable, type, relationFeatureIdField, comment, label, enableWidget=True)[source]¶ abstract class for any many2many attribute
-
class
ddattribute.
DdN2mAttribute
(relationTable, relatedTable, subType, comment, label, relationFeatureIdField, relationRelatedIdField, relatedIdField, relatedDisplayField, fieldList=[], relatedForeignKeys=[], enableWidget=True)[source]¶ a DdAttribute for a n2m relation, subtype can be list or tree relationTable and relatedTable are DdTable objects
-
buildDisplayStatement
(relationSchema, relationTable, relatedSchema, relatedTable, relationFeatureIdField, relatedIdField, relatedDisplayField, relationRelatedIdField, fieldList)[source]¶
-
-
class
ddattribute.
DdPushButtonAttribute
(comment, label, enableWidget=True)[source]¶ a DdAttribute that draws a pushButton in the mask. the button must be implemented as subclass of dduserclass.DdPushButton
ddui¶
Classes that make up or steer the DataDrivenUI
-
class
ddui.
DataDrivenUi
(iface)[source]¶ Bases:
object
Creates the DataDrivenUi
When subclassing this class, you want to rewrite createUi and use DdManager’s setUi method to apply your custom ui to the layer
-
configureLayer
(ddTable, skip, labels, fieldOrder, fieldGroups, minMax, noSearchFields, db, createAction, helpText, fieldDisable)[source]¶ read configuration from db
-
createUi
(thisTable, db, skip=[], labels={}, fieldOrder=[], fieldGroups={}, minMax={}, noSearchFields=[], showParents=True, showChildren=True, inputMask=True, searchMask=True, helpText='', createAction=True, readConfigTables=False, fieldDisable=[])[source]¶ creates default uis for this table (DdTable instance) showChildren [Boolean]: show tabs for 1-to-1 relations (children) see ddmanager.initLayer for other parameters
-
getAttributes
(thisTable, db, labels, minMax, skip=[], fieldDisable=[])[source]¶ query the DB and create DdAttributes
-
getForeignKeys
(thisTable, db)[source]¶ querys this table’s foreign keys and returns a dict attnum: [str: Type of the lookup field, str: sql to query lookup values, str: Name of the value field in the lookup table, str: Comment on lookup table]
-
getN2mAttributes
(db, thisTable, attName, attNum, labels, showChildren, skip=[], fieldDisable=[])[source]¶ find those tables (n2mtable) where our pk is a fk
-
-
class
ddui.
DdArrayTableWidget
(attribute)[source]¶ Bases:
ddui.DdLineEdit
a table widget to show/edit values of an array field
-
appendRow
(aValue, link=None, operator=None, checkIfNone=True)[source]¶ add a new row to the QTableWidget
-
chkStateChanged
(newState)[source]¶ slot: disables the input widget if the null checkbox is checked and vice versa
-
fillRow
(thisRow, aValue, link=None, operator=None, checkIfNone=True)[source]¶ fill thisRow with aValue
-
fromString
(aValue)[source]¶ convert aValue from its string representation to a value of the appropriate class default implementation for string
-
getFeatureValue
(layer, feature)[source]¶ returns an array[str] representing the value in this field for this feature; if the value is null, None is returned, if it is a new feature the default is returned.
-
setRowValue
(thisRow, aValue, checkIfNon=True)[source]¶ sets this row’s value to thisValue; default implementation for strings
-
setSearchCombo
(thisRow, link=None, operator=None)[source]¶ sets combo boxes for searching to columns 0 and 1
-
-
class
ddui.
DdArrayTableWidgetBool
(attribute)[source]¶ Bases:
ddui.DdArrayTableWidget
a table widget to show/edit values of a boolean array field
-
class
ddui.
DdArrayTableWidgetDate
(attribute)[source]¶ Bases:
ddui.DdArrayTableWidget
a table widget to show/edit values of a date array field
-
class
ddui.
DdArrayTableWidgetDouble
(attribute)[source]¶ Bases:
ddui.DdArrayTableWidget
a table widget to show/edit values of an integer array field
-
class
ddui.
DdArrayTableWidgetInt
(attribute)[source]¶ Bases:
ddui.DdArrayTableWidget
a table widget to show/edit values of an integer array field
-
class
ddui.
DdCheckBox
(attribute)[source]¶ Bases:
ddui.DdLineEditBoolean
subclass DdLineEditBoolean to issue a deprecation warning
-
class
ddui.
DdComboBox
(attribute)[source]¶ Bases:
ddui.DdLineEdit
input widget (QComboBox) for a foreign key
-
getFeatureValue
(layer, feature)[source]¶ returns a value representing the value in this field for this feature
-
-
class
ddui.
DdDateEdit
(attribute)[source]¶ Bases:
ddui.DdLineEdit
input widget (QDateEdit) for a date field
-
getFeatureValue
(layer, feature)[source]¶ returns a QDate representing the value in this field for this feature
-
-
class
ddui.
DdDialogWidget
[source]¶ Bases:
ddui.DdWidget
This is the mask ui
-
class
ddui.
DdEventFilter
[source]¶ Bases:
PyQt4.QtCore.QObject
Event filter class to be applied to DdLineEdit’s input widgets throws a signal even when the input widget is not enabled
-
doubleClicked
¶
-
-
class
ddui.
DdFormWidget
(ddTable, hasToolBox=False, layer=None)[source]¶ Bases:
ddui.DdWidget
DdForms are the content of DdDialog, each DdDialog needs at least one DdForm (tab). The class arranges its input widgets either in a QToolBox or in the DdDialogWidget’s current tab A form can represent a (parent) layer with the corresponding (parent) feature
-
class
ddui.
DdInputWidget
(ddAttribute)[source]¶ Bases:
ddui.DdWidget
abstract super class for any input widget, corresponds to a DdAttribute
-
class
ddui.
DdLineEdit
(attribute)[source]¶ Bases:
ddui.DdInputWidget
abstract class for all Input Widgets that can be represented in one line, creates a QLineEdit as default InputWidget, adds it together with a QCheckBox (to store null values) and a label to a QFormLayout.
-
chkStateChanged
(newState)[source]¶ slot: disables the input widget if the null checkbox is checked and vice versa
-
getFeatureValue
(layer, feature)[source]¶ returns a str representing the value in this field for this feature; if the value is null, None is returned, if it is a new feature the default value is returned if available.
-
getFieldIndex
(layer)[source]¶ return the field index for this DdInputWidget’s attribute’s name in this layer
-
manageChk
(thisValue)[source]¶ check/uncheck the null checkbox depending on the value and the attribute’s notNull property
-
onDoubleClick
()[source]¶ slot called when event filter on self.inputWidget throws doubleClick signal
-
-
class
ddui.
DdLineEditBoolean
(attribute)[source]¶ Bases:
ddui.DdLineEdit
input widget Radio Buttons labeld with yes/no for a boolean field
-
class
ddui.
DdLineEditChar
(attribute)[source]¶ Bases:
ddui.DdLineEdit
input widget (QLineEdit) for a char or varchar
-
class
ddui.
DdLineEditDouble
(attribute)[source]¶ Bases:
ddui.DdLineEdit
input widget (QLineEdit) for a DoubleValue
-
class
ddui.
DdLineEditGeometry
(attribute)[source]¶ Bases:
ddui.DdLineEditInt
-
class
ddui.
DdLineEditInt
(attribute)[source]¶ Bases:
ddui.DdLineEdit
input widget (QLineEdit) for an IntegerValue
-
setNull
(setnull)[source]¶ Set this inputWidget to NULL; set only to default if default is an integer
-
setValidator
(min=None, max=None)[source]¶ sets an appropriate QValidator for the QLineEdit if this DdInputWidget’s attribute has min/max values validator is set to them A Python2 int covers PostgreSQL’s int2, int4 and int8 Upon initialization setValidator is called with the current value as min and max
-
-
class
ddui.
DdN2mListWidget
(attribute)[source]¶ Bases:
ddui.DdN2mWidget
input widget (clickable QListWidget) for simple n2m relations
-
class
ddui.
DdN2mTableWidget
(attribute)[source]¶ Bases:
ddui.DdN2mWidget
a input widget for n-to-m relations with more than one field in the relation table The input widget consists of a QTableWidget and an add (+) and a remove (-) button
-
doubleClick
(thisRow, thisColumn)[source]¶ slot to be called when the user double clicks on the QTableWidget
-
-
class
ddui.
DdN2mTreeWidget
(attribute)[source]¶ Bases:
ddui.DdN2mWidget
input widget (clickable QTreeWidget) for n2m relations with more than one additional field in the related table TreeWidget is initialized directly from the DB
-
class
ddui.
DdN2mWidget
(attribute)[source]¶ Bases:
ddui.DdInputWidget
abstract class for any n-to-m relation
-
class
ddui.
DdTextEdit
(attribute)[source]¶ Bases:
ddui.DdLineEdit
input widget (QTextEdit) for a text field
-
class
ddui.
DdWidget
[source]¶ Bases:
object
abstract base class of all ui-widgets
-
applySearch
(parentElement)[source]¶ read the appropriate parentElement’s tag and apply to the widget
-
checkInput
(layer, feature)[source]¶ check if input is valid returns True if not implemented in child class
-
getPk
(feature, layer)[source]¶ only relevant for QGIS 2.16 and newer: read the pk-id value either from the feature itself or, in case of a bigint pk field from the field
-