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 var tokensBySymbolModel: TokensBySymbolModel {}
|
||||||
|
|
||||||
readonly property double maxCryptoBalance: parseFloat(maxCryptoBalanceText.text)
|
readonly property double maxCryptoBalance: parseFloat(maxCryptoBalanceText.text)
|
||||||
readonly property double rate: parseFloat(rateText.text)
|
|
||||||
readonly property int decimals: parseInt(decimalsText.text)
|
readonly property int decimals: parseInt(decimalsText.text)
|
||||||
|
|
||||||
Logs { id: logs }
|
Logs { id: logs }
|
||||||
|
|
||||||
|
Component.onCompleted: amountToSendInput.input.forceActiveFocus()
|
||||||
|
|
||||||
SplitView {
|
SplitView {
|
||||||
orientation: Qt.Vertical
|
orientation: Qt.Vertical
|
||||||
SplitView.fillWidth: true
|
SplitView.fillWidth: true
|
||||||
|
@ -38,14 +39,14 @@ SplitView {
|
||||||
maxInputBalance: inputIsFiat ? root.maxCryptoBalance*amountToSendInput.selectedHolding.marketDetails.currencyPrice.amount
|
maxInputBalance: inputIsFiat ? root.maxCryptoBalance*amountToSendInput.selectedHolding.marketDetails.currencyPrice.amount
|
||||||
: root.maxCryptoBalance
|
: root.maxCryptoBalance
|
||||||
currentCurrency: "Fiat"
|
currentCurrency: "Fiat"
|
||||||
formatCurrencyAmount: function(amount, symbol, options = null, locale = null) {
|
formatCurrencyAmount: function(amount, symbol, options, locale) {
|
||||||
const currencyAmount = {
|
const currencyAmount = {
|
||||||
amount: amount,
|
amount: amount,
|
||||||
symbol: symbol,
|
symbol: symbol,
|
||||||
displayDecimals: root.decimals,
|
displayDecimals: root.decimals,
|
||||||
stripTrailingZeroes: true
|
stripTrailingZeroes: true
|
||||||
}
|
}
|
||||||
return LocaleUtils.currencyAmountToLocaleString(currencyAmount, options)
|
return LocaleUtils.currencyAmountToLocaleString(currencyAmount, options, locale)
|
||||||
}
|
}
|
||||||
onReCalculateSuggestedRoute: function() {
|
onReCalculateSuggestedRoute: function() {
|
||||||
logs.logEvent("onReCalculateSuggestedRoute")
|
logs.logEvent("onReCalculateSuggestedRoute")
|
||||||
|
@ -80,19 +81,6 @@ SplitView {
|
||||||
text: "1000000"
|
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 {
|
Label {
|
||||||
Layout.topMargin: 10
|
Layout.topMargin: 10
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
|
@ -20,6 +20,7 @@ SplitView {
|
||||||
StatusAmountInput {
|
StatusAmountInput {
|
||||||
id: input
|
id: input
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
locale: Qt.locale(ctrlLocaleName.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +35,10 @@ SplitView {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Label {
|
Label {
|
||||||
text: "Valid:"
|
text: "Valid:\t"
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.alignment: Qt.AlignRight
|
|
||||||
horizontalAlignment: Text.AlignRight
|
|
||||||
font.bold: true
|
font.bold: true
|
||||||
text: input.valid ? "true" : "false"
|
text: input.valid ? "true" : "false"
|
||||||
}
|
}
|
||||||
|
@ -47,14 +46,11 @@ SplitView {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Label {
|
Label {
|
||||||
text: "Locale:"
|
text: "Locale:\t"
|
||||||
}
|
}
|
||||||
Label {
|
TextField {
|
||||||
Layout.fillWidth: true
|
id: ctrlLocaleName
|
||||||
Layout.alignment: Qt.AlignRight
|
placeholderText: "Default locale: %1".arg(input.locale.name)
|
||||||
horizontalAlignment: Text.AlignRight
|
|
||||||
font.bold: true
|
|
||||||
text: input.locale.name
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ StatusInput {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property var locale: LocaleUtils.userInputLocale
|
property var locale: LocaleUtils.userInputLocale
|
||||||
|
validationMode: StatusInput.ValidationMode.IgnoreInvalidInput
|
||||||
|
|
||||||
input.edit.objectName: "amountInput"
|
input.edit.objectName: "amountInput"
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ StatusInput {
|
||||||
StatusFloatValidator {
|
StatusFloatValidator {
|
||||||
bottom: 0
|
bottom: 0
|
||||||
errorMessage: ""
|
errorMessage: ""
|
||||||
locale: LocaleUtils.userInputLocale
|
locale: root.locale
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ StatusInput {
|
||||||
if(root.text.indexOf(root.locale.decimalPoint) === -1)
|
if(root.text.indexOf(root.locale.decimalPoint) === -1)
|
||||||
root.input.insert(root.input.cursorPosition, root.locale.decimalPoint)
|
root.input.insert(root.input.cursorPosition, root.locale.decimalPoint)
|
||||||
event.accepted = true
|
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
|
event.accepted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,10 @@ StatusValidator {
|
||||||
\qmlproperty DoubleValidator StatusFloatValidator::qmlDoubleValidator
|
\qmlproperty DoubleValidator StatusFloatValidator::qmlDoubleValidator
|
||||||
This property holds a default qml double validator instance.
|
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"
|
name: "floatValidator"
|
||||||
errorMessage: qsTr("Please enter a valid numeric value.")
|
errorMessage: qsTr("Please enter a valid numeric value.")
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
pragma Singleton
|
pragma Singleton
|
||||||
|
|
||||||
import QtQml 2.14
|
import QtQml 2.15
|
||||||
import Qt.labs.settings 1.0
|
import Qt.labs.settings 1.1
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: root
|
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) {
|
function integralPartLength(num) {
|
||||||
num = Math.abs(num)
|
num = Math.abs(num)
|
||||||
|
|
|
@ -116,8 +116,6 @@ ColumnLayout {
|
||||||
AmountInput {
|
AmountInput {
|
||||||
id: amountInput
|
id: amountInput
|
||||||
|
|
||||||
locale: LocaleUtils.userInputLocale
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.bottomMargin: (validationError !== "") ? root.spacing * 2 : 0
|
Layout.bottomMargin: (validationError !== "") ? root.spacing * 2 : 0
|
||||||
customHeight: d.defaultHeight
|
customHeight: d.defaultHeight
|
||||||
|
|
|
@ -11,7 +11,7 @@ Input {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property int maximumLength: 10
|
property int maximumLength: 10
|
||||||
property var locale: Qt.locale()
|
property var locale: LocaleUtils.userInputLocale
|
||||||
|
|
||||||
readonly property alias amount: d.amount
|
readonly property alias amount: d.amount
|
||||||
property alias multiplierIndex: d.multiplierIndex
|
property alias multiplierIndex: d.multiplierIndex
|
||||||
|
@ -59,7 +59,7 @@ Input {
|
||||||
|
|
||||||
function getEffectiveDigitsCount(str) {
|
function getEffectiveDigitsCount(str) {
|
||||||
const digits = LocaleUtils.getLocalizedDigitsCount(text, root.locale)
|
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() {
|
function validate() {
|
||||||
|
@ -119,8 +119,6 @@ Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator: DoubleValidator {
|
validator: DoubleValidator {
|
||||||
id: doubleValidator
|
|
||||||
|
|
||||||
decimals: root.allowDecimals ? 100 : 0
|
decimals: root.allowDecimals ? 100 : 0
|
||||||
bottom: 0
|
bottom: 0
|
||||||
notation: DoubleValidator.StandardNotation
|
notation: DoubleValidator.StandardNotation
|
||||||
|
|
Loading…
Reference in New Issue