Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow attribute and alias names in actions
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14283 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 25, 2010
1 parent 65963bd commit 7733abd
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 181 deletions.
13 changes: 7 additions & 6 deletions python/core/qgsattributeaction.sip
Expand Up @@ -37,7 +37,7 @@ class QgsAttributeAction
#include "qgsattributeaction.h"
%End
public:
QgsAttributeAction();
QgsAttributeAction( QgsVectorLayer * );

//! Destructor
virtual ~QgsAttributeAction();
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -26,6 +26,7 @@ SET(QGIS_APP_SRCS
qgsgraduatedsymboldialog.cpp
qgshelpviewer.cpp
qgsidentifyresults.cpp
qgsfeatureaction.cpp
qgslabeldialog.cpp
qgslabelengineconfigdialog.cpp
qgslabelinggui.cpp
Expand Down Expand Up @@ -155,6 +156,7 @@ SET (QGIS_APP_MOC_HDRS
qgsgraduatedsymboldialog.h
qgshelpviewer.h
qgsidentifyresults.h
qgsfeatureaction.h
qgslabeldialog.h
qgsmanageconnectionsdialog.h
qgsmaptoolidentify.h
Expand Down
7 changes: 2 additions & 5 deletions src/app/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -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() ) );
Expand Down
42 changes: 42 additions & 0 deletions src/app/qgsfeatureaction.cpp
@@ -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 );
}
49 changes: 49 additions & 0 deletions src/app/qgsfeatureaction.h
@@ -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

0 comments on commit 7733abd

Please sign in to comment.