sc/qa/unit/ucalc.cxx           |   74 +++++++++++++++++++++++++++++++++++++++++
 sc/source/core/data/table2.cxx |    3 -
 2 files changed, 74 insertions(+), 3 deletions(-)

New commits:
commit 2114e198e931ba33a6be6acf7aeecb1f5cb8309f
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Jul 30 14:05:32 2024 +0200
Commit:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
CommitDate: Thu Aug 8 22:46:13 2024 +0200

    tdf#156689: don't initialize the last columns from the default attributes
    
    Regression from dd8e061406fac581d399da088c7f0187278035dc
    "tdf#153437 sc: fix broken formatting without performance regression"
    
    Change-Id: Ifacc48db93f28ec7b539af640e95eff8ad5ec535
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171242
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit e552de24b646f8dc59551203edd901dad6af0ff5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171289
    Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>
    Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ae0d6967def8..e8c2856f2d24 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -227,6 +227,80 @@ CPPUNIT_TEST_FIXTURE(Test, testSharedStringPool)
     m_pDoc->DeleteTab(0);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testBackgroundColorDeleteColumn)
+{
+    m_pDoc->InsertTab(0, u"Table1"_ustr);
+
+    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->getCellAttributeHelper());
+    aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    m_pDoc->ApplyPatternAreaTab(3, 0, 3, m_pDoc->MaxRow(), 0, aCellBlueColor);
+
+    // Delete column 10
+    m_pDoc->DeleteCol(ScRange(9,0,0,9,m_pDoc->MaxRow(),0));
+
+    // Check patterns
+    const SfxPoolItem* pItem = nullptr;
+    m_pDoc->GetPattern(ScAddress(3, 1000, 
0))->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
+    CPPUNIT_ASSERT(pItem);
+    CPPUNIT_ASSERT_EQUAL(COL_BLUE, static_cast<const 
SvxBrushItem*>(pItem)->GetColor());
+
+    // Delete column 2
+    m_pDoc->DeleteCol(ScRange(1,0,0,1,m_pDoc->MaxRow(),0));
+
+    // Check patterns
+    pItem = nullptr;
+    m_pDoc->GetPattern(ScAddress(2, 1000, 
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_FIXTURE(Test, testBackgroundColorDeleteRow)
+{
+    m_pDoc->InsertTab(0, u"Table1"_ustr);
+
+    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->getCellAttributeHelper());
+    aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    m_pDoc->ApplyPatternAreaTab(0, 3, m_pDoc->MaxCol(), 3, 0, aCellBlueColor);
+
+    // Delete row 10
+    m_pDoc->DeleteRow(ScRange(0,9,0,m_pDoc->MaxCol(),9,0));
+
+    // Check patterns
+    const SfxPoolItem* 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());
+
+    // Delete row 2
+    m_pDoc->DeleteRow(ScRange(0,1,0,m_pDoc->MaxCol(),1,0));
+
+    // Check patterns
+    pItem = nullptr;
+    m_pDoc->GetPattern(ScAddress(1000, 2, 
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_FIXTURE(Test, testSharedStringPoolUndoDoc)
 {
     struct
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 4629ce8036d1..933b9a37930e 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -400,9 +400,6 @@ void ScTable::DeleteCol(
     {
         for (SCCOL nCol = nStartCol + nSize; nCol < aCol.size(); ++nCol)
             aCol[nCol].SwapCol(aCol[nCol - nSize]);
-        // When delete column(s), initialize the last columns from the default 
attributes
-        for (SCCOL nCol = aCol.size() < static_cast<SCCOL>(nSize) ? 0 : 
aCol.size() - nSize; nCol < aCol.size(); ++nCol)
-            aCol[nCol].Init(nCol, aCol[nCol].GetTab(), rDocument, false);
     }
     else
     {

Reply via email to