From b0dd9f3b314106bd3cd811ce02ff2cae5ee1eb50 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Tue, 8 Oct 2013 14:35:55 +0200 Subject: Doc: Fix warnings in StocQt Qt Quick demo Fix a number of warnings from QML engine by adding some boundary & sanity checks for properties. Also address UI update issues by having XMLHTTPRequest calls to trigger by a timer, instead of directly binding them to multiple change notifier signals. Task-number: QTBUG-33867 Change-Id: I48f573050b5dc3e3fe6e75bc423fe86ecc4a2469 Reviewed-by: Geir Vattekar Reviewed-by: Alan Alpert --- examples/quick/demos/stocqt/content/StockChart.qml | 5 +++-- examples/quick/demos/stocqt/content/StockModel.qml | 11 +++++++---- examples/quick/demos/stocqt/content/StockView.qml | 2 ++ examples/quick/demos/stocqt/stocqt.qml | 14 ++++++++++---- 4 files changed, 22 insertions(+), 10 deletions(-) (limited to 'examples/quick') diff --git a/examples/quick/demos/stocqt/content/StockChart.qml b/examples/quick/demos/stocqt/content/StockChart.qml index 8235b5a632..f7e0d0206b 100644 --- a/examples/quick/demos/stocqt/content/StockChart.qml +++ b/examples/quick/demos/stocqt/content/StockChart.qml @@ -48,8 +48,8 @@ Rectangle { property var _months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] property var stockModel: null - property var startDate - property var endDate + property var startDate: new Date() + property var endDate: new Date() property var settings function update() { @@ -228,6 +228,7 @@ Rectangle { last = stockModel.indexOf(chart.endDate) first = last - (chart.endDate.getTime() - chart.startDate.getTime())/86400000; + first = Math.max(first, 0); console.log("painting... first:" + first + ", last:" + last); var highestPrice = stockModel.highestPrice; diff --git a/examples/quick/demos/stocqt/content/StockModel.qml b/examples/quick/demos/stocqt/content/StockModel.qml index d127afc5c5..f9ed9c87d4 100644 --- a/examples/quick/demos/stocqt/content/StockModel.qml +++ b/examples/quick/demos/stocqt/content/StockModel.qml @@ -122,11 +122,14 @@ ListModel { } function updateStock() { - var xhr = new XMLHttpRequest; - var req = requestUrl(); - xhr.open("GET", req); + if (!req) + return; + + var xhr = new XMLHttpRequest; + + xhr.open("GET", req, true); model.ready = false; model.clear(); @@ -145,7 +148,7 @@ ListModel { if (model.count > 0) { model.ready = true; model.stockPrice = model.get(0).adjusted; - model.stockPriceChanged = Math.round((model.stockPrice - model.get(2).adjusted) * 100) / 100; + model.stockPriceChanged = model.count > 1 ? (Math.round((model.stockPrice - model.get(1).close) * 100) / 100) : 0; model.dataReady(); //emit signal } } diff --git a/examples/quick/demos/stocqt/content/StockView.qml b/examples/quick/demos/stocqt/content/StockView.qml index eefcf0aeb4..ce55fdf3d3 100644 --- a/examples/quick/demos/stocqt/content/StockView.qml +++ b/examples/quick/demos/stocqt/content/StockView.qml @@ -53,6 +53,8 @@ Rectangle { signal settingsClicked function update() { + if (!settings) + return; chart.endDate = settings.endDate chart.update() } diff --git a/examples/quick/demos/stocqt/stocqt.qml b/examples/quick/demos/stocqt/stocqt.qml index 9bcffd972f..3e231ab8bf 100644 --- a/examples/quick/demos/stocqt/stocqt.qml +++ b/examples/quick/demos/stocqt/stocqt.qml @@ -52,17 +52,23 @@ ListView { boundsBehavior: Flickable.StopAtBounds currentIndex: 1 + Timer { + id: updateTimer + interval: 500 + onTriggered: stock.updateStock() + } + StockModel { id: stock stockId: listView.currentStockId stockName: listView.currentStockName startDate: settings.startDate endDate: settings.endDate - onStockIdChanged: updateStock() - onStartDateChanged: updateStock() - onEndDateChanged: updateStock() + onStockIdChanged: updateTimer.restart() + onStartDateChanged: updateTimer.restart() + onEndDateChanged: updateTimer.restart() onDataReady: { - root.currentIndex = 1 + root.positionViewAtIndex(1, ListView.SnapPosition) stockView.update() } } -- cgit v1.2.3