diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-02-10 18:17:11 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-04-13 14:52:35 +0000 |
commit | a8193faf3ee531a701706cc23cf7556275d505a0 (patch) | |
tree | 8dd682b95fce3d6e25426f0ca2adfe5b0b10be85 /examples | |
parent | b36d26bbddeff8bfe23b526612ce135b418ac9a8 (diff) |
Add qtquickcontrols window to mapviewer.
Change-Id: I0dfbb86eb2566a1a0f551b5f21abf6e4574a2de3
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/location/mapviewer/mapviewer.qml | 278 | ||||
-rw-r--r-- | examples/location/mapviewer/qmlmapviewerwrapper.cpp | 21 |
2 files changed, 153 insertions, 146 deletions
diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index b8fef415..b13d4179 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -38,21 +38,159 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick 2.4 +import QtQuick.Controls 1.3 import QtLocation 5.3 import QtPositioning 5.2 import QtLocation.examples 5.0 import "content/map" import "content/dialogs" -Item { - id: page - width: parent ? parent.width : 360 - height: parent ? parent.height : 640 +ApplicationWindow { + id: appWindow + title: qsTr("Mapviewer") + height: 640 + width: 360 + visible: true + property variant map property variant minimap property variant parameters + function geocodeMessage(){ + var street, district, city, county, state, countryCode, country, postalCode, latitude, longitude, text + latitude = Math.round(map.geocodeModel.get(0).coordinate.latitude * 10000) / 10000 + longitude =Math.round(map.geocodeModel.get(0).coordinate.longitude * 10000) / 10000 + street = map.geocodeModel.get(0).address.street + district = map.geocodeModel.get(0).address.district + city = map.geocodeModel.get(0).address.city + county = map.geocodeModel.get(0).address.county + state = map.geocodeModel.get(0).address.state + countryCode = map.geocodeModel.get(0).address.countryCode + country = map.geocodeModel.get(0).address.country + postalCode = map.geocodeModel.get(0).address.postalCode + + text = "<b>Latitude:</b> " + latitude + "<br/>" + text +="<b>Longitude:</b> " + longitude + "<br/>" + "<br/>" + if (street) text +="<b>Street: </b>"+ street + " <br/>" + if (district) text +="<b>District: </b>"+ district +" <br/>" + if (city) text +="<b>City: </b>"+ city + " <br/>" + if (county) text +="<b>County: </b>"+ county + " <br/>" + if (state) text +="<b>State: </b>"+ state + " <br/>" + if (countryCode) text +="<b>Country code: </b>"+ countryCode + " <br/>" + if (country) text +="<b>Country: </b>"+ country + " <br/>" + if (postalCode) text +="<b>PostalCode: </b>"+ postalCode + " <br/>" + return text + } + + function createMap(provider){ + var plugin + if (parameters && parameters.length>0) + plugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin{ name:"' + provider + '"; parameters: appWindow.parameters}', page) + else + plugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin{ name:"' + provider + '"}', page) + + if (map) { + map.destroy() + minimap = null + } + + map = Qt.createQmlObject ('import QtLocation 5.3;\ + import "content/map";\ + MapComponent{\ + z : backgroundRect.z + 1;\ + width: page.width;\ + height: page.height - mainMenu.height;\ + onFollowmeChanged: {toolsMenu.update()}\ + onSupportedMapTypesChanged: {mapTypeMenu.update()}\ + onCoordinatesCaptured: {\ + messageDialog.state = "Coordinates";\ + messageDialog.text = "<b>Latitude:</b> " + roundNumber(latitude,4) + "<br/><b>Longitude:</b> " + roundNumber(longitude,4);\ + page.state = "Message";\ + }\ + onGeocodeFinished:{\ + if (map.geocodeModel.status == GeocodeModel.Ready){\ + if (map.geocodeModel.count == 0) {messageDialog.state = "UnknownGeocodeError";}\ + else if (map.geocodeModel.count > 1) {messageDialog.state = "AmbiguousGeocode";}\ + else {messageDialog.state = "LocationInfo";}\ + }\ + else if (map.geocodeModel.status == GeocodeModel.Error) {messageDialog.state = "GeocodeError";}\ + page.state = "Message";\ + }\ + onShowDistance:{\ + messageDialog.state = "Distance";\ + messageDialog.text = "<b>Distance:</b> " + distance;\ + page.state = "Message";\ + }\ + onMoveMarker: {\ + page.state = "Coordinates";\ + }\ + onRouteError: {\ + messageDialog.state = "RouteError";\ + page.state = "Message";\ + }\ + onRequestLocale:{\ + page.state = "Locale";\ + }\ + onShowGeocodeInfo:{\ + messageDialog.state = "LocationInfo";\ + page.state = "Message";\ + }\ + onResetState: {\ + page.state = "";\ + }\ + onErrorChanged: {\ + if (map.error != Map.NoError) {\ + messageDialog.state = "ProviderError";\ + messageDialog.text = map.errorString + "<br/><br/><b>Try to select other provider</b>";\ + if (map.error == Map.MissingRequiredParameterError) \ + messageDialog.text += "<br/>or see \'mapviewer --help\'\ + how to pass plugin parameters.";\ + page.state = "Message";\ + }\ + }\ + }',page) + + + map.plugin = plugin; + tempGeocodeModel.plugin = plugin; + mapTypeMenu.update(); + toolsMenu.update(); + } + + function getPlugins(){ + var plugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin {}', page) + var tempPlugin + var myArray = new Array() + for (var i = 0; i<plugin.availableServiceProviders.length; i++){ + tempPlugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin {name: "' + plugin.availableServiceProviders[i]+ '"}', page) + if (tempPlugin.supportsMapping()) + myArray.push(tempPlugin.name) + } + myArray.sort() + return myArray + } + + function setPluginParameters(pluginParameters) { + var parameters = new Array() + for (var prop in pluginParameters){ + var parameter = Qt.createQmlObject('import QtLocation 5.3; PluginParameter{ name: "'+ prop + '"; value: "' + pluginParameters[prop]+'"}',page) + parameters.push(parameter) + } + appWindow.parameters=parameters + if (providerMenu.exclusiveButton !== "") + createMap(providerMenu.exclusiveButton); + else if (providerMenu.children.length > 0) { + providerMenu.exclusiveButton = providerMenu.children[0].text + } + } + +Item { + id: page + //fixme + width: appWindow.width + height: appWindow.height + Rectangle { id: backgroundRect anchors.fill: parent @@ -494,135 +632,6 @@ Item { } } - function geocodeMessage(){ - var street, district, city, county, state, countryCode, country, postalCode, latitude, longitude, text - latitude = Math.round(map.geocodeModel.get(0).coordinate.latitude * 10000) / 10000 - longitude =Math.round(map.geocodeModel.get(0).coordinate.longitude * 10000) / 10000 - street = map.geocodeModel.get(0).address.street - district = map.geocodeModel.get(0).address.district - city = map.geocodeModel.get(0).address.city - county = map.geocodeModel.get(0).address.county - state = map.geocodeModel.get(0).address.state - countryCode = map.geocodeModel.get(0).address.countryCode - country = map.geocodeModel.get(0).address.country - postalCode = map.geocodeModel.get(0).address.postalCode - - text = "<b>Latitude:</b> " + latitude + "<br/>" - text +="<b>Longitude:</b> " + longitude + "<br/>" + "<br/>" - if (street) text +="<b>Street: </b>"+ street + " <br/>" - if (district) text +="<b>District: </b>"+ district +" <br/>" - if (city) text +="<b>City: </b>"+ city + " <br/>" - if (county) text +="<b>County: </b>"+ county + " <br/>" - if (state) text +="<b>State: </b>"+ state + " <br/>" - if (countryCode) text +="<b>Country code: </b>"+ countryCode + " <br/>" - if (country) text +="<b>Country: </b>"+ country + " <br/>" - if (postalCode) text +="<b>PostalCode: </b>"+ postalCode + " <br/>" - return text - } - - function createMap(provider){ - var plugin - if (parameters && parameters.length > 0) - plugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin{ name:"' + provider + '"; parameters: page.parameters}', page) - else - plugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin{ name:"' + provider + '"}', page) - - if (map) { - map.destroy() - minimap = null - } - - map = Qt.createQmlObject ('import QtLocation 5.3;\ - import "content/map";\ - MapComponent{\ - z : backgroundRect.z + 1;\ - width: page.width;\ - height: page.height - mainMenu.height;\ - onFollowmeChanged: {toolsMenu.update()}\ - onSupportedMapTypesChanged: {mapTypeMenu.update()}\ - onCoordinatesCaptured: {\ - messageDialog.state = "Coordinates";\ - messageDialog.text = "<b>Latitude:</b> " + roundNumber(latitude,4) + "<br/><b>Longitude:</b> " + roundNumber(longitude,4);\ - page.state = "Message";\ - }\ - onGeocodeFinished:{\ - if (map.geocodeModel.status == GeocodeModel.Ready){\ - if (map.geocodeModel.count == 0) {messageDialog.state = "UnknownGeocodeError";}\ - else if (map.geocodeModel.count > 1) {messageDialog.state = "AmbiguousGeocode";}\ - else {messageDialog.state = "LocationInfo";}\ - }\ - else if (map.geocodeModel.status == GeocodeModel.Error) {messageDialog.state = "GeocodeError";}\ - page.state = "Message";\ - }\ - onShowDistance:{\ - messageDialog.state = "Distance";\ - messageDialog.text = "<b>Distance:</b> " + distance;\ - page.state = "Message";\ - }\ - onMoveMarker: {\ - page.state = "Coordinates";\ - }\ - onRouteError: {\ - messageDialog.state = "RouteError";\ - page.state = "Message";\ - }\ - onRequestLocale:{\ - page.state = "Locale";\ - }\ - onShowGeocodeInfo:{\ - messageDialog.state = "LocationInfo";\ - page.state = "Message";\ - }\ - onResetState: {\ - page.state = "";\ - }\ - onErrorChanged: {\ - if (map.error != Map.NoError) {\ - messageDialog.state = "ProviderError";\ - messageDialog.text = map.errorString + "<br/><br/><b>Try to select other provider</b>";\ - if (map.error == Map.MissingRequiredParameterError) \ - messageDialog.text += "<br/>or see \'mapviewer --help\'\ - how to pass plugin parameters.";\ - page.state = "Message";\ - }\ - }\ - }',page) - - - map.plugin = plugin; - tempGeocodeModel.plugin = plugin; - mapTypeMenu.update(); - toolsMenu.update(); - - } - - function getPlugins(){ - var plugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin {}', page) - var tempPlugin - var myArray = new Array() - for (var i = 0; i<plugin.availableServiceProviders.length; i++){ - tempPlugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin {name: "' + plugin.availableServiceProviders[i]+ '"}', page) - if (tempPlugin.supportsMapping()) - myArray.push(tempPlugin.name) - } - myArray.sort() - return myArray - } - - function setPluginParameters(pluginParameters) { - var parameters = new Array() - for (var prop in pluginParameters){ - var parameter = Qt.createQmlObject('import QtLocation 5.3; PluginParameter{ name: "'+ prop + '"; value: "' + pluginParameters[prop]+'"}',page) - parameters.push(parameter) - } - page.parameters=parameters - if (providerMenu.exclusiveButton !== "") - createMap(providerMenu.exclusiveButton); - else if (providerMenu.children.length > 0) { - providerMenu.exclusiveButton = providerMenu.children[0].text - } - } - //=====================States of page===================== states: [ State { @@ -703,3 +712,4 @@ Item { } ] } +} diff --git a/examples/location/mapviewer/qmlmapviewerwrapper.cpp b/examples/location/mapviewer/qmlmapviewerwrapper.cpp index cd82ac27..18504b81 100644 --- a/examples/location/mapviewer/qmlmapviewerwrapper.cpp +++ b/examples/location/mapviewer/qmlmapviewerwrapper.cpp @@ -41,7 +41,7 @@ #include <QtCore/QStringList> #include <QtCore/QTextStream> #include <QtGui/QGuiApplication> -#include <QtQml/QQmlEngine> +#include <QtQml/QQmlApplicationEngine> #include <QtQml/QQmlContext> #include <QtQuick/QQuickView> #include <QtQuick/QQuickItem> @@ -95,20 +95,17 @@ int main(int argc, char *argv[]) if (parseArgs(args, parameters)) exit(0); const QString mainQmlApp = QLatin1String("qrc:///mapviewer.qml"); - QQuickView view; - view.engine()->addImportPath(QLatin1String(":/imports")); + QQmlApplicationEngine engine; - view.rootContext()->setContextProperty("appDirPath", QCoreApplication::applicationDirPath()); - view.setSource(QUrl(mainQmlApp)); - view.setResizeMode(QQuickView::SizeRootObjectToView); - - QQuickItem *object = view.rootObject(); - QMetaObject::invokeMethod(object, "setPluginParameters", + engine.addImportPath(QLatin1String(":/imports")); + engine.rootContext()->setContextProperty("appDirPath", QCoreApplication::applicationDirPath()); + engine.load(QUrl(mainQmlApp)); + QObject *item = engine.rootObjects().first(); + Q_ASSERT(item); + QMetaObject::invokeMethod(item, "setPluginParameters", Q_ARG(QVariant, QVariant::fromValue(parameters))); - QObject::connect(view.engine(), SIGNAL(quit()), qApp, SLOT(quit())); - view.setGeometry(QRect(100, 100, 360, 640)); - view.show(); + QObject::connect(&engine, SIGNAL(quit()), qApp, SLOT(quit())); return application.exec(); } |