cui/source/options/cfgchart.cxx |   83 +++++++++-------------------------------
 cui/source/options/cfgchart.hxx |   27 +------------
 cui/source/options/optchart.cxx |   11 +----
 cui/source/options/optchart.hxx |    1 
 cui/source/options/treeopt.cxx  |    3 -
 5 files changed, 26 insertions(+), 99 deletions(-)

New commits:
commit 85cdae23f1bb184d50500deb37f24d650f5e9230
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Mar 10 12:52:57 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Mar 10 19:26:05 2023 +0000

    Use officecfg instead of SvxChartOptions
    
    Change-Id: Ie7fddd86baa029890cd6874fdfae186098d00407
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148604
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/cui/source/options/cfgchart.cxx b/cui/source/options/cfgchart.cxx
index 13ed520d0306..8d1bd5e4130e 100644
--- a/cui/source/options/cfgchart.cxx
+++ b/cui/source/options/cfgchart.cxx
@@ -24,6 +24,7 @@
 #include <dialmgr.hxx>
 #include <strings.hrc>
 #include <utility>
+#include <officecfg/Office/Chart.hxx>
 
 #define ROW_COLOR_COUNT 12
 
@@ -159,45 +160,10 @@ bool SvxChartColorTable::operator==( const 
SvxChartColorTable & _rOther ) const
 
 
 
-SvxChartOptions::SvxChartOptions() :
-    ::utl::ConfigItem( "Office.Chart" ),
-    mbIsInitialized( false ),
-    maPropertyNames{ "DefaultColor/Series" }
+SvxChartColorTable SvxChartOptions::GetDefaultColors()
 {
-}
-
-SvxChartOptions::~SvxChartOptions()
-{
-}
-
-const SvxChartColorTable& SvxChartOptions::GetDefaultColors()
-{
-    if ( !mbIsInitialized )
-        mbIsInitialized = RetrieveOptions();
-    return maDefColors;
-}
-
-void SvxChartOptions::SetDefaultColors( const SvxChartColorTable& aCol )
-{
-    maDefColors = aCol;
-    SetModified();
-}
-
-bool SvxChartOptions::RetrieveOptions()
-{
-    // get sequence containing all properties
-
-    uno::Sequence< OUString > aNames = GetPropertyNames();
-    uno::Sequence< uno::Any > aProperties( aNames.getLength());
-    aProperties = GetProperties( aNames );
-
-    if( aProperties.getLength() != aNames.getLength())
-        return false;
-
     // 1. default colors for series
-    maDefColors.clear();
-    uno::Sequence< sal_Int64 > aColorSeq;
-    aProperties[ 0 ] >>= aColorSeq;
+    uno::Sequence< sal_Int64 > aColorSeq = 
officecfg::Office::Chart::DefaultColor::Series::get();
 
     sal_Int32 nCount = aColorSeq.getLength();
     Color aCol;
@@ -217,48 +183,37 @@ bool SvxChartOptions::RetrieveOptions()
         aPrefix = aResName;
 
     // set color values
+    SvxChartColorTable  aDefColors;
     for( sal_Int32 i=0; i < nCount; i++ )
     {
         aCol = Color(ColorTransparency, aColorSeq[ i ]);
 
         aName = aPrefix + OUString::number(i + 1) + aPostfix;
 
-        maDefColors.append( XColorEntry( aCol, aName ));
+        aDefColors.append( XColorEntry( aCol, aName ));
     }
-    return true;
+
+    return aDefColors;
 }
 
-void SvxChartOptions::ImplCommit()
+void SvxChartOptions::SetDefaultColors( const SvxChartColorTable& rDefColors )
 {
-    uno::Sequence< OUString > aNames = GetPropertyNames();
-    uno::Sequence< uno::Any > aValues( aNames.getLength());
-
-    if( aValues.hasElements() )
+    // 1. default colors for series
+    // convert list to sequence
+    const size_t nCount = rDefColors.size();
+    uno::Sequence< sal_Int64 > aColors( nCount );
+    auto aColorsRange = asNonConstRange(aColors);
+    for( size_t i=0; i < nCount; i++ )
     {
-        // 1. default colors for series
-        // convert list to sequence
-        const size_t nCount = maDefColors.size();
-        uno::Sequence< sal_Int64 > aColors( nCount );
-        auto aColorsRange = asNonConstRange(aColors);
-        for( size_t i=0; i < nCount; i++ )
-        {
-            Color aData = maDefColors.getColor( i );
-            aColorsRange[ i ] = sal_uInt32(aData);
-        }
-
-        aValues.getArray()[0] <<= aColors;
+        Color aData = rDefColors.getColor( i );
+        aColorsRange[ i ] = sal_uInt32(aData);
     }
-
-    PutProperties( aNames, aValues );
-}
-
-void SvxChartOptions::Notify( const css::uno::Sequence< OUString >& )
-{
+    std::shared_ptr<comphelper::ConfigurationChanges> 
batch(comphelper::ConfigurationChanges::create());
+    officecfg::Office::Chart::DefaultColor::Series::set(aColors, batch);
+    batch->commit();
 }
 
 
-
-
 SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_, 
SvxChartColorTable aTable ) :
     SfxPoolItem( nWhich_ ),
     m_aColorTable(std::move( aTable ))
