mapwidgetcontextmenu: add the actionSelected() signal

The actionSelected() signal is now dispatched when the user selects
an action from the menu (see the "actions" object). Then the declaration
of the MapWidgetContextMenu object in mapwidget.qml can catch that
signal in the onActionSelected() slot and obtain the action via
switch() branching.

The actions enumeration is kept in QML for now, with the idea that
specific C++ methods from the mapwidgethelper class will be called
directly (if marked as Q_INVOCABLE), instead of a generic
onMapAction(action) C++ method in the helper. But if the actions
are possible from QML (like copying to clipboard) and are also
small and non-expensive, it might be better to keep them
in mapwidget.qml.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-07-21 01:28:58 +03:00 committed by Dirk Hohndel
parent 413e471244
commit 4d0d0e102b
2 changed files with 24 additions and 5 deletions

View file

@ -141,5 +141,19 @@ Item {
MapWidgetContextMenu {
id: contextMenu
y: 10; x: map.width - y
onActionSelected: {
// TODO: perform action actions
switch (action) {
case contextMenu.actions.OPEN_LOCATION_IN_GOOGLE_MAPS:
console.log("OPEN_LOCATION_IN_GOOGLE_MAPS");
break;
case contextMenu.actions.COPY_LOCATION_DECIMAL:
console.log("COPY_LOCATION_DECIMAL");
break;
case contextMenu.actions.COPY_LOCATION_SEXAGESIMAL:
console.log("COPY_LOCATION_SEXAGESIMAL");
break;
}
}
}
}

View file

@ -2,15 +2,18 @@
import QtQuick 2.7
Item {
readonly property var menuItemIndex: {
id: container
signal actionSelected(int action)
readonly property var actions: {
"OPEN_LOCATION_IN_GOOGLE_MAPS": 0,
"COPY_LOCATION_DECIMAL": 1,
"COPY_LOCATION_SEXAGESIMAL": 2
}
readonly property var menuItemData: [
{ idx: menuItemIndex.OPEN_LOCATION_IN_GOOGLE_MAPS, itemText: qsTr("Open location in Google Maps") },
{ idx: menuItemIndex.COPY_LOCATION_DECIMAL, itemText: qsTr("Copy location to clipboard (decimal)") },
{ idx: menuItemIndex.COPY_LOCATION_SEXAGESIMAL, itemText: qsTr("Copy location to clipboard (sexagesimal)") }
{ idx: actions.OPEN_LOCATION_IN_GOOGLE_MAPS, itemText: qsTr("Open location in Google Maps") },
{ idx: actions.COPY_LOCATION_DECIMAL, itemText: qsTr("Copy location to clipboard (decimal)") },
{ idx: actions.COPY_LOCATION_SEXAGESIMAL, itemText: qsTr("Copy location to clipboard (sexagesimal)") }
]
readonly property real itemTextPadding: 10.0
readonly property real itemHeight: 30.0
@ -107,7 +110,9 @@ Item {
onClicked: {
if (opacity < 1.0)
return;
listModel.selectedIdx = listView.indexAt(mouseX, mouseY)
var idx = listView.indexAt(mouseX, mouseY)
listModel.selectedIdx = idx
container.actionSelected(idx)
timerListViewVisible.restart()
}
}