diff options
Diffstat (limited to 'examples/quick/demos/stocqt/content/StockListView.qml')
-rw-r--r-- | examples/quick/demos/stocqt/content/StockListView.qml | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/examples/quick/demos/stocqt/content/StockListView.qml b/examples/quick/demos/stocqt/content/StockListView.qml index d1f735fde3..59f36b42cc 100644 --- a/examples/quick/demos/stocqt/content/StockListView.qml +++ b/examples/quick/demos/stocqt/content/StockListView.qml @@ -62,6 +62,7 @@ Rectangle { focus: true snapMode: ListView.SnapToItem model: StockListModel{} + currentIndex: -1 // Don't pre-select any item function requestUrl(stockId) { var endDate = new Date(""); //today @@ -95,7 +96,7 @@ Rectangle { xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.LOADING || xhr.readyState === XMLHttpRequest.DONE) { var records = xhr.responseText.split('\n'); - if (records.length > 0) { + if (records.length > 0 && xhr.status == 200) { var r = records[1].split(','); var today = parseFloat(r[4]); model.setProperty(index, "value", today.toFixed(2)); @@ -113,6 +114,9 @@ Rectangle { model.setProperty(index, "changePercentage", "+" + changePercentage.toFixed(2) + "%"); else model.setProperty(index, "changePercentage", changePercentage.toFixed(2) + "%"); + } else { + var unknown = "n/a"; + model.set(index, {"value": unknown, "change": unknown, "changePercentage": unknown}); } } } @@ -120,9 +124,10 @@ Rectangle { } onCurrentIndexChanged: { - mainRect.listViewActive = 0; - root.currentStockId = model.get(currentIndex).stockId; - root.currentStockName = model.get(currentIndex).name; + if (currentItem) { + root.currentStockId = model.get(currentIndex).stockId; + root.currentStockName = model.get(currentIndex).name; + } } delegate: Rectangle { @@ -132,7 +137,10 @@ Rectangle { MouseArea { anchors.fill: parent; onClicked: { - view.currentIndex = index; + if (view.currentIndex == index) + mainRect.currentIndex = 1; + else + view.currentIndex = index; } } @@ -243,7 +251,7 @@ Rectangle { } highlight: Rectangle { - width: parent.width + width: view.width color: "#eeeeee" } } |