sw/inc/format.hxx              |    5 +++-
 sw/source/core/attr/format.cxx |   45 +++++++++++++++++++++++------------------
 2 files changed, 30 insertions(+), 20 deletions(-)

New commits:
commit 9fc06b81e954d91a63f80a54953d636139426ee2
Author:     Szymon Kłos <[email protected]>
AuthorDate: Mon Nov 24 13:01:55 2025 +0000
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Nov 25 09:58:34 2025 +0100

    sw: setup favourite style once
    
    - the GrabBag values don't change after import much
    - better to parse qFormat once and setup favourite value
      we can cache and return quickly when requested
    - it is more efficient than checking grab bag every time we do
      iteration over styles
    
    Change-Id: I7b54831a84cd6528a40cf853f0d4f5061f05af82
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194442
    Code-Style: Miklos Vajna <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sw/inc/format.hxx b/sw/inc/format.hxx
index bfdf45af9c5f..67d4db13331d 100644
--- a/sw/inc/format.hxx
+++ b/sw/inc/format.hxx
@@ -62,6 +62,7 @@ class SW_DLLPUBLIC SwFormat : public sw::BorderCacheOwner, 
public sw::Broadcasti
     bool   m_bAutoUpdateOnDirectFormat : 1;/**< TRUE: Set attributes of a 
whole paragraph
                                        at format (UI-side!). */
     bool m_bHidden : 1;
+    bool m_bIsFavourite : 1;        ///< Show in the basic UI
     std::shared_ptr<SfxGrabBagItem> m_pGrabBagItem; ///< Style InteropGrabBag.
     virtual void InvalidateInSwFntCache(sal_uInt16) {};
     virtual void InvalidateInSwFntCache() {};
@@ -72,6 +73,7 @@ protected:
     SwFormat( const SwFormat& rFormat );
     virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
     void Destr();
+    void ParseFavourites();
 
 public:
 
@@ -178,7 +180,8 @@ public:
     bool IsAuto() const                 { return m_bAutoFormat; }
     void SetAuto( bool bNew )           { m_bAutoFormat = bNew; }
 
-    bool IsFavourite() const;
+    bool IsFavourite() const            { return m_bIsFavourite; }
+    void SetFavourite(bool bValue)      { m_bIsFavourite = bValue; }
 
     bool IsHidden() const               { return m_bHidden; }
     void SetHidden( bool bValue )       { m_bHidden = bValue; }
diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx
index ed11607a3a8f..59d9012dee93 100644
--- a/sw/source/core/attr/format.cxx
+++ b/sw/source/core/attr/format.cxx
@@ -49,6 +49,7 @@ SwFormat::SwFormat( SwAttrPool& rPool, const OUString& 
rFormatNm,
     m_bAutoUpdateOnDirectFormat = false; // LAYER_IMPL
     m_bAutoFormat = true;
     m_bFormatInDTOR = m_bHidden = false;
+    m_bIsFavourite = true;
 
     if( pDrvdFrame )
     {
@@ -69,6 +70,7 @@ SwFormat::SwFormat( const SwFormat& rFormat ) :
     m_bFormatInDTOR = false; // LAYER_IMPL
     m_bAutoFormat = rFormat.m_bAutoFormat;
     m_bHidden = rFormat.m_bHidden;
+    m_bIsFavourite = rFormat.m_bIsFavourite;
     m_bAutoUpdateOnDirectFormat = rFormat.m_bAutoUpdateOnDirectFormat;
 
     if( auto pDerived = rFormat.DerivedFrom() )
@@ -117,6 +119,7 @@ SwFormat &SwFormat::operator=(const SwFormat& rFormat)
 
     m_bAutoFormat = rFormat.m_bAutoFormat;
     m_bHidden = rFormat.m_bHidden;
+    m_bIsFavourite = rFormat.m_bIsFavourite;
     m_bAutoUpdateOnDirectFormat = rFormat.m_bAutoUpdateOnDirectFormat;
     return *this;
 }
@@ -725,6 +728,29 @@ void SwFormat::SetGrabBagItem(const uno::Any& rVal)
         m_pGrabBagItem = std::make_shared<SfxGrabBagItem>();
 
     m_pGrabBagItem->PutValue(rVal, 0);
+
+    ParseFavourites();
+}
+
+void SwFormat::ParseFavourites()
+{
+    const auto& rItems = m_pGrabBagItem->GetGrabBag();
+    const auto aIt = rItems.find(u"qFormat"_ustr);
+    if (aIt != rItems.end())
+    {
+        sal_Int32 nVal = 0;
+        if (aIt->second >>= nVal)
+        {
+            if (nVal == 0)
+                SetFavourite(false);
+            else
+                SetFavourite(true);
+        }
+    }
+    else
+    {
+        SetFavourite(false);
+    }
 }
 
 std::unique_ptr<SvxBrushItem> SwFormat::makeBackgroundBrushItem(bool bInP) 
const
@@ -754,25 +780,6 @@ void SwFormat::RemoveAllUnos()
     SwClientNotify(*this, aMsgHint);
 }
 
-bool SwFormat::IsFavourite() const
-{
-    if (!m_pGrabBagItem) return false;
-
-    const auto& rItems = m_pGrabBagItem->GetGrabBag();
-    const auto aIt = rItems.find(u"qFormat"_ustr);
-    if (aIt != rItems.end())
-    {
-        sal_Int32 nVal = 0;
-        if (aIt->second >>= nVal)
-        {
-            if (nVal == 1)
-                return true;
-        }
-    }
-
-    return false;
-}
-
 bool SwFormat::IsUsed() const
 {
     auto pDoc = GetDoc();

Reply via email to