QGIS API Documentation  2.14.0-Essen
qgsidentifymenu.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsidentifymenu.cpp - menu to be used in identify map tool
3  ---------------------
4  begin : August 2014
5  copyright : (C) 2014 by Denis Rouzaud
6  email : [email protected]
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 #include <QMouseEvent>
17 
18 #include "qgsidentifymenu.h"
19 
20 #include "qgsapplication.h"
21 #include "qgsattributeaction.h"
22 #include "qgshighlight.h"
23 
24 
26 CustomActionRegistry::CustomActionRegistry( QObject* parent )
27  : QgsMapLayerActionRegistry( parent )
28 {
29 }
31 
33  : QMenu( canvas )
34  , mCanvas( canvas )
35  , mAllowMultipleReturn( true )
36  , mExecWithSingleResult( false )
37  , mShowFeatureActions( false )
38  , mResultsIfExternalAction( false )
39  , mMaxLayerDisplay( 10 )
40  , mMaxFeatureDisplay( 10 )
41  , mDefaultActionName( tr( "Identify" ) )
42  , mCustomActionRegistry( CustomActionRegistry::instance() )
43 {
44 }
45 
47 {
48  deleteRubberBands();
49 }
50 
51 
53 {
54  if ( maxLayerDisplay < 0 )
55  {
56  QgsDebugMsg( "invalid value for number of layers displayed." );
57  }
58  mMaxLayerDisplay = maxLayerDisplay;
59 }
60 
61 
63 {
64  if ( maxFeatureDisplay < 0 )
65  {
66  QgsDebugMsg( "invalid value for number of layers displayed." );
67  }
68  mMaxFeatureDisplay = maxFeatureDisplay;
69 }
70 
71 
73 {
74  clear();
75  mLayerIdResults.clear();
76 
78 
79  if ( idResults.isEmpty() )
80  {
81  return returnResults;
82  }
83  if ( idResults.count() == 1 && !mExecWithSingleResult )
84  {
85  returnResults << idResults[0];
86  return returnResults;
87  }
88 
89  // sort results by layer
90  Q_FOREACH ( const QgsMapToolIdentify::IdentifyResult& result, idResults )
91  {
92  QgsMapLayer *layer = result.mLayer;
93  if ( mLayerIdResults.contains( layer ) )
94  {
95  mLayerIdResults[layer].append( result );
96  }
97  else
98  {
99  mLayerIdResults.insert( layer, QList<QgsMapToolIdentify::IdentifyResult>() << result );
100  }
101  }
102 
103  // add results to the menu
104  bool singleLayer = mLayerIdResults.count() == 1;
105  int count = 0;
107  while ( it.hasNext() )
108  {
109  if ( mMaxLayerDisplay != 0 && count > mMaxLayerDisplay )
110  break;
111  ++count;
112  it.next();
113  QgsMapLayer* layer = it.key();
114  if ( layer->type() == QgsMapLayer::RasterLayer )
115  {
116  addRasterLayer( layer );
117  }
118  else if ( layer->type() == QgsMapLayer::VectorLayer )
119  {
120  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( layer );
121  if ( !vl )
122  continue;
123  addVectorLayer( vl, it.value(), singleLayer );
124  }
125  }
126 
127  // add an "identify all" action on the top level
128  if ( !singleLayer && mAllowMultipleReturn && idResults.count() > 1 )
129  {
130  addSeparator();
131  QAction* allAction = new QAction( QgsApplication::getThemeIcon( "/mActionIdentify.svg" ), tr( "%1 all (%2)" ).arg( mDefaultActionName ).arg( idResults.count() ), this );
132  allAction->setData( QVariant::fromValue<ActionData>( ActionData( nullptr ) ) );
133  connect( allAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
134  addAction( allAction );
135  }
136 
137  // exec
138  QAction* selectedAction = QMenu::exec( pos );
139  bool externalAction;
140  returnResults = results( selectedAction, externalAction );
141 
142  // delete actions
143  clear();
144  // also remove the QgsActionMenu
145  qDeleteAll( findChildren<QgsActionMenu*>() );
146 
147  if ( externalAction && !mResultsIfExternalAction )
148  {
150  }
151  else
152  {
153  return returnResults;
154  }
155 }
156 
158 {
159  deleteRubberBands();
160  QMenu::closeEvent( e );
161 }
162 
163 void QgsIdentifyMenu::addRasterLayer( QgsMapLayer* layer )
164 {
165  QAction* layerAction;
166  QMenu* layerMenu = nullptr;
167 
169  QList<QgsMapLayerAction*> layerActions = mCustomActionRegistry.mapLayerActions( layer, QgsMapLayerAction::Layer );
170  int nCustomActions = layerActions.count();
171  if ( nCustomActions )
172  {
173  separators.append( layerActions[0] );
174  }
175  if ( mShowFeatureActions )
176  {
177  layerActions.append( QgsMapLayerActionRegistry::instance()->mapLayerActions( layer, QgsMapLayerAction::Layer ) );
178  if ( layerActions.count() > nCustomActions )
179  {
180  separators.append( layerActions[nCustomActions] );
181  }
182  }
183 
184  // use a menu only if actions will be listed
185  if ( layerActions.isEmpty() )
186  {
187  layerAction = new QAction( layer->name(), this );
188  }
189  else
190  {
191  layerMenu = new QMenu( layer->name(), this );
192  layerAction = layerMenu->menuAction();
193  }
194 
195  // add layer action to the top menu
196  layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconRasterLayer.png" ) );
197  layerAction->setData( QVariant::fromValue<ActionData>( ActionData( layer ) ) );
198  connect( layerAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
199  addAction( layerAction );
200 
201  // no need to go further if there is no menu
202  if ( !layerMenu )
203  return;
204 
205  // add default identify action
206  QAction* identifyFeatureAction = new QAction( mDefaultActionName, layerMenu );
207  connect( identifyFeatureAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
208  identifyFeatureAction->setData( QVariant::fromValue<ActionData>( ActionData( layer ) ) );
209  layerMenu->addAction( identifyFeatureAction );
210 
211  // add custom/layer actions
212  Q_FOREACH ( QgsMapLayerAction* mapLayerAction, layerActions )
213  {
214  QAction* action = new QAction( mapLayerAction->icon(), mapLayerAction->text(), layerMenu );
215  action->setData( QVariant::fromValue<ActionData>( ActionData( layer, true ) ) );
216  connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
217  connect( action, SIGNAL( triggered() ), this, SLOT( triggerMapLayerAction() ) );
218  layerMenu->addAction( action );
219  if ( separators.contains( mapLayerAction ) )
220  {
221  layerMenu->insertSeparator( action );
222  }
223  }
224 }
225 
226 void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QList<QgsMapToolIdentify::IdentifyResult>& results, bool singleLayer )
227 {
228  QAction* layerAction = nullptr;
229  QMenu* layerMenu = nullptr;
230 
231  // do not add actions with MultipleFeatures as target if only 1 feature is found for this layer
232  // targets defines which actions will be shown
233  QgsMapLayerAction::Targets targets = results.count() > 1 ? QgsMapLayerAction::Layer | QgsMapLayerAction::MultipleFeatures : QgsMapLayerAction::Layer;
234 
236  QList<QgsMapLayerAction*> layerActions = mCustomActionRegistry.mapLayerActions( layer, targets );
237  int nCustomActions = layerActions.count();
238  if ( nCustomActions )
239  {
240  separators << layerActions[0];
241  }
242  if ( mShowFeatureActions )
243  {
244  layerActions << QgsMapLayerActionRegistry::instance()->mapLayerActions( layer, targets );
245 
246  if ( layerActions.count() > nCustomActions )
247  {
248  separators << layerActions[nCustomActions];
249  }
250  }
251 
252  // determines if a menu should be created or not. Following cases:
253  // 1. only one result and no feature action to be shown => just create an action
254  // 2. several features (2a) or display feature actions (2b) => create a menu
255  // 3. case 2 but only one layer (singeLayer) => do not create a menu, but give the top menu instead
256 
257  bool createMenu = results.count() > 1 || !layerActions.isEmpty();
258 
259  // case 2b: still create a menu for layer, if there is a sub-level for features
260  // i.e custom actions or map layer actions at feature level
261  if ( !createMenu )
262  {
263  createMenu = !mCustomActionRegistry.mapLayerActions( layer, QgsMapLayerAction::SingleFeature ).isEmpty();
264  if ( !createMenu && mShowFeatureActions )
265  {
266  QgsActionMenu* featureActionMenu = new QgsActionMenu( layer, &( results[0].mFeature ), this );
267  createMenu = !featureActionMenu->actions().isEmpty();
268  delete featureActionMenu;
269  }
270  }
271 
272  // use a menu only if actions will be listed
273  if ( !createMenu )
274  {
275  // case 1
276  QString featureTitle = results[0].mFeature.attribute( layer->displayField() ).toString();
277  if ( featureTitle.isEmpty() )
278  featureTitle = QString( "%1" ).arg( results[0].mFeature.id() );
279  layerAction = new QAction( QString( "%1 (%2)" ).arg( layer->name(), featureTitle ), this );
280  }
281  else
282  {
283  if ( singleLayer )
284  {
285  // case 3
286  layerMenu = this;
287  }
288  else
289  {
290  // case 2a
291  if ( results.count() > 1 )
292  {
293  layerMenu = new QMenu( layer->name(), this );
294  }
295  // case 2b
296  else
297  {
298  QString featureTitle = results[0].mFeature.attribute( layer->displayField() ).toString();
299  if ( featureTitle.isEmpty() )
300  featureTitle = QString( "%1" ).arg( results[0].mFeature.id() );
301  layerMenu = new QMenu( QString( "%1 (%2)" ).arg( layer->name(), featureTitle ), this );
302  }
303  layerAction = layerMenu->menuAction();
304  }
305  }
306 
307  // case 1 or 2
308  if ( layerAction )
309  {
310  // icons
311  switch ( layer->geometryType() )
312  {
313  case QGis::Point:
314  layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconPointLayer.png" ) );
315  break;
316  case QGis::Line:
317  layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconLineLayer.png" ) );
318  break;
319  case QGis::Polygon:
320  layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconPolygonLayer.png" ) );
321  break;
322  default:
323  break;
324  }
325 
326  // add layer action to the top menu
327  layerAction->setData( QVariant::fromValue<ActionData>( ActionData( layer ) ) );
328  connect( layerAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
329  addAction( layerAction );
330  }
331 
332  // case 1. no need to go further
333  if ( !layerMenu )
334  return;
335 
336  // add results to the menu
337  int count = 0;
338  Q_FOREACH ( const QgsMapToolIdentify::IdentifyResult& result, results )
339  {
340  if ( mMaxFeatureDisplay != 0 && count > mMaxFeatureDisplay )
341  break;
342  ++count;
343 
344  QAction* featureAction = nullptr;
345  QMenu* featureMenu = nullptr;
346  QgsActionMenu* featureActionMenu = nullptr;
347 
348  QList<QgsMapLayerAction*> customFeatureActions = mCustomActionRegistry.mapLayerActions( layer, QgsMapLayerAction::SingleFeature );
349  if ( mShowFeatureActions )
350  {
351  featureActionMenu = new QgsActionMenu( layer, result.mFeature.id(), layerMenu );
352  }
353 
354  // feature title
355  QString featureTitle = result.mFeature.attribute( layer->displayField() ).toString();
356  if ( featureTitle.isEmpty() )
357  featureTitle = QString( "%1" ).arg( result.mFeature.id() );
358 
359  if ( customFeatureActions.isEmpty() && ( !featureActionMenu || featureActionMenu->actions().isEmpty() ) )
360  {
361  featureAction = new QAction( featureTitle, layerMenu );
362  // add the feature action (or menu) to the layer menu
363  featureAction->setData( QVariant::fromValue<ActionData>( ActionData( layer, result.mFeature.id() ) ) );
364  connect( featureAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
365  layerMenu->addAction( featureAction );
366  }
367  else if ( results.count() == 1 )
368  {
369  // if we are here with only one results, this means there is a sub-feature level (for actions)
370  // => skip the feature level since there would be only a single entry
371  // => give the layer menu as pointer instead of a new feature menu
372  featureMenu = layerMenu;
373  }
374  else
375  {
376  featureMenu = new QMenu( featureTitle, layerMenu );
377 
378  // get the action from the menu
379  featureAction = featureMenu->menuAction();
380  // add the feature action (or menu) to the layer menu
381  featureAction->setData( QVariant::fromValue<ActionData>( ActionData( layer, result.mFeature.id() ) ) );
382  connect( featureAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
383  layerMenu->addAction( featureAction );
384  }
385 
386  // if no feature menu, no need to go further
387  if ( !featureMenu )
388  continue;
389 
390  // add default identify action
391  QAction* identifyFeatureAction = new QAction( QgsApplication::getThemeIcon( "/mActionIdentify.svg" ), mDefaultActionName, featureMenu );
392  connect( identifyFeatureAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
393  identifyFeatureAction->setData( QVariant::fromValue<ActionData>( ActionData( layer, result.mFeature.id() ) ) );
394  featureMenu->addAction( identifyFeatureAction );
395  featureMenu->addSeparator();
396 
397  // custom action at feature level
398  Q_FOREACH ( QgsMapLayerAction* mapLayerAction, customFeatureActions )
399  {
400  QAction* action = new QAction( mapLayerAction->icon(), mapLayerAction->text(), featureMenu );
401  action->setData( QVariant::fromValue<ActionData>( ActionData( layer, result.mFeature.id(), mapLayerAction ) ) );
402  connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
403  connect( action, SIGNAL( triggered() ), this, SLOT( triggerMapLayerAction() ) );
404  featureMenu->addAction( action );
405  }
406  // use QgsActionMenu for feature actions
407  if ( featureActionMenu )
408  {
409  Q_FOREACH ( QAction* action, featureActionMenu->actions() )
410  {
411  connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
412  featureMenu->addAction( action );
413  }
414  }
415  }
416 
417  // back to layer level
418 
419  // identify all action
420  if ( mAllowMultipleReturn && results.count() > 1 )
421  {
422  layerMenu->addSeparator();
423  QAction* allAction = new QAction( QgsApplication::getThemeIcon( "/mActionIdentify.svg" ), tr( "%1 all (%2)" ).arg( mDefaultActionName ).arg( results.count() ), layerMenu );
424  allAction->setData( QVariant::fromValue<ActionData>( ActionData( layer ) ) );
425  connect( allAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
426  layerMenu->addAction( allAction );
427  }
428 
429  // add custom/layer actions
430  Q_FOREACH ( QgsMapLayerAction* mapLayerAction, layerActions )
431  {
432  QString title = mapLayerAction->text();
433  if ( mapLayerAction->targets().testFlag( QgsMapLayerAction::MultipleFeatures ) )
434  title.append( QString( " (%1)" ).arg( results.count() ) );
435  QAction* action = new QAction( mapLayerAction->icon(), title, layerMenu );
436  action->setData( QVariant::fromValue<ActionData>( ActionData( layer, mapLayerAction ) ) );
437  connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
438  connect( action, SIGNAL( triggered() ), this, SLOT( triggerMapLayerAction() ) );
439  layerMenu->addAction( action );
440  if ( separators.contains( mapLayerAction ) )
441  {
442  layerMenu->insertSeparator( action );
443  }
444  }
445 }
446 
447 void QgsIdentifyMenu::triggerMapLayerAction()
448 {
449  QAction* action = qobject_cast<QAction*>( sender() );
450  if ( !action )
451  return;
452  QVariant varData = action->data();
453  if ( !varData.isValid() || !varData.canConvert<ActionData>() )
454  return;
455 
456  ActionData actData = action->data().value<ActionData>();
457 
458  if ( actData.mIsValid && actData.mMapLayerAction )
459  {
460  // layer
461  if ( actData.mMapLayerAction->targets().testFlag( QgsMapLayerAction::Layer ) )
462  {
463  actData.mMapLayerAction->triggerForLayer( actData.mLayer );
464  }
465 
466  // multiples features
467  if ( actData.mMapLayerAction->targets().testFlag( QgsMapLayerAction::MultipleFeatures ) )
468  {
469  QList<QgsFeature> featureList;
470  Q_FOREACH ( const QgsMapToolIdentify::IdentifyResult& result, mLayerIdResults[actData.mLayer] )
471  {
472  featureList << result.mFeature;
473  }
474  actData.mMapLayerAction->triggerForFeatures( actData.mLayer, featureList );
475  }
476 
477  // single feature
478  if ( actData.mMapLayerAction->targets().testFlag( QgsMapLayerAction::SingleFeature ) )
479  {
480  Q_FOREACH ( const QgsMapToolIdentify::IdentifyResult& result, mLayerIdResults[actData.mLayer] )
481  {
482  if ( result.mFeature.id() == actData.mFeatureId )
483  {
484  actData.mMapLayerAction->triggerForFeature( actData.mLayer, new QgsFeature( result.mFeature ) );
485  return;
486  }
487  }
488  QgsDebugMsg( QString( "Identify menu: could not retrieve feature for action %1" ).arg( action->text() ) );
489  }
490  }
491 }
492 
493 
494 QList<QgsMapToolIdentify::IdentifyResult> QgsIdentifyMenu::results( QAction* action, bool &externalAction )
495 {
497 
498  externalAction = false;
499 
500  ActionData actData;
501  bool hasData = false;
502 
503  if ( !action )
504  return idResults;
505 
506  QVariant varData = action->data();
507  if ( !varData.isValid() )
508  {
509  QgsDebugMsg( "Identify menu: could not retrieve results from menu entry (invalid data)" );
510  return idResults;
511  }
512 
513  if ( varData.canConvert<ActionData>() )
514  {
515  actData = action->data().value<ActionData>();
516  if ( actData.mIsValid )
517  {
518  externalAction = actData.mIsExternalAction;
519  hasData = true;
520  }
521  }
522 
523  if ( !hasData && varData.canConvert<QgsActionMenu::ActionData>() )
524  {
526  if ( dataSrc.actionType != QgsActionMenu::Invalid )
527  {
528  externalAction = true;
529  actData = ActionData( dataSrc.mapLayer, dataSrc.featureId );
530  hasData = true;
531  }
532  }
533 
534  if ( !hasData )
535  {
536  QgsDebugMsg( "Identify menu: could not retrieve results from menu entry (no data found)" );
537  return idResults;
538  }
539 
540  // return all results
541  if ( actData.mAllResults )
542  {
543  // this means "All" action was triggered
545  while ( it.hasNext() )
546  {
547  it.next();
548  idResults << it.value();
549  }
550  return idResults;
551  }
552 
553  if ( !mLayerIdResults.contains( actData.mLayer ) )
554  {
555  QgsDebugMsg( "Identify menu: could not retrieve results from menu entry (layer not found)" );
556  return idResults;
557  }
558 
559  if ( actData.mLevel == LayerLevel )
560  {
561  return mLayerIdResults[actData.mLayer];
562  }
563 
564  if ( actData.mLevel == FeatureLevel )
565  {
566  Q_FOREACH ( const QgsMapToolIdentify::IdentifyResult& res, mLayerIdResults[actData.mLayer] )
567  {
568  if ( res.mFeature.id() == actData.mFeatureId )
569  {
570  idResults << res;
571  return idResults;
572  }
573  }
574  }
575 
576  QgsDebugMsg( "Identify menu: could not retrieve results from menu entry (don't know what happened')" );
577  return idResults;
578 }
579 
580 void QgsIdentifyMenu::handleMenuHover()
581 {
582  if ( !mCanvas )
583  return;
584 
585  deleteRubberBands();
586 
587  QAction* senderAction = qobject_cast<QAction*>( sender() );
588  if ( !senderAction )
589  return;
590 
591  bool externalAction;
592  QList<QgsMapToolIdentify::IdentifyResult> idResults = results( senderAction, externalAction );
593 
594  Q_FOREACH ( const QgsMapToolIdentify::IdentifyResult& result, idResults )
595  {
596  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( result.mLayer );
597  if ( !vl )
598  continue;
599 
600  QgsHighlight *hl = new QgsHighlight( mCanvas, result.mFeature.constGeometry(), vl );
601  QSettings settings;
602  QColor color = QColor( settings.value( "/Map/highlight/color", QGis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
603  int alpha = settings.value( "/Map/highlight/colorAlpha", QGis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt();
604  double buffer = settings.value( "/Map/highlight/buffer", QGis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble();
605  double minWidth = settings.value( "/Map/highlight/minWidth", QGis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble();
606  hl->setColor( color ); // sets also fill with default alpha
607  color.setAlpha( alpha );
608  hl->setFillColor( color ); // sets fill with alpha
609  hl->setBuffer( buffer );
610  hl->setMinWidth( minWidth );
611  mRubberBands.append( hl );
612  connect( vl, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
613  }
614 }
615 
616 void QgsIdentifyMenu::deleteRubberBands()
617 {
619  for ( ; it != mRubberBands.constEnd(); ++it )
620  delete *it;
621  mRubberBands.clear();
622 }
623 
624 void QgsIdentifyMenu::layerDestroyed()
625 {
626  QList<QgsHighlight*>::iterator it = mRubberBands.begin();
627  while ( it != mRubberBands.end() )
628  {
629  if (( *it )->layer() == sender() )
630  {
631  delete *it;
632  it = mRubberBands.erase( it );
633  }
634  else
635  {
636  ++it;
637  }
638  }
639 }
640 
642 {
643  mCustomActionRegistry.clear();
644 
645 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:65
void hovered(QAction *action)
bool canConvert(Type t) const
void clear()
QAction * insertSeparator(QAction *before)
static double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
Definition: qgis.h:239
Base class for all map layer types.
Definition: qgsmaplayer.h:49
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition: qgis.h:235
QString & append(QChar ch)
QgsMapLayer::LayerType type() const
Get the type of the layer.
Definition: qgsmaplayer.cpp:99
bool contains(const Key &key) const
QString name() const
Get the display name of the layer.
QString name() const
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QObject * sender() const
int value() const
QVariant data() const
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
void setIcon(const QIcon &icon)
void addAction(QAction *action)
void setFillColor(const QColor &fillColor)
Set polygons fill color.
void triggered(QAction *action)
T value() const
void setAlpha(int alpha)
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, const QgsMapLayerAction::Targets &targets=QgsMapLayerAction::AllActions)
Returns the map layer actions which can run on the specified layer.
iterator erase(iterator pos)
uint count() const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
void clear()
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
void setBuffer(double buffer)
Set line / outline buffer in millimeters.
Definition: qgshighlight.h:63
void clear()
int count(const T &value) const
void append(const T &value)
QgsMapLayerAction * mMapLayerAction
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:30
bool isEmpty() const
QgsIdentifyMenu(QgsMapCanvas *canvas)
QgsIdentifyMenu is a menu to be used to choose within a list of QgsMapTool::IdentifyReults.
bool isEmpty() const
A class for highlight features on the map.
Definition: qgshighlight.h:36
QPoint pos() const
const QString displayField() const
Returns the primary display field name used in the identify results dialog.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QString title() const
QAction * addSeparator()
const Key & key() const
This class tracks map layer actions.
const T & value() const
QMenu(QWidget *parent)
QAction * exec()
const Targets & targets() const
Return availibity of action.
void setMaxFeatureDisplay(int maxFeatureDisplay)
Defines the maximimum number of features displayed in the menu for vector layers (default is 10)...
void setData(const QVariant &userData)
iterator end()
void triggerForFeatures(QgsMapLayer *layer, const QList< QgsFeature > &featureList)
Triggers the action with the specified layer and list of feature.
virtual void closeEvent(QCloseEvent *e) override
bool contains(const T &value) const
static QgsMapLayerActionRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:271
void setColor(const QColor &color)
Set line/outline to color, polygon fill to color with alpha = 63.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:82
bool isValid() const
iterator insert(const Key &key, const T &value)
QAction * menuAction() const
virtual void closeEvent(QCloseEvent *event)
const_iterator constEnd() const
const_iterator constBegin() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QList< QAction * > actions() const
void removeCustomActions()
remove all custom actions from the menu to be built
Represents a vector layer which manages a vector based data sets.
void setMaxLayerDisplay(int maxLayerDisplay)
Defines the maximimum number of layers displayed in the menu (default is 10).
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void triggerForLayer(QgsMapLayer *layer)
Triggers the action with the specified layer.
void triggerForFeature(QgsMapLayer *layer, const QgsFeature *feature)
Triggers the action with the specified layer and feature.
static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/outline minimum width in mm.
Definition: qgis.h:243
int count(const Key &key) const
iterator begin()
An action which can run on map layers.
void destroyed(QObject *obj)
bool hasNext() const
void setMinWidth(double width)
Set minimum line / outline width in millimeters.
Definition: qgshighlight.h:67