Skip to content

Commit

Permalink
Create MMTextFormEditor.qml
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasMizera committed Jan 31, 2024
1 parent 1e4e35a commit 3734e89
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions app/qml/form/editors/MMTextFormEditor.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

import QtQuick
import QtQuick.Controls

import "../../inputs"

/*
* Text Edit for QGIS Attribute Form
* Requires various global properties set to function, see featureform Loader section.
* These properties are injected here via 'fieldXYZ' properties and captured with underscore `_`.
*
* Should be used only within feature form.
* See MMTextInput
*/

MMTextInput {
id: root

property var _field: parent.field
property var _fieldValue: parent.fieldValue
property bool _fieldValueIsNull: parent.fieldValueIsNull

property bool _fieldShouldShowTitle: parent.fieldShouldShowTitle
property bool _fieldIsReadOnly: parent.fieldIsReadOnly

property string _fieldTitle: parent.fieldTitle
property string _fieldErrorMessage: parent.fieldErrorMessage
property string _fieldWarningMessage: parent.fieldWarningMessage

signal editorValueChanged( var newValue, bool isNull )

text: _fieldValue === undefined || _fieldValueIsNull ? '' : _fieldValue

showClearIcon: false

enabled: !_fieldIsReadOnly
textFieldComponent.readOnly: _fieldIsReadOnly
textFieldComponent.inputMethodHints: root._field.isNumeric ? Qt.ImhFormattedNumbersOnly : Qt.ImhNone

title: _fieldShouldShowTitle ? _fieldTitle : ""

warningMsg: _fieldWarningMessage
errorMsg: _fieldErrorMessage

textFieldComponent.maximumLength: {
if ( ( !root._field.isNumeric ) && ( root._field.length > 0 ) ) {
return root._field.length
}
return internal.textMaxCharactersLimit
}

onTextEdited: function ( text ) {
let val = text
if ( root._field.isNumeric )
{
val = val.replace( ",", "." ).replace( / /g, '' ) // replace comma with dot and remove spaces
}

root.editorValueChanged( val, val === "" )
}

// Avoid Android's uncommited text
textFieldComponent.onPreeditTextChanged: if ( __androidUtils.isAndroid ) Qt.inputMethod.commit()

QtObject {
id: internal

property int textMaxCharactersLimit: 32767 // Qt default
}
}

1 comment on commit 3734e89

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 24.01.512511 just submitted!

Please sign in to comment.