chart2/source/view/main/DataTableView.cxx | 88 +++++++++++++++++------------- svx/source/table/tablemodel.cxx | 14 +++- 2 files changed, 61 insertions(+), 41 deletions(-)
New commits: commit 9a1336e81c84c3386658eff25da34eca7fd86b77 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Oct 24 13:31:28 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Oct 25 11:57:59 2024 +0200 tdf#153182 PPTX Chart with datamodel rendered incorrectly Partial fix. (*) fixed bugs where the use of continue in loops meant that a tracking variable was not being updated (*) improved exception message in TableModel::getCellByPosition (*) rather than exiting the view generation process with an exception, log a warning and skip that part of the view process The root of the problem here is that we don't seem to be importing data-tables from PPTX properly. I suspect that we need more import code, in particular, we probably need to read some flag that indicates if we have header rows and columns. Change-Id: Iaa9a1593bc185a5bb4f36a434117bbd5bf323e18 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175551 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/chart2/source/view/main/DataTableView.cxx b/chart2/source/view/main/DataTableView.cxx index 147643d0c2d3..c0104efb2841 100644 --- a/chart2/source/view/main/DataTableView.cxx +++ b/chart2/source/view/main/DataTableView.cxx @@ -330,15 +330,15 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV auto xText = xCellTextRange->getText(); xText->insertString(xText->getStart(), rString, false); auto xTextPropertySet = getFirstParagraphProperties(xText); - if (!xTextPropertySet.is()) - continue; - - bool bLeft - = (bOutline && nColumn == 1) || (bVBorder && nColumn > 1 && nColumn < nColumnCount); - bool bRight = (bOutline && nColumn == nColumnCount) - || (bVBorder && nColumn > 1 && nColumn < nColumnCount); - setCellCharAndParagraphProperties(xTextPropertySet); - setCellProperties(xPropertySet, bLeft, bOutline, bRight, bOutline); + if (xTextPropertySet) + { + bool bLeft = (bOutline && nColumn == 1) + || (bVBorder && nColumn > 1 && nColumn < nColumnCount); + bool bRight = (bOutline && nColumn == nColumnCount) + || (bVBorder && nColumn > 1 && nColumn < nColumnCount); + setCellCharAndParagraphProperties(xTextPropertySet); + setCellProperties(xPropertySet, bLeft, bOutline, bRight, bOutline); + } } nColumn++; } @@ -399,18 +399,19 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV auto xText = xCellTextRange->getText(); xText->insertString(xText->getStart(), rSeriesName, false); auto xTextPropertySet = getFirstParagraphProperties(xText); - if (!xTextPropertySet.is()) - continue; - setCellCharAndParagraphProperties(xTextPropertySet); - setCellProperties(xCellPropertySet, bOutline, bTop, bOutline, bBottom); - - xCellPropertySet->setPropertyValue(u"ParaAdjust"_ustr, - uno::Any(style::ParagraphAdjust_LEFT)); - if (bKeys) + if (xTextPropertySet) { - xCellPropertySet->setPropertyValue( - u"ParaLeftMargin"_ustr, - uno::Any(nMaxSymbolWidth + sal_Int32(2 * constSymbolMargin))); + setCellCharAndParagraphProperties(xTextPropertySet); + setCellProperties(xCellPropertySet, bOutline, bTop, bOutline, bBottom); + + xCellPropertySet->setPropertyValue(u"ParaAdjust"_ustr, + uno::Any(style::ParagraphAdjust_LEFT)); + if (bKeys) + { + xCellPropertySet->setPropertyValue( + u"ParaLeftMargin"_ustr, + uno::Any(nMaxSymbolWidth + sal_Int32(2 * constSymbolMargin))); + } } } nRow++; @@ -418,11 +419,22 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV // TABLE nRow = 1; + const sal_Int32 nTableModelRowCount = m_xTable->getRowCount(); + const sal_Int32 nTableModelColCount = m_xTable->getColumnCount(); + // tdf#153182 the broken bounds are most likely because we dont know if the + // data-table has header rows and columns. Most likely it does not. + bool bBrokenBounds = false; for (auto const& rSeries : m_pDataSeriesValues) { nColumn = 1; for (auto const& rValue : rSeries) { + if (nRow >= nTableModelRowCount || nColumn >= nTableModelColCount) + { + bBrokenBounds = true; + SAL_WARN("chart2", "exceeding bounds of table model?"); + break; + } uno::Reference<table::XCell> xCell = m_xTable->getCellByPosition(nColumn, nRow); uno::Reference<beans::XPropertySet> xCellPropertySet(xCell, uno::UNO_QUERY); uno::Reference<text::XTextRange> xCellTextRange(xCell, uno::UNO_QUERY); @@ -431,31 +443,33 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV auto xText = xCellTextRange->getText(); xText->insertString(xText->getStart(), rValue, false); auto xTextPropertySet = getFirstParagraphProperties(xText); - if (!xTextPropertySet.is()) - continue; - - bool bLeft = false; - bool bTop = false; - bool bRight = false; - bool bBottom = false; + if (xTextPropertySet.is()) + { + bool bLeft = false; + bool bTop = false; + bool bRight = false; + bool bBottom = false; - if (nColumn > 1 && bVBorder) - bLeft = true; + if (nColumn > 1 && bVBorder) + bLeft = true; - if (nRow > 1 && bHBorder) - bTop = true; + if (nRow > 1 && bHBorder) + bTop = true; - if (nRow == nRowCount && bOutline) - bBottom = true; + if (nRow == nRowCount && bOutline) + bBottom = true; - if (nColumn == nColumnCount && bOutline) - bRight = true; + if (nColumn == nColumnCount && bOutline) + bRight = true; - setCellCharAndParagraphProperties(xTextPropertySet); - setCellProperties(xCellPropertySet, bLeft, bTop, bRight, bBottom); + setCellCharAndParagraphProperties(xTextPropertySet); + setCellProperties(xCellPropertySet, bLeft, bTop, bRight, bBottom); + } } nColumn++; } + if (bBrokenBounds) + break; nRow++; } diff --git a/svx/source/table/tablemodel.cxx b/svx/source/table/tablemodel.cxx index 184eaa13cfb4..7fb11fd7a482 100644 --- a/svx/source/table/tablemodel.cxx +++ b/svx/source/table/tablemodel.cxx @@ -378,11 +378,17 @@ uno::Reference<css::table::XCell> SAL_CALL TableModel::getCellByPosition( sal_In { ::SolarMutexGuard aGuard; - CellRef xCell( getCell( nColumn, nRow ) ); - if( xCell.is() ) - return xCell; + sal_Int32 nRowCount = getRowCountImpl(); + if( nRow < 0 || nRow >= nRowCount ) + throw lang::IndexOutOfBoundsException(OUString::Concat("row ") + OUString::number(nRow) + + " out of range 0.." + OUString::number(nRowCount)); - throw lang::IndexOutOfBoundsException(); + sal_Int32 nColCount = getColumnCountImpl(); + if( nColumn < 0 || nColumn >= nColCount ) + throw lang::IndexOutOfBoundsException(OUString::Concat("col ") + OUString::number(nColumn) + + " out of range 0.." + OUString::number(nColCount)); + + return maRows[nRow]->maCells[nColumn]; }