diff options
Diffstat (limited to 'examples/quick/demos/stocqt/content/StockListModel.qml')
-rw-r--r-- | examples/quick/demos/stocqt/content/StockListModel.qml | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/examples/quick/demos/stocqt/content/StockListModel.qml b/examples/quick/demos/stocqt/content/StockListModel.qml index 948edc41cc..6c2068e8c3 100644 --- a/examples/quick/demos/stocqt/content/StockListModel.qml +++ b/examples/quick/demos/stocqt/content/StockListModel.qml @@ -47,9 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - import QtQuick 2.0 - +import "stocqt.js" as JSLibrary ListModel { id: stocks @@ -60,28 +59,13 @@ ListModel { } } - function requestUrl(stockId) { - var endDate = new Date(""); // today - var startDate = new Date() - startDate.setDate(startDate.getDate() - 5); - - var request = "http://ichart.finance.yahoo.com/table.csv?"; - request += "s=" + stockId; - request += "&g=d"; - request += "&a=" + startDate.getMonth(); - request += "&b=" + startDate.getDate(); - request += "&c=" + startDate.getFullYear(); - request += "&d=" + endDate.getMonth(); - request += "&e=" + endDate.getDate(); - request += "&f=" + endDate.getFullYear(); - request += "&g=d"; - request += "&ignore=.csv"; - return request; - } - function getCloseValue(index) { - var req = requestUrl(get(index).stockId); + var endDate = new Date(); // today + var startDate = new Date(); + startDate.setDate(endDate.getDate() - 7); + + var req = JSLibrary.requestUrl(get(index).stockId, startDate, endDate); if (!req) return; @@ -97,12 +81,14 @@ ListModel { if (records.length > 0 && xhr.status == 200) { var r = records[1].split(','); var today = parseFloat(r[4]); + if (!isNaN(today)) setProperty(index, "value", today.toFixed(2)); if (records.length > 2) { r = records[2].split(','); var yesterday = parseFloat(r[4]); var change = today - yesterday; + if (change >= 0.0) setProperty(index, "change", "+" + change.toFixed(2)); else |