Skip to content

Commit

Permalink
Fixes qgis#52740 : remove properties widget when layout item is destr…
Browse files Browse the repository at this point in the history
…oyed
  • Loading branch information
troopa81 committed Oct 17, 2023
1 parent 99d0f8a commit 3b4e2bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,8 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPa

if ( auto widget = qobject_cast< QgsLayoutItemBaseWidget * >( mItemPropertiesStack->mainPanel() ) )
{
if ( widget->layoutObject() == item )
const QgsLayoutObject *currentItem = widget->layoutObject();
if ( currentItem == item )
{
// already showing properties for this item - we don't want to create a new panel
if ( bringPanelToFront )
Expand All @@ -1354,6 +1355,9 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPa
if ( bringPanelToFront )
mItemDock->setUserVisible( true );

disconnect( currentItem, &QgsLayoutItem::destroyed, this, &QgsLayoutDesignerDialog::onItemDestroyed );
connect( item, &QgsLayoutItem::destroyed, this, &QgsLayoutDesignerDialog::onItemDestroyed );

return;
}
}
Expand All @@ -1373,10 +1377,7 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPa
connect( ppWidget, &QgsLayoutPagePropertiesWidget::pageOrientationChanged, this, &QgsLayoutDesignerDialog::pageOrientationChanged );

widget->setDockMode( true );
connect( item, &QgsLayoutItem::destroyed, widget.get(), [this]
{
delete mItemPropertiesStack->takeMainPanel();
} );
connect( item, &QgsLayoutItem::destroyed, this, &QgsLayoutDesignerDialog::onItemDestroyed );

mItemPropertiesStack->setMainPanel( widget.release() );
if ( bringPanelToFront )
Expand Down Expand Up @@ -5075,3 +5076,12 @@ void QgsLayoutDesignerDialog::toolButtonActionTriggered( QAction *action )

bt->setDefaultAction( action );
}

void QgsLayoutDesignerDialog::onItemDestroyed( QObject *item )
{
if ( QgsLayoutItemBaseWidget *widget = qobject_cast< QgsLayoutItemBaseWidget * >( mItemPropertiesStack->mainPanel() ) )
{
if ( widget->layoutObject() == item )
delete mItemPropertiesStack->takeMainPanel();
}
}
2 changes: 1 addition & 1 deletion src/app/layout/qgslayoutdesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
void backgroundTaskCountChanged( int total );
void onMapPreviewRefreshed();
void onItemAdded( QgsLayoutItem *item );
void onItemDestroyed( QObject *item );

private:

Expand Down Expand Up @@ -599,4 +600,3 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
};

#endif // QGSLAYOUTDESIGNERDIALOG_H

0 comments on commit 3b4e2bb

Please sign in to comment.