From 5173774db038b45f5fc0d00decc8f5e4d74dfa0e Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 25 Aug 2017 16:15:07 -0700 Subject: [PATCH] MUCH faster filter! --- .../qml/hifi/commerce/inventory/Inventory.qml | 25 ++----------------- .../hifi/commerce/inventory/InventoryItem.qml | 10 ++++++++ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/inventory/Inventory.qml b/interface/resources/qml/hifi/commerce/inventory/Inventory.qml index acb3028e1f..44b5a60729 100644 --- a/interface/resources/qml/hifi/commerce/inventory/Inventory.qml +++ b/interface/resources/qml/hifi/commerce/inventory/Inventory.qml @@ -53,7 +53,6 @@ Rectangle { console.log("Failed to get inventory", result.message); } else { inventoryModel.append(result.data.assets); - filteredInventoryModel.append(result.data.assets); } } } @@ -149,24 +148,6 @@ Rectangle { property int previousLength: 0; anchors.fill: parent; placeholderText: "Filter"; - - onTextChanged: { - if (filterBar.text.length < previousLength) { - filteredInventoryModel.clear(); - - for (var i = 0; i < inventoryModel.count; i++) { - filteredInventoryModel.append(inventoryModel.get(i)); - } - } - - for (var i = 0; i < filteredInventoryModel.count; i++) { - if (filteredInventoryModel.get(i).title.toLowerCase().indexOf(filterBar.text.toLowerCase()) === -1) { - filteredInventoryModel.remove(i); - i--; - } - } - previousLength = filterBar.text.length; - } } } // @@ -176,14 +157,11 @@ Rectangle { ListModel { id: inventoryModel; } - ListModel { - id: filteredInventoryModel; - } ListView { id: inventoryContentsList; clip: true; - model: filteredInventoryModel; + model: inventoryModel; // Anchors anchors.top: filterBarContainer.bottom; anchors.topMargin: 12; @@ -194,6 +172,7 @@ Rectangle { itemName: title; itemId: id; itemPreviewImageUrl: preview; + filterText: filterBar.text; anchors.topMargin: 12; anchors.bottomMargin: 12; diff --git a/interface/resources/qml/hifi/commerce/inventory/InventoryItem.qml b/interface/resources/qml/hifi/commerce/inventory/InventoryItem.qml index cfb6e96093..4b5c0b9ba0 100644 --- a/interface/resources/qml/hifi/commerce/inventory/InventoryItem.qml +++ b/interface/resources/qml/hifi/commerce/inventory/InventoryItem.qml @@ -29,12 +29,18 @@ Rectangle { property string itemId: ""; property string itemPreviewImageUrl: ""; property string itemHref: ""; + property string filterText: ""; // Style color: hifi.colors.white; // Size width: parent.width; height: 120; + visible: passesFilter(); + onFilterTextChanged: { + root.visible = passesFilter(); + } + Image { id: itemPreviewImage; source: root.itemPreviewImageUrl; @@ -137,6 +143,10 @@ Rectangle { // FUNCTION DEFINITIONS START // signal sendToInventory(var message); + + function passesFilter() { + return root.itemName.toLowerCase().indexOf(root.filterText.toLowerCase()) !== -1; + } // // FUNCTION DEFINITIONS END //