Skip to content

Commit

Permalink
fix QgsMapLayerAction SIP + do not copy features in identify menu (fo…
Browse files Browse the repository at this point in the history
…llowup 21c81d6)
  • Loading branch information
3nids committed Sep 17, 2014
1 parent 096d941 commit 2188de6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
24 changes: 16 additions & 8 deletions python/gui/qgsmaplayeractionregistry.sip
Expand Up @@ -7,40 +7,48 @@ class QgsMapLayerAction : QAction
public:
enum Target
{
Layer ,
Layer,
SingleFeature,
MultipleFeatures,
AllActions
};
typedef QFlags<QgsMapLayerAction::Target> Targets;

/**Creates a map layer action which can run on any layer*/
//! Creates a map layer action which can run on any layer
//! @note using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatiblity reasons.
QgsMapLayerAction( QString name, QObject *parent, Targets targets = AllActions );
/**Creates a map layer action which can run only on a specific layer*/

//! Creates a map layer action which can run only on a specific layer
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Targets targets = AllActions );
/**Creates a map layer action which can run on a specific type of layer*/

//! Creates a map layer action which can run on a specific type of layer
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Targets targets = AllActions );

~QgsMapLayerAction();

/** True if action can run using the specified layer */
bool canRunUsingLayer( QgsMapLayer* layer ) const;

/** Triggers the action with the specified layer and list of feature. */
void triggerForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
void triggerForFeatures( QgsMapLayer* layer, const QList<QgsFeature> featureList );

/** Triggers the action with the specified layer and feature. */
void triggerForFeature( QgsMapLayer* layer, const QgsFeature* feature );

/** Triggers the action with the specified layer. This also emits the triggered() slot. */
/** Triggers the action with the specified layer. */
void triggerForLayer( QgsMapLayer* layer );

/** Define the targets of the action */
void setTargets( Targets targets );
/** Return availibity of action */
const Targets& targets() const;

signals:
/** Triggered when action has been run for a specific list of features */
void triggeredForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
void triggeredForFeatures( QgsMapLayer* layer, const QList<QgsFeature> featureList );

/** Triggered when action has been run for a specific feature */
void triggeredForFeature( QgsMapLayer* layer, const QgsFeature* feature );
void triggeredForFeature( QgsMapLayer* layer, const QgsFeature& feature );

/** Triggered when action has been run for a specific layer */
void triggeredForLayer( QgsMapLayer* layer );
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsmaptoolidentifyaction.cpp
Expand Up @@ -56,7 +56,7 @@ QgsMapToolIdentifyAction::QgsMapToolIdentifyAction( QgsMapCanvas * canvas )
mIdentifyMenu->setAllowMultipleReturn( true );

QgsMapLayerAction* attrTableAction = new QgsMapLayerAction( tr( "Show attribute table" ), mIdentifyMenu, QgsMapLayer::VectorLayer, QgsMapLayerAction::MultipleFeatures );
connect( attrTableAction, SIGNAL( triggeredForFeatures( QgsMapLayer*, QList<const QgsFeature*> ) ), this, SLOT( showAttributeTable( QgsMapLayer*, QList<const QgsFeature*> ) ) );
connect( attrTableAction, SIGNAL( triggeredForFeatures( QgsMapLayer*, const QList<QgsFeature> ) ), this, SLOT( showAttributeTable( QgsMapLayer*, const QList<QgsFeature> ) ) );
identifyMenu()->addCustomAction( attrTableAction );
}

Expand All @@ -81,7 +81,7 @@ QgsIdentifyResultsDialog *QgsMapToolIdentifyAction::resultsDialog()
return mResultsDialog;
}

void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer* layer, QList<const QgsFeature*> featureList )
void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer* layer, const QList<QgsFeature> featureList )
{
resultsDialog()->clear();

Expand All @@ -90,9 +90,9 @@ void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer* layer, QList<con
return;

QString filter = "$id IN (";
Q_FOREACH ( const QgsFeature* feature, featureList )
Q_FOREACH ( const QgsFeature feature, featureList )

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Sep 17, 2014

Member

better to use const QgsFeature& feature

This comment has been minimized.

Copy link
@3nids

3nids Sep 17, 2014

Author Member

thanks!

{
filter.append( QString( "%1," ).arg( feature->id() ) );
filter.append( QString( "%1," ).arg( feature.id() ) );
}
filter = filter.replace( QRegExp( ",$" ), ")" );

Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsmaptoolidentifyaction.h
Expand Up @@ -72,7 +72,8 @@ class APP_EXPORT QgsMapToolIdentifyAction : public QgsMapToolIdentify
void copyToClipboard( QgsFeatureStore & );

private slots:
void showAttributeTable( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
void showAttributeTable( QgsMapLayer* layer, const QList<QgsFeature> featureList );

private:
//! Pointer to the identify results dialog for name/value pairs
QPointer<QgsIdentifyResultsDialog> mResultsDialog;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsidentifymenu.cpp
Expand Up @@ -413,10 +413,10 @@ void QgsIdentifyMenu::triggerMapLayerAction()
// multiples features
if ( actData.mMapLayerAction->targets().testFlag( QgsMapLayerAction::MultipleFeatures ) )
{
QList<const QgsFeature*> featureList;
QList<QgsFeature> featureList;
Q_FOREACH ( QgsMapToolIdentify::IdentifyResult result, mLayerIdResults[actData.mLayer] )
{
featureList << new QgsFeature( result.mFeature );
featureList << result.mFeature;
}
actData.mMapLayerAction->triggerForFeatures( actData.mLayer, featureList );
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaplayeractionregistry.cpp
Expand Up @@ -72,7 +72,7 @@ bool QgsMapLayerAction::canRunUsingLayer( QgsMapLayer* layer ) const
return false;
}

void QgsMapLayerAction::triggerForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList )
void QgsMapLayerAction::triggerForFeatures( QgsMapLayer* layer, const QList<QgsFeature> featureList )
{
emit triggeredForFeatures( layer, featureList );
}
Expand Down
10 changes: 5 additions & 5 deletions src/gui/qgsmaplayeractionregistry.h
Expand Up @@ -47,10 +47,10 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
//! @note using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatiblity reasons.
QgsMapLayerAction( QString name, QObject *parent, Targets targets = AllActions );

/**Creates a map layer action which can run only on a specific layer*/
//! Creates a map layer action which can run only on a specific layer
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Targets targets = AllActions );

/**Creates a map layer action which can run on a specific type of layer*/
//! Creates a map layer action which can run on a specific type of layer
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Targets targets = AllActions );

~QgsMapLayerAction();
Expand All @@ -59,9 +59,9 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
bool canRunUsingLayer( QgsMapLayer* layer ) const;

/** Triggers the action with the specified layer and list of feature. */
void triggerForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
void triggerForFeatures( QgsMapLayer* layer, const QList<QgsFeature> featureList );

/** Triggers the action with the specified layer and feature. */
/** Triggers the action with the specified layer and feature. */
void triggerForFeature( QgsMapLayer* layer, const QgsFeature* feature );

/** Triggers the action with the specified layer. */
Expand All @@ -74,7 +74,7 @@ class GUI_EXPORT QgsMapLayerAction : public QAction

signals:
/** Triggered when action has been run for a specific list of features */
void triggeredForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
void triggeredForFeatures( QgsMapLayer* layer, const QList<QgsFeature> featureList );

/** Triggered when action has been run for a specific feature */
void triggeredForFeature( QgsMapLayer* layer, const QgsFeature& feature );
Expand Down

0 comments on commit 2188de6

Please sign in to comment.