QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsidentifymenu.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsidentifymenu.h - menu to be used in identify map tool
3 ---------------------
4 begin : August 2014
5 copyright : (C) 2014 by Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSIDENTIFYMENU_H
17#define QGSIDENTIFYMENU_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
23#include "qgsmaptoolidentify.h"
24
25#include <QMenu>
26
27#ifndef SIP_RUN
29class CustomActionRegistry : public QgsMapLayerActionRegistry
30{
31 Q_OBJECT
32
33 public:
35 CustomActionRegistry() = default;
36 // remove all actions
37 void clear() { mMapLayerActionList.clear(); }
38};
40#endif
41
52class GUI_EXPORT QgsIdentifyMenu : public QMenu
53{
54 Q_OBJECT
55
56 public:
62
64 {
65 ActionData() = default;
66
67 ActionData( QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction = nullptr )
68 : mIsValid( true )
69 , mAllResults( !layer )
70 , mIsExternalAction( nullptr != mapLayerAction )
71 , mLayer( layer )
72 , mMapLayerAction( mapLayerAction )
73 {}
74
75 ActionData( QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction = nullptr )
76 : mIsValid( true )
77 , mIsExternalAction( nullptr != mapLayerAction )
78 , mLayer( layer )
79 , mFeatureId( fid )
81 , mMapLayerAction( mapLayerAction )
82 {}
83
84 bool mIsValid = false;
85 bool mAllResults = false;
86 bool mIsExternalAction = false;
87 QgsMapLayer *mLayer = nullptr;
91 };
92
96 explicit QgsIdentifyMenu( QgsMapCanvas *canvas );
97
98 ~QgsIdentifyMenu() override;
99
100
111 static QList<QgsMapToolIdentify::IdentifyResult> findFeaturesOnCanvas( QgsMapMouseEvent *event, QgsMapCanvas *canvas, const QList<Qgis::GeometryType> &geometryTypes );
112
114 void setAllowMultipleReturn( bool multipleReturn ) { mAllowMultipleReturn = multipleReturn; }
115 bool allowMultipleReturn() { return mAllowMultipleReturn; }
116
118 void setExecWithSingleResult( bool execWithSingleResult ) { mExecWithSingleResult = execWithSingleResult; }
119 bool execWithSingleResult() { return mExecWithSingleResult; }
120
125 void setExpressionContextScope( const QgsExpressionContextScope &scope );
126
131 QgsExpressionContextScope expressionContextScope() const;
132
139 void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
140 bool showFeatureActions() { return mShowFeatureActions; }
141
147 bool resultsIfExternalAction() { return mResultsIfExternalAction; }
148
153 void setMaxLayerDisplay( int maxLayerDisplay );
154 int maxLayerDisplay() { return mMaxLayerDisplay; }
155
160 void setMaxFeatureDisplay( int maxFeatureDisplay );
161 int maxFeatureDisplay() { return mMaxFeatureDisplay; }
162
164 void addCustomAction( QgsMapLayerAction *action ) { mCustomActionRegistry.addMapLayerAction( action ); }
165
167 void removeCustomActions();
168
174 QList<QgsMapToolIdentify::IdentifyResult> exec( const QList<QgsMapToolIdentify::IdentifyResult> &idResults, QPoint pos );
175
181 Q_DECL_DEPRECATED static void styleHighlight( QgsHighlight *highlight ) SIP_DEPRECATED;
182
183 signals:
184
191 void messageEmitted( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
192
200
201 protected:
202 void closeEvent( QCloseEvent *e ) override;
203
204 private slots:
205 void handleMenuHover();
206 void deleteRubberBands();
207 void layerDestroyed();
208 void triggerMapLayerAction();
209
210 private:
212 void addRasterLayer( QgsMapLayer *layer );
213
218 void addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapToolIdentify::IdentifyResult> &results, bool singleLayer = false );
219
221 QList<QgsMapToolIdentify::IdentifyResult> results( QAction *action, bool &externalAction );
222
223 QgsMapCanvas *mCanvas = nullptr;
224 QList<QgsHighlight *> mRubberBands;
225 bool mAllowMultipleReturn = true;
226 bool mExecWithSingleResult = false;
227 bool mShowFeatureActions = false;
228 bool mResultsIfExternalAction = false;
229 int mMaxLayerDisplay = 10;
230 int mMaxFeatureDisplay = 10;
231
232 QgsExpressionContextScope mExpressionContextScope;
233
234 // name of the action to be displayed for feature default action, if other actions are shown
235 QString mDefaultActionName;
236
237 // custom menu actions regirstry
238 CustomActionRegistry mCustomActionRegistry;
239
240 // map layers with their results, this is the odering of the menu
241 QMap<QgsMapLayer *, QList<QgsMapToolIdentify::IdentifyResult>> mLayerIdResults;
242};
243
245
246#endif // QGSIDENTIFYMENU_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:156
@ Info
Information message.
Definition qgis.h:157
Single scope for storing variables and functions for use within a QgsExpressionContext.
Highlights features on the map.
void setAllowMultipleReturn(bool multipleReturn)
define if the menu executed can return multiple results (e.g. all results or all identified features ...
void setResultsIfExternalAction(bool resultsIfExternalAction)
setResultsIfExternalAction if set to false (default) the menu will not return any results if an exter...
void addCustomAction(QgsMapLayerAction *action)
adds a new custom action to the menu
QgsIdentifyMenu(QgsMapCanvas *canvas)
QgsIdentifyMenu is a menu to be used to choose within a list of QgsMapTool::IdentifyReults.
void setShowFeatureActions(bool showFeatureActions)
define if attribute actions(1) and map layer actions(2) can be listed and run from the menu
void messageDiscarded()
Emitted when the previous message from the tool should be cleared from the application message bar.
void setExecWithSingleResult(bool execWithSingleResult)
define if the menu will be shown with a single identify result
void closeEvent(QCloseEvent *e) override
static QList< QgsMapToolIdentify::IdentifyResult > findFeaturesOnCanvas(QgsMapMouseEvent *event, QgsMapCanvas *canvas, const QList< Qgis::GeometryType > &geometryTypes)
Searches for features on the map canvas, which are located at the specified event point.
bool resultsIfExternalAction()
void messageEmitted(const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
Emitted when a message should be shown to the user in the application message bar.
Map canvas is a class for displaying all GIS data types on a canvas.
A registry which tracks map layer actions.
An action which can run on map layers.
Base class for all map layer types.
Definition qgsmaplayer.h:80
A mouse event which is the result of a user interaction with a QgsMapCanvas.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QgsIdentifyMenu::MenuLevel mLevel
ActionData(QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction=nullptr)
QgsMapLayerAction * mMapLayerAction
ActionData(QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction=nullptr)