Skip to content

Commit

Permalink
Fixes #52740 : remove properties widget when layout item is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and github-actions[bot] committed Oct 18, 2023
1 parent 74ae947 commit 00eaa2d
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
Expand Up @@ -1320,7 +1320,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 @@ -1336,6 +1337,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 @@ -1355,10 +1359,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 @@ -5035,3 +5036,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
Expand Up @@ -416,6 +416,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 @@ -587,4 +588,3 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
};

#endif // QGSLAYOUTDESIGNERDIALOG_H

0 comments on commit 00eaa2d

Please sign in to comment.