@@ -69,7 +69,7 @@ QgsExpressionContext QgsAttributeTableDialog::createExpressionContext() const
69
69
70
70
void QgsAttributeTableDialog::updateMultiEditButtonState ()
71
71
{
72
- if ( mLayer ->editFormConfig ().layout () == QgsEditFormConfig::UiFileLayout )
72
+ if ( ! mLayer || ( mLayer ->editFormConfig ().layout () == QgsEditFormConfig::UiFileLayout ) )
73
73
return ;
74
74
75
75
mActionToggleMultiEdit ->setEnabled ( mLayer ->isEditable () );
@@ -199,7 +199,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
199
199
// info from layer to table
200
200
connect ( mLayer , &QgsVectorLayer::editingStarted, this , &QgsAttributeTableDialog::editingToggled );
201
201
connect ( mLayer , &QgsVectorLayer::editingStopped, this , &QgsAttributeTableDialog::editingToggled );
202
- connect ( mLayer , &QObject::destroyed, this , &QWidget::close );
202
+ connect ( mLayer , &QObject::destroyed, mMainView , &QgsDualView::cancelProgress );
203
203
connect ( mLayer , &QgsVectorLayer::selectionChanged, this , &QgsAttributeTableDialog::updateTitle );
204
204
connect ( mLayer , &QgsVectorLayer::featureAdded, this , &QgsAttributeTableDialog::updateTitle );
205
205
connect ( mLayer , &QgsVectorLayer::featuresDeleted, this , &QgsAttributeTableDialog::updateTitle );
@@ -292,59 +292,69 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
292
292
break ;
293
293
}
294
294
295
- mUpdateExpressionText ->registerExpressionContextGenerator ( this );
296
- mFieldCombo ->setFilters ( QgsFieldProxyModel::AllTypes | QgsFieldProxyModel::HideReadOnly );
297
- mFieldCombo ->setLayer ( mLayer );
298
-
299
- connect ( mRunFieldCalc , &QAbstractButton::clicked, this , &QgsAttributeTableDialog::updateFieldFromExpression );
300
- connect ( mRunFieldCalcSelected , &QAbstractButton::clicked, this , &QgsAttributeTableDialog::updateFieldFromExpressionSelected );
301
- // NW TODO Fix in 2.6 - Doesn't work with field model for some reason.
302
- // connect( mUpdateExpressionText, SIGNAL( returnPressed() ), this, SLOT( updateFieldFromExpression() ) );
303
- connect ( mUpdateExpressionText , static_cast < void ( QgsFieldExpressionWidget::* )( const QString &, bool ) > ( &QgsFieldExpressionWidget::fieldChanged ), this , &QgsAttributeTableDialog::updateButtonStatus );
304
- mUpdateExpressionText ->setLayer ( mLayer );
305
- mUpdateExpressionText ->setLeftHandButtonStyle ( true );
306
-
307
- int initialView = settings.value ( QStringLiteral ( " qgis/attributeTableView" ), -1 ).toInt ();
308
- if ( initialView < 0 )
295
+ // Layer might have been destroyed while loading!
296
+ if ( mLayer )
309
297
{
310
- initialView = settings.value ( QStringLiteral ( " qgis/attributeTableLastView" ), QgsDualView::AttributeTable ).toInt ();
311
- }
312
- mMainView ->setView ( static_cast < QgsDualView::ViewMode >( initialView ) );
313
- mMainViewButtonGroup ->button ( initialView )->setChecked ( true );
298
+ mUpdateExpressionText ->registerExpressionContextGenerator ( this );
299
+ mFieldCombo ->setFilters ( QgsFieldProxyModel::AllTypes | QgsFieldProxyModel::HideReadOnly );
300
+ mFieldCombo ->setLayer ( mLayer );
301
+
302
+ connect ( mRunFieldCalc , &QAbstractButton::clicked, this , &QgsAttributeTableDialog::updateFieldFromExpression );
303
+ connect ( mRunFieldCalcSelected , &QAbstractButton::clicked, this , &QgsAttributeTableDialog::updateFieldFromExpressionSelected );
304
+ // NW TODO Fix in 2.6 - Doesn't work with field model for some reason.
305
+ // connect( mUpdateExpressionText, SIGNAL( returnPressed() ), this, SLOT( updateFieldFromExpression() ) );
306
+ connect ( mUpdateExpressionText , static_cast < void ( QgsFieldExpressionWidget::* )( const QString &, bool ) > ( &QgsFieldExpressionWidget::fieldChanged ), this , &QgsAttributeTableDialog::updateButtonStatus );
307
+ mUpdateExpressionText ->setLayer ( mLayer );
308
+ mUpdateExpressionText ->setLeftHandButtonStyle ( true );
309
+
310
+ int initialView = settings.value ( QStringLiteral ( " qgis/attributeTableView" ), -1 ).toInt ();
311
+ if ( initialView < 0 )
312
+ {
313
+ initialView = settings.value ( QStringLiteral ( " qgis/attributeTableLastView" ), QgsDualView::AttributeTable ).toInt ();
314
+ }
315
+ mMainView ->setView ( static_cast < QgsDualView::ViewMode >( initialView ) );
316
+ mMainViewButtonGroup ->button ( initialView )->setChecked ( true );
314
317
315
- connect ( mActionToggleMultiEdit , &QAction::toggled, mMainView , &QgsDualView::setMultiEditEnabled );
316
- connect ( mActionSearchForm , &QAction::toggled, mMainView , &QgsDualView::toggleSearchMode );
317
- updateMultiEditButtonState ();
318
+ connect ( mActionToggleMultiEdit , &QAction::toggled, mMainView , &QgsDualView::setMultiEditEnabled );
319
+ connect ( mActionSearchForm , &QAction::toggled, mMainView , &QgsDualView::toggleSearchMode );
320
+ updateMultiEditButtonState ();
318
321
319
- if ( mLayer ->editFormConfig ().layout () == QgsEditFormConfig::UiFileLayout )
320
- {
321
- // not supported with custom UI
322
- mActionToggleMultiEdit ->setEnabled ( false );
323
- mActionToggleMultiEdit ->setToolTip ( tr ( " Multiedit is not supported when using custom UI forms" ) );
324
- mActionSearchForm ->setEnabled ( false );
325
- mActionSearchForm ->setToolTip ( tr ( " Search is not supported when using custom UI forms" ) );
326
- }
322
+ if ( mLayer ->editFormConfig ().layout () == QgsEditFormConfig::UiFileLayout )
323
+ {
324
+ // not supported with custom UI
325
+ mActionToggleMultiEdit ->setEnabled ( false );
326
+ mActionToggleMultiEdit ->setToolTip ( tr ( " Multiedit is not supported when using custom UI forms" ) );
327
+ mActionSearchForm ->setEnabled ( false );
328
+ mActionSearchForm ->setToolTip ( tr ( " Search is not supported when using custom UI forms" ) );
329
+ }
327
330
328
- QList<QgsAction> actions = mLayer ->actions ()->actions ( QStringLiteral ( " Layer" ) );
331
+ QList<QgsAction> actions = mLayer ->actions ()->actions ( QStringLiteral ( " Layer" ) );
329
332
330
- if ( actions.isEmpty () )
331
- {
332
- mActionFeatureActions ->setVisible ( false );
333
+ if ( actions.isEmpty () )
334
+ {
335
+ mActionFeatureActions ->setVisible ( false );
336
+ }
337
+ else
338
+ {
339
+ QMenu *actionMenu = new QMenu ();
340
+ Q_FOREACH ( const QgsAction &action, actions )
341
+ {
342
+ QAction *qAction = actionMenu->addAction ( action.icon (), action.shortTitle () );
343
+ qAction->setToolTip ( action.name () );
344
+ qAction->setData ( QVariant::fromValue<QgsAction>( action ) );
345
+ connect ( qAction, &QAction::triggered, this , &QgsAttributeTableDialog::layerActionTriggered );
346
+ }
347
+ mActionFeatureActions ->setMenu ( actionMenu );
348
+ }
349
+
350
+ editingToggled ();
351
+ // Close and delete if the layer has been destroyed
352
+ connect ( mLayer , &QObject::destroyed, this , &QWidget::close );
333
353
}
334
354
else
335
355
{
336
- QMenu *actionMenu = new QMenu ();
337
- Q_FOREACH ( const QgsAction &action, actions )
338
- {
339
- QAction *qAction = actionMenu->addAction ( action.icon (), action.shortTitle () );
340
- qAction->setToolTip ( action.name () );
341
- qAction->setData ( QVariant::fromValue<QgsAction>( action ) );
342
- connect ( qAction, &QAction::triggered, this , &QgsAttributeTableDialog::layerActionTriggered );
343
- }
344
- mActionFeatureActions ->setMenu ( actionMenu );
356
+ QWidget::close ();
345
357
}
346
-
347
- editingToggled ();
348
358
}
349
359
350
360
QgsAttributeTableDialog::~QgsAttributeTableDialog ()
@@ -354,6 +364,10 @@ QgsAttributeTableDialog::~QgsAttributeTableDialog()
354
364
355
365
void QgsAttributeTableDialog::updateTitle ()
356
366
{
367
+ if ( ! mLayer )
368
+ {
369
+ return ;
370
+ }
357
371
QWidget *w = mDock ? qobject_cast<QWidget *>( mDock ) : qobject_cast<QWidget *>( this );
358
372
w->setWindowTitle ( tr ( " %1 :: Features Total: %2, Filtered: %3, Selected: %4" )
359
373
.arg ( mLayer ->name () )
0 commit comments