tdf#147394 delete crash legend

regression from
    commit 63e8c2ccd39263b24f644c3d0394044a2613eb88
    Author: Noel Grandin <noelgrandin@gmail.com>
    Date:   Sat Jan 29 21:21:27 2022 +0200
    use more concrete types in chart2, Diagram

Change-Id: I6598bb7c116bd94272a805e77751aa8cf5dc174a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129882
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index ccf18ae..92035d9 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -616,13 +616,17 @@ bool ChartController::executeDispatch_Delete()
                rtl::Reference< Diagram > xDiagram( xChartDoc->getFirstChartDiagram());
                if( xDiagram.is())
                {
                    UndoGuard aUndoGuard(
                        ActionDescriptionProvider::createDescription(
                            ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
                        m_xUndoManager );
                    xDiagram->setPropertyValue( "Show", uno::Any( false ));
                    bReturn = true;
                    aUndoGuard.commit();
                    uno::Reference< beans::XPropertySet > xLegendProp( xDiagram->getLegend(), uno::UNO_QUERY );
                    if( xLegendProp.is())
                    {
                        UndoGuard aUndoGuard(
                            ActionDescriptionProvider::createDescription(
                                ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
                            m_xUndoManager );
                        xLegendProp->setPropertyValue( "Show", uno::Any( false ));
                        bReturn = true;
                        aUndoGuard.commit();
                    }
                }
                break;
            }