65 changes: 54 additions & 11 deletions src/core/qgsattributeaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,63 @@ class CORE_EXPORT QgsAttributeAction
// dialog box.
void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );

//! Does the action using the given values. defaultValueIndex is an
// index into values which indicates which value in the values vector
// is to be used if the action has a default placeholder.
// @note parameter executePython deprecated (and missing in python binding)
/*! Does the action using the given values. defaultValueIndex is an
* index into values which indicates which value in the values vector
* is to be used if the action has a default placeholder.
* @note parameter executePython deprecated (and missing in python binding)
* @deprecated
*/
Q_DECL_DEPRECATED void doAction( int index,
const QgsAttributeMap &attributes,
int defaultValueIndex = 0,
void ( *executePython )( const QString & ) = 0 );

/*! Does the given values. defaultValueIndex is the index of the
* field to be used if the action has a $currfield placeholder.
* @note added in 1.9
*/
void doAction( int index,
const QgsAttributeMap &attributes,
int defaultValueIndex = 0,
void ( *executePython )( const QString & ) = 0 );
QgsFeature &feat,
int defaultValueIndex = 0 );

/*! Does the action using the expression builder to expand it
* and getting values from the passed feature attribute map.
* substitutionMap is used to pass custom substitutions, to replace
* each key in the map with the associated value
* @note added in 1.9
*/
void doAction( int index,
QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap = 0 );

//! Removes all actions
void clearActions() { mActions.clear(); }

//! Expands the given action, replacing all %'s with the value as
// given.
//! Return the layer
QgsVectorLayer *layer() { return mLayer; }

/*! Expands the given action, replacing all %'s with the value as
* given.
* @deprecated
*/
Q_DECL_DEPRECATED QString expandAction( QString action,
const QgsAttributeMap &attributes,
uint defaultValueIndex );

/*! Expands the given action using the expression builder
* This function currently replaces each expression between [% and %]
* placeholders in the action with the result of its evaluation on
* the feature passed as argument.
*
* Additional substitutions can be passed through the substitutionMap
* parameter
*
* @note added in 1.9
*/
QString expandAction( QString action,
const QgsAttributeMap &attributes,
uint defaultValueIndex );
QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap = 0 );


//! Writes the actions out in XML format
bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
Expand All @@ -142,6 +182,9 @@ class CORE_EXPORT QgsAttributeAction
QList<QgsAction> mActions;
QgsVectorLayer *mLayer;
static void ( *smPythonExecute )( const QString & );

void runAction( const QgsAction &action,
void ( *executePython )( const QString & ) = 0 );
};

#endif
14 changes: 3 additions & 11 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,13 @@ void QgsAttributeTableModel::incomingChangeLayout()

void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
{
QgsAttributeMap attributes;

for ( int i = 0; i < mAttributes.size(); i++ )
{
attributes.insert( mAttributes[i], data( index( idx.row(), i ), Qt::EditRole ) );
}

mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ) );
QgsFeature f = feature( idx );
mLayer->actions()->doAction( action, f, fieldIdx( idx.column() ) );
}

QgsFeature QgsAttributeTableModel::feature( QModelIndex &idx )
QgsFeature QgsAttributeTableModel::feature( const QModelIndex &idx ) const
{
QgsFeature f;
QgsAttributeMap attributes;

f.setFeatureId( rowToId( idx.row() ) );
for ( int i = 0; i < mAttributes.size(); i++ )
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
void executeAction( int action, const QModelIndex &idx ) const;

/** return feature attributes at given index */
QgsFeature feature( QModelIndex &idx );
QgsFeature feature( const QModelIndex &idx ) const;

signals:
/**
Expand Down
32 changes: 32 additions & 0 deletions src/ui/qgsattributeactiondialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,38 @@
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="insertExpressionButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Inserts an expression into the action</string>
</property>
<property name="text">
<string>Insert expression...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="fieldComboBox">
<property name="toolTip">
Expand Down