Skip to content

Commit

Permalink
Merge pull request #4396 from opengisch/canvas_menu_features
Browse files Browse the repository at this point in the history
Brand new map canvas menu features list functionality
  • Loading branch information
nirvn authored Jul 7, 2023
2 parents 45287b3 + fe1eb6b commit a03bfbf
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 7 deletions.
6 changes: 1 addition & 5 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,7 @@
<file>themes/qfield/xhdpi/ic_explore_white_24dp.png</file>
<file>themes/qfield/xxhdpi/ic_explore_white_24dp.png</file>
<file>themes/qfield/xxxhdpi/ic_explore_white_24dp.png</file>
<file>themes/qfield/hdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/mdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/xhdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/xxhdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/xxxhdpi/ic_info_white_18dp.png</file>
<file>themes/qfield/nodpi/ic_info_white_24dp.svg</file>
<file>themes/qfield/nodpi/ic_baseline-list_alt-24dp.svg</file>
<file>themes/qfield/hdpi/ic_baseline-list_alt-24px.png</file>
<file>themes/qfield/mdpi/ic_baseline-list_alt-24px.png</file>
Expand Down
4 changes: 4 additions & 0 deletions images/themes/qfield/nodpi/ic_info_white_24dp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/core/multifeaturelistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MultiFeatureListModel : public QSortFilterProxyModel
{
FeatureIdRole = Qt::UserRole + 1,
FeatureSelectedRole,
FeatureNameRole,
FeatureRole,
LayerNameRole,
LayerRole,
Expand Down
2 changes: 2 additions & 0 deletions src/core/multifeaturelistmodelbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ QHash<int, QByteArray> MultiFeatureListModelBase::roleNames() const
roleNames[Qt::DisplayRole] = "display";
roleNames[MultiFeatureListModel::FeatureIdRole] = "featureId";
roleNames[MultiFeatureListModel::FeatureSelectedRole] = "featureSelected";
roleNames[MultiFeatureListModel::FeatureNameRole] = "featureName";
roleNames[MultiFeatureListModel::FeatureRole] = "feature";
roleNames[MultiFeatureListModel::LayerNameRole] = "layerName";
roleNames[MultiFeatureListModel::LayerRole] = "currentLayer";
Expand Down Expand Up @@ -248,6 +249,7 @@ QVariant MultiFeatureListModelBase::data( const QModelIndex &index, int role ) c
return feature->second;

case Qt::DisplayRole:
case MultiFeatureListModel::FeatureNameRole:
{
return FeatureUtils::displayName( feature->first, feature->second );
}
Expand Down
3 changes: 3 additions & 0 deletions src/qml/FeatureListForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ Rectangle {
featureForm.selection.focusedItem = -1
featureForm.state = "FeatureList"
featureForm.multiSelection = true

moveFeaturesToolbar.initializeMoveFeatures()
}
}

