Skip to content
Permalink
Browse files

Rename scopes to "Field", "Feature", "Layer"

  • Loading branch information
m-kuhn committed Nov 16, 2016
1 parent 5b4a88f commit e7d8b2cabf5063f87428157438c68a0dfe812d4d
@@ -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() )
{
@@ -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 );
@@ -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() )
{
@@ -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();
@@ -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 )
{
@@ -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();
@@ -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(),
@@ -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;
}
@@ -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.
@@ -143,8 +142,6 @@ class CORE_EXPORT QgsActionManager

QVariantMap mDefaultActions;

int mDefaultAction;

QgsExpressionContext createExpressionContext() const;
};

@@ -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
@@ -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( "" );
@@ -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" ) );

0 comments on commit e7d8b2c

Please sign in to comment.
You can’t perform that action at this time.