[Libreoffice-commits] .: sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Feb 24 12:56:19 PST 2012


 sc/source/filter/excel/xichart.cxx |  122 +++++++++++++++++++------------------
 sc/source/filter/inc/xichart.hxx   |    8 --
 2 files changed, 66 insertions(+), 64 deletions(-)

New commits:
commit ba8918aebd2b9f030e0fd684accc9bf21bd1eac3
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Fri Feb 24 15:55:55 2012 -0500

    Untangled the code a bit.

diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx
index a483064..5503c21 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -1830,30 +1830,56 @@ void XclImpChSeries::ReadSubRecord( XclImpStream& rStrm )
     }
 }
 
-void XclImpChSeries::SetDataFormat( XclImpChDataFormatRef xDataFmt )
+void XclImpChSeries::SetDataFormat( const XclImpChDataFormatRef& xDataFmt )
 {
-    if( xDataFmt )
+    if (!xDataFmt)
+        return;
+
+    sal_uInt16 nPointIdx = xDataFmt->GetPointPos().mnPointIdx;
+    if (nPointIdx == EXC_CHDATAFORMAT_ALLPOINTS)
     {
-        XclImpChDataFormatRef* pxDataFmt = GetDataFormatRef( xDataFmt->GetPointPos().mnPointIdx );
-        // do not overwrite existing data format
-        if( pxDataFmt && !*pxDataFmt )
-        {
-            *pxDataFmt = xDataFmt;
-            // #i51639# register series format index at chart type group
-            if( (pxDataFmt == &mxSeriesFmt) && !HasParentSeries() )
-                if( XclImpChTypeGroup* pTypeGroup = GetChartData().GetTypeGroup( mnGroupIdx ).get() )
-                    pTypeGroup->SetUsedFormatIndex( xDataFmt->GetFormatIdx() );
-        }
+        if (mxSeriesFmt)
+            // Don't overwrite the existing format.
+            return;
+
+        mxSeriesFmt = xDataFmt;
+        if (HasParentSeries())
+            return;
+
+        XclImpChTypeGroupRef pTypeGroup = GetChartData().GetTypeGroup(mnGroupIdx);
+        if (pTypeGroup)
+            pTypeGroup->SetUsedFormatIndex(xDataFmt->GetFormatIdx());
+
+        return;
+    }
+
+    if (nPointIdx >= EXC_CHDATAFORMAT_MAXPOINTCOUNT)
+        // Above the max point count.  Bail out.
+        return;
+
+    XclImpChDataFormatMap::iterator itr = maPointFmts.lower_bound(nPointIdx);
+    if (itr == maPointFmts.end() || maPointFmts.key_comp()(nPointIdx, itr->first))
+    {
+        // No object exists at this point index position.  Insert it.
+        itr = maPointFmts.insert(itr, XclImpChDataFormatMap::value_type(nPointIdx, xDataFmt));
     }
 }
 
-void XclImpChSeries::SetDataLabel( XclImpChTextRef xLabel )
+void XclImpChSeries::SetDataLabel( const XclImpChTextRef& xLabel )
 {
-    if( xLabel )
+    if (!xLabel)
+        return;
+
+    sal_uInt16 nPointIdx = xLabel->GetPointPos().mnPointIdx;
+    if ((nPointIdx != EXC_CHDATAFORMAT_ALLPOINTS) && (nPointIdx >= EXC_CHDATAFORMAT_MAXPOINTCOUNT))
+        // Above the maximum allowed data points. Bail out.
+        return;
+
+    XclImpChTextMap::iterator itr = maLabels.lower_bound(nPointIdx);
+    if (itr == maLabels.end() || maLabels.key_comp()(nPointIdx, itr->first))
     {
-        XclImpChTextRef* pxLabel = GetDataLabelRef( xLabel->GetPointPos().mnPointIdx );
-        if( pxLabel && !*pxLabel )
-            *pxLabel = xLabel;
+        // No object exists at this point index position.  Insert it.
+        itr = maLabels.insert(itr, XclImpChTextMap::value_type(nPointIdx, xLabel));
     }
 }
 
