Skip to content

Commit 7733abd

Browse files
author
jef
committed
allow attribute and alias names in actions
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14283 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 65963bd commit 7733abd

12 files changed

+303
-181
lines changed

python/core/qgsattributeaction.sip

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QgsAttributeAction
3737
#include "qgsattributeaction.h"
3838
%End
3939
public:
40-
QgsAttributeAction();
40+
QgsAttributeAction( QgsVectorLayer * );
4141

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

5960
//! Removes all actions
6061
void clearActions();
6162

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

6768
//! Writes the actions out in XML format
6869
bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;

src/app/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SET(QGIS_APP_SRCS
2626
qgsgraduatedsymboldialog.cpp
2727
qgshelpviewer.cpp
2828
qgsidentifyresults.cpp
29+
qgsfeatureaction.cpp
2930
qgslabeldialog.cpp
3031
qgslabelengineconfigdialog.cpp
3132
qgslabelinggui.cpp
@@ -155,6 +156,7 @@ SET (QGIS_APP_MOC_HDRS
155156
qgsgraduatedsymboldialog.h
156157
qgshelpviewer.h
157158
qgsidentifyresults.h
159+
qgsfeatureaction.h
158160
qgslabeldialog.h
159161
qgsmanageconnectionsdialog.h
160162
qgsmaptoolidentify.h

src/app/attributetable/qgsattributetablemodel.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,11 @@ void QgsAttributeTableModel::incomingChangeLayout()
499499

500500
void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
501501
{
502-
QList< QPair<QString, QString> > attributes;
502+
QgsAttributeMap attributes;
503503

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

512509
mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ) );

src/app/qgsfeatureaction.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/***************************************************************************
2+
qgsfeatureaction.cpp - description
3+
-------------------
4+
begin : 2010-09-20
5+
copyright : (C) 2010 by Jürgen E. Fischer
6+
email : jef at norbit dot de
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id$ */
18+
19+
#include "qgsfeatureaction.h"
20+
#include "qgsvectorlayer.h"
21+
#include "qgsidentifyresults.h"
22+
23+
QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *results, QgsVectorLayer *vl, int action, QTreeWidgetItem *featItem )
24+
: QAction( name, results )
25+
, mLayer( vl )
26+
, mAction( action )
27+
{
28+
results->retrieveAttributes( featItem, mAttributes, mIdx );
29+
}
30+
31+
QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *layer, int action, QObject *parent )
32+
: QAction( name, parent )
33+
, mLayer( layer )
34+
, mAction( action )
35+
{
36+
mAttributes = f.attributeMap();
37+
}
38+
39+
void QgsFeatureAction::execute()
40+
{
41+
mLayer->actions()->doAction( mAction, mAttributes, mIdx );
42+
}

src/app/qgsfeatureaction.h

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************************************
2+
qgsfeatureaction.h - description
3+
------------------
4+
begin : 2010-09-20
5+
copyright : (C) 2010 by Jürgen E. Fischer
6+
email : jef at norbit dot de
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id$ */
18+
#ifndef QGSFEATUREACTION_H
19+
#define QGSFEATUREACTION_H
20+
21+
#include "qgsfeature.h"
22+
23+
#include <QList>
24+
#include <QPair>
25+
#include <QAction>
26+
27+
class QgsIdentifyResults;
28+
class QgsVectorLayer;
29+
class QTreeWidgetItem;
30+
31+
class QgsFeatureAction : public QAction
32+
{
33+
Q_OBJECT
34+
35+
public:
36+
QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *vl, int action, QObject *parent );
37+
QgsFeatureAction( const QString &name, QgsIdentifyResults *results, QgsVectorLayer *vl, int action, QTreeWidgetItem *featItem );
38+
39+
public slots:
40+
void execute();
41+
42+
private:
43+
QgsVectorLayer *mLayer;
44+
int mAction;
45+
int mIdx;
46+
QgsAttributeMap mAttributes;
47+
};
48+
49+
#endif

0 commit comments

Comments
 (0)