summaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-11-15 16:40:38 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2016-11-15 16:44:16 +0100
commitb7a8b5a284bdf306a45b11e1c5ce308be007d1de (patch)
tree35ebcf4b3440abb24df67b579e00847417d42c19 /examples/quick
parent441e6bbdb01733c0f9860ce881b61f5907d2d2f8 (diff)
parent365a3ac6ae50eb53253eca92bfdf4c527b3a5c05 (diff)
Merge remote-tracking branch 'origin/5.7' into 5.8
Conflicts: src/qml/jsruntime/qv4string.cpp The conflict resolution for qv4tsring.cpp is to essentially omit the change of commit 64714ea431f2fd355ed27edc69dba4e992511e75 as the code in 5.8 already uses the add/mul_overflow functions. This merge also reverts commit f4ac007f4a19bc095ff15d415a6629986de78e49 as we can deal with dead store elimination now. Change-Id: Iee08c87cbe1a2ff23a73ce621d56262b4e007c56
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/demos/stocqt/content/StockListModel.qml66
-rw-r--r--examples/quick/demos/stocqt/content/StockListView.qml60
-rw-r--r--examples/quick/shared/shared.h1
3 files changed, 67 insertions, 60 deletions
diff --git a/examples/quick/demos/stocqt/content/StockListModel.qml b/examples/quick/demos/stocqt/content/StockListModel.qml
index be00e7bb1c..9b48124bda 100644
--- a/examples/quick/demos/stocqt/content/StockListModel.qml
+++ b/examples/quick/demos/stocqt/content/StockListModel.qml
@@ -42,6 +42,72 @@ import QtQuick 2.0
ListModel {
id: stocks
+
+ // pre-fetch data for all entries
+ Component.onCompleted: {
+ for (var idx = 0; idx < count; ++idx) {
+ getCloseValue(idx)
+ }
+ }
+
+ 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);
+
+ if (!req)
+ return;
+
+ var xhr = new XMLHttpRequest;
+
+ xhr.open("GET", req, true);
+
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState === XMLHttpRequest.LOADING || xhr.readyState === XMLHttpRequest.DONE) {
+ var records = xhr.responseText.split('\n');
+ if (records.length > 0 && xhr.status == 200) {
+ var r = records[1].split(',');
+ var today = parseFloat(r[4]);
+ setProperty(index, "value", today.toFixed(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
+ setProperty(index, "change", change.toFixed(2));
+
+ var changePercentage = (change / yesterday) * 100.0;
+ if (changePercentage >= 0.0)
+ setProperty(index, "changePercentage", "+" + changePercentage.toFixed(2) + "%");
+ else
+ setProperty(index, "changePercentage", changePercentage.toFixed(2) + "%");
+ } else {
+ var unknown = "n/a";
+ set(index, {"value": unknown, "change": unknown, "changePercentage": unknown});
+ }
+ }
+ }
+ xhr.send()
+ }
// Uncomment to test invalid entries
// ListElement {name: "The Qt Company"; stockId: "TQTC"; value: "999.0"; change: "0.0"; changePercentage: "0.0"}
diff --git a/examples/quick/demos/stocqt/content/StockListView.qml b/examples/quick/demos/stocqt/content/StockListView.qml
index 59f36b42cc..d2bd52a69d 100644
--- a/examples/quick/demos/stocqt/content/StockListView.qml
+++ b/examples/quick/demos/stocqt/content/StockListView.qml
@@ -64,65 +64,6 @@ Rectangle {
model: StockListModel{}
currentIndex: -1 // Don't pre-select any item
- 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(model.get(index).stockId);
-
- if (!req)
- return;
-
- var xhr = new XMLHttpRequest;
-
- xhr.open("GET", req, true);
-
- xhr.onreadystatechange = function() {
- if (xhr.readyState === XMLHttpRequest.LOADING || xhr.readyState === XMLHttpRequest.DONE) {
- var records = xhr.responseText.split('\n');
- if (records.length > 0 && xhr.status == 200) {
- var r = records[1].split(',');
- var today = parseFloat(r[4]);
- model.setProperty(index, "value", today.toFixed(2));
-
- r = records[2].split(',');
- var yesterday = parseFloat(r[4]);
- var change = today - yesterday;
- if (change >= 0.0)
- model.setProperty(index, "change", "+" + change.toFixed(2));
- else
- model.setProperty(index, "change", change.toFixed(2));
-
- var changePercentage = (change / yesterday) * 100.0;
- if (changePercentage >= 0.0)
- 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});
- }
- }
- }
- xhr.send()
- }
-
onCurrentIndexChanged: {
if (currentItem) {
root.currentStockId = model.get(currentIndex).stockId;
@@ -175,7 +116,6 @@ Rectangle {
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: value
- Component.onCompleted: view.getCloseValue(index);
}
Text {
diff --git a/examples/quick/shared/shared.h b/examples/quick/shared/shared.h
index d8fb80b97e..0eed618d9d 100644
--- a/examples/quick/shared/shared.h
+++ b/examples/quick/shared/shared.h
@@ -44,6 +44,7 @@
#include <QQuickView> //Not using QQmlApplicationEngine because many examples don't have a Window{}
#define DECLARATIVE_EXAMPLE_MAIN(NAME) int main(int argc, char* argv[]) \
{\
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\
QGuiApplication app(argc,argv);\
app.setOrganizationName("QtProject");\
app.setOrganizationDomain("qt-project.org");\