From cf3736edfc27fc7615e4893b2deb902f3c9dbaa0 Mon Sep 17 00:00:00 2001
From: Jens Bache-Wiig <jens.bache-wiig@nokia.com>
Date: Fri, 20 May 2011 17:56:43 +0200
Subject: [PATCH] Fixes to editor and item selection

---
 components/TableView.qml     |  5 ++---
 examples/ItemViewGallery.qml | 15 ++++++++-------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/components/TableView.qml b/components/TableView.qml
index f3f7510a1..acdaeaa30 100644
--- a/components/TableView.qml
+++ b/components/TableView.qml
@@ -199,12 +199,11 @@ FocusScope{
                 autodecrement = false
             }
 
-            var x = Math.min(contentX + tree.width - 5, Math.max(mouseX + contentX, contentX))
             var y = Math.min(contentY + tree.height - 5, Math.max(mouseY + contentY, contentY))
 
-            var newIndex =tree.indexAt(x, y)
+            var newIndex = tree.indexAt(0, y)
             if (newIndex > 0)
-                tree.currentIndex = tree.indexAt(x, y)
+                tree.currentIndex = tree.indexAt(0, y)
         }
         onPressed:  {
             tree.forceActiveFocus()
diff --git a/examples/ItemViewGallery.qml b/examples/ItemViewGallery.qml
index 7a2913f47..13ed6230e 100644
--- a/examples/ItemViewGallery.qml
+++ b/examples/ItemViewGallery.qml
@@ -236,7 +236,7 @@ Rectangle {
                 }
 
                 Component {
-                    id: delegate3
+                    id: editableDelegate
                     Item {
                         Text {
                             width: parent.width
@@ -248,13 +248,14 @@ Rectangle {
                             color: itemForeground
                             visible: !itemSelected
                         }
-                        TextInput{
-                            color: itemForeground
+                        Loader { // Initialize text editor lazily to improve performance
                             anchors.fill: parent
                             anchors.margins: 4
-                            visible: itemSelected
-                            text: itemValue ? itemValue : ""
-                            onTextChanged:  model.setProperty(rowIndex, itemProperty, text)
+                            property string modelText: itemValue
+                            property string editorText: item ? item.text : itemValue
+                            onEditorTextChanged: model.setProperty(rowIndex, itemProperty, editorText)
+                            sourceComponent: itemSelected ? editor : null
+                            Component {id: editor ; TextInput{ color: itemForeground ; text: modelText} }
                         }
                     }
                 }
@@ -321,7 +322,7 @@ Rectangle {
                         case 1:
                             return delegate2
                         case 2:
-                            return delegate3
+                            return editableDelegate
                         }
                     }
                 }
-- 
GitLab