diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2017-12-01 15:25:56 +0300 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-12-11 23:29:26 +0100 |
commit | 3f614f431475e1bf3bb3bbeac59b0681309628b7 (patch) | |
tree | 104fc56d968dd51802b658d97775c02e06424524 /sc/qa | |
parent | 7d202623b007979d9d0f93f6cd62c3c031d6d1d4 (diff) |
tdf#95295: don't add duplicate conditional formats
This tries to make sure that on copy, any conditional formatting
that has same entries (conditions and formats) as another condition
in the table, is not appended to the conditions list, but updates
existing condition's range. This should prevent multiplication of
entries with duplicating conditions and formats, and fragmenting
ranges.
Existing unit tests had to be adjusted, because they had ensured
exactly that behaviour that is changed in this commit: that new
items are added to the list, and e.g. multiple elements are created
when a single cell is copied to a range.
Change-Id: I46adb883bab7249571b912d56fea0c7918b3516d
Reviewed-on: https://gerrit.libreoffice.org/45656
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_condformat.cxx | 76 |
2 files changed, 64 insertions, 14 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index ed8bf0c09e0e..74729debe9ea 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -482,6 +482,7 @@ public: void testCondCopyPaste(); void testCondCopyPasteSingleCell(); //e.g. fdo#82503 void testCondCopyPasteSingleCellToRange(); //e.g. fdo#82503 + void testCondCopyPasteSingleCellIntoSameFormatRange(); // e.g., tdf#95295 void testCondCopyPasteSingleRowToRange(); //e.g. tdf#106242 void testCondCopyPasteSingleRowToRange2(); void testCondCopyPasteSheetBetweenDoc(); @@ -780,6 +781,7 @@ public: CPPUNIT_TEST(testCondCopyPaste); CPPUNIT_TEST(testCondCopyPasteSingleCell); CPPUNIT_TEST(testCondCopyPasteSingleCellToRange); + CPPUNIT_TEST(testCondCopyPasteSingleCellIntoSameFormatRange); CPPUNIT_TEST(testCondCopyPasteSingleRowToRange); CPPUNIT_TEST(testCondCopyPasteSingleRowToRange2); CPPUNIT_TEST(testCondCopyPasteSheetBetweenDoc); diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx index f98d2e94b8eb..e0f18ca1fd5b 100644 --- a/sc/qa/unit/ucalc_condformat.cxx +++ b/sc/qa/unit/ucalc_condformat.cxx @@ -288,14 +288,19 @@ void Test::testCondCopyPaste() ScConditionalFormat* pPastedFormat = m_pDoc->GetCondFormat(7,7,0); CPPUNIT_ASSERT(pPastedFormat); - CPPUNIT_ASSERT_EQUAL(ScRangeList(aTargetRange), pPastedFormat->GetRange()); - CPPUNIT_ASSERT( nIndex != pPastedFormat->GetKey()); + // Pasting the same conditional format must modify existing format, making its range + // combined of previous range and newly pasted range having the conditional format. + // No new conditional formats must be created. + CPPUNIT_ASSERT_EQUAL(size_t(1), m_pDoc->GetCondFormList(0)->size()); + aRangeList.Join(aTargetRange); + CPPUNIT_ASSERT_EQUAL(aRangeList, pPastedFormat->GetRange()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nIndex), pPastedFormat->GetKey()); const SfxPoolItem* pItem = m_pDoc->GetAttr( 7, 7, 0, ATTR_CONDITIONAL ); const ScCondFormatItem* pCondFormatItem = static_cast<const ScCondFormatItem*>(pItem); CPPUNIT_ASSERT(pCondFormatItem); CPPUNIT_ASSERT_EQUAL(size_t(1), pCondFormatItem->GetCondFormatData().size()); - CPPUNIT_ASSERT( nIndex != pCondFormatItem->GetCondFormatData().at(0) ); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nIndex), pCondFormatItem->GetCondFormatData().at(0)); m_pDoc->DeleteTab(0); } @@ -322,14 +327,19 @@ void Test::testCondCopyPasteSingleCell() ScConditionalFormat* pPastedFormat = m_pDoc->GetCondFormat(4,4,0); CPPUNIT_ASSERT(pPastedFormat); - CPPUNIT_ASSERT_EQUAL(ScRangeList(aTargetRange), pPastedFormat->GetRange()); - CPPUNIT_ASSERT( nIndex != pPastedFormat->GetKey()); + // Pasting the same conditional format must modify existing format, making its range + // combined of previous range and newly pasted range having the conditional format. + // No new conditional formats must be created. + CPPUNIT_ASSERT_EQUAL(size_t(1), m_pDoc->GetCondFormList(0)->size()); + aRangeList.Join(aTargetRange); + CPPUNIT_ASSERT_EQUAL(aRangeList, pPastedFormat->GetRange()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nIndex), pPastedFormat->GetKey()); const SfxPoolItem* pItem = m_pDoc->GetAttr( 4, 4, 0, ATTR_CONDITIONAL ); const ScCondFormatItem* pCondFormatItem = static_cast<const ScCondFormatItem*>(pItem); CPPUNIT_ASSERT(pCondFormatItem); CPPUNIT_ASSERT_EQUAL(size_t(1), pCondFormatItem->GetCondFormatData().size()); - CPPUNIT_ASSERT( nIndex != pCondFormatItem->GetCondFormatData().at(0) ); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nIndex), pCondFormatItem->GetCondFormatData().at(0) ); m_pDoc->DeleteTab(0); } @@ -352,7 +362,11 @@ void Test::testCondCopyPasteSingleCellToRange() ScRange aTargetRange(4,4,0,5,8,0); pasteOneCellFromClip(m_pDoc, aTargetRange, &aClipDoc); - std::set<sal_uLong> aCondFormatIndices; + // Pasting the same conditional format must modify existing format, making its range + // combined of previous range and newly pasted range having the conditional format. + // No new conditional formats must be created. + CPPUNIT_ASSERT_EQUAL(size_t(1), m_pDoc->GetCondFormList(0)->size()); + aRangeList.Join(aTargetRange); for(SCROW nRow = 4; nRow <= 8; ++nRow) { for (SCCOL nCol = 4; nCol <= 5; ++nCol) @@ -360,24 +374,58 @@ void Test::testCondCopyPasteSingleCellToRange() ScConditionalFormat* pPastedFormat = m_pDoc->GetCondFormat(nCol, nRow, 0); CPPUNIT_ASSERT(pPastedFormat); - CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(nCol, nRow, 0)), pPastedFormat->GetRange()); + CPPUNIT_ASSERT_EQUAL(aRangeList, pPastedFormat->GetRange()); sal_uLong nPastedKey = pPastedFormat->GetKey(); - CPPUNIT_ASSERT( nIndex != nPastedKey); + CPPUNIT_ASSERT_EQUAL(nIndex, nPastedKey); const SfxPoolItem* pItem = m_pDoc->GetAttr( nCol, nRow, 0, ATTR_CONDITIONAL ); const ScCondFormatItem* pCondFormatItem = static_cast<const ScCondFormatItem*>(pItem); CPPUNIT_ASSERT(pCondFormatItem); CPPUNIT_ASSERT_EQUAL(size_t(1), pCondFormatItem->GetCondFormatData().size()); - CPPUNIT_ASSERT( nIndex != pCondFormatItem->GetCondFormatData().at(0) ); - auto itr = aCondFormatIndices.find(nPastedKey); - CPPUNIT_ASSERT(bool(itr == aCondFormatIndices.end())); - aCondFormatIndices.insert(nPastedKey); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nIndex), pCondFormatItem->GetCondFormatData().at(0) ); } } m_pDoc->DeleteTab(0); } +void Test::testCondCopyPasteSingleCellIntoSameFormatRange() +{ + m_pDoc->InsertTab(0, "Test"); + + ScConditionalFormat* pFormat = new ScConditionalFormat(1, m_pDoc); + ScRange aCondFormatRange(0, 0, 0, 3, 3, 0); + ScRangeList aRangeList(aCondFormatRange); + pFormat->SetRange(aRangeList); + + ScCondFormatEntry* pEntry = new ScCondFormatEntry(ScConditionMode::Direct, "=B2", "", m_pDoc, ScAddress(0, 0, 0), ScGlobal::GetRscString(STR_STYLENAME_RESULT)); + pFormat->AddEntry(pEntry); + sal_uLong nIndex = m_pDoc->AddCondFormat(pFormat, 0); + + ScDocument aClipDoc(SCDOCMODE_CLIP); + copyToClip(m_pDoc, ScRange(1, 1, 0, 1, 1, 0), &aClipDoc); + + ScRange aTargetRange(2, 2, 0, 2, 2, 0); + pasteFromClip(m_pDoc, aTargetRange, &aClipDoc); + + ScConditionalFormat* pPastedFormat = m_pDoc->GetCondFormat(2, 2, 0); + CPPUNIT_ASSERT(pPastedFormat); + + // Pasting the same conditional format into the same range must not modify existing format, + // since it already covers the pasted range. No new conditional formats must be created. + CPPUNIT_ASSERT_EQUAL(size_t(1), m_pDoc->GetCondFormList(0)->size()); + CPPUNIT_ASSERT_EQUAL(aRangeList, pPastedFormat->GetRange()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nIndex), pPastedFormat->GetKey()); + const SfxPoolItem* pItem = m_pDoc->GetAttr(2, 2, 0, ATTR_CONDITIONAL); + const ScCondFormatItem* pCondFormatItem = static_cast<const ScCondFormatItem*>(pItem); + + CPPUNIT_ASSERT(pCondFormatItem); + CPPUNIT_ASSERT_EQUAL(size_t(1), pCondFormatItem->GetCondFormatData().size()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nIndex), pCondFormatItem->GetCondFormatData().at(0)); + + m_pDoc->DeleteTab(0); +} + void Test::testCondCopyPasteSingleRowToRange() { m_pDoc->InsertTab(0, "Test"); @@ -398,7 +446,7 @@ void Test::testCondCopyPasteSingleRowToRange() ScConditionalFormat* pNewFormat = m_pDoc->GetCondFormat(0, 4, 0); CPPUNIT_ASSERT(pNewFormat); - CPPUNIT_ASSERT(pNewFormat->GetKey() != pFormat->GetKey()); + CPPUNIT_ASSERT_EQUAL(pNewFormat->GetKey(), pFormat->GetKey()); for (SCCOL nCol = 1; nCol <= MAXCOL; ++nCol) { |