Skip to content

Commit

Permalink
Rename scopes to "Field", "Feature", "Layer"
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 16, 2016
1 parent 5b4a88f commit e7d8b2c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Expand Up @@ -309,7 +309,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mActionSearchForm->setToolTip( tr( "Search is not supported when using custom UI forms" ) );
}

QList<QgsAction> actions = mLayer->actions()->listActions( QStringLiteral( "AttributeTable" ) );
QList<QgsAction> actions = mLayer->actions()->listActions( QStringLiteral( "Layer" ) );

if ( actions.isEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfeatureaction.cpp
Expand Up @@ -66,7 +66,7 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, f, cloneFeature, parentWidget(), true, context );
dialog->setWindowFlags( dialog->windowFlags() | Qt::Tool );

QList<QgsAction> actions = mLayer->actions()->listActions();
QList<QgsAction> actions = mLayer->actions()->listActions( QStringLiteral( "Feature" ) );
if ( !actions.isEmpty() )
{
dialog->setContextMenuPolicy( Qt::ActionsContextMenu );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -480,7 +480,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat

//get valid QgsMapLayerActions for this layer
QList< QgsMapLayerAction* > registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer );
QList<QgsAction> actions = vlayer->actions()->listActions( QStringLiteral( "AttributeTableRow" ) );
QList<QgsAction> actions = vlayer->actions()->listActions( QStringLiteral( "Feature" ) );

if ( !vlayer->fields().isEmpty() || !actions.isEmpty() || !registeredActions.isEmpty() )
{
Expand Down Expand Up @@ -1092,7 +1092,7 @@ void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent* event )

