Skip to content
Permalink
Browse files
save feature attribute changes from plugins to layer
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14284 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 25, 2010
1 parent 7733abd commit 75079a731bb26b54488bd8b08d432c769ccfb507
Showing with 66 additions and 6 deletions.
  1. +1 −1 python/gui/qgisinterface.sip
  2. +61 −4 src/app/qgisappinterface.cpp
  3. +4 −1 src/app/qgisappinterface.h
@@ -258,7 +258,7 @@ class QgisInterface : QObject

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

signals:
/** Emited whenever current (selected) layer changes.
@@ -20,6 +20,8 @@
#include <QFileInfo>
#include <QString>
#include <QMenu>
#include <QDialog>
#include <QAbstractButton>

#include "qgisappinterface.h"
#include "qgisapp.h"
@@ -32,6 +34,8 @@
#include "qgsattributedialog.h"
#include "qgsfield.h"
#include "qgsvectordataprovider.h"
#include "qgsfeatureaction.h"
#include "qgsattributeaction.h"

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

bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f )
bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, bool updateFeatureOnly )
{
if ( !vlayer )
return false;
@@ -373,8 +377,61 @@ bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f )
}
}

QgsAttributeDialog *mypDialog = new QgsAttributeDialog( vlayer, &f );
bool res = mypDialog->exec();
delete mypDialog;
QgsAttributeMap src = f.attributeMap();

if ( !updateFeatureOnly && vlayer->isEditable() )
vlayer->beginEditCommand( tr( "Feature form edit" ) );

QgsAttributeDialog *ad = new QgsAttributeDialog( vlayer, &f );

if ( vlayer->actions()->size() > 0 )
{
ad->dialog()->setContextMenuPolicy( Qt::ActionsContextMenu );

QAction *a = new QAction( tr( "Run actions" ), ad->dialog() );
a->setEnabled( false );
ad->dialog()->addAction( a );

for ( int i = 0; i < vlayer->actions()->size(); i++ )
{
const QgsAction &action = vlayer->actions()->at( i );

if ( !action.runable() )
continue;

QgsFeatureAction *a = new QgsFeatureAction( action.name(), f, vlayer, i, ad->dialog() );
ad->dialog()->addAction( a );
connect( a, SIGNAL( triggered() ), a, SLOT( execute() ) );

QAbstractButton *pb = ad->dialog()->findChild<QAbstractButton *>( action.name() );
if ( pb )
connect( pb, SIGNAL( clicked() ), a, SLOT( execute() ) );
}
}

bool res = ad->exec();

if ( !updateFeatureOnly && vlayer->isEditable() )
{
if ( res )
{
const QgsAttributeMap &dst = f.attributeMap();
for ( QgsAttributeMap::const_iterator it = dst.begin(); it != dst.end(); it++ )
{
if ( !src.contains( it.key() ) || it.value() != src[it.key()] )
{
vlayer->changeAttributeValue( f.id(), it.key(), it.value() );
}
}
vlayer->endEditCommand();
}
else
{
vlayer->destroyEditCommand();
}
}

delete ad;

return res;
}
@@ -264,8 +264,11 @@ class QgisAppInterface : public QgisInterface

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

signals:
void currentThemeChanged( QString );

0 comments on commit 75079a7

Please sign in to comment.