diff options
-rw-r--r-- | src/controls/ComboBox.qml | 27 | ||||
-rw-r--r-- | src/controls/plugin.cpp | 6 | ||||
-rw-r--r-- | src/layouts/qquicklinearlayout.cpp | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 18 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_gridlayout.qml | 22 |
5 files changed, 73 insertions, 5 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml index b546837f..4161de56 100644 --- a/src/controls/ComboBox.qml +++ b/src/controls/ComboBox.qml @@ -119,6 +119,9 @@ Control { /*! \qmlproperty int ComboBox::currentIndex The index of the currently selected item in the ComboBox. + Setting currentIndex to \c -1 will reset the selection and clear the text + label. If \l editable is \c true, you may also need to manually clear \l editText. + \sa model */ property alias currentIndex: popup.__selectedIndex @@ -342,7 +345,6 @@ Control { enabled: editable focus: true clip: contentWidth > width - text: currentText anchors.fill: parent anchors.leftMargin: 8 @@ -358,9 +360,11 @@ Control { onAccepted: { var idx = input.find(editText, Qt.MatchFixedString) if (idx > -1) { + editTextMatches = true; currentIndex = idx; editText = textAt(idx); } else { + editTextMatches = false; currentIndex = -1; popup.currentText = editText; } @@ -369,6 +373,7 @@ Control { property bool blockUpdate: false property string prevText + property bool editTextMatches: true function find (text, searchType) { for (var i = 0 ; i < popupItems.count ; ++i) { @@ -425,7 +430,7 @@ Control { Keys.onPressed: allowComplete = (event.key !== Qt.Key_Backspace && event.key !== Qt.Key_Delete); onTextChanged: { - if (editable && !blockUpdate && allowComplete) { + if (editable && !blockUpdate && allowComplete && text.length > 0) { var completed = input.tryComplete(text) if (completed.length > text.length) { var oldtext = input.text; @@ -437,6 +442,13 @@ Control { } } + Binding { + target: input + property: "text" + value: popup.currentText + when: input.editTextMatches + } + onTextRoleChanged: popup.resolveTextValue(textRole) Menu { @@ -449,7 +461,12 @@ Control { onSelectedTextChanged: if (selectedText) popup.currentText = selectedText property string selectedText - on__SelectedIndexChanged: updateSelectedText() + on__SelectedIndexChanged: { + if (__selectedIndex === -1) + popup.currentText = "" + else + updateSelectedText() + } property string textRole: "" property bool ready: false @@ -559,8 +576,10 @@ Control { function updateSelectedText() { var selectedItem; - if (__selectedIndex !== -1 && (selectedItem = items[__selectedIndex])) + if (__selectedIndex !== -1 && (selectedItem = items[__selectedIndex])) { + input.editTextMatches = true selectedText = selectedItem.text + } } } diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp index 2a676e48..55be136a 100644 --- a/src/controls/plugin.cpp +++ b/src/controls/plugin.cpp @@ -61,6 +61,11 @@ #include "Private/qquickstyleitem_p.h" #endif +static void initResources() +{ + Q_INIT_RESOURCE(controls); +} + QT_BEGIN_NAMESPACE static const struct { @@ -100,6 +105,7 @@ static const struct { void QtQuickControlsPlugin::registerTypes(const char *uri) { + initResources(); qmlRegisterType<QQuickAction>(uri, 1, 0, "Action"); qmlRegisterType<QQuickExclusiveGroup>(uri, 1, 0, "ExclusiveGroup"); qmlRegisterType<QQuickMenu>(uri, 1, 0, "MenuPrivate"); diff --git a/src/layouts/qquicklinearlayout.cpp b/src/layouts/qquicklinearlayout.cpp index bc77cd43..2e9c3536 100644 --- a/src/layouts/qquicklinearlayout.cpp +++ b/src/layouts/qquicklinearlayout.cpp @@ -723,6 +723,9 @@ void QQuickGridLayout::insertLayoutItems() Q_ASSERT(columnSpan >= 1); Q_ASSERT(rowSpan >= 1); + const int sp = span[flowOrientation]; + if (sp > flowBound) + return; if (row >= 0) nextRow = row; @@ -745,7 +748,7 @@ void QQuickGridLayout::insertLayoutItems() bool cellAcceptsItem; while (true) { // Check if the item does not span beyond the layout bound - cellAcceptsItem = (flowColumn + span[flowOrientation]) <= flowBound; + cellAcceptsItem = (flowColumn + sp) <= flowBound; // Check if all the required cells are not taken for (int rs = 0; cellAcceptsItem && rs < rowSpan; ++rs) { diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index f63a6ee7..6758c982 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -267,6 +267,7 @@ TestCase { compare(comboBox.acceptedCount, 3) comboBox.editText = "" + compare(comboBox.editText, "") keyPress(Qt.Key_A) compare(comboBox.currentText, "Cocomuffin") @@ -679,5 +680,22 @@ TestCase { } return index } + + function test_minusOneIndexResetsSelection_QTBUG_35794() { + var qmlObjects = ['import QtQuick.Controls 1.1 ; ComboBox { model: ["A", "B", "C"] }', + 'import QtQuick.Controls 1.1 ; ComboBox { editable: true; model: ["A", "B", "C"] }'] + for (var i = 0; i < qmlObjects.length; i++) { + var comboBox = Qt.createQmlObject(qmlObjects[i], testCase, ''); + compare(comboBox.currentIndex, 0) + compare(comboBox.currentText, "A") + comboBox.currentIndex = -1 + compare(comboBox.currentIndex, -1) + compare(comboBox.currentText, "") + comboBox.currentIndex = 1 + compare(comboBox.currentIndex, 1) + compare(comboBox.currentText, "B") + comboBox.destroy() + } + } } } diff --git a/tests/auto/controls/data/tst_gridlayout.qml b/tests/auto/controls/data/tst_gridlayout.qml index a9cf2f9f..3d14bca0 100644 --- a/tests/auto/controls/data/tst_gridlayout.qml +++ b/tests/auto/controls/data/tst_gridlayout.qml @@ -438,6 +438,28 @@ Item { layout.destroy(); } + Component { + id: layout_spanIsMoreThanColumns_Component + + GridLayout { + columnSpacing: 1 + rowSpacing: 1 + columns: 2 + + Rectangle { + implicitWidth: 10 + implicitHeight: 10 + Layout.columnSpan: 3 + } + } + } + + function test_spanIsMoreThanColumns() { + var layout = layout_spanIsMoreThanColumns_Component.createObject(container); + // item was not added, therefore implicit width is 0 + compare(layout.implicitWidth, 0); + layout.destroy(); + } function test_sizeHints() { var layout = layout_spanAcrossEmptyRows_Component.createObject(container); |