diff options
author | Hossein <hossein@libreoffice.org> | 2022-10-10 15:48:02 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-10-19 08:33:08 +0200 |
commit | a71e40d37f177b2d4461db158282ae1c620e774e (patch) | |
tree | 309b3d63508ef0bab23be9d8b5fc86c2ec703698 | |
parent | tdf#151352 crash closing form while TOTD dialog is displayed (diff) | |
download | core-a71e40d37f177b2d4461db158282ae1c620e774e.tar.gz core-a71e40d37f177b2d4461db158282ae1c620e774e.zip |
tdf#149718 Fix crash on insert chart for tables with merged cells
Previously inserting charts for tables with merged cells lead to crash.
This was because a wrong assumption in unochart.cxx, specifically
SwChartDataProvider::Impl_createDataSource() that every row has the same
number of columns. Therefore the code was using the number of columns in
the first row as the number of columns for all the rows, which is wrong.
For example, inserting a chart for the second column of this table leads
to a crash:
[ ]
[ 1 ][ 2 ]
In this way, an assertion failure was created because the number of
columns where counted from the first row, which has merged cells, and
therefore fewer number of columns compared to the last column of the
selected part.
To solve tdf#149718, now we use the maximum number of columns calculated
across all the rows. In this way, the remainder of the function does not
need a fix, although a cleanup for the whole function can be interesting
and help avoid using tiny extra memory space.
A UITest is provided to avoid this bug in the future. To run the test:
cd sw && make -srj1 UITest_sw_chart \
UITEST_TEST_NAME="tdf149718.tdf149718.test_chart_from_table_with_merged_cells" \
SAL_USE_VCLPLUGIN=gen
Change-Id: I3c1000d7f177417e98d3a8ceae7886824c1053a6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140092
Tested-by: Jenkins
Reviewed-by: Hossein <hossein@libreoffice.org>
(cherry picked from commit d1707bc31261d16893c1f5240c803d283e293ec1)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141192
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sw/qa/uitest/chart/tdf149718.py | 40 | ||||
-rw-r--r-- | sw/source/core/unocore/unochart.cxx | 8 |
2 files changed, 47 insertions, 1 deletions
diff --git a/sw/qa/uitest/chart/tdf149718.py b/sw/qa/uitest/chart/tdf149718.py new file mode 100644 index 000000000000..873379a36909 --- /dev/null +++ b/sw/qa/uitest/chart/tdf149718.py @@ -0,0 +1,40 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from uitest.framework import UITestCase +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict +from uitest.uihelper.common import select_pos + +class tdf149718( UITestCase ): + + def test_chart_from_table_with_merged_cells( self ): + with self.ui_test.create_doc_in_start_center("writer") as document: + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + with self.ui_test.execute_dialog_through_command(".uno:InsertTable") as xDialog: + formatlbinstable = xDialog.getChild("formatlbinstable") + entry = formatlbinstable.getChild("1") + entry.executeAction("SELECT", tuple()) + xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"})) + + self.xUITest.executeCommand(".uno:GoDown") + self.xUITest.executeCommand(".uno:CharRightSel") + self.xUITest.executeCommand(".uno:MergeCells") + + self.xUITest.executeCommand(".uno:GoDown") + xWriterEdit.executeAction("TYPE", mkPropertyValues({"TEXT": "1"})) + self.xUITest.executeCommand(".uno:GoLeft") + self.xUITest.executeCommand(".uno:GoLeft") + xWriterEdit.executeAction("TYPE", mkPropertyValues({"TEXT": "1"})) + self.xUITest.executeCommand(".uno:CharRightSel") + with self.ui_test.execute_dialog_through_command(".uno:InsertObjectChart", close_button="finish") as xDialog: + xWizard = xDialog.getChild('Wizard') + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx index edaa628c68f4..e1b8e14e33f5 100644 --- a/sw/source/core/unocore/unochart.cxx +++ b/sw/source/core/unocore/unochart.cxx @@ -644,7 +644,13 @@ uno::Reference< chart2::data::XDataSource > SwChartDataProvider::Impl_createData // get a character map in the size of the table to mark // all the ranges to use in sal_Int32 nRows = pTable->GetTabLines().size(); - sal_Int32 nCols = pTable->GetTabLines().front()->GetTabBoxes().size(); + sal_Int32 nCols = 0; + // As per tdf#149718 one should know that some cells can be merged together. + // Therefore, the number of columns (boxes in each row) are not necessarily + // equal. Here, we calculate the maximum number of columns in all rows. + for (sal_Int32 i = 0; i < nRows; ++i) + nCols = std::max(nCols, static_cast<sal_Int32>(pTable->GetTabLines()[i]->GetTabBoxes().size())); + std::vector<std::vector<char>> aMap(nRows); for (sal_Int32 i = 0; i < nRows; ++i) aMap[i].resize(nCols); |