[Libreoffice-commits] core.git: chart2/source svx/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Fri May 7 19:52:14 UTC 2021


 chart2/source/inc/chartview/DrawModelWrapper.hxx |    2 -
 chart2/source/view/main/ChartItemPool.cxx        |   35 +++++++++++++++++++++--
 chart2/source/view/main/ChartItemPool.hxx        |    5 +--
 chart2/source/view/main/DrawModelWrapper.cxx     |   29 -------------------
 svx/source/unodraw/UnoNameItemTable.cxx          |    2 -
 5 files changed, 37 insertions(+), 36 deletions(-)

New commits:
commit 2ed8c34bca56c1a30d727b21d9096cb77e88197a
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed May 5 10:54:44 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri May 7 21:51:32 2021 +0200

    use a single global item pool for chart2 draw model
    
    which exposed a bug in SvxUnoNameItemTable::replaceByName
    
    Change-Id: If3207df6d46a2185b78ea5c3e1c145527b42d7cd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115126
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/chart2/source/inc/chartview/DrawModelWrapper.hxx b/chart2/source/inc/chartview/DrawModelWrapper.hxx
index d4bab8a2a861..644501dcdace 100644
--- a/chart2/source/inc/chartview/DrawModelWrapper.hxx
+++ b/chart2/source/inc/chartview/DrawModelWrapper.hxx
@@ -37,8 +37,6 @@ namespace chart
 class OOO_DLLPUBLIC_CHARTVIEW DrawModelWrapper : private SdrModel
 {
 private:
-    SfxItemPool* m_pChartItemPool;
-
     css::uno::Reference< css::drawing::XDrawPage > m_xMainDrawPage;
     css::uno::Reference< css::drawing::XDrawPage > m_xHiddenDrawPage;
 
diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx
index 8b5bade3ebc3..2b3e59dc3c31 100644
--- a/chart2/source/view/main/ChartItemPool.cxx
+++ b/chart2/source/view/main/ChartItemPool.cxx
@@ -21,8 +21,13 @@
 #include <chartview/ChartSfxItemIds.hxx>
 #include <svx/chrtitem.hxx>
 #include <svx/sdangitm.hxx>
+#include <svx/svdobj.hxx>
+#include <svx/svdpool.hxx>
+#include <svx/svx3ditems.hxx>
 #include <svl/intitem.hxx>
+#include <editeng/editeng.hxx>
 #include <editeng/brushitem.hxx>
+#include <editeng/eeitem.hxx>
 #include <editeng/sizeitem.hxx>
 #include <svl/stritem.hxx>
 #include <svl/ilstitem.hxx>
@@ -209,9 +214,35 @@ MapUnit ChartItemPool::GetMetric(sal_uInt16 /* nWhich */) const
     return MapUnit::Map100thMM;
 }
 
-SfxItemPool* ChartItemPool::CreateChartItemPool()
+namespace {
+struct PoolDeleter
 {
-    return new ChartItemPool();
+    void operator()(SfxItemPool* pPool)
+    {
+        SfxItemPool::Free(pPool);
+    }
+};
+}
+static std::unique_ptr<SfxItemPool, PoolDeleter> g_Pool1, g_Pool2, g_Pool3;
+
+SfxItemPool& ChartItemPool::GetGlobalChartItemPool()
+{
+    if (!g_Pool1)
+    {
+        // similar logic to SdrModel's pool, but with our chart pool tagged on the end
+        g_Pool1.reset(new SdrItemPool(nullptr));
+        g_Pool2.reset(EditEngine::CreatePool());
+        g_Pool3.reset(new ChartItemPool());
+        g_Pool1->SetSecondaryPool(g_Pool2.get());
+
+        g_Pool1->SetDefaultMetric(MapUnit::Map100thMM);
+        g_Pool1->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) );
+        g_Pool1->SetPoolDefaultItem(makeSvx3DPercentDiagonalItem (5));
+
+        g_Pool2->SetSecondaryPool(g_Pool3.get());
+        g_Pool1->FreezeIdRanges();
+    }
+    return *g_Pool1;
 }
 
 } //  namespace chart
