From b5a1b6023a37b4961b32fc194704a12093d458c3 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 11 Nov 2023 14:27:32 +0700 Subject: [PATCH] Disable active layer search filter when no vector layer is active/selected and inform user via toast message --- src/core/projectinfo.cpp | 2 ++ src/qml/LocatorItem.qml | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/projectinfo.cpp b/src/core/projectinfo.cpp index dc887c00c8..72f752a5b8 100644 --- a/src/core/projectinfo.cpp +++ b/src/core/projectinfo.cpp @@ -310,6 +310,8 @@ void ProjectInfo::setActiveLayer( QgsMapLayer *layer ) mSettings.beginGroup( QStringLiteral( "/qgis/projectInfo/%1" ).arg( mFilePath ) ); mSettings.setValue( QStringLiteral( "activeLayer" ), layer->id() ); mSettings.endGroup(); + + emit activeLayerChanged(); } QgsMapLayer *ProjectInfo::activeLayer() const diff --git a/src/qml/LocatorItem.qml b/src/qml/LocatorItem.qml index 2f2341612b..992c5b0849 100644 --- a/src/qml/LocatorItem.qml +++ b/src/qml/LocatorItem.qml @@ -275,7 +275,7 @@ Item { anchors.topMargin: 24 model: searchField.displayText !== '' ? locator.proxyModel() : locatorFilters width: parent.width - height: resultsList.count > 0 ? Math.min( childrenRect.height, mainWindow.height / 2 - searchFieldRect.height - 10 ) : 0 + height: resultsList.count > 0 ? Math.min( contentHeight, mainWindow.height / 2 - searchFieldRect.height - 10 ) : 0 clip: true delegate: searchField.displayText !== '' ? resultsComponent : filtersComponent @@ -288,10 +288,10 @@ Item { id: delegateRect anchors.margins: 10 - height: textArea.childrenRect.height + textArea.topPadding + textArea.bottomPadding width: resultsList.width + height: textArea.childrenRect.height + textArea.topPadding + textArea.bottomPadding color: "transparent" - opacity: 0.95 + opacity: (Prefix === 'f' && dashBoard.activeLayer == undefined) ? 0.35 : 0.95 Ripple { clip: true @@ -316,7 +316,7 @@ Item { id: nameCell anchors.left: parent.left anchors.right: parent.right - text: Name + ' (' + Prefix + ')' + text: Name + ' (' + Prefix + ')' + (Prefix === 'f' && dashBoard.activeLayer ? ' — ' + dashBoard.activeLayer.name : '') leftPadding: 5 font.bold: false font.pointSize: Theme.resultFont.pointSize @@ -352,7 +352,11 @@ Item { anchors.fill: parent onClicked: { - searchField.text = Prefix + ' '; + if (Prefix === 'f' && dashBoard.activeLayer == undefined) { + displayToast(qsTr('Activate a vector layer in the legend first to use this functionality'), 'warning') + } else { + searchField.text = Prefix + ' ' + } } } }