Skip to content

Commit

Permalink
save feature attribute changes from plugins to layer
Browse files Browse the repository at this point in the history
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 75079a7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgisinterface.sip
Expand Up @@ -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.
Expand Down
65 changes: 61 additions & 4 deletions src/app/qgisappinterface.cpp
Expand Up @@ -20,6 +20,8 @@
#include <QFileInfo>
#include <QString>
#include <QMenu>
#include <QDialog>
#include <QAbstractButton>

#include "qgisappinterface.h"
#include "qgisapp.h"
Expand All @@ -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 ),
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
5 changes: 4 additions & 1 deletion src/app/qgisappinterface.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 75079a7

Please sign in to comment.