summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2022-04-28 19:48:52 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2022-05-03 16:29:33 +0200
commitb47b35e0ab6efceeaa2dbe8b598c21afa5944d67 (patch)
tree6f674a9620f238384342aa4681f5d06b3ae5cd92
parentf248b99b6f7f93b5170b4c50d7827fa0dd23421e (diff)
tdf#146573 sw: recalculate cells with footnotes
Commit 915d3eebc1dc4f18d7a1992db801ee8313ee46c0 "tdf#39828 sw: fix table formula calculation at track changes" allowed to use footnotes in value cells unintentionally. The only problem was that modifying cells with footnotes didn't trigger formula recalculation in text tables, according to the incomplete SwTableBox::IsValidNumTextNd(). Instead of asking formula recalculation pressing F9, now IsValidNumTextNd was extended to skip footnotes, similar to the already skipped comments. Also clean-up to testTdf39828 (remove copy-paste code), and clean-up to commit 915d3eebc1dc4f18d7a1992db801ee8313ee46c0 "tdf#39828 sw: fix table formula calculation at track changes" to avoid of unnecessary calls of GetRedlineText(), which is an expensive call, especially when there are a lot of redlines with overlapping (see commit d467cd0dd9e9cf3b018859a592e2638527bc7add "tdf#135683 speedup DocumentRedlineManager::GetRedlinePos"). Change-Id: I00243ef0985805414723e26fe26d6e9c04ce86cf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133579 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 978e22f8cfb3db573bed3fd4b14a515cf090f7e5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133722 Tested-by: Jenkins
-rw-r--r--sw/qa/extras/uiwriter/uiwriter3.cxx40
-rw-r--r--sw/source/core/fields/cellfml.cxx5
-rw-r--r--sw/source/core/table/swtable.cxx3
3 files changed, 41 insertions, 7 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 3c453ab313da..1b90efde6bac 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -3005,9 +3005,6 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf87199)
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf39828)
{
SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf39828.fodt");
- SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
-
- pWrtShell->GotoNextTOXBase();
// show changes
pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
@@ -3036,6 +3033,43 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf39828)
CPPUNIT_ASSERT_EQUAL(OUString("8"), xCellA4->getString());
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf146573)
+{
+ SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf39828.fodt");
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+ // remove redlines, add a footnote, and change the value
+ // of the cell with the footnote
+ dispatchCommand(mxComponent, ".uno:AcceptAllTrackedChanges", {});
+ Scheduler::ProcessEventsToIdle();
+ pWrtShell->Right(CRSR_SKIP_CELLS, /*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false);
+ dispatchCommand(mxComponent, ".uno:InsertFootnote", {});
+ dispatchCommand(mxComponent, ".uno:PageUp", {}); // leave footnote
+ pWrtShell->Left(CRSR_SKIP_CELLS, /*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false);
+ pWrtShell->Left(CRSR_SKIP_CELLS, /*bSelect=*/true, /*nCount=*/1, /*bBasicCall=*/false);
+ pWrtShell->Insert("100");
+
+ // trigger recalculation by leaving the cell
+ pWrtShell->Down(/*bSelect=*/false, /*nCount=*/1);
+
+ uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
+ uno::UNO_QUERY);
+ uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable->getRows()->getCount());
+
+ uno::Reference<text::XTextRange> xCellA1(xTextTable->getCellByName("A1"), uno::UNO_QUERY);
+ // value "100" and footnote index "1"
+ CPPUNIT_ASSERT_EQUAL(OUString("1001"), xCellA1->getString());
+ uno::Reference<text::XTextRange> xCellA3(xTextTable->getCellByName("A3"), uno::UNO_QUERY);
+ // This was 4 (missing recalculation)
+ CPPUNIT_ASSERT_EQUAL(OUString("102"), xCellA3->getString());
+ uno::Reference<text::XTextRange> xCellA4(xTextTable->getCellByName("A4"), uno::UNO_QUERY);
+ // This was 8 (missing recalculation)
+ CPPUNIT_ASSERT_EQUAL(OUString("204"), xCellA4->getString());
+}
+
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132603)
{
createSwDoc();
diff --git a/sw/source/core/fields/cellfml.cxx b/sw/source/core/fields/cellfml.cxx
index f74b80401596..7306b0fef8c8 100644
--- a/sw/source/core/fields/cellfml.cxx
+++ b/sw/source/core/fields/cellfml.cxx
@@ -152,9 +152,8 @@ double SwTableBox::GetValue( SwTableCalcPara& rCalcPara ) const
OUString sText = pTextNd->GetText();
// use text of the tracked changes
- if ( sText != pTextNd->GetRedlineText() &&
- sText.getLength() > 0 &&
- sText[0] != CH_TXTATR_BREAKWORD && sText[0] != CH_TXTATR_INWORD )
+ if ( sText.getLength() > 0 &&
+ sText[0] != CH_TXTATR_BREAKWORD && sText[0] != CH_TXTATR_INWORD )
{
sText = pTextNd->GetRedlineText();
}
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 101f5245f5ad..da159df14bd2 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -2714,7 +2714,8 @@ SwNodeOffset SwTableBox::IsValidNumTextNd( bool bCheckAttr ) const
continue;
}
}
- else if( RES_TXTATR_ANNOTATION == pAttr->Which() )
+ else if( RES_TXTATR_ANNOTATION == pAttr->Which() ||
+ RES_TXTATR_FTN == pAttr->Which() )
{
continue;
}