diff --git a/cui/source/options/cfgchart.hxx b/cui/source/options/cfgchart.hxx
index 8e49e190d00c..ce39b0a1734a 100644
--- a/cui/source/options/cfgchart.hxx
+++ b/cui/source/options/cfgchart.hxx
@@ -19,10 +19,8 @@
 
 #pragma once
 
-#include <unotools/configitem.hxx>
 #include <svl/poolitem.hxx>
 #include <svx/xtable.hxx>
-
 #include <vector>
 
 class SvxChartColorTable
@@ -51,29 +49,10 @@ public:
 
 // all options
 
-class SvxChartOptions : public ::utl::ConfigItem
+namespace SvxChartOptions
 {
-private:
-    SvxChartColorTable          maDefColors;
-    bool                        mbIsInitialized;
-
-    css::uno::Sequence< OUString >
-                                maPropertyNames;
-
-    const css::uno::Sequence< OUString >& GetPropertyNames() const
-        { return maPropertyNames; }
-    bool RetrieveOptions();
-
-    virtual void                ImplCommit() override;
-
-public:
-    SvxChartOptions();
-    virtual ~SvxChartOptions() override;
-
-    const SvxChartColorTable&   GetDefaultColors();
-    void                        SetDefaultColors( const SvxChartColorTable& 
aCol );
-
-    virtual void Notify( const css::uno::Sequence< OUString >& 
_rPropertyNames) override;
+    SvxChartColorTable GetDefaultColors();
+    void SetDefaultColors( const SvxChartColorTable& aCol );
 };
 
 
diff --git a/cui/source/options/optchart.cxx b/cui/source/options/optchart.cxx
index af9b92322802..5d6b15e9991f 100644
--- a/cui/source/options/optchart.cxx
+++ b/cui/source/options/optchart.cxx
@@ -109,8 +109,6 @@ 
SvxDefaultColorOptPage::SvxDefaultColorOptPage(weld::Container* pPage, weld::Dia
     m_xValSetColorBox->SetStyle( m_xValSetColorBox->GetStyle()
                                     | WB_ITEMBORDER | WB_NAMEFIELD | 
WB_VSCROLL );
 
-    m_SvxChartOptionsUniquePtr.reset(new SvxChartOptions);
-
     if ( const SvxChartColorTableItem* pEditOptionsItem = 
rInAttrs.GetItemIfSet( SID_SCH_EDITOPTIONS, false ) )
     {
         m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>(
@@ -120,7 +118,7 @@ 
SvxDefaultColorOptPage::SvxDefaultColorOptPage(weld::Container* pPage, weld::Dia
     {
         m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>();
         m_SvxChartColorTableUniquePtr->useDefault();
-        
m_SvxChartOptionsUniquePtr->SetDefaultColors(*m_SvxChartColorTableUniquePtr);
+        SvxChartOptions::SetDefaultColors(*m_SvxChartColorTableUniquePtr);
     }
 
     Construct();
@@ -175,11 +173,8 @@ void SvxDefaultColorOptPage::FillPaletteLB()
 
 void SvxDefaultColorOptPage::SaveChartOptions()
 {
-    if (m_SvxChartOptionsUniquePtr && m_SvxChartColorTableUniquePtr)
-    {
-        
m_SvxChartOptionsUniquePtr->SetDefaultColors(*m_SvxChartColorTableUniquePtr);
-        m_SvxChartOptionsUniquePtr->Commit();
-    }
+    if (m_SvxChartColorTableUniquePtr)
+        SvxChartOptions::SetDefaultColors(*m_SvxChartColorTableUniquePtr);
 }
 
 // event handlers
diff --git a/cui/source/options/optchart.hxx b/cui/source/options/optchart.hxx
index 11221617a9d1..08bd26a8cacb 100644
--- a/cui/source/options/optchart.hxx
+++ b/cui/source/options/optchart.hxx
@@ -32,7 +32,6 @@ typedef std::vector<Color> ImpColorList;
 class SvxDefaultColorOptPage : public SfxTabPage
 {
 private:
-    std::unique_ptr<SvxChartOptions>        m_SvxChartOptionsUniquePtr;
     // no reason to use a cloned SfxItem here (SvxChartColorTableItem)
     // that just leads to non-const SfxItem and potential trouble
     std::unique_ptr<SvxChartColorTable>     m_SvxChartColorTableUniquePtr;
diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx
index 68fcda9f43e7..37d7f745dd80 100644
--- a/cui/source/options/treeopt.cxx
+++ b/cui/source/options/treeopt.cxx
@@ -1134,9 +1134,8 @@ std::optional<SfxItemSet> 
OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId )
 
         case SID_SCH_EDITOPTIONS:
         {
-            SvxChartOptions aChartOpt;
             pRet.emplace( SfxGetpApp()->GetPool(), 
svl::Items<SID_SCH_EDITOPTIONS, SID_SCH_EDITOPTIONS> );
-            pRet->Put( SvxChartColorTableItem( SID_SCH_EDITOPTIONS, 
aChartOpt.GetDefaultColors() ) );
+            pRet->Put( SvxChartColorTableItem( SID_SCH_EDITOPTIONS, 
SvxChartOptions::GetDefaultColors() ) );
             break;
         }
     }

Reply via email to