diff options
author | Mika Salmela <mika.salmela@digia.com> | 2014-05-02 14:14:55 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-02 14:40:23 +0200 |
commit | d98362f5e9cc5c07cff5f32672aa448b0a0c31c4 (patch) | |
tree | 1cdc1d3dea8934b46f95b28912f9e3e244ff8d10 /examples/quick/demos/stocqt/content/StockModel.qml | |
parent | 7996ac4c0a679ca5e476c2d3e3e0b84582e40c22 (diff) |
StocQt demo improvement
Along with general demo improvements, this task implements the new layout
to the StocQt demo. Also few bugs on the functionality are corrected, like
drawing the stock graph on right way and initial values reset on stock
model when changing active stock.
Task-number: QTBUG-38254
Change-Id: I9d3387ed0e3f23512b8e60c70246589c10237818
Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
Diffstat (limited to 'examples/quick/demos/stocqt/content/StockModel.qml')
-rw-r--r-- | examples/quick/demos/stocqt/content/StockModel.qml | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/examples/quick/demos/stocqt/content/StockModel.qml b/examples/quick/demos/stocqt/content/StockModel.qml index f9ed9c87d4..682c96bb53 100644 --- a/examples/quick/demos/stocqt/content/StockModel.qml +++ b/examples/quick/demos/stocqt/content/StockModel.qml @@ -44,8 +44,6 @@ ListModel { id: model property string stockId: "" property string stockName: "" - property var startDate - property var endDate property string stockDataCycle: "d" property bool ready: false property real stockPrice: 0.0 @@ -56,19 +54,28 @@ ListModel { signal dataReady function indexOf(date) { - var end = new Date(model.get(0).date); - var start = new Date(model.get(model.count - 1).date); - if (end <= date) - return model.count -1; + var newest = new Date(model.get(0).date); + var oldest = new Date(model.get(model.count - 1).date); + if (newest <= date) + return -1; - if (start >= date) - return 0; + if (oldest >= date) + return model.count - 1; + var currDiff = 0; + var bestDiff = Math.abs(date.getTime() - newest.getTime()); + var retval = 0; for (var i = 0; i < model.count; i++) { var d = new Date(model.get(i).date); - if ( d === date) - return i; + currDiff = Math.abs(d.getTime() - date.getTime()); + if (currDiff < bestDiff) { + bestDiff = currDiff; + retval = i; + } + if (currDiff > bestDiff) + return retval; } + return -1; } @@ -76,11 +83,9 @@ ListModel { if (stockId === "") return; - if (startDate === undefined) - startDate = new Date(1995, 3, 25); //default: 25 April 1995 + var startDate = new Date(2011, 4, 25); - if (endDate === undefined) - endDate = new Date(); //today + var endDate = new Date(); //today if (stockDataCycle !== "d" && stockDataCycle !== "w" && stockDataCycle !== "m") stockDataCycle = "d"; @@ -94,11 +99,11 @@ ListModel { */ var request = "http://ichart.finance.yahoo.com/table.csv?"; request += "s=" + stockId; - request += "&a=" + startDate.getDate(); - request += "&b=" + startDate.getMonth(); + request += "&a=" + startDate.getMonth(); + request += "&b=" + startDate.getDate(); request += "&c=" + startDate.getFullYear(); - request += "&d=" + endDate.getDate(); - request += "&e=" + endDate.getMonth(); + request += "&d=" + endDate.getMonth(); + request += "&e=" + endDate.getDate(); request += "&f=" + endDate.getFullYear(); request += "&g=" + stockDataCycle; request += "&ignore=.csv"; @@ -133,6 +138,10 @@ ListModel { model.ready = false; model.clear(); + + highestPrice = 0; + highestVolume = 0; + var i = 1; //skip the first line xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.LOADING || xhr.readyState === XMLHttpRequest.DONE) { |