diff --git a/examples/gallery/content/Controls.qml b/examples/gallery/content/Controls.qml index 7db11db2f757f5239e2085a720efcd34d11cc4c5..0a2c74ab278c2214c45d211de77c77e75c6584ef 100644 --- a/examples/gallery/content/Controls.qml +++ b/examples/gallery/content/Controls.qml @@ -81,7 +81,7 @@ Item { id: combo; model: choices; width: parent.width; - selectedIndex: 2 + currentIndex: 2 KeyNavigation.tab: t1 } Row { diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml index e7308f84683eb6695b98e6678c513a0662bf32df..6d245bd173ee9206d14629b8b83b01a9a7bbe352 100644 --- a/src/controls/ComboBox.qml +++ b/src/controls/ComboBox.qml @@ -49,19 +49,8 @@ import "Styles/Settings.js" as Settings \ingroup controls \brief ComboBox is a combined button and popup list. - The popup menu itself is platform native, and cannot by styled from QML code. - - Add menu items to the comboBox by either adding MenuItem children inside the popup, or - assign it a ListModel (or both). - - The ComboBox contains the following API (in addition to the BasicButton API): - - ListModel model - this model will be used, in addition to MenuItem children, to - create items inside the popup menu - int selectedIndex - the index of the selected item in the popup menu. - string selectedText - the text of the selected menu item. - - Example 1: + Add menu items to the comboBox by either adding MenuItem children inside the popup or + assign it a ListModel, or a list of strings. \qml ComboBox { @@ -72,7 +61,7 @@ import "Styles/Settings.js" as Settings ListElement { text: "Coconut"; color: "Brown" } } width: 200 - onSelectedIndexChanged: console.debug(selectedText + ", " + menuItems.get(selectedIndex).color) + onCurrentIndexChanged: console.debug(currentText + ", " + menuItems.get(currentIndex).color) } \endqml @@ -81,15 +70,8 @@ import "Styles/Settings.js" as Settings \qml ComboBox { width: 200 - MenuItem { - text: "Pineapple" - onSelected: console.debug(text) - - } - MenuItem { - text: "Grape" - onSelected: console.debug(text) - } + MenuItem { text: "Pineapple" } + MenuItem { text: "Grape" } } \endqml */ @@ -98,14 +80,17 @@ Control { id: comboBox default property alias items: popup.items + /*! The model to populate the ComboBox from. */ property alias model: popup.model property alias textRole: popup.textRole - property alias selectedIndex: popup.selectedIndex - readonly property alias selectedText: popup.selectedText - - readonly property bool pressed: mouseArea.pressed && mouseArea.containsMouse || popup.__popupVisible + /*! The index of the currently selected item in the ComboBox. */ + property alias currentIndex: popup.__selectedIndex + /*! The text of the currently selected item in the ComboBox. */ + readonly property alias currentText: popup.selectedText + /* \internal */ + readonly property bool __pressed: mouseArea.pressed && mouseArea.containsMouse || popup.__popupVisible /* \internal */ property alias __containsMouse: mouseArea.containsMouse @@ -123,8 +108,8 @@ Control { StyleItem { id: styleItem } Component.onCompleted: { - if (selectedIndex === -1) - selectedIndex = 0 + if (currentIndex === -1) + currentIndex = 0 if (styleItem.style == "mac") { popup.x -= 10 popup.y += 4 @@ -137,14 +122,14 @@ Control { style: __style.popupStyle - readonly property string selectedText: items[selectedIndex] ? items[selectedIndex].text : "" + readonly property string selectedText: items[__selectedIndex] ? items[__selectedIndex].text : "" property string textRole: "" property var model property int modelSize: 0 property bool ready: false // 'centerSelectedText' means that the menu will be positioned - // so that the selected text' top left corner will be at x, y. + // so that the current text' top left corner will be at x, y. property bool centerSelectedText: true property int x: 0 @@ -206,10 +191,10 @@ Control { } function show() { - if (items[comboBox.selectedIndex]) - items[comboBox.selectedIndex].checked = true - __currentIndex = comboBox.selectedIndex - __popup(x, y, centerSelectedText ? comboBox.selectedIndex : 0) + if (items[__selectedIndex]) + items[__selectedIndex].checked = true + __currentIndex = comboBox.currentIndex + __popup(x, y, centerSelectedText ? __selectedIndex : 0) } } @@ -219,6 +204,6 @@ Control { if (!popup.popupVisible) popup.show() } - Keys.onUpPressed: { if (selectedIndex > 0) selectedIndex-- } - Keys.onDownPressed: { if (selectedIndex < popup.modelSize - 1) selectedIndex++ } + Keys.onUpPressed: { if (currentIndex > 0) currentIndex-- } + Keys.onDownPressed: { if (currentIndex < popup.modelSize - 1) currentIndex++ } } diff --git a/src/controls/qtmenu.cpp b/src/controls/qtmenu.cpp index bed3d6ab7620f266b87697df9be17b5715ce23a1..ca1d3e10730b12db48a10fb0dfa234222fd13910 100644 --- a/src/controls/qtmenu.cpp +++ b/src/controls/qtmenu.cpp @@ -115,12 +115,6 @@ QT_BEGIN_NAMESPACE \sa iconSource */ -/*! - \qmlproperty int Menu::selectedIndex - - The index of the last selected item in the menu. -*/ - /*! \qmlmethod void Menu::popup() @@ -188,7 +182,7 @@ void QtMenu::setSelectedIndex(int index) return; m_selectedIndex = index; - emit selectedIndexChanged(); + emit __selectedIndexChanged(); } void QtMenu::updateSelectedIndex() diff --git a/src/controls/qtmenu_p.h b/src/controls/qtmenu_p.h index bd3fc7c8eadc9632ee3b64d875fdb64cb5400990..650d8e80f33656292d3652f539933fd4a39d8445 100644 --- a/src/controls/qtmenu_p.h +++ b/src/controls/qtmenu_p.h @@ -64,8 +64,8 @@ class QtMenu : public QtMenuText Q_PROPERTY(QString title READ text WRITE setText NOTIFY titleChanged) Q_PROPERTY(QQmlListProperty<QObject> items READ menuItems NOTIFY itemsChanged) Q_CLASSINFO("DefaultProperty", "items") - Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged) + Q_PROPERTY(int __selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY __selectedIndexChanged) Q_PROPERTY(bool __popupVisible READ popupVisible NOTIFY popupVisibleChanged) Q_PROPERTY(QQuickItem *__contentItem READ menuContentItem WRITE setMenuContentItem) Q_PROPERTY(int __minimumWidth READ minimumWidth WRITE setMinimumWidth) @@ -86,10 +86,10 @@ public Q_SLOTS: void __dismissMenu(); Q_SIGNALS: - void selectedIndexChanged(); void itemsChanged(); void titleChanged(); + void __selectedIndexChanged(); void __menuClosed(); void popupVisibleChanged(); diff --git a/src/styles/ComboBoxStyle.qml b/src/styles/ComboBoxStyle.qml index 260fc5492d358f34ffe5d280e79c2a1be876e542..e9ca29ffb9caf3640fa0bbcd13b0be4e80549584 100644 --- a/src/styles/ComboBoxStyle.qml +++ b/src/styles/ComboBoxStyle.qml @@ -53,8 +53,8 @@ Style { implicitHeight: 20 gradient: Gradient{ - GradientStop{color: control.pressed ? "lightgray" : "white" ; position: 0} - GradientStop{color: control.pressed ? "lightgray" : "lightgray" ; position: 1} + GradientStop{color: control.__pressed ? "lightgray" : "white" ; position: 0} + GradientStop{color: control.__pressed ? "lightgray" : "lightgray" ; position: 1} } radius:4 @@ -62,7 +62,7 @@ Style { Text { anchors.centerIn: parent - text: control.selectedText + text: control.currentText } } diff --git a/src/styles/Desktop/ComboBoxStyle.qml b/src/styles/Desktop/ComboBoxStyle.qml index c1d21a83a33ec3f42d376de3b2630caf01859ae3..368f7e87568d8d10a2c98b125294fe47bff15d97 100644 --- a/src/styles/Desktop/ComboBoxStyle.qml +++ b/src/styles/Desktop/ComboBoxStyle.qml @@ -55,11 +55,11 @@ Style { width: parent.width anchors.verticalCenter: parent.verticalCenter elementType: "combobox" - sunken: control.pressed + sunken: control.__pressed raised: !sunken hover: control.__containsMouse enabled: control.enabled - text: control.selectedText + text: control.currentText hasFocus: control.activeFocus contentHeight: 18 contentWidth: 80 diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 781cada06d5ba93438a7729c14c9431747202691..9c7ab77229f045afcef89e223120a3c3ae1e3d0f 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -57,29 +57,27 @@ TestCase { } function test_keyupdown() { - var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox {}', testCase, ''); - comboBox.model = 4 + var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox { model: 4 }', testCase, ''); - compare(comboBox.selectedIndex, 0) + compare(comboBox.currentIndex, 0) comboBox.forceActiveFocus() keyPress(Qt.Key_Down) - compare(comboBox.selectedIndex, 1) + compare(comboBox.currentIndex, 1) keyPress(Qt.Key_Down) - compare(comboBox.selectedIndex, 2) + compare(comboBox.currentIndex, 2) keyPress(Qt.Key_Up) - compare(comboBox.selectedIndex, 1) + compare(comboBox.currentIndex, 1) } function test_textrole() { var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox {}', testCase, ''); comboBox.textRole = "text" comboBox.model = model - compare(comboBox.selectedIndex, 0) - compare(comboBox.selectedText, "Banana") + compare(comboBox.currentIndex, 0) + compare(comboBox.currentText, "Banana") comboBox.textRole = "color" - compare(comboBox.selectedIndex, 0) - compare(comboBox.selectedText, "Yellow") + compare(comboBox.currentText, "Yellow") } } diff --git a/tests/auto/controls/data/tst_menu.qml b/tests/auto/controls/data/tst_menu.qml index 9884d466bdd5722c8243f3dc6a692e3713710cc4..8d039e1dc70c676d8013060f5eb9ebb7ba12da9e 100644 --- a/tests/auto/controls/data/tst_menu.qml +++ b/tests/auto/controls/data/tst_menu.qml @@ -56,7 +56,7 @@ TestCase { SignalSpy { id: menuSpy target: testcase.menu - signalName: "selectedIndexChanged" + signalName: "__selectedIndexChanged" } SignalSpy { @@ -113,7 +113,7 @@ TestCase { compare(menuItemSpy.count, 1) compare(menuSpy.count, 1) - compare(menu.selectedIndex, 2) + compare(menu.__selectedIndex, 2) } function test_check() { @@ -138,7 +138,7 @@ TestCase { compare(menuItemSpy.count, 2) compare(menuSpy.count, 2) - compare(menu.selectedIndex, 3) + compare(menu.__selectedIndex, 3) } ExclusiveGroup { id: eg } @@ -167,19 +167,19 @@ TestCase { compare(menuItemSpy.count, 2) compare(menuSpy.count, 2) - compare(menu.selectedIndex, 3) + compare(menu.__selectedIndex, 3) } - function test_selectedIndex() { + function test___selectedIndex() { for (var i = 0; i < menu.items.length; i++) menu.items[i].checkable = true - menu.selectedIndex = 3 - compare(menu.selectedIndex, 3) - verify(!menu.items[menu.selectedIndex].checked) + menu.__selectedIndex = 3 + compare(menu.__selectedIndex, 3) + verify(!menu.items[menu.__selectedIndex].checked) menu.items[2].trigger() - compare(menu.selectedIndex, 2) - verify(menu.items[menu.selectedIndex].checked) + compare(menu.__selectedIndex, 2) + verify(menu.items[menu.__selectedIndex].checked) } }