20
20
#include < QFileInfo>
21
21
#include < QString>
22
22
#include < QMenu>
23
+ #include < QDialog>
24
+ #include < QAbstractButton>
23
25
24
26
#include " qgisappinterface.h"
25
27
#include " qgisapp.h"
32
34
#include " qgsattributedialog.h"
33
35
#include " qgsfield.h"
34
36
#include " qgsvectordataprovider.h"
37
+ #include " qgsfeatureaction.h"
38
+ #include " qgsattributeaction.h"
35
39
36
40
QgisAppInterface::QgisAppInterface ( QgisApp * _qgis )
37
41
: qgis( _qgis ),
@@ -356,7 +360,7 @@ QAction *QgisAppInterface::actionCheckQgisVersion() { return qgis->actionCheckQg
356
360
QAction *QgisAppInterface::actionHelpSeparator2 () { return qgis->actionHelpSeparator2 (); }
357
361
QAction *QgisAppInterface::actionAbout () { return qgis->actionAbout (); }
358
362
359
- bool QgisAppInterface::openFeatureForm ( QgsVectorLayer *vlayer, QgsFeature &f )
363
+ bool QgisAppInterface::openFeatureForm ( QgsVectorLayer *vlayer, QgsFeature &f, bool updateFeatureOnly )
360
364
{
361
365
if ( !vlayer )
362
366
return false ;
@@ -373,8 +377,61 @@ bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f )
373
377
}
374
378
}
375
379
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
+
379
436
return res;
380
437
}
0 commit comments