Skip to content
Permalink
Browse files

Fix crash when deleting layout items

Fixes #17876, #17770
  • Loading branch information
nyalldawson committed Jan 19, 2018
1 parent 0516136 commit fe13c0e81b74a9d85fa68a2334621c241772e0b8
Showing with 21 additions and 3 deletions.
  1. +20 −2 src/gui/layout/qgslayoutitemwidget.cpp
  2. +1 −1 src/gui/layout/qgslayoutitemwidget.h
@@ -190,6 +190,9 @@ QgsLayoutAtlas *QgsLayoutItemBaseWidget::layoutAtlas() const

void QgsLayoutItemPropertiesWidget::updateVariables()
{
if ( !mItem )
return;

QgsExpressionContext context = mItem->createExpressionContext();
mVariableEditor->setContext( &context );
int editableIndex = context.indexOfScope( tr( "Layout Item" ) );
@@ -295,8 +298,11 @@ void QgsLayoutItemPropertiesWidget::setItem( QgsLayoutItem *item )
disconnect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
}
mItem = item;
connect( mItem, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
if ( mItem )
{
connect( mItem, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsLayoutObject::changed, this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
}

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

void QgsLayoutItemPropertiesWidget::changeItemPosition()
{
if ( !mItem )
return;

mItem->layout()->undoStack()->beginCommand( mItem, tr( "Move Item" ), QgsLayoutItem::UndoIncrementalMove );

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

void QgsLayoutItemPropertiesWidget::changeItemReference( QgsLayoutItem::ReferencePoint point )
{
if ( !mItem )
return;

mItem->layout()->undoStack()->beginCommand( mItem, tr( "Change Item Reference" ) );
mItem->setReferencePoint( point );
mItem->layout()->undoStack()->endCommand();
}

void QgsLayoutItemPropertiesWidget::changeItemSize()
{
if ( !mItem )
return;

mItem->layout()->undoStack()->beginCommand( mItem, tr( "Resize Item" ), QgsLayoutItem::UndoIncrementalResize );

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

void QgsLayoutItemPropertiesWidget::variablesChanged()
{
if ( !mItem )
return;

QgsExpressionContextUtils::setLayoutItemVariables( mItem, mVariableEditor->variablesInActiveScope() );
}

@@ -265,7 +265,7 @@ class GUI_EXPORT QgsLayoutItemPropertiesWidget: public QWidget, private Ui::QgsL

private:

QgsLayoutItem *mItem = nullptr;
QPointer< QgsLayoutItem > mItem;
QgsLayoutConfigObject *mConfigObject = nullptr;

bool mFreezeXPosSpin = false;

0 comments on commit fe13c0e

Please sign in to comment.
You can’t perform that action at this time.