Skip to content

Commit 73e690e

Browse files
author
jef
committed
save feature attribute changes from plugins to layer
git-svn-id: http://svn.osgeo.org/qgis/trunk@14284 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c8c0172 commit 73e690e

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

python/gui/qgisinterface.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class QgisInterface : QObject
258258

259259
//! open feature form
260260
// @added in 1.6
261-
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f ) = 0;
261+
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false ) = 0;
262262

263263
signals:
264264
/** Emited whenever current (selected) layer changes.

src/app/qgisappinterface.cpp

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <QFileInfo>
2121
#include <QString>
2222
#include <QMenu>
23+
#include <QDialog>
24+
#include <QAbstractButton>
2325

2426
#include "qgisappinterface.h"
2527
#include "qgisapp.h"
@@ -32,6 +34,8 @@
3234
#include "qgsattributedialog.h"
3335
#include "qgsfield.h"
3436
#include "qgsvectordataprovider.h"
37+
#include "qgsfeatureaction.h"
38+
#include "qgsattributeaction.h"
3539

3640
QgisAppInterface::QgisAppInterface( QgisApp * _qgis )
3741
: qgis( _qgis ),
@@ -356,7 +360,7 @@ QAction *QgisAppInterface::actionCheckQgisVersion() { return qgis->actionCheckQg
356360
QAction *QgisAppInterface::actionHelpSeparator2() { return qgis->actionHelpSeparator2(); }
357361
QAction *QgisAppInterface::actionAbout() { return qgis->actionAbout(); }
358362

359-
bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f )
363+
bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, bool updateFeatureOnly )
360364
{
361365
if ( !vlayer )
362366
return false;
@@ -373,8 +377,61 @@ bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f )
373377
}
374378
}
375379

376-
QgsAttributeDialog *mypDialog = new QgsAttributeDialog( vlayer, &f );
377-
bool res = mypDialog->exec();
378-
delete mypDialog;
380+
QgsAttributeMap src = f.attributeMap();
381+
382+
if ( !updateFeatureOnly && vlayer->isEditable() )
383+
vlayer->beginEditCommand( tr( "Feature form edit" ) );
384+
385+
QgsAttributeDialog *ad = new QgsAttributeDialog( vlayer, &f );
386+
387+
if ( vlayer->actions()->size() > 0 )
388+
{
389+
ad->dialog()->setContextMenuPolicy( Qt::ActionsContextMenu );
390+
391+
QAction *a = new QAction( tr( "Run actions" ), ad->dialog() );
392+
a->setEnabled( false );
393+
ad->dialog()->addAction( a );
394+
395+
for ( int i = 0; i < vlayer->actions()->size(); i++ )
396+
{
397+
const QgsAction &action = vlayer->actions()->at( i );
398+
399+
if ( !action.runable() )
400+
continue;
401+
402+
QgsFeatureAction *a = new QgsFeatureAction( action.name(), f, vlayer, i, ad->dialog() );
403+
ad->dialog()->addAction( a );
404+
connect( a, SIGNAL( triggered() ), a, SLOT( execute() ) );
405+
406+
QAbstractButton *pb = ad->dialog()->findChild<QAbstractButton *>( action.name() );
407+
if ( pb )
408+
connect( pb, SIGNAL( clicked() ), a, SLOT( execute() ) );
409+
}
410+
}
411+
412+
bool res = ad->exec();
413+
414+
if ( !updateFeatureOnly && vlayer->isEditable() )
415+
{
416+
if ( res )
417+
{
418+
const QgsAttributeMap &dst = f.attributeMap();
419+
for ( QgsAttributeMap::const_iterator it = dst.begin(); it != dst.end(); it++ )
420+
{
421+
if ( !src.contains( it.key() ) || it.value() != src[it.key()] )
422+
{
423+
vlayer->changeAttributeValue( f.id(), it.key(), it.value() );
424+
}
425+
}
426+
vlayer->endEditCommand();
427+
}
428+
else
429+
{
430+
vlayer->destroyEditCommand();
431+
}
432+
}
433+
434+
delete ad;
435+
379436
return res;
380437
}

src/app/qgisappinterface.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@ class QgisAppInterface : public QgisInterface
264264

265265
//! open feature form
266266
// returns true when dialog was accepted
267+
// @param l vector layer
268+
// @param f feature to show/modify
269+
// @param updateFeatureOnly only update the feature update (don't change any attributes of the layer)
267270
// @added in 1.6
268-
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f );
271+
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false );
269272

270273
signals:
271274
void currentThemeChanged( QString );

0 commit comments

Comments
 (0)