Skip to content

Commit fe13c0e

Browse files
committedJan 19, 2018
Fix crash when deleting layout items
Fixes #17876, #17770
1 parent 0516136 commit fe13c0e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
 

‎src/gui/layout/qgslayoutitemwidget.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ QgsLayoutAtlas *QgsLayoutItemBaseWidget::layoutAtlas() const
190190

191191
void QgsLayoutItemPropertiesWidget::updateVariables()
192192
{
193+
if ( !mItem )
194+
return;
195+
193196
QgsExpressionContext context = mItem->createExpressionContext();
194197
mVariableEditor->setContext( &context );
195198
int editableIndex = context.indexOfScope( tr( "Layout Item" ) );
@@ -295,8 +298,11 @@ void QgsLayoutItemPropertiesWidget::setItem( QgsLayoutItem *item )
295298
disconnect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
296299
}
297300
mItem = item;
298-
connect( mItem, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
299-
connect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
301+
if ( mItem )
302+
{
303+
connect( mItem, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
304+
connect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
305+
}
300306

301307
setValuesForGuiElements();
302308
}
@@ -329,6 +335,9 @@ void QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged( const Q
329335

330336
void QgsLayoutItemPropertiesWidget::changeItemPosition()
331337
{
338+
if ( !mItem )
339+
return;
340+
332341
mItem->layout()->undoStack()->beginCommand( mItem, tr( "Move Item" ), QgsLayoutItem::UndoIncrementalMove );
333342

334343
QgsLayoutPoint point( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
@@ -339,13 +348,19 @@ void QgsLayoutItemPropertiesWidget::changeItemPosition()
339348

340349
void QgsLayoutItemPropertiesWidget::changeItemReference( QgsLayoutItem::ReferencePoint point )
341350
{
351+
if ( !mItem )
352+
return;
353+
342354
mItem->layout()->undoStack()->beginCommand( mItem, tr( "Change Item Reference" ) );
343355
mItem->setReferencePoint( point );
344356
mItem->layout()->undoStack()->endCommand();
345357
}
346358

347359
void QgsLayoutItemPropertiesWidget::changeItemSize()
348360
{
361+
if ( !mItem )
362+
return;
363+
349364
mItem->layout()->undoStack()->beginCommand( mItem, tr( "Resize Item" ), QgsLayoutItem::UndoIncrementalResize );
350365

351366
QgsLayoutSize size( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
@@ -356,6 +371,9 @@ void QgsLayoutItemPropertiesWidget::changeItemSize()
356371

357372
void QgsLayoutItemPropertiesWidget::variablesChanged()
358373
{
374+
if ( !mItem )
375+
return;
376+
359377
QgsExpressionContextUtils::setLayoutItemVariables( mItem, mVariableEditor->variablesInActiveScope() );
360378
}
361379

‎src/gui/layout/qgslayoutitemwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class GUI_EXPORT QgsLayoutItemPropertiesWidget: public QWidget, private Ui::QgsL
265265

266266
private:
267267

268-
QgsLayoutItem *mItem = nullptr;
268+
QPointer< QgsLayoutItem > mItem;
269269
QgsLayoutConfigObject *mConfigObject = nullptr;
270270

271271
bool mFreezeXPosSpin = false;

0 commit comments

Comments
 (0)
Please sign in to comment.