summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-02-10 18:17:11 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2015-04-13 14:52:48 +0000
commit135b48dd0c1c6893109238716019c2283d5a3561 (patch)
tree8f78680f55600b14073b0a6a31f0cb41cbfef12c
parent8fc647f7c458de87739f45cf3e4cd47d0d35e91b (diff)
downloadqtlocation-135b48dd0c1c6893109238716019c2283d5a3561.tar.gz
Rewirte mapviewer main menu handling.
Use qtquickcontrols for provider, maptypes and tools menu. Change-Id: I0805e9af7ed8eed2a0d4422e543c79dd3183c3af Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--examples/location/mapviewer/MainMenu.qml123
-rw-r--r--examples/location/mapviewer/mapviewer.qml252
-rw-r--r--examples/location/mapviewer/mapviewerwrapper.qrc1
-rw-r--r--examples/location/mapviewer/qmlmapviewerwrapper.cpp2
4 files changed, 192 insertions, 186 deletions
diff --git a/examples/location/mapviewer/MainMenu.qml b/examples/location/mapviewer/MainMenu.qml
new file mode 100644
index 00000000..fb982bd5
--- /dev/null
+++ b/examples/location/mapviewer/MainMenu.qml
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.4
+import QtQuick.Controls 1.3
+import QtLocation 5.3
+
+MenuBar {
+
+ property variant providerMenu: providerMenu
+ property variant mapTypeMenu: mapTypeMenu
+ property variant toolsMenu: toolsMenu
+ property alias isFollowMe: toolsMenu.isFollowMe
+ property alias isMiniMap: toolsMenu.isMiniMap
+
+ signal selectProvider(string providerName)
+ signal selectMapType(variant mapType)
+ signal selectTool(string tool);
+ signal toggleMapState(string state)
+
+ Menu {
+ id: providerMenu
+ title: qsTr("Provider")
+
+ function createMenu(plugins){
+ clear()
+ for (var i = 0; i < plugins.length; i++) {
+ createProviderMenuItem(plugins[i]);
+ }
+ }
+
+ function createProviderMenuItem(provider){
+ var item = addItem(provider);
+ item.checkable = true;
+ item.triggered.connect(function(){selectProvider(provider)})
+ }
+ }
+
+ Menu {
+ id: mapTypeMenu
+ title: qsTr("MapType")
+
+ function createMenu(map){
+ clear()
+ for (var i = 0; i<map.supportedMapTypes.length; i++) {
+ createMapTypeMenuItem(map.supportedMapTypes[i]).checked =
+ (map.activeMapType === map.supportedMapTypes[i]);
+ }
+ }
+
+ function createMapTypeMenuItem(mapType){
+ var item = addItem(mapType.name);
+ item.checkable = true;
+ item.triggered.connect(function(){selectMapType(mapType)})
+ return item;
+ }
+ }
+
+ Menu {
+ id: toolsMenu
+ title: qsTr("Tools")
+ property bool isFollowMe: false;
+ property bool isMiniMap: false;
+
+ function createMenu(map){
+ clear()
+ if (map.plugin.supportsGeocoding(Plugin.ReverseGeocodingFeature)) {
+ addItem(qsTr("Reverse geocode")).triggered.connect(function(){selectTool("RevGeocode")})
+ }
+ if (map.plugin.supportsGeocoding()) {
+ addItem(qsTr("Geocode")).triggered.connect(function(){selectTool("Geocode")})
+ }
+ if (map.plugin.supportsRouting()) {
+ addItem(qsTr("Route")).triggered.connect(function(){selectTool("Route")})
+ }
+
+ var item = addItem("")
+ item.text = Qt.binding(function() { return isMiniMap ? qsTr("Hide minimap") : qsTr("Minimap") })
+ item.triggered.connect(function() {toggleMapState("MiniMap")})
+
+ item = addItem("")
+ item.text = Qt.binding(function() { return isFollowMe ? qsTr("Stop following") : qsTr("Follow me")})
+ item.triggered.connect(function() {toggleMapState("FollowMe")})
+ }
+ }
+}
diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml
index f6f90f84..7091d3e9 100644
--- a/examples/location/mapviewer/mapviewer.qml
+++ b/examples/location/mapviewer/mapviewer.qml
@@ -42,7 +42,7 @@ import QtQuick 2.4
import QtQuick.Controls 1.3
import QtLocation 5.3
import QtPositioning 5.2
-import QtLocation.examples 5.0
+import QtLocation.examples 5.0 as OwnControls
import "content/map"
import "content/dialogs"
@@ -57,6 +57,56 @@ ApplicationWindow {
property variant minimap
property variant parameters
+ menuBar: MainMenu {
+ id: mainMenu
+
+ onSelectProvider: {
+ for (var i = 0; i < providerMenu.items.length; i++) {
+ providerMenu.items[i].checked = providerMenu.items[i].text === providerName
+ }
+ if (minimap) {
+ minimap.destroy()
+ minimap = null
+ }
+ createMap(providerName)
+ if (map.error === Map.NoError) {
+ selectMapType(map.activeMapType)
+ toolsMenu.createMenu(map);
+ } else {
+ mapTypeMenu.clear();
+ toolsMenu.clear();
+ }
+ }
+
+ onSelectMapType: {
+ for (var i = 0; i < mapTypeMenu.items.length; i++) {
+ mapTypeMenu.items[i].checked = mapTypeMenu.items[i].text === mapType.name
+ }
+ map.activeMapType = mapType
+ }
+
+ onSelectTool: {
+ page.state = tool;
+ }
+
+ onToggleMapState: {
+ if (state === "MiniMap") {
+ if (minimap) {
+ minimap.destroy()
+ minimap = null
+ isMiniMap = false
+ } else {
+ minimap = Qt.createQmlObject ('import "content/map"; MiniMap{ z: map.z + 2 }', map)
+ isMiniMap = true
+ }
+ page.state = ""
+ } else if (state === "FollowMe") {
+ map.followme =! map.followme;
+ page.state = ""
+ }
+ }
+ }
+
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
@@ -85,6 +135,7 @@ ApplicationWindow {
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
@@ -100,9 +151,9 @@ ApplicationWindow {
MapComponent{\
z : backgroundRect.z + 1;\
width: page.width;\
- height: page.height - mainMenu.height;\
- onFollowmeChanged: {toolsMenu.update()}\
- onSupportedMapTypesChanged: {mapTypeMenu.update()}\
+ height: page.height;\
+ onFollowmeChanged: {mainMenu.isFollowMe = map.followme}\
+ onSupportedMapTypesChanged: {mainMenu.mapTypeMenu.createMenu(map)}\
onCoordinatesCaptured: {\
messageDialog.state = "Coordinates";\
messageDialog.text = "<b>Latitude:</b> " + roundNumber(latitude,4) + "<br/><b>Longitude:</b> " + roundNumber(longitude,4);\
@@ -150,13 +201,9 @@ ApplicationWindow {
}\
}\
}',page)
-
-
map.plugin = plugin;
map.zoomLevel = (map.maximumZoomLevel - map.minimumZoomLevel)/2
tempGeocodeModel.plugin = plugin;
- mapTypeMenu.update();
- toolsMenu.update();
}
function getPlugins(){
@@ -172,25 +219,24 @@ ApplicationWindow {
return myArray
}
- function setPluginParameters(pluginParameters) {
+ function initializeProvders(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
+ appWindow.parameters = parameters
+ var plugins = getPlugins()
+ mainMenu.providerMenu.createMenu(plugins)
+ for (var i = 0; i<plugins.length; i++) {
+ if (plugins[i] === "osm")
+ mainMenu.selectProvider(plugins[i])
}
}
Item {
id: page
- //fixme
- width: appWindow.width
- height: appWindow.height
+ anchors.fill: parent
Rectangle {
id: backgroundRect
@@ -199,146 +245,6 @@ Item {
z:2
}
- //=====================Menu=====================
- Menu {
- id:mainMenu
- anchors.bottom: parent.bottom
- z: backgroundRect.z + 3
-
- Component.onCompleted: {
- addItem("Tools")
- addItem("Map Type")
- addItem("Provider")
- }
-
- onClicked: {
- switch (button) {
- case "Tools": {
- page.state = "Tools"
- break;
- }
- case "Map Type": {
- page.state = "MapType"
- break;
- }
- case "Provider": {
- page.state = "Provider"
- break;
- }
- }
- }
- }
-
- Menu {
- id: toolsMenu
- z: backgroundRect.z + 2
- y: page.height
- horizontalOrientation: false
-
- onClicked: {
- switch (button) {
- case "Reverse geocode": {
- page.state = "RevGeocode"
- break;
- }
- case "Geocode": {
- page.state = "Geocode"
- break;
- }
- case "Route": {
- page.state = "Route"
- break;
- }
- case "Follow me": {
- map.followme =true
- page.state = ""
- break;
- }
- case "Stop following": {
- map.followme =false
- page.state = ""
- break;
- }
- case "Minimap": {
- minimap = Qt.createQmlObject ('import "content/map"; MiniMap{ z: map.z + 2 }', map)
- page.state = ""
- break;
- }
- case "Hide minimap": {
- if (minimap) minimap.destroy()
- minimap = null
- page.state = ""
- break;
- }
- }
- }
- function update(){
- clear()
- if (map.plugin.supportsGeocoding(Plugin.ReverseGeocodingFeature)) {
- addItem("Reverse geocode")
- }
- if (map.plugin.supportsGeocoding()) {
- addItem("Geocode")
- }
- if (map.plugin.supportsRouting()) {
- addItem("Route")
- }
- var item = addItem("Follow me")
- item.text = Qt.binding(function() { return map.followme ? "Stop following" : "Follow me" });
- item = addItem("Minimap")
- item.text = Qt.binding(function() { return minimap ? "Hide minimap" : "Minimap" });
- }
- }
-
- Menu {
- id: mapTypeMenu
- z: backgroundRect.z + 2
- y: page.height
- horizontalOrientation: false
- exclusive: true
-
- onClicked: {
- page.state = ""
- }
-
- onExclusiveButtonChanged: {
- for (var i = 0; i<map.supportedMapTypes.length; i++){
- if (exclusiveButton == map.supportedMapTypes[i].name){
- map.activeMapType = map.supportedMapTypes[i]
- break;
- }
- }
- }
-
- function update(){
- clear()
- for (var i = 0; i<map.supportedMapTypes.length; i++)
- addItem(map.supportedMapTypes[i].name)
-
- if (map.supportedMapTypes.length > 0)
- exclusiveButton = map.activeMapType.name
- }
- }
-
- Menu {
- id: providerMenu
- z: backgroundRect.z + 2
- y: page.height
- horizontalOrientation: false
- exclusive: true
-
- Component.onCompleted: {
- var plugins = getPlugins()
- for (var i = 0; i<plugins.length; i++) {
- addItem(plugins[i])
- if (plugins[i] === "osm")
- exclusiveButton = plugins[i]
- }
- }
-
- onExclusiveButtonChanged: createMap(exclusiveButton)
- }
-
//=====================Dialogs=====================
Message {
id: messageDialog
@@ -515,7 +421,7 @@ Item {
//Geocode Dialog
//! [geocode0]
- InputDialog {
+ OwnControls.InputDialog {
id: geocodeDialog
//! [geocode0]
title: "Geocode"
@@ -557,7 +463,7 @@ Item {
//! [geocode2]
//Reverse Geocode Dialog
- InputDialog {
+ OwnControls.InputDialog {
id: reverseGeocodeDialog
title: "Reverse Geocode"
z: backgroundRect.z + 2
@@ -581,7 +487,7 @@ Item {
}
//Get new coordinates for marker
- InputDialog {
+ OwnControls.InputDialog {
id: coordinatesDialog
title: "New coordinates"
z: backgroundRect.z + 2
@@ -612,7 +518,7 @@ Item {
}
//Get new locale
- InputDialog {
+ OwnControls.InputDialog {
id: localeDialog
title: "New Locale"
z: backgroundRect.z + 2
@@ -656,18 +562,6 @@ Item {
PropertyChanges { target: messageDialog; opacity: 1 }
},
State {
- name : "Tools"
- PropertyChanges { target: toolsMenu; y: page.height - toolsMenu.height - mainMenu.height }
- },
- State {
- name : "Provider"
- PropertyChanges { target: providerMenu; y: page.height - providerMenu.height - mainMenu.height }
- },
- State {
- name : "MapType"
- PropertyChanges { target: mapTypeMenu; y: page.height - mapTypeMenu.height - mainMenu.height }
- },
- State {
name : "Locale"
PropertyChanges { target: localeDialog; opacity: 1 }
}
@@ -698,18 +592,6 @@ Item {
Transition {
to: ""
NumberAnimation { properties: "opacity" ; duration: 500; easing.type: Easing.Linear }
- },
- Transition {
- to: "Provider"
- NumberAnimation { properties: "y" ; duration: 300; easing.type: Easing.Linear }
- },
- Transition {
- to: "MapType"
- NumberAnimation { properties: "y" ; duration: 300; easing.type: Easing.Linear }
- },
- Transition {
- to: "Tools"
- NumberAnimation { properties: "y" ; duration: 300; easing.type: Easing.Linear }
}
]
}
diff --git a/examples/location/mapviewer/mapviewerwrapper.qrc b/examples/location/mapviewer/mapviewerwrapper.qrc
index e8fe4df6..c77cb95c 100644
--- a/examples/location/mapviewer/mapviewerwrapper.qrc
+++ b/examples/location/mapviewer/mapviewerwrapper.qrc
@@ -12,5 +12,6 @@
<file>content/dialogs/RouteDialog.qml</file>
<file>content/map/ImageItem.qml</file>
<file>content/map/MiniMap.qml</file>
+ <file>MainMenu.qml</file>
</qresource>
</RCC>
diff --git a/examples/location/mapviewer/qmlmapviewerwrapper.cpp b/examples/location/mapviewer/qmlmapviewerwrapper.cpp
index 18504b81..cda642ec 100644
--- a/examples/location/mapviewer/qmlmapviewerwrapper.cpp
+++ b/examples/location/mapviewer/qmlmapviewerwrapper.cpp
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
engine.load(QUrl(mainQmlApp));
QObject *item = engine.rootObjects().first();
Q_ASSERT(item);
- QMetaObject::invokeMethod(item, "setPluginParameters",
+ QMetaObject::invokeMethod(item, "initializeProvders",
Q_ARG(QVariant, QVariant::fromValue(parameters)));
QObject::connect(&engine, SIGNAL(quit()), qApp, SLOT(quit()));