From 135b48dd0c1c6893109238716019c2283d5a3561 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 10 Feb 2015 18:17:11 +0100 Subject: Rewirte mapviewer main menu handling. Use qtquickcontrols for provider, maptypes and tools menu. Change-Id: I0805e9af7ed8eed2a0d4422e543c79dd3183c3af Reviewed-by: Alex Blasche --- examples/location/mapviewer/MainMenu.qml | 123 ++++++++++ examples/location/mapviewer/mapviewer.qml | 252 ++++++--------------- examples/location/mapviewer/mapviewerwrapper.qrc | 1 + .../location/mapviewer/qmlmapviewerwrapper.cpp | 2 +- 4 files changed, 192 insertions(+), 186 deletions(-) create mode 100644 examples/location/mapviewer/MainMenu.qml 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; i0) 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 = "Latitude: " + roundNumber(latitude,4) + "
Longitude: " + 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 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; icontent/dialogs/RouteDialog.qml content/map/ImageItem.qml content/map/MiniMap.qml + MainMenu.qml 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())); -- cgit v1.2.1