23
23
#include " qgsexpressionbuilderdialog.h"
24
24
#include " qgsattributeaction.h"
25
25
#include " qgsvectordataprovider.h"
26
+ #include " qgsmessagelog.h"
26
27
27
28
#include < QDialog>
28
29
#include < QMenu>
@@ -229,6 +230,7 @@ void QgsDualView::initLayerCache( QgsVectorLayer* layer )
229
230
connect ( layer, SIGNAL ( editingStopped () ), this , SLOT ( editingToggled () ) );
230
231
connect ( layer, SIGNAL ( attributeAdded ( int ) ), this , SLOT ( attributeAdded ( int ) ) );
231
232
connect ( layer, SIGNAL ( attributeDeleted ( int ) ), this , SLOT ( attributeDeleted ( int ) ) );
233
+ connect ( layer, SIGNAL ( featureDeleted ( QgsFeatureId ) ), this , SLOT ( featureDeleted ( QgsFeatureId ) ) );
232
234
}
233
235
234
236
void QgsDualView::initModels ( QgsMapCanvas* mapCanvas )
@@ -255,7 +257,7 @@ void QgsDualView::on_mFeatureList_currentEditSelectionChanged( const QgsFeature
255
257
// Backup old dialog and delete only after creating the new dialog, so we can "hot-swap" the contained QgsFeature
256
258
QgsAttributeDialog* oldDialog = mAttributeDialog ;
257
259
258
- if ( mAttributeDialog ->dialog () )
260
+ if ( mAttributeDialog && mAttributeDialog ->dialog () )
259
261
{
260
262
saveEditChanges ();
261
263
mAttributeEditorLayout ->removeWidget ( mAttributeDialog ->dialog () );
@@ -290,6 +292,12 @@ void QgsDualView::saveEditChanges()
290
292
// Get the edited feature
291
293
const QgsAttributes &dst = mAttributeDialog ->feature ()->attributes ();
292
294
295
+ if ( src.count () != dst.count () )
296
+ {
297
+ // bail out
298
+ return ;
299
+ }
300
+
293
301
mLayerCache ->layer ()->beginEditCommand ( tr ( " Attributes changed" ) );
294
302
295
303
for ( int i = 0 ; i < dst.count (); ++i )
@@ -348,7 +356,7 @@ void QgsDualView::previewColumnChanged( QObject* action )
348
356
void QgsDualView::editingToggled ()
349
357
{
350
358
// Reload the attribute dialog widget and commit changes if any
351
- if ( mAttributeDialog ->dialog () && mAttributeDialog ->feature () )
359
+ if ( mAttributeDialog && mAttributeDialog ->dialog () && mAttributeDialog ->feature () )
352
360
{
353
361
on_mFeatureList_currentEditSelectionChanged ( *mAttributeDialog ->feature () );
354
362
}
@@ -457,6 +465,22 @@ void QgsDualView::attributeAdded( int attribute )
457
465
}
458
466
}
459
467
468
+ void QgsDualView::featureDeleted ( QgsFeatureId fid )
469
+ {
470
+ if ( mAttributeDialog && mAttributeDialog ->dialog () )
471
+ {
472
+ QgsFeature* feat = mAttributeDialog ->feature ();
473
+ if ( feat )
474
+ {
475
+ if ( fid == feat->id () )
476
+ {
477
+ delete ( mAttributeDialog );
478
+ mAttributeDialog = NULL ;
479
+ }
480
+ }
481
+ }
482
+ }
483
+
460
484
void QgsDualView::reloadAttribute ( const int & idx )
461
485
{
462
486
if ( mAttributeDialog && mAttributeDialog ->dialog () )
0 commit comments