Skip to content

Commit

Permalink
Rework MMRelationReferenceEditor (#3337)
Browse files Browse the repository at this point in the history
* Rework MMFormRelationReferenceEditor

* Address review comments
  • Loading branch information
tomasMizera authored Apr 18, 2024
1 parent 3328417 commit b2c51f4
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions app/qml/form/editors/MMFormRelationReferenceEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,44 @@
***************************************************************************/

import QtQuick
import QtQuick.Controls

import mm 1.0 as MM

import "../../inputs" as MMInputs
import "../../components" as MMComponents
import "../../components/private" as MMPrivateComponents
import "../components" as MMFormComponents

MMInputs.MMBaseInput {
MMPrivateComponents.MMBaseSingleLineInput {
id: root

property var _fieldValue: parent.fieldValue
property var _fieldConfig: parent.fieldConfig
property var _fieldActiveProject: parent.fieldActiveProject
property bool _fieldValueIsNull: parent.fieldValueIsNull

property bool _fieldIsReadOnly: parent.fieldIsReadOnly
property string _fieldTitle: parent.fieldTitle

property bool _fieldShouldShowTitle: parent.fieldShouldShowTitle
property string _fieldTitle: parent.fieldTitle
property string _fieldErrorMessage: parent.fieldErrorMessage
property string _fieldWarningMessage: parent.fieldWarningMessage

property bool _fieldRememberValueSupported: parent.fieldRememberValueSupported
property bool _fieldRememberValueState: parent.fieldRememberValueState

signal openLinkedFeature( /* FeaturePair */ var linkedFeature )
signal editorValueChanged( var newValue, bool isNull )
signal rememberValueBoxClicked( bool state )

on_FieldValueChanged: {
title.text = rModel.attributeFromForeignKey( root._fieldValue, MM.FeaturesModel.FeatureTitle ) || ""
textField.text = rModel.attributeFromForeignKey( root._fieldValue, MM.FeaturesModel.FeatureTitle ) || ""
}

title: _fieldShouldShowTitle ? _fieldTitle : ""

errorMsg: _fieldErrorMessage
warningMsg: _fieldWarningMessage

enabled: !_fieldIsReadOnly
readOnly: _fieldIsReadOnly

hasCheckbox: _fieldRememberValueSupported
checkboxChecked: _fieldRememberValueState
Expand All @@ -48,51 +54,35 @@ MMInputs.MMBaseInput {
root.rememberValueBoxClicked( checkboxChecked )
}

MM.RelationReferenceFeaturesModel {
id: rModel

config: root._fieldConfig
project: root._fieldActiveProject

onModelReset: title.text = rModel.attributeFromForeignKey( root._fieldValue, MM.FeaturesModel.FeatureTitle ) || ""
}

content: Text {
id: title
textField.readOnly: true

anchors.fill: parent
font: __style.p5
text: root._fieldValue
color: __style.nightColor
verticalAlignment: Text.AlignVCenter
}

onContentClicked: {
textField.onReleased: { // can be opened even when the field is readonly
let featurePair = rModel.attributeFromForeignKey( root._fieldValue, MM.FeaturesModel.FeaturePair )

if ( featurePair == null || !featurePair.valid ) return
if ( featurePair === null || !featurePair.valid ) return

openLinkedFeature( featurePair )
}

rightAction: MMComponents.MMIcon {
id: rightIcon

anchors.verticalCenter: parent.verticalCenter

rightContent: MMComponents.MMIcon {
size: __style.icon24
source: __style.linkIcon
color: enabled ? __style.forestColor : __style.mediumGreenColor
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreyColor
}

onRightActionClicked: {
if ( root._fieldIsReadOnly )
return

onRightContentClicked: {
listLoader.active = true
listLoader.focus = true
}

MM.RelationReferenceFeaturesModel {
id: rModel

config: root._fieldConfig
project: root._fieldActiveProject

onModelReset: textField.text = rModel.attributeFromForeignKey( root._fieldValue, MM.FeaturesModel.FeatureTitle ) || ""
}

Loader {
id: listLoader

Expand Down

0 comments on commit b2c51f4

Please sign in to comment.