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