diff options
author | László Németh <nemeth@numbertext.org> | 2022-02-07 18:03:45 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-02-14 11:00:08 +0100 |
commit | d44e32ce0ef5e0176f0402a393658f960aa90687 (patch) | |
tree | 789ddeed7be5ba9fb11aa582e719d8e8fe3aa04f /sw/qa/extras/uiwriter | |
parent | f2c9b1c82cca66f843c157f05e198a7ce64ed360 (diff) |
tdf#147181 tdf#147322 sw: fix drag & drop multiple table rows
With change tracking, moving multiple table rows tracked
only the first row as deleted, and in the insertion point,
as inserted.
Without change tracking, only the first row were deleted
from the original position. This is a regression of tdf#84806
from commit 5e8aa259e48d5602b932353bb146ebb523982cf2
"tdf#146967 sw table: fix freezing in Hide Changes mode".
Add unit tests for the change tracking fix and for the original
table moving fix in commit 7fe64353dc9950e19182a59a486a1ecac27cf98e
"tdf#84806 Writer: drag and drop selected tables, don't empty".
Conflicts:
sw/qa/extras/uiwriter/uiwriter4.cxx
Change-Id: I43250fcef4bbf482e67a7414f4f655e75d226b55
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129635
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry-picked from commit 2bb9ad2078e355b71ab25db0c46f3d0bb19cf6d4)
Change-Id: Id90664ba7611bb0fb7f03bcdf029ae4f211904cb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129742
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/qa/extras/uiwriter')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter4.cxx | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index 090938240c63..f7ff97ca1f02 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -103,6 +103,7 @@ #include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp> #include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/linguistic2/XLinguProperties.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> #include <com/sun/star/text/XPageCursor.hpp> @@ -260,6 +261,8 @@ public: void testTdf115013(); void testTdf114536(); void testTdf115065(); + void testTdf84806_MovingMultipleTableRows(); + void testTdf147181_TrackedMovingOfMultipleTableRows(); void testTdf115132(); void testXDrawPagesSupplier(); void testTdf116403(); @@ -382,6 +385,8 @@ public: CPPUNIT_TEST(testTdf115013); CPPUNIT_TEST(testTdf114536); CPPUNIT_TEST(testTdf115065); + CPPUNIT_TEST(testTdf84806_MovingMultipleTableRows); + CPPUNIT_TEST(testTdf147181_TrackedMovingOfMultipleTableRows); CPPUNIT_TEST(testTdf115132); CPPUNIT_TEST(testXDrawPagesSupplier); CPPUNIT_TEST(testTdf116403); @@ -2922,6 +2927,143 @@ void SwUiWriterTest4::testTdf115065() pWrtShell->Copy(*pWrtShell, ptFrom, ptTo); } +void SwUiWriterTest4::testTdf84806_MovingMultipleTableRows() +{ + // Moving of multiple table rows. + // Source table (first one) has two rows; + // destination (second one) has only one row + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf115065.odt"); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables->getCount()); + uno::Reference<container::XNameAccess> xTableNames = xTablesSupplier->getTextTables(); + CPPUNIT_ASSERT(xTableNames->hasByName("Table1")); + CPPUNIT_ASSERT(xTableNames->hasByName("Table2")); + uno::Reference<text::XTextTable> xTable1(xTableNames->getByName("Table1"), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable2(xTableNames->getByName("Table2"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable1->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable2->getRows()->getCount()); + + // without redlining + CPPUNIT_ASSERT_MESSAGE("redlining should be off", + !pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + + sw::UndoManager& rUndoManager = pDoc->GetUndoManager(); + + pWrtShell->GotoTable("Table2"); + SwRect aRect = pWrtShell->GetCurrFrame()->getFrameArea(); + // Destination point is the middle of the first cell of second table + Point ptTo(aRect.Left() + aRect.Width() / 2, aRect.Top() + aRect.Height() / 2); + + // Move rows of the first table into the second table + pWrtShell->GotoTable("Table1"); + pWrtShell->SelTable(); + rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell); + xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, /*bXSelection=*/true); + + // This was 2 tables + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable2->getRows()->getCount()); + + // Undo results 2 tables + rUndoManager.Undo(); + uno::Reference<container::XIndexAccess> xTables2(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables2->getCount()); + uno::Reference<text::XTextTable> xTable1b(xTableNames->getByName("Table1"), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable2b(xTableNames->getByName("Table2"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable1b->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable2b->getRows()->getCount()); + + // FIXME assert with Redo() +} + +void SwUiWriterTest4::testTdf147181_TrackedMovingOfMultipleTableRows() +{ + // Tracked moving of multiple table rows. + // Source table (first one) has two rows; + // destination (second one) has only one row + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf115065.odt"); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables->getCount()); + uno::Reference<container::XNameAccess> xTableNames = xTablesSupplier->getTextTables(); + CPPUNIT_ASSERT(xTableNames->hasByName("Table1")); + CPPUNIT_ASSERT(xTableNames->hasByName("Table2")); + uno::Reference<text::XTextTable> xTable1(xTableNames->getByName("Table1"), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable2(xTableNames->getByName("Table2"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable1->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable2->getRows()->getCount()); + + // FIXME: doesn't work with empty rows, yet + pWrtShell->Insert("x"); + pWrtShell->Down(false); + pWrtShell->Insert("x"); + + // enable redlining + dispatchCommand(mxComponent, ".uno:TrackChanges", {}); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + + // show changes + CPPUNIT_ASSERT_MESSAGE( + "redlines should be visible", + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + sw::UndoManager& rUndoManager = pDoc->GetUndoManager(); + + pWrtShell->GotoTable("Table2"); + SwRect aRect = pWrtShell->GetCurrFrame()->getFrameArea(); + // Destination point is the middle of the first cell of second table + Point ptTo(aRect.Left() + aRect.Width() / 2, aRect.Top() + aRect.Height() / 2); + + // Move rows of the first table into the second table + pWrtShell->GotoTable("Table1"); + pWrtShell->SelTable(); + rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell); + xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, /*bXSelection=*/true); + + // still 2 tables, but the second one has got 3 rows + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable1->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable2->getRows()->getCount()); + + // accept changes results 1 table (removing moved table) + dispatchCommand(mxComponent, ".uno:AcceptAllTrackedChanges", {}); + Scheduler::ProcessEventsToIdle(); + uno::Reference<container::XIndexAccess> xTables2(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables2->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable2->getRows()->getCount()); + + // Undo results 2 tables + rUndoManager.Undo(); + rUndoManager.Undo(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables2->getCount()); + uno::Reference<text::XTextTable> xTable1b(xTableNames->getByName("Table1"), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable2b(xTableNames->getByName("Table2"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable1b->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable2b->getRows()->getCount()); + + // reject changes results 2 table again, with the original row counts + dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {}); + uno::Reference<container::XIndexAccess> xTables3(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables3->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable1b->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable2b->getRows()->getCount()); +} + void SwUiWriterTest4::testTdf115132() { SwDoc* pDoc = createSwDoc(); |