Skip to content
Permalink
Browse files
allow attribute and alias names in actions
git-svn-id: http://svn.osgeo.org/qgis/trunk@14283 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 25, 2010
1 parent ff198a8 commit c8c01721e0f29c98ae45dc113b49fd55a9bfab3d
@@ -37,7 +37,7 @@ class QgsAttributeAction
#include "qgsattributeaction.h"
%End
public:
QgsAttributeAction();
QgsAttributeAction( QgsVectorLayer * );

//! Destructor
virtual ~QgsAttributeAction();
@@ -53,16 +53,17 @@ class QgsAttributeAction
// index into values which indicates which value in the values vector
// is to be used if the action has a default placeholder.
// @note added to python API in 1.6 (without executePython parameter)
void doAction( int index, const QList< QPair<QString, QString> > &values,
void doAction( int index,
const QMap<int, QVariant> &values,
int defaultValueIndex = 0 );

//! Removes all actions
void clearActions();

//! Expands the given action, replacing all %'s with the value as
// given.
static QString expandAction( QString action, const QList< QPair<QString, QString> > &values,
uint defaultValueIndex );
//! Expands the given action, replacing all %'s with the value as given.
QString expandAction( QString action,
const QMap<int, QVariant> &values,
uint defaultValueIndex );

//! Writes the actions out in XML format
bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
@@ -26,6 +26,7 @@ SET(QGIS_APP_SRCS
qgsgraduatedsymboldialog.cpp
qgshelpviewer.cpp
qgsidentifyresults.cpp
qgsfeatureaction.cpp
qgslabeldialog.cpp
qgslabelengineconfigdialog.cpp
qgslabelinggui.cpp
@@ -155,6 +156,7 @@ SET (QGIS_APP_MOC_HDRS
qgsgraduatedsymboldialog.h
qgshelpviewer.h
qgsidentifyresults.h
qgsfeatureaction.h
qgslabeldialog.h
qgsmanageconnectionsdialog.h
qgsmaptoolidentify.h
@@ -499,14 +499,11 @@ void QgsAttributeTableModel::incomingChangeLayout()

void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
{
QList< QPair<QString, QString> > attributes;
QgsAttributeMap attributes;

for ( int i = 0; i < mAttributes.size(); i++ )
{
attributes << QPair<QString, QString>(
mLayer->pendingFields()[ mAttributes[i] ].name(),
data( index( idx.row(), i ), Qt::EditRole ).toString()
);
attributes.insert( i, data( index( idx.row(), i ), Qt::EditRole ) );
}

mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ) );
@@ -0,0 +1,42 @@
/***************************************************************************
qgsfeatureaction.cpp - description
-------------------
begin : 2010-09-20
copyright : (C) 2010 by Jürgen E. Fischer
email : jef at norbit dot de
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */

#include "qgsfeatureaction.h"
#include "qgsvectorlayer.h"
#include "qgsidentifyresults.h"

QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *results, QgsVectorLayer *vl, int action, QTreeWidgetItem *featItem )
: QAction( name, results )
, mLayer( vl )
, mAction( action )
{
results->retrieveAttributes( featItem, mAttributes, mIdx );
}

QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *layer, int action, QObject *parent )
: QAction( name, parent )
, mLayer( layer )
, mAction( action )
{
mAttributes = f.attributeMap();
}

void QgsFeatureAction::execute()
{
mLayer->actions()->doAction( mAction, mAttributes, mIdx );
}
@@ -0,0 +1,49 @@
/***************************************************************************
qgsfeatureaction.h - description
------------------
begin : 2010-09-20
copyright : (C) 2010 by Jürgen E. Fischer
email : jef at norbit dot de
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#ifndef QGSFEATUREACTION_H
#define QGSFEATUREACTION_H

#include "qgsfeature.h"

#include <QList>
#include <QPair>
#include <QAction>

class QgsIdentifyResults;
class QgsVectorLayer;
class QTreeWidgetItem;

class QgsFeatureAction : public QAction
{
Q_OBJECT

public:
QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *vl, int action, QObject *parent );
QgsFeatureAction( const QString &name, QgsIdentifyResults *results, QgsVectorLayer *vl, int action, QTreeWidgetItem *featItem );

public slots:
void execute();

private:
QgsVectorLayer *mLayer;
int mAction;
int mIdx;
QgsAttributeMap mAttributes;
};

#endif
Loading

0 comments on commit c8c0172

Please sign in to comment.