diff --git a/Calendar.qml b/Calendar.qml index 52b84aa..7920c11 100644 --- a/Calendar.qml +++ b/Calendar.qml @@ -4,13 +4,11 @@ import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.2 -Rectangle { +MirrorWindow { id: root -// width: 360 -// height: 700 color: "black" - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter + windowHeight: 3 + windowWidth: 1 ListView { anchors.fill: parent diff --git a/JSONListModel.qml b/JSONListModel.qml new file mode 100644 index 0000000..edb9de2 --- /dev/null +++ b/JSONListModel.qml @@ -0,0 +1,52 @@ +/* JSONListModel - a QML ListModel with JSON and JSONPath support + * + * Copyright (c) 2012 Romain Pokrzywka (KDAB) (romain@kdab.com) + * Licensed under the MIT licence (http://opensource.org/licenses/mit-license.php) + */ + +import QtQuick 2.2 +import "jsonpath.js" as JSONPath + +Item { + property string source: "" + property string json: "" + property string query: "" + + property ListModel model : ListModel { id: jsonModel } + property alias count: jsonModel.count + + onSourceChanged: { + var xhr = new XMLHttpRequest; + xhr.open("GET", source); + xhr.onreadystatechange = function() { + if (xhr.readyState == XMLHttpRequest.DONE) + json = xhr.responseText; + } + xhr.send(); + } + + onJsonChanged: updateJSONModel() + onQueryChanged: updateJSONModel() + + function updateJSONModel() { + jsonModel.clear(); + + if ( json === "" ) + return; + + var objectArray = parseJSONString(json, query); + for ( var key in objectArray ) { + var jo = objectArray[key]; + console.log(jo); + jsonModel.append( jo ); + } + } + + function parseJSONString(jsonString, jsonPathQuery) { + var objectArray = JSON.parse(jsonString); + if ( jsonPathQuery !== "" ) + objectArray = JSONPath.jsonPath(objectArray, jsonPathQuery); + + return objectArray; + } +} diff --git a/QmlMirror.pro b/QmlMirror.pro index b3ab271..4a9ec3f 100644 --- a/QmlMirror.pro +++ b/QmlMirror.pro @@ -24,4 +24,6 @@ DISTFILES += \ Calendar.qml \ lala.qml \ MirrorText.qml \ - MirrorWindow.qml + MirrorWindow.qml \ + JSONListModel.qml \ + jsonpath.js diff --git a/QmlMirror.qml b/QmlMirror.qml index 7beb105..35c2caa 100644 --- a/QmlMirror.qml +++ b/QmlMirror.qml @@ -8,6 +8,7 @@ import QtQuick 2.2 import QtQuick.Controls 1.1 +import QtQuick.Layouts 1.1 import QtQuick.Window 2.0 Rectangle { @@ -22,38 +23,30 @@ Rectangle { height: 100 } - Clock { - id: clockId - anchors.top: positionId.bottom - anchors.left: parent.left - width: 360 - } - - Calendar { - anchors.top: clockId.bottom - anchors.left: parent.left - width: 360 - height: 480 - } Rectangle { - id: weatherId - width: 360 - height: 400 anchors.top: positionId.bottom - anchors.right: parent.right - Weather { - width: 360 - height: 400 + width: 1080 + Row { + Column { + Clock { + } + TaskWarrior { + } + } + + Column { + MirrorWindow {} + } + + Column { + Weather { + } + + Transport { + id: transportId + } + } } } - - Transport { - id: transportId - anchors.top: weatherId.bottom - anchors.right: parent.right - width: 360 - height: 400 - } - } diff --git a/TaskWarrior.qml b/TaskWarrior.qml index e79dcd1..4bd7e73 100644 --- a/TaskWarrior.qml +++ b/TaskWarrior.qml @@ -4,8 +4,7 @@ import QtQuick 2.2 Rectangle { id: root - anchors.fill: parent - color: "white" + color: "black" property string fileName: "jsondata.txt" @@ -23,6 +22,7 @@ Rectangle { delegate: Text { text: model.description + color: "white" Component.onCompleted: { console.log("Text: " + text) } diff --git a/Transport.qml b/Transport.qml index 854edce..06fc70f 100644 --- a/Transport.qml +++ b/Transport.qml @@ -11,8 +11,9 @@ import QtQuick.Layouts 1.1 import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.2 -Item { +MirrorWindow { id: root + windowHeight: 3 ListModel { id: lineModel diff --git a/Weather.qml b/Weather.qml index 59d589d..5329e8f 100644 --- a/Weather.qml +++ b/Weather.qml @@ -10,8 +10,10 @@ import QtQuick 2.0 import net.frozentux.weatherinfo 1.0 -Rectangle { +MirrorWindow { color: "black" + windowHeight: 3 + WeatherInfo { id: weatherdata diff --git a/jsonpath.js b/jsonpath.js new file mode 100644 index 0000000..8107803 --- /dev/null +++ b/jsonpath.js @@ -0,0 +1,88 @@ +/* JSONPath 0.8.5 - XPath for JSON + * + * Copyright (c) 2007 Stefan Goessner (goessner.net) + * Licensed under the MIT (MIT-LICENSE.txt) licence. + * + */ +function jsonPath(obj, expr, arg) { + var P = { + resultType: arg && arg.resultType || "VALUE", + result: [], + normalize: function(expr) { + var subx = []; + return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){return "[#"+(subx.push($1||$2)-1)+"]";}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */ + .replace(/'?\.'?|\['?/g, ";") + .replace(/;;;|;;/g, ";..;") + .replace(/;$|'?\]|'$/g, "") + .replace(/#([0-9]+)/g, function($0,$1){return subx[$1];}); + }, + asPath: function(path) { + var x = path.split(";"), p = "$"; + for (var i=1,n=x.length; ithrottle.start(); if (d->nErrors < 10) ++d->nErrors; @@ -377,6 +380,8 @@ void AppModel::refreshWeather() query.addQueryItem("q", d->city); query.addQueryItem("mode", "json"); + query.addQueryItem("APPID", "42c2f93b39eed8f38f08e8ddc321d98f"); + url.setQuery(query); QNetworkReply *rep = d->nam->get(QNetworkRequest(url)); @@ -435,6 +440,7 @@ void AppModel::handleWeatherNetworkData(QObject *replyObj) query.addQueryItem("q", d->city); query.addQueryItem("mode", "json"); query.addQueryItem("cnt", "5"); + query.addQueryItem("APPID", "42c2f93b39eed8f38f08e8ddc321d98f"); url.setQuery(query); QNetworkReply *rep = d->nam->get(QNetworkRequest(url));