aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/templates/qquickspinbox.cpp27
-rw-r--r--src/templates/qquickspinbox_p.h1
2 files changed, 12 insertions, 16 deletions
diff --git a/src/templates/qquickspinbox.cpp b/src/templates/qquickspinbox.cpp
index 33ea6e79..bda955d0 100644
--- a/src/templates/qquickspinbox.cpp
+++ b/src/templates/qquickspinbox.cpp
@@ -116,8 +116,8 @@ public:
QQuickSpinButton *up;
QQuickSpinButton *down;
QValidator *validator;
- QJSValue textFromValue;
- QJSValue valueFromText;
+ mutable QJSValue textFromValue;
+ mutable QJSValue valueFromText;
};
int QQuickSpinBoxPrivate::boundValue(int value) const
@@ -384,6 +384,11 @@ void QQuickSpinBox::setValidator(QValidator *validator)
QJSValue QQuickSpinBox::textFromValue() const
{
Q_D(const QQuickSpinBox);
+ if (!d->textFromValue.isCallable()) {
+ QQmlEngine *engine = qmlEngine(this);
+ if (engine)
+ d->textFromValue = engine->evaluate(QStringLiteral("function(value, locale) { return Number(value).toLocaleString(locale, 'f', 0); }"));
+ }
return d->textFromValue;
}
@@ -420,6 +425,11 @@ void QQuickSpinBox::setTextFromValue(const QJSValue &callback)
QJSValue QQuickSpinBox::valueFromText() const
{
Q_D(const QQuickSpinBox);
+ if (!d->valueFromText.isCallable()) {
+ QQmlEngine *engine = qmlEngine(this);
+ if (engine)
+ d->valueFromText = engine->evaluate(QStringLiteral("function(text, locale) { return Number.fromLocaleString(locale, text); }"));
+ }
return d->valueFromText;
}
@@ -587,19 +597,6 @@ void QQuickSpinBox::timerEvent(QTimerEvent *event)
}
}
-void QQuickSpinBox::componentComplete()
-{
- Q_D(QQuickSpinBox);
- QQuickControl::componentComplete();
- QQmlEngine *engine = qmlEngine(this);
- if (engine) {
- if (!d->textFromValue.isCallable())
- setTextFromValue(engine->evaluate(QStringLiteral("function(value, locale) { return Number(value).toLocaleString(locale, 'f', 0); }")));
- if (!d->valueFromText.isCallable())
- setValueFromText(engine->evaluate(QStringLiteral("function(text, locale) { return Number.fromLocaleString(locale, text); }")));
- }
-}
-
void QQuickSpinBox::itemChange(ItemChange change, const ItemChangeData &value)
{
Q_D(QQuickSpinBox);
diff --git a/src/templates/qquickspinbox_p.h b/src/templates/qquickspinbox_p.h
index 0ad5e70d..c7d1f6c6 100644
--- a/src/templates/qquickspinbox_p.h
+++ b/src/templates/qquickspinbox_p.h
@@ -121,7 +121,6 @@ protected:
void mouseUngrabEvent() Q_DECL_OVERRIDE;
void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
- void componentComplete() Q_DECL_OVERRIDE;
void itemChange(ItemChange change, const ItemChangeData &value) Q_DECL_OVERRIDE;
void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE;