sw/inc/swtable.hxx                  |    4 +--
 sw/qa/extras/layout/layout.cxx      |   44 ++++++++++++++++++++++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter5.cxx |    4 +--
 sw/source/core/layout/tabfrm.cxx    |    7 +++++
 sw/source/core/layout/wsfrm.cxx     |    4 +--
 sw/source/core/table/swtable.cxx    |   25 ++++++++++++++++++--
 sw/source/uibase/app/docsh2.cxx     |    2 -
 7 files changed, 81 insertions(+), 9 deletions(-)

New commits:
commit aff269c18b9029fec992135a406dc5031927c401
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon May 15 19:11:11 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed May 17 19:45:01 2023 +0200

    tdf#155345 sw tracked table column: hide them in Hide Changes mode
    
    And if all columns are deleted, hide the table in Hide Changes mode.
    
    Follow-up to commit ffd8d20d368a885d6d786749278fa438573227a7
    "tdf#150673 sw xmloff: import/export tracked table column" and
    commit f481c2c8e74bded11fac754e493560391229dbcd
    "tdf#144057 sw track changes: hide deleted table rows".
    
    Change-Id: Ic8f0254d607d629ed6386df94b16a939cde17506
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151805
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx
index 77ec4163eb31..e8b4ad35602f 100644
--- a/sw/inc/swtable.hxx
+++ b/sw/inc/swtable.hxx
@@ -354,8 +354,8 @@ public:
 
     // is it a table deleted completely with change tracking
     bool IsDeleted() const;
-    // is it a table with deleted row(s)
-    bool HasDeletedRow() const;
+    // is it a table with a deleted row or cell
+    bool HasDeletedRowOrCell() const;
     // it doesn't contain box content (except single empty nested tables of 
the boxes
     // which could remain after deletion of text content of the selected table)
     bool IsEmpty() const;
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index ab10a2af2bf0..07f041faaf96 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -3302,6 +3302,50 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf144347)
     assertXPath(pXmlDoc, "/root/page[1]/body/tab", 0);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf155345)
+{
+    createSwDoc("tdf144057.fodt");
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+    CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
+
+    // reject all deletions
+    dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {});
+
+    // enable redlining
+    dispatchCommand(mxComponent, ".uno:TrackChanges", {});
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+
+    // delete table column with track changes
+    dispatchCommand(mxComponent, ".uno:DeleteColumns", {});
+
+    discardDumpedLayout();
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    // show tracked column deletions
+    assertXPath(pXmlDoc, "/root/page", 4);
+
+    // hide tracked table column deletions
+    dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {});
+    CPPUNIT_ASSERT(pLayout->IsHideRedlines());
+    pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()->CalcLayout();
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+
+    // This was 4 (unhidden tracked table column deletions)
+    assertXPath(pXmlDoc, "/root/page", 2);
+
+    // show tracked table column deletions again
+    dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {});
+    CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
+    pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()->CalcLayout();
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "/root/page", 4);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf109137)
 {
     createSwDoc("tdf109137.docx");
diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index 0bb6db185e37..00cc35e13998 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -1907,7 +1907,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf150976)
     SwTabFrame* pTabFrame = static_cast<SwTabFrame*>(pTable);
 
     // This was false (not deleted row)
-    CPPUNIT_ASSERT(pTabFrame->GetTable()->HasDeletedRow());
+    CPPUNIT_ASSERT(pTabFrame->GetTable()->HasDeletedRowOrCell());
 
     // accept all tracked changes
     dispatchCommand(mxComponent, ".uno:AcceptAllTrackedChanges", {});
@@ -1960,7 +1960,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf151657)
     SwTabFrame* pTabFrame = static_cast<SwTabFrame*>(pTable);
 
     // This was false (not deleted row)
-    CPPUNIT_ASSERT(pTabFrame->GetTable()->HasDeletedRow());
+    CPPUNIT_ASSERT(pTabFrame->GetTable()->HasDeletedRowOrCell());
 
     // accept all tracked changes
     dispatchCommand(mxComponent, ".uno:AcceptAllTrackedChanges", {});
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 86685f620e37..5ce99f43023d 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -4001,8 +4001,15 @@ SwRowFrame::SwRowFrame(const SwTableLine &rLine, 
SwFrame* pSib, bool bInsertCont
     //Create the boxes and insert them.
     const SwTableBoxes &rBoxes = rLine.GetTabBoxes();
     SwFrame *pTmpPrev = nullptr;
+
+    bool bHiddenRedlines = getRootFrame()->IsHideRedlines() &&
+        
!GetFormat()->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().empty();
     for ( size_t i = 0; i < rBoxes.size(); ++i )
     {
+        // skip cells deleted with track changes
+        if ( bHiddenRedlines && RedlineType::Delete == 
rBoxes[i]->GetRedlineType() )
+            continue;
+
         SwCellFrame *pNew = new SwCellFrame( *rBoxes[i], this, bInsertContent 
);
         pNew->InsertBehind( this, pTmpPrev );
         pTmpPrev = pNew;
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index 233e973ed178..e30e3ecc401a 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -4505,7 +4505,7 @@ static void UnHideRedlines(SwRootFrame & rLayout,
                 }
                 pTableNd->DelFrames(&rLayout);
             }
-            else if ( pTableNd->GetTable().HasDeletedRow() )
+            else if ( pTableNd->GetTable().HasDeletedRowOrCell() )
             {
                 pTableNd->DelFrames(&rLayout);
                 if ( !pTableNd->GetTable().IsDeleted() )
@@ -4515,7 +4515,7 @@ static void UnHideRedlines(SwRootFrame & rLayout,
             }
         }
         else if (rNode.IsTableNode() && !rLayout.IsHideRedlines() &&
-            rNode.GetTableNode()->GetTable().HasDeletedRow() )
+            rNode.GetTableNode()->GetTable().HasDeletedRowOrCell() )
         {
             SwTableNode * pTableNd = rNode.GetTableNode();
             pTableNd->DelFrames(&rLayout);
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 8b2d395c05eb..2ea8bffd48e3 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -1584,7 +1584,7 @@ bool SwTable::IsEmpty() const
     return true;
 }
 
-bool SwTable::HasDeletedRow() const
+bool SwTable::HasDeletedRowOrCell() const
 {
     const SwRedlineTable& aRedlineTable = 
GetFrameFormat()->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
     if ( aRedlineTable.empty() )
@@ -1593,8 +1593,17 @@ bool SwTable::HasDeletedRow() const
     SwRedlineTable::size_type nRedlinePos = 0;
     for (size_t i = 0; i < m_aLines.size(); ++i)
     {
+        // has a deleted row
         if ( m_aLines[i]->IsDeleted(nRedlinePos) )
             return true;
+
+        // has a deleted cell in the not deleted row
+        SwTableBoxes& rBoxes = m_aLines[i]->GetTabBoxes();
+        for( size_t j = 0; j < rBoxes.size(); ++j )
+        {
+            if ( RedlineType::Delete == rBoxes[j]->GetRedlineType() )
+                return true;
+        }
     }
     return false;
 }
@@ -1929,7 +1938,19 @@ bool SwTableLine::IsTracked(SwRedlineTable::size_type& 
rRedlinePos, bool bOnlyDe
 
 bool SwTableLine::IsDeleted(SwRedlineTable::size_type& rRedlinePos) const
 {
-   return IsTracked(rRedlinePos, true);
+   // if not a deleted row, check the deleted columns
+   if ( !IsTracked(rRedlinePos, /*bOnlyDeleted=*/true) )
+   {
+       const SwTableBoxes& rBoxes = GetTabBoxes();
+       for( size_t i = 0; i < rBoxes.size(); ++i )
+       {
+           // there is a not deleted column
+           if ( rBoxes[i]->GetRedlineType() != RedlineType::Delete )
+               return false;
+       }
+   }
+
+   return true;
 }
 
 RedlineType SwTableLine::GetRedlineType() const
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index 8f5c4e8d40b8..4de0e8eae7ed 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -1329,7 +1329,7 @@ void SwDocShell::Execute(SfxRequest& rReq)
                         SwTableNode* pTableNd =
                             pRedline->GetPoint()->GetNode().FindTableNode();
                         if ( pTableNd && pTableNd !=
-                                pOldTableNd && 
pTableNd->GetTable().HasDeletedRow() )
+                                pOldTableNd && 
pTableNd->GetTable().HasDeletedRowOrCell() )
                         {
                             SfxBoolItem aShow(FN_REDLINE_SHOW, true);
                             SfxViewShell* pViewShell = GetView()

Reply via email to