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>
This commit is contained in:
parent
68d074fb91
commit
36b7ae3671
3 changed files with 98 additions and 0 deletions
|
@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_uicalc2, \
|
||||||
comphelper \
|
comphelper \
|
||||||
cppu \
|
cppu \
|
||||||
cppuhelper \
|
cppuhelper \
|
||||||
|
editeng \
|
||||||
i18nlangtag \
|
i18nlangtag \
|
||||||
sal \
|
sal \
|
||||||
sc \
|
sc \
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../helper/qahelper.hxx"
|
#include "../helper/qahelper.hxx"
|
||||||
|
#include <editeng/brushitem.hxx>
|
||||||
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
||||||
#include <svx/svdpage.hxx>
|
#include <svx/svdpage.hxx>
|
||||||
#include <vcl/keycodes.hxx>
|
#include <vcl/keycodes.hxx>
|
||||||
|
@ -26,8 +27,10 @@
|
||||||
#include <inputopt.hxx>
|
#include <inputopt.hxx>
|
||||||
#include <postit.hxx>
|
#include <postit.hxx>
|
||||||
#include <rangeutl.hxx>
|
#include <rangeutl.hxx>
|
||||||
|
#include <scitems.hxx>
|
||||||
#include <scmod.hxx>
|
#include <scmod.hxx>
|
||||||
#include <tabvwsh.hxx>
|
#include <tabvwsh.hxx>
|
||||||
|
#include <undomanager.hxx>
|
||||||
#include <viewdata.hxx>
|
#include <viewdata.hxx>
|
||||||
|
|
||||||
using namespace ::com::sun::star;
|
using namespace ::com::sun::star;
|
||||||
|
@ -1489,6 +1492,83 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf156174)
|
||||||
CPPUNIT_ASSERT(!pDBs->empty());
|
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();
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
|
|
@ -1319,6 +1319,13 @@ void ScTable::CopyToTable(
|
||||||
const bool bToUndoDoc = pDestTab->rDocument.IsUndo();
|
const bool bToUndoDoc = pDestTab->rDocument.IsUndo();
|
||||||
const bool bFromUndoDoc = 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)
|
if ((bToUndoDoc || bFromUndoDoc) && (nFlags & InsertDeleteFlags::CONTENTS) && mpRangeName)
|
||||||
{
|
{
|
||||||
// Copying formulas may create sheet-local named expressions on the
|
// 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++)
|
for (SCCOL i = nCol1; i <= ClampToAllocatedColumns(nCol2); i++)
|
||||||
aCol[i].CopyToColumn(rCxt, nRow1, nRow2, bToUndoDoc ? nFlags : nTempFlags, bMarked,
|
aCol[i].CopyToColumn(rCxt, nRow1, nRow2, bToUndoDoc ? nFlags : nTempFlags, bMarked,
|
||||||
pDestTab->CreateColumnIfNotExists(i), pMarkData, bAsLink, bGlobalNamesToLocal);
|
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
|
if (!bColRowFlags) // Column widths/Row heights/Flags
|
||||||
|
|
Loading…
Reference in a new issue