sw/inc/deletelistener.hxx  |    1 +
 sw/source/core/doc/doc.cxx |   23 ++++++-----------------
 2 files changed, 7 insertions(+), 17 deletions(-)

New commits:
commit 6a2393e4e7e0347ad47ca8f7cf2bc35b11c3dbeb
Author:     Bjoern Michaelsen <[email protected]>
AuthorDate: Sun Feb 16 17:26:48 2025 +0100
Commit:     Bjoern Michaelsen <[email protected]>
CommitDate: Mon Feb 17 09:07:51 2025 +0100

    getting rid of FieldTypeGuard/SwClient
    
    Change-Id: Icd10490f2d0acda8f05fdf037683957f20afa750
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181748
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>
    Reviewed-by: Bjoern Michaelsen <[email protected]>

diff --git a/sw/inc/deletelistener.hxx b/sw/inc/deletelistener.hxx
index c787fa861f7f..631e0a6060f3 100644
--- a/sw/inc/deletelistener.hxx
+++ b/sw/inc/deletelistener.hxx
@@ -52,6 +52,7 @@ public:
     }
 
     T* operator->() { return m_pBroadcasting; }
+    const T* operator->() const { return m_pBroadcasting; }
     T& operator*() { return *m_pBroadcasting; }
     explicit operator bool() const { return m_pBroadcasting; }
 };
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index a7351ea9ef7a..97ef7e27ed10 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -95,6 +95,7 @@
 #include <shellres.hxx>
 #include <txtfrm.hxx>
 #include <attrhint.hxx>
+#include <deletelistener.hxx>
 
 #include <vector>
 #include <map>
@@ -1788,33 +1789,21 @@ bool SwDoc::RemoveInvisibleContent()
     GetIDocumentUndoRedo().StartUndo( SwUndoId::UI_DELETE_INVISIBLECNTNT, 
nullptr );
 
     {
-        class FieldTypeGuard : public SwClient
-        {
-        public:
-            explicit FieldTypeGuard(SwFieldType* pType)
-                : SwClient(pType)
-            {
-            }
-            const SwFieldType* get() const
-            {
-                return static_cast<const SwFieldType*>(GetRegisteredIn());
-            }
-        };
         // Removing some nodes for one SwFieldIds::Database type might remove 
the type from
         // document's field types, invalidating iterators. So, we need to 
create own list of
         // matching types prior to processing them.
-        std::vector<std::unique_ptr<FieldTypeGuard>> aHidingFieldTypes;
+        std::vector<sw::WeakBroadcastingPtr<SwFieldType>> aHidingFieldTypes;
         for (std::unique_ptr<SwFieldType> const & pType : 
*getIDocumentFieldsAccess().GetFieldTypes())
         {
             if (FieldCanHideParaWeight(pType->Which()))
-                
aHidingFieldTypes.push_back(std::make_unique<FieldTypeGuard>(pType.get()));
+                aHidingFieldTypes.push_back(pType.get());
         }
-        for (const auto& pTypeGuard : aHidingFieldTypes)
+        for (const auto& pWeakType : aHidingFieldTypes)
         {
-            if (const SwFieldType* pType = pTypeGuard->get())
+            if (pWeakType)
             {
                 std::vector<SwFormatField*> vFields;
-                pType->GatherFields(vFields);
+                pWeakType->GatherFields(vFields);
                 for(auto pFormatField: vFields)
                     bRet |= HandleHidingField(*pFormatField, GetNodes(), 
getIDocumentContentOperations());
             }

Reply via email to