From b1a438bf94c6ae0984fc39912b32d5dbf20e3817 Mon Sep 17 00:00:00 2001
From: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Date: Mon, 11 Mar 2013 18:09:27 +0100
Subject: [PATCH] ComboBox: Rename 'selectedIndex' property to 'currentIndex'

Also, removed 'pressed' property. In Menu, we removed 'selectedProperty'
as well. (And by 'removed', we mean 'made it private'.)

Auto-tests have also been updated.

Change-Id: I4b4f9c81aad1165df1d2925964a9cd383079aa9c
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
---
 examples/gallery/content/Controls.qml     |  2 +-
 src/controls/ComboBox.qml                 | 59 +++++++++--------------
 src/controls/qtmenu.cpp                   |  8 +--
 src/controls/qtmenu_p.h                   |  4 +-
 src/styles/ComboBoxStyle.qml              |  6 +--
 src/styles/Desktop/ComboBoxStyle.qml      |  4 +-
 tests/auto/controls/data/tst_combobox.qml | 18 +++----
 tests/auto/controls/data/tst_menu.qml     | 20 ++++----
 8 files changed, 49 insertions(+), 72 deletions(-)

diff --git a/examples/gallery/content/Controls.qml b/examples/gallery/content/Controls.qml
index 7db11db2f..0a2c74ab2 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 e7308f846..6d245bd17 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 bed3d6ab7..ca1d3e107 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 bd3fc7c8e..650d8e80f 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 260fc5492..e9ca29ffb 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 c1d21a83a..368f7e875 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 781cada06..9c7ab7722 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 9884d466b..8d039e1dc 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)
     }
 }
-- 
GitLab