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-06-27 12:34:59 +0200 |
commit | 0692344caa7b79b7bef980326ede85ce5867631c (patch) | |
tree | ec311b98c165ec325c33974be4c3c1f4919e77de | |
parent | Update git submodules (diff) | |
download | core-0692344caa7b79b7bef980326ede85ce5867631c.tar.gz core-0692344caa7b79b7bef980326ede85ce5867631c.zip |
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>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153493
Reviewed-by: Stéphane Guillou <stephane.guillou@libreoffice.org>
Tested-by: Jenkins
-rw-r--r-- | sc/qa/unit/ucalc_copypaste.cxx | 45 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 9 |
2 files changed, 52 insertions, 2 deletions
diff --git a/sc/qa/unit/ucalc_copypaste.cxx b/sc/qa/unit/ucalc_copypaste.cxx index b6062cb04c72..e63353c860ec 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> @@ -135,6 +136,7 @@ public: // tdf#80137 void testCopyPasteMatrixFormula(); + void testUndoBackgroundColor(); CPPUNIT_TEST_SUITE(TestCopyPaste); @@ -239,6 +241,7 @@ public: CPPUNIT_TEST(testMixDataWithFormulaTdf116413); CPPUNIT_TEST(testCopyPasteMatrixFormula); + CPPUNIT_TEST(testUndoBackgroundColor); CPPUNIT_TEST_SUITE_END(); @@ -10905,6 +10908,48 @@ void TestCopyPaste::testCopyPasteMatrixFormula() m_pDoc->DeleteTab(0); } +void 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_TEST_SUITE_REGISTRATION(TestCopyPaste); CPPUNIT_PLUGIN_IMPLEMENT(); 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 ) |