Skip to content

Commit

Permalink
tdf#146487 Don't show generic diagram title when there is an empty ti…
Browse files Browse the repository at this point in the history
…tle given

Bugdoc has autoTitleDeleted set to false (so title should be visible), but then an empty title is given.
In this case no default string should be added to the title, only in case of Pie Charts.
Any other Chart types show the default title in MS-Office.

Co-authored-by: Balazs Varga <[email protected]>

Change-Id: Ib445099a4a3d113cff6b1ffdfd093fe41c34716b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155681
Tested-by: Samuel Mehrbrodt <[email protected]>
Reviewed-by: Samuel Mehrbrodt <[email protected]>
  • Loading branch information
smehrbrodt committed Jan 18, 2024
1 parent 1f540c4 commit 135ce25
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
11 changes: 11 additions & 0 deletions chart2/qa/extras/chart2import.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,17 @@ CPPUNIT_TEST_FIXTURE(Chart2ImportTest, testTdf121205)
CPPUNIT_ASSERT_EQUAL(OUString("Firstline\nSecondline\nThirdline"), aTitle);
}

CPPUNIT_TEST_FIXTURE(Chart2ImportTest, testTdf146487)
{
loadFromFile(u"pptx/tdf146487.pptx");
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());

Reference<chart2::XTitled> xTitled(xChartDoc, uno::UNO_QUERY_THROW);
uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
CPPUNIT_ASSERT_MESSAGE("chart doc should not have a title", !xTitle.is());
}

CPPUNIT_TEST_FIXTURE(Chart2ImportTest, testFixedSizeBarChartVeryLongLabel)
{
// Bar chart area size is fixed (not automatic) so we can't resize
Expand Down
Binary file added chart2/qa/extras/data/pptx/tdf146487.pptx
Binary file not shown.
3 changes: 3 additions & 0 deletions oox/inc/drawingml/chart/plotareaconverter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public:

/** Returns the automatic chart title if the chart contains only one series. */
const OUString& getAutomaticTitle() const { return maAutoTitle; }
/** Returns true, if the chart contains only one series and have title textbox (even empty). */
bool isSingleSeriesTitle() const { return mbSingleSeriesTitle; }
/** Returns true, if chart type supports wall and floor format in 3D mode. */
bool isWall3dChart() const { return mbWall3dChart; }

Expand All @@ -82,6 +84,7 @@ private:
bool mb3dChart;
bool mbWall3dChart;
bool mbPieChart;
bool mbSingleSeriesTitle;;
};


Expand Down
3 changes: 3 additions & 0 deletions oox/inc/drawingml/chart/typegroupconverter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public:
/** Returns series title, if the chart type group contains only one single series. */
OUString getSingleSeriesTitle() const;

/** Returns true, if the chart contains only one series and have title textbox (even empty). */
bool isSingleSeriesTitle() const;

/** Creates a coordinate system according to the contained chart type. */
css::uno::Reference< css::chart2::XCoordinateSystem >
createCoordinateSystem();
Expand Down
14 changes: 13 additions & 1 deletion oox/source/drawingml/chart/chartspaceconverter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <drawingml/chart/titleconverter.hxx>
#include <ooxresid.hxx>
#include <strings.hrc>
#include <drawingml/textbody.hxx>

using namespace ::com::sun::star;
using ::com::sun::star::uno::Reference;
Expand Down Expand Up @@ -183,7 +184,18 @@ void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExtern
OUString aAutoTitle = aPlotAreaConv.getAutomaticTitle();
if( mrModel.mxTitle.is() || !aAutoTitle.isEmpty() )
{
if( aAutoTitle.isEmpty() )
// tdf#146487 In some cases, we need to show the empty title
bool bShowEmptyTitle = aAutoTitle.isEmpty() && !mrModel.mbAutoTitleDel
&& aPlotAreaConv.isSingleSeriesTitle()
&& mrModel.mxTitle->mxShapeProp.is()
&& mrModel.mxTitle->mxTextProp.is()
&& mrModel.mxTitle->mxTextProp->isEmpty();
// Also for tdf#146487
bool bEmptyRichText = mrModel.mxTitle->mxText.is()
&& mrModel.mxTitle->mxText->mxTextBody.is()
&& mrModel.mxTitle->mxText->mxTextBody->isEmpty();

if (aAutoTitle.isEmpty() && !bShowEmptyTitle && !bEmptyRichText)
aAutoTitle = OoxResId(STR_DIAGRAM_TITLE);
Reference< XTitled > xTitled( getChartDocument(), UNO_QUERY_THROW );
TitleConverter aTitleConv( *this, mrModel.mxTitle.getOrCreate() );
Expand Down
10 changes: 9 additions & 1 deletion oox/source/drawingml/chart/plotareaconverter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class AxesSetConverter : public ConverterBase< AxesSetModel >

/** Returns the automatic chart title if the axes set contains only one series. */
const OUString& getAutomaticTitle() const { return maAutoTitle; }
/** Returns true, if the chart contains only one series and have title textbox (even empty). */
bool isSingleSeriesTitle() const { return mbSingleSeriesTitle; }
/** Returns true, if the chart is three-dimensional. */
bool is3dChart() const { return mb3dChart; }
/** Returns true, if chart type supports wall and floor format in 3D mode. */
Expand All @@ -88,13 +90,15 @@ class AxesSetConverter : public ConverterBase< AxesSetModel >
bool mb3dChart;
bool mbWall3dChart;
bool mbPieChart;
bool mbSingleSeriesTitle;
};

AxesSetConverter::AxesSetConverter( const ConverterRoot& rParent, AxesSetModel& rModel ) :
ConverterBase< AxesSetModel >( rParent, rModel ),
mb3dChart( false ),
mbWall3dChart( false ),
mbPieChart( false )
mbPieChart( false ),
mbSingleSeriesTitle( false )
{
}

Expand Down Expand Up @@ -127,7 +131,10 @@ void AxesSetConverter::convertFromModel( const Reference< XDiagram >& rxDiagram,

// get automatic chart title, if there is only one type group
if( aTypeGroups.size() == 1 )
{
maAutoTitle = rFirstTypeGroup.getSingleSeriesTitle();
mbSingleSeriesTitle = rFirstTypeGroup.isSingleSeriesTitle();
}

/* Create a coordinate system. For now, all type groups from all axes sets
have to be inserted into one coordinate system. Later, chart2 should
Expand Down Expand Up @@ -422,6 +429,7 @@ void PlotAreaConverter::convertFromModel( View3DModel& rView3DModel )
if(nAxesSetIdx == nStartAxesSetIdx)
{
maAutoTitle = aAxesSetConv.getAutomaticTitle();
mbSingleSeriesTitle = aAxesSetConv.isSingleSeriesTitle();
mb3dChart = aAxesSetConv.is3dChart();
mbWall3dChart = aAxesSetConv.isWall3dChart();
mbPieChart = aAxesSetConv.isPieChart();
Expand Down
9 changes: 9 additions & 0 deletions oox/source/drawingml/chart/typegroupconverter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ OUString TypeGroupConverter::getSingleSeriesTitle() const
return aSeriesTitle;
}

bool TypeGroupConverter::isSingleSeriesTitle() const
{
if (!mrModel.maSeries.empty() && (maTypeInfo.mbSingleSeriesVis || (mrModel.maSeries.size() == 1)) &&
mrModel.maSeries.front()->mxText.is())
return true;

return false;
}

Reference< XCoordinateSystem > TypeGroupConverter::createCoordinateSystem()
{
// create the coordinate system object
Expand Down

0 comments on commit 135ce25

Please sign in to comment.