[QGIS Commit] r14284 - in trunk/qgis: python/gui src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Sep 25 16:11:22 EDT 2010
Author: jef
Date: 2010-09-25 20:11:22 +0000 (Sat, 25 Sep 2010)
New Revision: 14284
Modified:
trunk/qgis/python/gui/qgisinterface.sip
trunk/qgis/src/app/qgisappinterface.cpp
trunk/qgis/src/app/qgisappinterface.h
Log:
save feature attribute changes from plugins to layer
Modified: trunk/qgis/python/gui/qgisinterface.sip
===================================================================
--- trunk/qgis/python/gui/qgisinterface.sip 2010-09-25 20:09:20 UTC (rev 14283)
+++ trunk/qgis/python/gui/qgisinterface.sip 2010-09-25 20:11:22 UTC (rev 14284)
@@ -258,7 +258,7 @@
//! 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.
Modified: trunk/qgis/src/app/qgisappinterface.cpp
===================================================================
--- trunk/qgis/src/app/qgisappinterface.cpp 2010-09-25 20:09:20 UTC (rev 14283)
+++ trunk/qgis/src/app/qgisappinterface.cpp 2010-09-25 20:11:22 UTC (rev 14284)
@@ -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::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 @@
}
}
- 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;
}
Modified: trunk/qgis/src/app/qgisappinterface.h
===================================================================
--- trunk/qgis/src/app/qgisappinterface.h 2010-09-25 20:09:20 UTC (rev 14283)
+++ trunk/qgis/src/app/qgisappinterface.h 2010-09-25 20:11:22 UTC (rev 14284)
@@ -264,8 +264,11 @@
//! 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 );
More information about the QGIS-commit
mailing list