tdf#92768 Add rendering support for hiding title object in chart2

Change-Id: Ice6335d52d53dcbaa8711f9669597bf5321ecd7c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110889
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/chart2/source/controller/sidebar/ChartElementsPanel.cxx b/chart2/source/controller/sidebar/ChartElementsPanel.cxx
index b14705cc..5212186 100644
--- a/chart2/source/controller/sidebar/ChartElementsPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartElementsPanel.cxx
@@ -665,9 +665,7 @@ void ChartElementsPanel::setTitleVisible(TitleHelper::eTitleType eTitle, bool bV
    }
    else
    {
        // TODO tdf#92768 use TitleHelper::hideTitle() here once there is
        // rendering support for the property "Visible"
        TitleHelper::removeTitle(eTitle, mxModel);
        TitleHelper::hideTitle(eTitle, mxModel);
    }
}

diff --git a/chart2/source/inc/TitleHelper.hxx b/chart2/source/inc/TitleHelper.hxx
index 0628252..c85b5ce 100644
--- a/chart2/source/inc/TitleHelper.hxx
+++ b/chart2/source/inc/TitleHelper.hxx
@@ -89,6 +89,8 @@ public:
    static bool getTitleType( eTitleType& rType
                    , const css::uno::Reference< css::chart2::XTitle >& xTitle
                    , const css::uno::Reference< css::frame::XModel >& xModel );
    static void hideTitle( eTitleType nTitleIndex,
            const css::uno::Reference< css::frame::XModel > & xModel);
};

} //namespace chart
diff --git a/chart2/source/tools/TitleHelper.cxx b/chart2/source/tools/TitleHelper.cxx
index 600ebed..bc11c4f 100644
--- a/chart2/source/tools/TitleHelper.cxx
+++ b/chart2/source/tools/TitleHelper.cxx
@@ -436,6 +436,17 @@ bool TitleHelper::getTitleType( eTitleType& rType
    return false;
}

void TitleHelper::hideTitle( TitleHelper::eTitleType nTitleIndex
        , const css::uno::Reference< css::frame::XModel >& xModel)
{
    uno::Reference< chart2::XTitle > xTitled( TitleHelper::getTitle( nTitleIndex, xModel ) );
    if( xTitled.is())
    {
        css::uno::Reference<css::beans::XPropertySet> xProps(xTitled, css::uno::UNO_QUERY_THROW);
        xProps->setPropertyValue("Visible",css::uno::makeAny(false));
    }
}

} //namespace chart

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index c881441..93bf356 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -2131,7 +2131,7 @@ std::shared_ptr<VTitle> lcl_createTitle( TitleHelper::eTitleType eType

    uno::Reference< XTitle > xTitle( TitleHelper::getTitle( eType, rModel ) );
    OUString aCompleteString = TitleHelper::getCompleteString(xTitle);
    if (aCompleteString.isEmpty())
    if (aCompleteString.isEmpty() || !VTitle::isVisible(xTitle))
        return apVTitle;

    //create title
diff --git a/chart2/source/view/main/VTitle.cxx b/chart2/source/view/main/VTitle.cxx
index f0befe9..ad2e857 100644
--- a/chart2/source/view/main/VTitle.cxx
+++ b/chart2/source/view/main/VTitle.cxx
@@ -97,6 +97,21 @@ void VTitle::changePosition( const awt::Point& rPos )
    }
}

bool VTitle::isVisible(const uno::Reference< XTitle >& xTitle) {
    if (!xTitle.is()) {
        return false;
    }
    bool bShow = true;
    try {
        uno::Reference< beans::XPropertySet > xTitleProps(xTitle, uno::UNO_QUERY_THROW);
        xTitleProps->getPropertyValue("Visible") >>= bShow;
    } catch (const uno::Exception &) {
        DBG_UNHANDLED_EXCEPTION("chart2");
    }
    return bShow;
}


void VTitle::createShapes(
      const awt::Point& rPos
    , const awt::Size& rReferenceSize
diff --git a/chart2/source/view/main/VTitle.hxx b/chart2/source/view/main/VTitle.hxx
index 6d33007..cdfd0a8 100644
--- a/chart2/source/view/main/VTitle.hxx
+++ b/chart2/source/view/main/VTitle.hxx
@@ -51,6 +51,8 @@ public:
    css::awt::Size getUnrotatedSize() const;
    css::awt::Size getFinalSize() const;
    void    changePosition( const css::awt::Point& rPos );
    static bool isVisible(
            const css::uno::Reference< css::chart2::XTitle > & xTitle);

private:
    css::uno::Reference< css::drawing::XShapes >            m_xTarget;