aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/controls/SpinBox.qml1
-rw-r--r--src/imports/controls/material/SpinBox.qml1
-rw-r--r--src/imports/controls/plugins.qmltypes1
-rw-r--r--src/imports/controls/universal/SpinBox.qml1
-rw-r--r--src/imports/templates/plugins.qmltypes1
-rw-r--r--src/templates/qquickspinbox.cpp37
-rw-r--r--src/templates/qquickspinbox_p.h5
-rw-r--r--tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml1
-rw-r--r--tests/auto/controls/data/tst_spinbox.qml24
9 files changed, 66 insertions, 6 deletions
diff --git a/src/imports/controls/SpinBox.qml b/src/imports/controls/SpinBox.qml
index 77f89206..d3184626 100644
--- a/src/imports/controls/SpinBox.qml
+++ b/src/imports/controls/SpinBox.qml
@@ -74,6 +74,7 @@ T.SpinBox {
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
+ readOnly: !control.editable
validator: control.validator
inputMethodHints: Qt.ImhFormattedNumbersOnly
}
diff --git a/src/imports/controls/material/SpinBox.qml b/src/imports/controls/material/SpinBox.qml
index 5d2044e6..f6aba60d 100644
--- a/src/imports/controls/material/SpinBox.qml
+++ b/src/imports/controls/material/SpinBox.qml
@@ -75,6 +75,7 @@ T.SpinBox {
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
+ readOnly: !control.editable
validator: control.validator
inputMethodHints: Qt.ImhFormattedNumbersOnly
}
diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes
index 62206af5..efe56ce8 100644
--- a/src/imports/controls/plugins.qmltypes
+++ b/src/imports/controls/plugins.qmltypes
@@ -579,6 +579,7 @@ Module {
Property { name: "to"; type: "int" }
Property { name: "value"; type: "int" }
Property { name: "stepSize"; type: "int" }
+ Property { name: "editable"; type: "bool" }
Property { name: "validator"; type: "QValidator"; isPointer: true }
Property { name: "textFromValue"; type: "QJSValue" }
Property { name: "valueFromText"; type: "QJSValue" }
diff --git a/src/imports/controls/universal/SpinBox.qml b/src/imports/controls/universal/SpinBox.qml
index 77eb241e..b3185452 100644
--- a/src/imports/controls/universal/SpinBox.qml
+++ b/src/imports/controls/universal/SpinBox.qml
@@ -80,6 +80,7 @@ T.SpinBox {
verticalAlignment: TextInput.AlignVCenter
renderType: Text.NativeRendering
+ readOnly: !control.editable
validator: control.validator
inputMethodHints: Qt.ImhFormattedNumbersOnly
}
diff --git a/src/imports/templates/plugins.qmltypes b/src/imports/templates/plugins.qmltypes
index 7c0add11..05ea33ec 100644
--- a/src/imports/templates/plugins.qmltypes
+++ b/src/imports/templates/plugins.qmltypes
@@ -573,6 +573,7 @@ Module {
Property { name: "to"; type: "int" }
Property { name: "value"; type: "int" }
Property { name: "stepSize"; type: "int" }
+ Property { name: "editable"; type: "bool" }
Property { name: "validator"; type: "QValidator"; isPointer: true }
Property { name: "textFromValue"; type: "QJSValue" }
Property { name: "valueFromText"; type: "QJSValue" }
diff --git a/src/templates/qquickspinbox.cpp b/src/templates/qquickspinbox.cpp
index a0c94101..821c4fd0 100644
--- a/src/templates/qquickspinbox.cpp
+++ b/src/templates/qquickspinbox.cpp
@@ -61,8 +61,9 @@ static const int AUTO_REPEAT_INTERVAL = 100;
\image qtlabscontrols-spinbox.png
SpinBox allows the user to choose an integer value by clicking the up
- or down indicator buttons, by pressing up or down on the keyboard, or
- by entering a text value in the input field.
+ or down indicator buttons, or by pressing up or down on the keyboard.
+ Optionally, SpinBox can be also made \l editable, so the user can enter
+ a text value in the input field.
By default, SpinBox provides discrete values in the range of \c [0-99]
with a \l stepSize of \c 1.
@@ -90,7 +91,7 @@ class QQuickSpinBoxPrivate : public QQuickControlPrivate
Q_DECLARE_PUBLIC(QQuickSpinBox)
public:
- QQuickSpinBoxPrivate() : from(0), to(99), value(0), stepSize(1),
+ QQuickSpinBoxPrivate() : editable(false), from(0), to(99), value(0), stepSize(1),
delayTimer(0), repeatTimer(0), up(nullptr), down(nullptr), validator(nullptr) { }
int boundValue(int value) const;
@@ -107,6 +108,7 @@ public:
bool handleMouseReleaseEvent(QQuickItem *child, QMouseEvent *event);
bool handleMouseUngrabEvent(QQuickItem *child);
+ bool editable;
int from;
int to;
int value;
@@ -342,14 +344,37 @@ void QQuickSpinBox::setStepSize(int step)
}
/*!
+ \qmlproperty bool Qt.labs.controls::SpinBox::editable
+
+ This property holds whether the spinbox is editable. The default value is \c false.
+
+ \sa validator
+*/
+bool QQuickSpinBox::isEditable() const
+{
+ Q_D(const QQuickSpinBox);
+ return d->editable;
+}
+
+void QQuickSpinBox::setEditable(bool editable)
+{
+ Q_D(QQuickSpinBox);
+ if (d->editable == editable)
+ return;
+
+ d->editable = editable;
+ emit editableChanged();
+}
+
+/*!
\qmlproperty Validator Qt.labs.controls::SpinBox::validator
- This property holds the input text validator. By default, SpinBox uses
- \l IntValidator to accept input of integer numbers.
+ This property holds the input text validator for editable spinboxes. By
+ default, SpinBox uses \l IntValidator to accept input of integer numbers.
\snippet SpinBox.qml validator
- \sa textFromValue, valueFromText, {Control::locale}{locale}
+ \sa editable, textFromValue, valueFromText, {Control::locale}{locale}
*/
QValidator *QQuickSpinBox::validator() const
{
diff --git a/src/templates/qquickspinbox_p.h b/src/templates/qquickspinbox_p.h
index 831c73c2..67a1772c 100644
--- a/src/templates/qquickspinbox_p.h
+++ b/src/templates/qquickspinbox_p.h
@@ -65,6 +65,7 @@ class Q_LABSTEMPLATES_EXPORT QQuickSpinBox : public QQuickControl
Q_PROPERTY(int to READ to WRITE setTo NOTIFY toChanged FINAL)
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged FINAL)
Q_PROPERTY(int stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL)
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL)
Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL)
Q_PROPERTY(QJSValue textFromValue READ textFromValue WRITE setTextFromValue NOTIFY textFromValueChanged FINAL)
Q_PROPERTY(QJSValue valueFromText READ valueFromText WRITE setValueFromText NOTIFY valueFromTextChanged FINAL)
@@ -86,6 +87,9 @@ public:
int stepSize() const;
void setStepSize(int step);
+ bool isEditable() const;
+ void setEditable(bool editable);
+
QValidator *validator() const;
void setValidator(QValidator *validator);
@@ -107,6 +111,7 @@ Q_SIGNALS:
void toChanged();
void valueChanged();
void stepSizeChanged();
+ void editableChanged();
void validatorChanged();
void textFromValueChanged();
void valueFromTextChanged();
diff --git a/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml b/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml
index 08ecdda2..93601359 100644
--- a/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml
+++ b/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml
@@ -143,6 +143,7 @@ Item {
SpinBox {
id: spinbox
objectName: "spinbox"
+ editable: true
value: 50
}
// StackView
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml
index cdea8b66..e73c10b6 100644
--- a/tests/auto/controls/data/tst_spinbox.qml
+++ b/tests/auto/controls/data/tst_spinbox.qml
@@ -87,6 +87,7 @@ TestCase {
compare(control.to, 99)
compare(control.value, 0)
compare(control.stepSize, 1)
+ compare(control.editable, false)
compare(control.up.pressed, false)
compare(control.down.pressed, false)
@@ -326,4 +327,27 @@ TestCase {
control.destroy()
}
+
+ function test_editable() {
+ var control = spinBox.createObject(testCase)
+ verify(control)
+
+ control.contentItem.forceActiveFocus()
+ compare(control.contentItem.activeFocus, true)
+
+ compare(control.editable, false)
+ control.contentItem.selectAll()
+ keyClick(Qt.Key_5)
+ keyClick(Qt.Key_Return)
+ compare(control.value, 0)
+
+ control.editable = true
+ compare(control.editable, true)
+ control.contentItem.selectAll()
+ keyClick(Qt.Key_5)
+ keyClick(Qt.Key_Return)
+ compare(control.value, 5)
+
+ control.destroy()
+ }
}