diff options
author | Czeber László Ádám <czeber.laszloadam@nisz.hu> | 2023-05-24 09:05:16 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2023-05-31 11:49:58 +0200 |
commit | 7be7e1ff95af485a9cb00748800d3d084f96387c (patch) | |
tree | e3a73421a06e74490f0d53a7e9ba6a17cc8eac90 /sc | |
parent | 8259a99f41367a1d8326c9157fe1902915715879 (diff) |
tdf#153437 sc: fix broken formatting at Undo of row/column insertion
Performance fix for the 16k rows resulted broken
formatting during Undo of row insertion, e.g. rows
with background color fell apart, highlighting partially
also the row under the deleted row removed by Undo, or
Undo of inserted/copied columns removed the background
coloring at the place of the removed columns.
Formatting was always deleted after the last column
containing data, because the row was only allocated until
then. When deleting row(s) or column(s), allocate the last
column before updating the references.
Regression from commit 2e86718626a07e1656661df3ad69a64848bf4614
"don't allocate unnecessary columns when inserting a row".
Change-Id: I8d74d59ff0051fdfe183e14a16d987edc71d55e6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152185
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/ucalc_copypaste.cxx | 43 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 9 |
2 files changed, 50 insertions, 2 deletions
diff --git a/sc/qa/unit/ucalc_copypaste.cxx b/sc/qa/unit/ucalc_copypaste.cxx index 695b5b8f6214..bad57d8646a7 100644 --- a/sc/qa/unit/ucalc_copypaste.cxx +++ b/sc/qa/unit/ucalc_copypaste.cxx @@ -27,6 +27,7 @@ #include <refundo.hxx> #include <scitems.hxx> #include <scopetools.hxx> +#include <undomanager.hxx> #include <sfx2/docfile.hxx> @@ -10709,6 +10710,48 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, testCopyPasteMatrixFormula) m_pDoc->DeleteTab(0); } +CPPUNIT_TEST_FIXTURE(TestCopyPaste, testUndoBackgroundColor) +{ + m_pDoc->InsertTab(0, "Table1"); + + ScDocument aClipDoc(SCDOCMODE_CLIP); + ScMarkData aMark(m_pDoc->GetSheetLimits()); + + // Set Values to B1, C2, D5 + m_pDoc->SetValue(ScAddress(1, 0, 0), 1.0); // B1 + m_pDoc->SetValue(ScAddress(2, 1, 0), 2.0); // C2 + m_pDoc->SetValue(ScAddress(3, 4, 0), 3.0); // D5 + + // Add patterns + ScPatternAttr aCellBlueColor(m_pDoc->GetPool()); + aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND)); + m_pDoc->ApplyPatternAreaTab(0, 3, m_pDoc->MaxCol(), 3, 0, aCellBlueColor); + + // Insert a new row at row 3 + ScRange aRowOne(0, 2, 0, m_pDoc->MaxCol(), 2, 0); + aMark.SetMarkArea(aRowOne); + ScDocFunc& rFunc = m_xDocShell->GetDocFunc(); + rFunc.InsertCells(aRowOne, &aMark, INS_INSROWS_BEFORE, true, true); + + // Check patterns + const SfxPoolItem* pItem = nullptr; + m_pDoc->GetPattern(ScAddress(1000, 4, 0))->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem); + CPPUNIT_ASSERT(pItem); + CPPUNIT_ASSERT_EQUAL(COL_BLUE, static_cast<const SvxBrushItem*>(pItem)->GetColor()); + + // Undo the new row + m_pDoc->GetUndoManager()->Undo(); + + // Check patterns + // Failed if row 3 is not blue all the way through + pItem = nullptr; + m_pDoc->GetPattern(ScAddress(1000, 3, 0))->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem); + CPPUNIT_ASSERT(pItem); + CPPUNIT_ASSERT_EQUAL(COL_BLUE, static_cast<const SvxBrushItem*>(pItem)->GetColor()); + + m_pDoc->DeleteTab(0); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 78c49912bcc9..6cb5384c05f9 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -1851,8 +1851,13 @@ void ScTable::UpdateReference( } else { - for( SCCOL col : GetAllocatedColumnsRange( 0, rDocument.MaxCol())) - bUpdated |= aCol[col].UpdateReference(rCxt, pUndoDoc); + // When deleting row(s) or column(s), allocate the last column + // before updating the references + if (nDx < 0 || nDy < 0) + CreateColumnIfNotExists(rDocument.MaxCol()); + + for (SCCOL col : GetColumnsRange(0, rDocument.MaxCol())) + bUpdated |= CreateColumnIfNotExists(col).UpdateReference(rCxt, pUndoDoc); } if ( bIncludeDraw ) |