Skip to content
Permalink
Browse files

fix showing correct values

  • Loading branch information
tomasMizera authored and PeterPetrik committed Nov 17, 2020
1 parent 00c6ce2 commit 8f617e432cbfc83e6d0db1b57087c55f64b63202
Showing with 28 additions and 21 deletions.
  1. +19 −19 src/quickgui/plugin/editor/qgsquickvaluerelation.qml
  2. +9 −2 src/quickgui/plugin/qgsquickfeatureform.qml
@@ -31,15 +31,10 @@ Item {
property var widgetValue: value
property var currentFeatureLayerPair: featurePair
property string widgetType: ""
property bool isReadOnly: readOnly

property var model: QgsQuick.FeaturesListModel {
id: vrModel

// recalculate index when model changes
onModelReset: {
combobox.currentIndex = vrModel.rowFromAttribute( QgsQuick.FeaturesListModel.KeyColumn, value )
updateField()
}
}

id: fieldItem
@@ -52,9 +47,11 @@ Item {
rightMargin: 10 * QgsQuick.Utils.dp
}

Component.onCompleted: {
onCurrentFeatureLayerPairChanged: {
vrModel.setupValueRelation( config )
widgetType = customWidget.getTypeOfWidget( fieldItem, vrModel )
vrModel.currentFeature = currentFeatureLayerPair.feature
if ( widgetType === "" )
widgetType = customWidget.getTypeOfWidget( fieldItem, vrModel )
updateField()
}

@@ -89,8 +86,11 @@ Item {

// Called when data in different fields are changed.
function dataUpdated( feature ) {
vrModel.currentFeature = feature
combobox.popup.close()
if ( !isReadOnly ) {
vrModel.currentFeature = feature
updateField()
combobox.popup.close()
}
}

/**
@@ -111,37 +111,37 @@ Item {
* if value to be set is undefined, -1, empty string or similiar, it also resets current value
*/
function updateField() {

if ( vrModel.currentFeature !== currentFeatureLayerPair.feature )
vrModel.currentFeature = currentFeatureLayerPair.feature

if ( widgetValue == null || widgetValue === "" ) {
if ( widgetValue == null || widgetValue === "" || widgetValue === -1 ) {
textField.clear()
combobox.currentIndex = -1
return
}
let reset = false

if ( widgetType === "textfield" ) {
if ( allowMultipleValues && widgetValue.startsWith('{') )
{
let strings = vrModel.convertMultivalueFormat( widgetValue )
textField.text = strings.join(", ")
if ( !strings || strings.length === 0 )
setValue( "", true )
reset = true
}
else {
let text = vrModel.attributeFromValue( QgsQuick.FeaturesListModel.KeyColumn, widgetValue, QgsQuick.FeaturesListModel.FeatureTitle )
textField.text = text || "" // if text is undefined, clear text
textField.text = text || ""
if ( !text )
setValue( -1, true)
reset = true
}
}
else if ( widgetType === "combobox" ) {
let index = vrModel.rowFromAttribute( QgsQuick.FeaturesListModel.KeyColumn, widgetValue )
combobox.currentIndex = index
if ( index < 0 )
setValue( -1, true )
reset = true
}

if ( reset && !isReadOnly )
setValue( -1, true )
}

/**
@@ -94,11 +94,18 @@ Item {
*/
property var valueRelationOpened: function valueRelationOpened( widget, valueRelationModel ) {}

/**
* Called when field for value relation is created, by default it returns value "combobox".
* Return value of this function sets corresponding widget type. Currently accepted values are:
* - combobox -> QML combobox component.
* - textfield -> custom text widget that shows only title of selected feature in value relation
* and calls function "valueRelationOpened" when it is clicked.
* \param widget valuerelation widget for specific field to send valueChanged signal.
* \param valueRelationModel model of type FeaturesListModel bears features of related layer.
*/
property var getTypeOfWidget: function getTypeOfWidget( widget, valueRelationModel ) {
return "combobox"
}

property int valueRelationLimit: 4
}

/**

0 comments on commit 8f617e4

Please sign in to comment.
You can’t perform that action at this time.