diff options
author | Topi Reinio <topi.reinio@theqtcompany.com> | 2016-02-23 13:55:59 +0100 |
---|---|---|
committer | Topi Reiniƶ <topi.reinio@theqtcompany.com> | 2016-02-24 11:12:30 +0000 |
commit | 90e9b622f01465666f4ae3f88d1710a36bb2ed1f (patch) | |
tree | 924a7c09b5442a2954de8d6b494341af0db7c8dc /examples/quick/demos/stocqt/content/StockListView.qml | |
parent | d3f8a608e8e00915df38a2a43496127a93b5bcaf (diff) |
StocQt demo: Bugfixes and improvements
- Update the list of NASDAQ-100 companies
- Add code for handling invalid entries (stock IDs)
- Simplify top-level navigation logic. The app now
opens in list view with no stock pre-selected.
- Fix math for calculating change percentages
Change-Id: I6aaab45f5a391f9636123c0ddca73656fab79916
Task-number: QTBUG-50651
Reviewed-by: Mika Salmela <mika.salmela@theqtcompany.com>
Reviewed-by: Venugopal Shivashankar <venugopal.shivashankar@digia.com>
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" } } |