diff --git a/chart2/source/view/main/ChartItemPool.hxx b/chart2/source/view/main/ChartItemPool.hxx
index b424ed89e8e4..43f461a6aade 100644
--- a/chart2/source/view/main/ChartItemPool.hxx
+++ b/chart2/source/view/main/ChartItemPool.hxx
@@ -29,7 +29,6 @@ class ChartItemPool : public SfxItemPool
 private:
     std::unique_ptr<SfxItemInfo[]> pItemInfos;
 
-public:
     ChartItemPool();
     ChartItemPool(const ChartItemPool& rPool);
 
@@ -40,8 +39,8 @@ public:
     virtual SfxItemPool* Clone() const override;
     MapUnit GetMetric(sal_uInt16 nWhich) const override;
 
-    /// creates a pure chart item pool
-    static SfxItemPool* CreateChartItemPool();
+    /// get the pure chart item pool
+    static SfxItemPool& GetGlobalChartItemPool();
 };
 
 } //  namespace chart
diff --git a/chart2/source/view/main/DrawModelWrapper.cxx b/chart2/source/view/main/DrawModelWrapper.cxx
index 916087e6c69a..09daef1d6d54 100644
--- a/chart2/source/view/main/DrawModelWrapper.cxx
+++ b/chart2/source/view/main/DrawModelWrapper.cxx
@@ -48,23 +48,12 @@ namespace chart
 {
 
 DrawModelWrapper::DrawModelWrapper()
-:   SdrModel()
-    , m_pChartItemPool(nullptr)
+:   SdrModel(&ChartItemPool::GetGlobalChartItemPool())
 {
-    m_pChartItemPool = ChartItemPool::CreateChartItemPool();
-
     SetScaleUnit(MapUnit::Map100thMM);
     SetScaleFraction(Fraction(1, 1));
     SetDefaultFontHeight(423);     // 12pt
 
-    SfxItemPool* pMasterPool = &GetItemPool();
-    pMasterPool->SetDefaultMetric(MapUnit::Map100thMM);
-    pMasterPool->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) );
-    pMasterPool->SetPoolDefaultItem(makeSvx3DPercentDiagonalItem (5));
-
-    // append chart pool to end of pool chain
-    pMasterPool->GetLastPoolInChain()->SetSecondaryPool(m_pChartItemPool);
-    pMasterPool->FreezeIdRanges();
     SetTextDefaults();
 
     //this factory needs to be created before first use of 3D scenes once upon an office runtime
@@ -108,22 +97,6 @@ DrawModelWrapper::DrawModelWrapper()
 
 DrawModelWrapper::~DrawModelWrapper()
 {
-    //remove m_pChartItemPool from pool chain
-    if(m_pChartItemPool)
-    {
-        SfxItemPool* pPool = &GetItemPool();
-        for (;;)
-        {
-            SfxItemPool* pSecondary = pPool->GetSecondaryPool();
-            if(pSecondary == m_pChartItemPool)
-            {
-                pPool->SetSecondaryPool (nullptr);
-                break;
-            }
-            pPool = pSecondary;
-        }
-        SfxItemPool::Free(m_pChartItemPool);
-    }
     m_pRefDevice.disposeAndClear();
 }
 
diff --git a/svx/source/unodraw/UnoNameItemTable.cxx b/svx/source/unodraw/UnoNameItemTable.cxx
index 56a96534f02c..ac13c30ea88b 100644
--- a/svx/source/unodraw/UnoNameItemTable.cxx
+++ b/svx/source/unodraw/UnoNameItemTable.cxx
@@ -180,7 +180,7 @@ void SAL_CALL SvxUnoNameItemTable::replaceByName( const OUString& aApiName, cons
 
     if (mpModelPool)
     {
-        NameOrIndex aSample(mnWhich, aName);
+        SampleItem aSample(mnWhich, aName);
         for (const SfxPoolItem* pNameOrIndex : mpModelPool->FindItemSurrogate(mnWhich, aSample))
             if (isValid(static_cast<const NameOrIndex*>(pNameOrIndex)))
             {


More information about the Libreoffice-commits mailing list