aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@digia.com>2013-10-08 14:35:55 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-04 11:45:57 +0100
commitb0dd9f3b314106bd3cd811ce02ff2cae5ee1eb50 (patch)
treecb9531623843944d4052a779355be3109066bbc4 /examples
parenta79e400150e9d550cc4ddc0c0497778d8b78fe5d (diff)
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 <geir.vattekar@digia.com> Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/demos/stocqt/content/StockChart.qml5
-rw-r--r--examples/quick/demos/stocqt/content/StockModel.qml11
-rw-r--r--examples/quick/demos/stocqt/content/StockView.qml2
-rw-r--r--examples/quick/demos/stocqt/stocqt.qml14
4 files changed, 22 insertions, 10 deletions
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()
}
}