fix: do not display the thousands separator when editing
- teach `userInputLocale` about `Locale.OmitGroupSeparator` option which discards the said thousands separator - some more fixes to other inputs to do the same, and align what the validators do - StatusAmountInput: discard illegal characters, and reuse the same locale for the validator - StatusAmountInputPage: make it possible to select a different locale Fixes #14165
This commit is contained in:
parent
a045ca36fe
commit
5b242c6dd8
|
@ -14,11 +14,12 @@ SplitView {
|
|||
readonly property var tokensBySymbolModel: TokensBySymbolModel {}
|
||||
|
||||
readonly property double maxCryptoBalance: parseFloat(maxCryptoBalanceText.text)
|
||||
readonly property double rate: parseFloat(rateText.text)
|
||||
readonly property int decimals: parseInt(decimalsText.text)
|
||||
|
||||
Logs { id: logs }
|
||||
|
||||
|
||||
Component.onCompleted: amountToSendInput.input.forceActiveFocus()
|
||||
|
||||
SplitView {
|
||||
orientation: Qt.Vertical
|
||||
SplitView.fillWidth: true
|
||||
|
@ -38,14 +39,14 @@ SplitView {
|
|||
maxInputBalance: inputIsFiat ? root.maxCryptoBalance*amountToSendInput.selectedHolding.marketDetails.currencyPrice.amount
|
||||
: root.maxCryptoBalance
|
||||
currentCurrency: "Fiat"
|
||||
formatCurrencyAmount: function(amount, symbol, options = null, locale = null) {
|
||||
formatCurrencyAmount: function(amount, symbol, options, locale) {
|
||||
const currencyAmount = {
|
||||
amount: amount,
|
||||
symbol: symbol,
|
||||
displayDecimals: root.decimals,
|
||||
stripTrailingZeroes: true
|
||||
amount: amount,
|
||||
symbol: symbol,
|
||||
displayDecimals: root.decimals,
|
||||
stripTrailingZeroes: true
|
||||
}
|
||||
return LocaleUtils.currencyAmountToLocaleString(currencyAmount, options)
|
||||
return LocaleUtils.currencyAmountToLocaleString(currencyAmount, options, locale)
|
||||
}
|
||||
onReCalculateSuggestedRoute: function() {
|
||||
logs.logEvent("onReCalculateSuggestedRoute")
|
||||
|
@ -80,19 +81,6 @@ SplitView {
|
|||
text: "1000000"
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.topMargin: 10
|
||||
Layout.fillWidth: true
|
||||
text: "Fiat/Crypto rate"
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: rateText
|
||||
background: Rectangle { border.color: 'lightgrey' }
|
||||
Layout.preferredWidth: 200
|
||||
text: "10"
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.topMargin: 10
|
||||
Layout.fillWidth: true
|
||||
|
|
|
@ -20,6 +20,7 @@ SplitView {
|
|||
StatusAmountInput {
|
||||
id: input
|
||||
anchors.centerIn: parent
|
||||
locale: Qt.locale(ctrlLocaleName.text)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,12 +35,10 @@ SplitView {
|
|||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Label {
|
||||
text: "Valid:"
|
||||
text: "Valid:\t"
|
||||
}
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignRight
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.bold: true
|
||||
text: input.valid ? "true" : "false"
|
||||
}
|
||||
|
@ -47,14 +46,11 @@ SplitView {
|
|||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Label {
|
||||
text: "Locale:"
|
||||
text: "Locale:\t"
|
||||
}
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignRight
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.bold: true
|
||||
text: input.locale.name
|
||||
TextField {
|
||||
id: ctrlLocaleName
|
||||
placeholderText: "Default locale: %1".arg(input.locale.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ StatusInput {
|
|||
id: root
|
||||
|
||||
property var locale: LocaleUtils.userInputLocale
|
||||
validationMode: StatusInput.ValidationMode.IgnoreInvalidInput
|
||||
|
||||
input.edit.objectName: "amountInput"
|
||||
|
||||
|
@ -16,7 +17,7 @@ StatusInput {
|
|||
StatusFloatValidator {
|
||||
bottom: 0
|
||||
errorMessage: ""
|
||||
locale: LocaleUtils.userInputLocale
|
||||
locale: root.locale
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -27,7 +28,7 @@ StatusInput {
|
|||
if(root.text.indexOf(root.locale.decimalPoint) === -1)
|
||||
root.input.insert(root.input.cursorPosition, root.locale.decimalPoint)
|
||||
event.accepted = true
|
||||
} else if ((event.key > Qt.Key_9 && event.key <= Qt.Key_BraceRight) || event.key === Qt.Key_Space) {
|
||||
} else if ((event.key > Qt.Key_9 && event.key <= Qt.Key_BraceRight) || event.key === Qt.Key_Space || event.key === Qt.Key_Tab) {
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,10 @@ StatusValidator {
|
|||
\qmlproperty DoubleValidator StatusFloatValidator::qmlDoubleValidator
|
||||
This property holds a default qml double validator instance.
|
||||
*/
|
||||
readonly property DoubleValidator qmlDoubleValidator: DoubleValidator {}
|
||||
readonly property DoubleValidator qmlDoubleValidator: DoubleValidator {
|
||||
notation: DoubleValidator.StandardNotation
|
||||
locale: root.locale.name
|
||||
}
|
||||
|
||||
name: "floatValidator"
|
||||
errorMessage: qsTr("Please enter a valid numeric value.")
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQml 2.14
|
||||
import Qt.labs.settings 1.0
|
||||
import QtQml 2.15
|
||||
import Qt.labs.settings 1.1
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
readonly property var userInputLocale: Qt.locale()
|
||||
readonly property var userInputLocale: {
|
||||
const loc = Qt.locale()
|
||||
loc.numberOptions |= Locale.OmitGroupSeparator // no thousands separator in number-to-string functions
|
||||
return loc
|
||||
}
|
||||
|
||||
function integralPartLength(num) {
|
||||
num = Math.abs(num)
|
||||
|
|
|
@ -116,8 +116,6 @@ ColumnLayout {
|
|||
AmountInput {
|
||||
id: amountInput
|
||||
|
||||
locale: LocaleUtils.userInputLocale
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.bottomMargin: (validationError !== "") ? root.spacing * 2 : 0
|
||||
customHeight: d.defaultHeight
|
||||
|
|
|
@ -11,7 +11,7 @@ Input {
|
|||
id: root
|
||||
|
||||
property int maximumLength: 10
|
||||
property var locale: Qt.locale()
|
||||
property var locale: LocaleUtils.userInputLocale
|
||||
|
||||
readonly property alias amount: d.amount
|
||||
property alias multiplierIndex: d.multiplierIndex
|
||||
|
@ -59,7 +59,7 @@ Input {
|
|||
|
||||
function getEffectiveDigitsCount(str) {
|
||||
const digits = LocaleUtils.getLocalizedDigitsCount(text, root.locale)
|
||||
return str.startsWith(locale.decimalPoint) ? digits + 1 : digits
|
||||
return str.startsWith(root.locale.decimalPoint) ? digits + 1 : digits
|
||||
}
|
||||
|
||||
function validate() {
|
||||
|
@ -119,8 +119,6 @@ Input {
|
|||
}
|
||||
|
||||
validator: DoubleValidator {
|
||||
id: doubleValidator
|
||||
|
||||
decimals: root.allowDecimals ? 100 : 0
|
||||
bottom: 0
|
||||
notation: DoubleValidator.StandardNotation
|
||||
|
|
Loading…
Reference in New Issue