if ( featItem && vlayer )
{
QList<QgsAction> actions = vlayer->actions()->listActions( QStringLiteral( "FieldSpecific" ) );
QList<QgsAction> actions = vlayer->actions()->listActions( QStringLiteral( "Field" ) );
if ( !actions.isEmpty() )
{
mActionPopup->addSeparator();
Expand Down
21 changes: 16 additions & 5 deletions src/core/qgsactionmanager.cpp
Expand Up @@ -150,7 +150,13 @@ QgsExpressionContext QgsActionManager::createExpressionContext() const
bool QgsActionManager::writeXml( QDomNode& layer_node, QDomDocument& doc ) const
{
QDomElement aActions = doc.createElement( QStringLiteral( "attributeactions" ) );
aActions.setAttribute( QStringLiteral( "default" ), mDefaultAction );
for ( QVariantMap::const_iterator defaultAction = mDefaultActions.constBegin(); defaultAction != mDefaultActions.constEnd(); ++ defaultAction )
{
QDomElement defaultActionElement = doc.createElement( QStringLiteral( "defaultAction" ) );
defaultActionElement.setAttribute( QStringLiteral( "key" ), defaultAction.key() );
defaultActionElement.setAttribute( QStringLiteral( "value" ), defaultAction.value().toString() );
aActions.appendChild( defaultActionElement );
}

Q_FOREACH ( const QgsAction& action, mActions )
{
Expand Down Expand Up @@ -183,9 +189,7 @@ bool QgsActionManager::readXml( const QDomNode& layer_node )

if ( !aaNode.isNull() )
{
mDefaultAction = aaNode.toElement().attribute( QStringLiteral( "default" ), 0 ).toInt();

QDomNodeList actionsettings = aaNode.childNodes();
QDomNodeList actionsettings = aaNode.toElement().elementsByTagName( QStringLiteral( "actionsetting" ) );
for ( int i = 0; i < actionsettings.size(); ++i )
{
QDomElement setting = actionsettings.item( i ).toElement();
Expand All @@ -210,7 +214,6 @@ bool QgsActionManager::readXml( const QDomNode& layer_node )
}
}


mActions.append(
QgsAction( static_cast< QgsAction::ActionType >( setting.attributeNode( QStringLiteral( "type" ) ).value().toInt() ),
setting.attributeNode( QStringLiteral( "name" ) ).value(),
Expand All @@ -222,6 +225,14 @@ bool QgsActionManager::readXml( const QDomNode& layer_node )
)
);
}

QDomNodeList defaultActionNodes = aaNode.toElement().elementsByTagName( "defaultAction" );

for ( int i = 0; i < defaultActionNodes.size(); ++i )
{
QDomElement defaultValueElem = defaultActionNodes.at( i ).toElement();
mDefaultActions.insert( defaultValueElem.attribute( "key" ), defaultValueElem.attribute( "value" ) );
}
}
return true;
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/qgsactionmanager.h
Expand Up @@ -51,7 +51,6 @@ class CORE_EXPORT QgsActionManager
//! Constructor
QgsActionManager( QgsVectorLayer *layer )
: mLayer( layer )
, mDefaultAction( -1 )
{}

/** Add an action with the given name and action details.
Expand Down Expand Up @@ -143,8 +142,6 @@ class CORE_EXPORT QgsActionManager

QVariantMap mDefaultActions;

int mDefaultAction;

QgsExpressionContext createExpressionContext() const;
};

Expand Down
9 changes: 3 additions & 6 deletions src/core/qgsactionscoperegistry.cpp
Expand Up @@ -28,16 +28,13 @@ QgsActionScopeRegistry::QgsActionScopeRegistry( QObject* parent )
mActionScopes.insert( QgsActionScope( QStringLiteral( "Canvas" ), tr( "Canvas" ), tr( "Available for the action map tool on the canvas." ), canvasScope ) );

QgsExpressionContextScope fieldScope;
fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "current_field" ), QStringLiteral( "[field_value]" ), true ) );
fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_index" ), 0, true ) );
fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_name" ), "[field_name]", true ) );
fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_value" ), "[field_value]", true ) );
mActionScopes.insert( QgsActionScope( QStringLiteral( "FieldSpecific" ), tr( "Field Specific" ), tr( "Available for individual fields in the attribute table." ), fieldScope ) );

mActionScopes.insert( QgsActionScope( QStringLiteral( "AttributeTableRow" ), tr( "Attribute Table Row" ), tr( "Available for individual features (rows) in the attribute table." ) ) );
mActionScopes.insert( QgsActionScope( QStringLiteral( "FeatureForm" ), tr( "Feature Form" ), tr( "Available for individual features in their form." ) ) );

mActionScopes.insert( QgsActionScope( QStringLiteral( "AttributeTable" ), tr( "Attribute Table" ), tr( "Available as layer global action in the attribute table." ) ) );
mActionScopes.insert( QgsActionScope( QStringLiteral( "Field" ), tr( "Field Scope" ), tr( "Available for individual fields. For example in the attribute table." ), fieldScope ) );
mActionScopes.insert( QgsActionScope( QStringLiteral( "Feature" ), tr( "Feature Scope" ), tr( "Available for individual features. For example on feature forms or per row in the attribute table." ) ) );
mActionScopes.insert( QgsActionScope( QStringLiteral( "Layer Scope" ), tr( "Layer Scope" ), tr( "Available as layer global action. For example on top of the attribute table." ) ) );
}

QSet<QgsActionScope> QgsActionScopeRegistry::actionScopes() const
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetableview.cpp
Expand Up @@ -176,7 +176,7 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
QAction* defaultAction = nullptr;

// first add user created layer actions
QList<QgsAction> actions = mFilterModel->layer()->actions()->listActions( QStringLiteral( "AttributeTableRow" ) );
QList<QgsAction> actions = mFilterModel->layer()->actions()->listActions( QStringLiteral( "Feature" ) );
Q_FOREACH ( const QgsAction& action, actions )
{
QString actionTitle = !action.shortTitle().isEmpty() ? action.shortTitle() : action.icon().isNull() ? action.name() : QLatin1String( "" );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -390,7 +390,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
}

//add user-defined actions to context menu
QList<QgsAction> actions = mLayerCache->layer()->actions()->listActions( QStringLiteral( "FieldSpecific" ) );
QList<QgsAction> actions = mLayerCache->layer()->actions()->listActions( QStringLiteral( "Field" ) );
if ( !actions.isEmpty() )
{
QAction* a = menu->addAction( tr( "Run layer action" ) );
Expand Down

0 comments on commit e7d8b2c

Please sign in to comment.