@@ -1911,11 +1937,28 @@ void XclImpChSeries::FinalizeDataFormats()
         // set text labels to data formats
         for( XclImpChTextMap::iterator aTIt = maLabels.begin(), aTEnd = maLabels.end(); aTIt != aTEnd; ++aTIt )
         {
-            if( XclImpChDataFormatRef* pxDataFmt = GetDataFormatRef( aTIt->first ) )
+            sal_uInt16 nPointIdx = aTIt->first;
+            if (nPointIdx == EXC_CHDATAFORMAT_ALLPOINTS)
             {
-                if( !*pxDataFmt )
-                    *pxDataFmt = CreateDataFormat( aTIt->first, EXC_CHDATAFORMAT_DEFAULT );
-                (*pxDataFmt)->SetDataLabel( aTIt->second );
+                if (!mxSeriesFmt)
+                    mxSeriesFmt = CreateDataFormat(nPointIdx, EXC_CHDATAFORMAT_DEFAULT);
+                mxSeriesFmt->SetDataLabel(aTIt->second);
+            }
+            else if (nPointIdx < EXC_CHDATAFORMAT_MAXPOINTCOUNT)
+            {
+                XclImpChDataFormatRef p;
+                XclImpChDataFormatMap::iterator itr = maPointFmts.lower_bound(nPointIdx);
+                if (itr == maPointFmts.end() || maPointFmts.key_comp()(nPointIdx, itr->first))
+                {
+                    // No object exists at this point index position.  Insert
+                    // a new one.
+                    p = CreateDataFormat(nPointIdx, EXC_CHDATAFORMAT_DEFAULT);
+                    itr = maPointFmts.insert(
+                        itr, XclImpChDataFormatMap::value_type(nPointIdx, p));
+                }
+                else
+                    p = itr->second;
+                p->SetDataLabel(aTIt->second);
             }
         }
 
@@ -2108,43 +2151,6 @@ XclImpChDataFormatRef XclImpChSeries::CreateDataFormat( sal_uInt16 nPointIdx, sa
     return xDataFmt;
 }
 
-XclImpChDataFormatRef* XclImpChSeries::GetDataFormatRef( sal_uInt16 nPointIdx )
-{
-    if( nPointIdx == EXC_CHDATAFORMAT_ALLPOINTS )
-        return &mxSeriesFmt;
-
-    if (nPointIdx < EXC_CHDATAFORMAT_MAXPOINTCOUNT)
-    {
-        XclImpChDataFormatMap::iterator itr = maPointFmts.lower_bound(nPointIdx);
-        if (itr == maPointFmts.end() || maPointFmts.key_comp()(nPointIdx, itr->first))
-        {
-            // No object exists at this point index position.  Insert a new
-            // placeholder.
-            XclImpChDataFormatRef p;
-            itr = maPointFmts.insert(itr, XclImpChDataFormatMap::value_type(nPointIdx, p));
-        }
-        return &itr->second;
-    }
-    return 0;
-}
-
-XclImpChTextRef* XclImpChSeries::GetDataLabelRef( sal_uInt16 nPointIdx )
-{
-    if ((nPointIdx == EXC_CHDATAFORMAT_ALLPOINTS) || (nPointIdx < EXC_CHDATAFORMAT_MAXPOINTCOUNT))
-    {
-        XclImpChTextMap::iterator itr = maLabels.lower_bound(nPointIdx);
-        if (itr == maLabels.end() || maLabels.key_comp()(nPointIdx, itr->first))
-        {
-            // No object exists at this point index position.  Insert a new
-            // placeholder.
-            XclImpChTextRef p;
-            itr = maLabels.insert(itr, XclImpChTextMap::value_type(nPointIdx, p));
-        }
-        return &itr->second;
-    }
-    return 0;
-}
-
 void XclImpChSeries::ConvertTrendLines( Reference< XDataSeries > xDataSeries ) const
 {
     Reference< XRegressionCurveContainer > xRegCurveCont( xDataSeries, UNO_QUERY );
diff --git a/sc/source/filter/inc/xichart.hxx b/sc/source/filter/inc/xichart.hxx
index 08f7813..595eb17 100644
--- a/sc/source/filter/inc/xichart.hxx
+++ b/sc/source/filter/inc/xichart.hxx
@@ -817,9 +817,9 @@ public:
     virtual void        ReadSubRecord( XclImpStream& rStrm );
 
     /** Sets a data point or series format (CHDATAFORMAT group) for this series. */
-    void                SetDataFormat( XclImpChDataFormatRef xDataFmt );
+    void                SetDataFormat( const XclImpChDataFormatRef& xDataFmt );
     /** Sets a label text (CHTEXT group) attached  to a series or data point. */
-    void                SetDataLabel( XclImpChTextRef xLabel );
+    void                SetDataLabel( const XclImpChTextRef& xLabel );
     /** Adds error bar settings from the passed series to the own series. */
     void                AddChildSeries( const XclImpChSeries& rSeries );
     /** Updates missing series formatting by using default formatting from axes sets. */
@@ -866,10 +866,6 @@ private:
 
     /** Creates a new CHDATAFORMAT group with the specified point index. */
     XclImpChDataFormatRef CreateDataFormat( sal_uInt16 nPointIdx, sal_uInt16 nFormatIdx );
-    /** Returns the pointer to a CHDATAFORMAT group reference or 0 for invalid pointer index. */
-    XclImpChDataFormatRef* GetDataFormatRef( sal_uInt16 nPointIdx );
-    /** Returns the pointer to a CHTEXT group reference or 0 for invalid pointer index. */
-    XclImpChTextRef*    GetDataLabelRef( sal_uInt16 nPointIdx );
 
     /** Converts all trend lines and inserts them into the passed API data series object. */
     void                ConvertTrendLines( XDataSeriesRef xDataSeries ) const;


More information about the Libreoffice-commits mailing list