summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-12-21 16:57:27 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2023-12-22 08:33:37 +0100
commit36b7ae36715cbf47b451e41e47aebe28cf594bd8 (patch)
tree575f512c78e1f8bdb845d7173e5d584071809413 /sc
parent68d074fb910de7298cbefb6a3c3e192dae201837 (diff)
tdf#154044: Also store default column data, when copying to Undo document
And restore from it un Undo. Change-Id: I3e14b345cff25068d0555c5bceb4d6e97ce7cf76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161127 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/CppunitTest_sc_uicalc2.mk1
-rw-r--r--sc/qa/unit/uicalc/uicalc2.cxx80
-rw-r--r--sc/source/core/data/table2.cxx17
3 files changed, 98 insertions, 0 deletions
diff --git a/sc/CppunitTest_sc_uicalc2.mk b/sc/CppunitTest_sc_uicalc2.mk
index 647d4ec7abed..fbc467622f40 100644
--- a/sc/CppunitTest_sc_uicalc2.mk
+++ b/sc/CppunitTest_sc_uicalc2.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_uicalc2, \
comphelper \
cppu \
cppuhelper \
+ editeng \
i18nlangtag \
sal \
sc \
diff --git a/sc/qa/unit/uicalc/uicalc2.cxx b/sc/qa/unit/uicalc/uicalc2.cxx
index 1eaeb5cac4e3..9be6d83840bb 100644
--- a/sc/qa/unit/uicalc/uicalc2.cxx
+++ b/sc/qa/unit/uicalc/uicalc2.cxx
@@ -8,6 +8,7 @@
*/
#include "../helper/qahelper.hxx"
+#include <editeng/brushitem.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <svx/svdpage.hxx>
#include <vcl/keycodes.hxx>
@@ -26,8 +27,10 @@
#include <inputopt.hxx>
#include <postit.hxx>
#include <rangeutl.hxx>
+#include <scitems.hxx>
#include <scmod.hxx>
#include <tabvwsh.hxx>
+#include <undomanager.hxx>
#include <viewdata.hxx>
using namespace ::com::sun::star;
@@ -1489,6 +1492,83 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf156174)
CPPUNIT_ASSERT(!pDBs->empty());
}
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf154044)
+{
+ createScDoc();
+ ScDocument* pDoc = getScDoc();
+
+ auto getBackColor = [pDoc](SCCOL c) {
+ const ScPatternAttr* pattern = pDoc->GetPattern(c, 0, 0);
+ const SvxBrushItem& brush = pattern->GetItemSet().Get(ATTR_BACKGROUND);
+ return brush.GetColor();
+ };
+
+ CPPUNIT_ASSERT_EQUAL(INITIALCOLCOUNT, pDoc->GetAllocatedColumnsCount(0));
+ for (SCCOL i = 0; i <= pDoc->MaxCol(); ++i)
+ {
+ OString msg = "i=" + OString::number(i);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_AUTO, getBackColor(i));
+ }
+
+ // Set the background color of A1:CV1
+ auto aColorArg(
+ comphelper::InitPropertySequence({ { "BackgroundColor", uno::Any(COL_LIGHTBLUE) } }));
+ goToCell("A1:CV1");
+ dispatchCommand(mxComponent, ".uno:BackgroundColor", aColorArg);
+
+ // Partial row range allocates necessary columns
+ CPPUNIT_ASSERT_EQUAL(SCCOL(100), pDoc->GetAllocatedColumnsCount(0));
+
+ // Check that settings are applied
+ for (SCCOL i = 0; i < 100; ++i)
+ {
+ OString msg = "i=" + OString::number(i);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_LIGHTBLUE, getBackColor(i));
+ }
+
+ // Undo
+ SfxUndoManager* pUndoMgr = pDoc->GetUndoManager();
+ CPPUNIT_ASSERT(pUndoMgr);
+ pUndoMgr->Undo();
+
+ // Check that all the cells have restored the setting
+ for (SCCOL i = 0; i < 100; ++i)
+ {
+ OString msg = "i=" + OString::number(i);
+ // Without the fix in place, this would fail with
+ // - Expected: rgba[ffffff00]
+ // - Actual : rgba[0000ffff]
+ // - i=1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_AUTO, getBackColor(i));
+ }
+
+ // Also check the whole row selection case - it is handled specially: columns are not allocated.
+ // See commit 3db91487e57277f75d64d95d06d4ddcc29f1c4e0 (set properly attributes for cells in
+ // unallocated Calc columns, 2022-03-04).
+ goToCell("A1:" + pDoc->MaxColAsString() + "1");
+ dispatchCommand(mxComponent, ".uno:BackgroundColor", aColorArg);
+
+ // Check that settings are applied
+ for (SCCOL i = 0; i <= pDoc->MaxCol(); ++i)
+ {
+ OString msg = "i=" + OString::number(i);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_LIGHTBLUE, getBackColor(i));
+ }
+
+ // Undo
+ pUndoMgr->Undo();
+
+ // No additional columns have been allocated for whole-row range
+ CPPUNIT_ASSERT_EQUAL(SCCOL(100), pDoc->GetAllocatedColumnsCount(0));
+
+ // Check that all the cells have restored the setting
+ for (SCCOL i = 0; i <= pDoc->MaxCol(); ++i)
+ {
+ OString msg = "i=" + OString::number(i);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_AUTO, getBackColor(i));
+ }
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index ed8db48982b6..ec7f96731ac6 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1319,6 +1319,13 @@ void ScTable::CopyToTable(
const bool bToUndoDoc = pDestTab->rDocument.IsUndo();
const bool bFromUndoDoc = rDocument.IsUndo();
+ if (bToUndoDoc && (nFlags & InsertDeleteFlags::ATTRIB) && nCol2 >= aCol.size())
+ {
+ // tdf#154044: Copy also the default column data
+ aDefaultColData.AttrArray().CopyArea(nRow1, nRow2, 0,
+ pDestTab->aDefaultColData.AttrArray());
+ }
+
if ((bToUndoDoc || bFromUndoDoc) && (nFlags & InsertDeleteFlags::CONTENTS) && mpRangeName)
{
// Copying formulas may create sheet-local named expressions on the
@@ -1344,6 +1351,16 @@ void ScTable::CopyToTable(
for (SCCOL i = nCol1; i <= ClampToAllocatedColumns(nCol2); i++)
aCol[i].CopyToColumn(rCxt, nRow1, nRow2, bToUndoDoc ? nFlags : nTempFlags, bMarked,
pDestTab->CreateColumnIfNotExists(i), pMarkData, bAsLink, bGlobalNamesToLocal);
+ // tdf#154044: Restore from the default column data
+ if (bFromUndoDoc && (nFlags & InsertDeleteFlags::ATTRIB) && nCol2 >= aCol.size())
+ {
+ aDefaultColData.AttrArray().CopyArea(nRow1, nRow2, 0,
+ pDestTab->aDefaultColData.AttrArray());
+ SCCOL nMaxSetDefault = pDestTab->ClampToAllocatedColumns(nCol2);
+ for (SCCOL i = aCol.size(); i <= nMaxSetDefault; i++)
+ aDefaultColData.AttrArray().CopyArea(nRow1, nRow2, 0,
+ pDestTab->aCol[i].AttrArray());
+ }
}
if (!bColRowFlags) // Column widths/Row heights/Flags