Expand Down Expand Up @@ -568,6 +570,7 @@ Rectangle {
if (featureForm.multiSelection) {
if (featureForm.model.duplicateSelection()) {
displayToast( qsTr( "Successfully duplicated selected features, list updated to show newly-created features" ) )
moveFeaturesToolbar.initializeMoveFeatures()
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/qml/NavigationBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ Rectangle {
wrapMode: Text.Wrap
elide: Text.ElideRight


MouseArea {
anchors.fill: parent

Expand Down
107 changes: 106 additions & 1 deletion src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ ApplicationWindow {
}
} else {
if (!overlayFeatureFormDrawer.visible || !featureForm.canvasOperationRequested) {
identifyTool.isMenuRequest = false
identifyTool.identify(point)
}
}
Expand All @@ -492,6 +493,7 @@ ApplicationWindow {
onConfirmedClicked: (point) => {
if (!featureForm.canvasOperationRequested && !overlayFeatureFormDrawer.visible && featureForm.state != "FeatureFormEdit")
{
identifyTool.isMenuRequest = false
identifyTool.identify(point)
}
}
Expand All @@ -517,17 +519,22 @@ ApplicationWindow {
}
// do not use else, as if it was catch it has return before
if( !overlayFeatureFormDrawer.visible ) {
identifyTool.isMenuRequest = false
identifyTool.identify(point)
}
} else {
canvasMenu.point = mapCanvas.mapSettings.screenToCoordinate(point)
canvasMenu.popup(point.x, point.y)
identifyTool.isMenuRequest = true
identifyTool.identify(point)
}
}

onRightClicked: (point, type) => {
canvasMenu.point = mapCanvas.mapSettings.screenToCoordinate(point)
canvasMenu.popup(point.x, point.y)
identifyTool.isMenuRequest = true
identifyTool.identify(point)
}

onLongPressReleased: (type) => {
Expand All @@ -552,8 +559,10 @@ ApplicationWindow {
IdentifyTool {
id: identifyTool

property bool isMenuRequest: false

mapSettings: mapCanvas.mapSettings
model: featureForm.model
model: isMenuRequest ? canvasMenuFeatureListModel : featureForm.model
searchRadiusMm: 3
}

Expand Down Expand Up @@ -2379,6 +2388,102 @@ ApplicationWindow {
screenLocker.enabled = true
}
}

MenuSeparator {
width: parent.width
visible: canvasMenuFeatureListInstantiator.count > 0
}

Instantiator {
id: canvasMenuFeatureListInstantiator

model: MultiFeatureListModel {
id: canvasMenuFeatureListModel
}

Menu {
id: featureMenu

property int fid: featureId
property var featureLayer: currentLayer

topMargin: sceneTopMargin
bottomMargin: sceneBottomMargin

title: layerName + ': ' + featureName
font: Theme.defaultFont
leftPadding: 10

width: {
var result = 0;
var padding = 0;
for (var i = 0; i < count; ++i) {
var item = itemAt(i);
result = Math.max(item.contentItem.implicitWidth, result);
padding = Math.max(item.leftPadding, padding);
}
return Math.min(result + padding * 2,mainWindow.width - 20);
}

Component.onCompleted: {
if (featureMenu.icon !== undefined) {
featureMenu.icon.source = Theme.getThemeVectorIcon('ic_info_white_24dp')
}
}

MenuItem {
text: qsTr('Layer:') + ' ' + layerName
enabled: false
}
MenuItem {
text: qsTr('Feature:') + ' ' + featureName
enabled: false
}
MenuSeparator { width: parent.width }

MenuItem {
text: qsTr('Open Feature Form')
font: Theme.defaultFont
icon.source: Theme.getThemeIcon( "ic_baseline-list_alt-24px" )
leftPadding: 10

onTriggered: {
featureForm.model.setFeatures(menu.featureLayer, '$id = ' + menu.fid)
featureForm.selection.focusedItem = 0
featureForm.state = "FeatureForm"
}
}

MenuItem {
text: qsTr('Duplicate Feature')
font: Theme.defaultFont
enabled: projectInfo.insertRights
icon.source: Theme.getThemeVectorIcon( "ic_duplicate_black_24dp" )
leftPadding: 10

onTriggered: {
featureForm.model.setFeatures(menu.featureLayer, '$id = ' + menu.fid)
featureForm.selection.focusedItem = 0
featureForm.multiSelection = true
featureForm.selection.toggleSelectedItem(0)
featureForm.state = "FeatureList"
if (featureForm.model.canDuplicateSelection) {
if (featureForm.selection.model.duplicateFeature(featureForm.selection.focusedLayer,featureForm.selection.focusedFeature)) {
displayToast(qsTr('Successfully duplicated feature'))

featureForm.selection.focusedItem = -1
moveFeaturesToolbar.initializeMoveFeatures()
return;
}
}
displayToast(qsTr('Feature duplication not available'))
}
}
}

onObjectAdded: (index, object) => { canvasMenu.insertMenu(index+9, object) }
onObjectRemoved: (index, object) => { canvasMenu.removeMenu(object) }
}
}

Menu {
Expand Down

1 comment on commit a03bfbf

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.