summaryrefslogtreecommitdiff
path: root/chart2/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-10-24 13:31:28 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-10-25 11:57:59 +0200
commit9a1336e81c84c3386658eff25da34eca7fd86b77 (patch)
treea0e01cf263c478873b9f4506015ff17a298b1bc5 /chart2/source
parentd71cd10b5cefa9d0ce3c51340255ccd0399ef538 (diff)
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.grandin@collabora.co.uk> Tested-by: Jenkins
Diffstat (limited to 'chart2/source')
-rw-r--r--chart2/source/view/main/DataTableView.cxx88
1 files changed, 51 insertions, 37 deletions
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++;
}