[Libreoffice-commits] .: 10 commits - sc/inc sc/Library_sc.mk sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Feb 23 21:52:31 PST 2012


 sc/Library_sc.mk                 |    1 
 sc/inc/dpsave.hxx                |   23 ++
 sc/inc/dptabsrc.hxx              |    2 
 sc/inc/dputil.hxx                |   46 +++++
 sc/source/core/data/dpobject.cxx |    7 
 sc/source/core/data/dpoutput.cxx |   12 -
 sc/source/core/data/dpsave.cxx   |  111 +++++++++---
 sc/source/core/data/dptabsrc.cxx |  343 +++++++++++++++++++--------------------
 sc/source/core/data/dputil.cxx   |   59 ++++++
 sc/source/ui/dbgui/pvfundlg.cxx  |    2 
 sc/source/ui/dbgui/pvfundlg.src  |    5 
 sc/source/ui/dbgui/pvlaydlg.cxx  |    8 
 sc/source/ui/inc/pvfundlg.hxx    |    4 
 13 files changed, 397 insertions(+), 226 deletions(-)

New commits:
commit bbb0dcaa4ba4baf0c0489cf868f6002317beefe5
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Fri Feb 24 00:32:13 2012 -0500

    Corrected comment.

diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index 1955be7..e3df3f0 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -359,9 +359,9 @@ void ScDPLayoutDlg::InitWndSelect(const ScDPLabelDataVec& rLabels)
         aLabelDataArr.push_back(new ScDPLabelData(r));
         if (r.mnOriginalDim < 0 && !r.mbDataLayout)
         {
-            // TODO: For dimension with duplicates, use layout name only when
-            // all its duplicate dimensions use the same layout name.
-            // Otherwise use the original name.
+            // For dimension with duplicates, use the layout name of the
+            // original dimension if available.  Be aware that duplicate
+            // dimensions may have different layout names.
             aWndSelect.AddField(aLabelDataArr[i].getDisplayName(), i);
             aSelectArr.push_back(new ScDPFuncData(aLabelDataArr[i].mnCol, aLabelDataArr[i].mnFuncMask));
         }
commit d16537b8d30c29fe30d4c2e68784e21a90663e98
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 23:43:06 2012 -0500

    Now we only allow one function per data field.

diff --git a/sc/source/ui/dbgui/pvfundlg.cxx b/sc/source/ui/dbgui/pvfundlg.cxx
index 663e5a3..ffd23f3 100644
--- a/sc/source/ui/dbgui/pvfundlg.cxx
+++ b/sc/source/ui/dbgui/pvfundlg.cxx
@@ -166,7 +166,7 @@ static const ScDPListBoxWrapper::MapEntryType spShowFromMap[] =
 // ============================================================================
 
 ScDPFunctionListBox::ScDPFunctionListBox( Window* pParent, const ResId& rResId ) :
-    MultiListBox( pParent, rResId )
+    ListBox( pParent, rResId )
 {
     FillFunctionNames();
 }
diff --git a/sc/source/ui/dbgui/pvfundlg.src b/sc/source/ui/dbgui/pvfundlg.src
index d5203f2..a5982ae 100644
--- a/sc/source/ui/dbgui/pvfundlg.src
+++ b/sc/source/ui/dbgui/pvfundlg.src
@@ -62,15 +62,14 @@ ModalDialog RID_SCDLG_DPDATAFIELD
         Size = MAP_APPFONT ( 152 , 8 ) ;
         Text [ en-US ] = "~Function" ;
     };
-    MultiListBox LB_FUNC
+    ListBox LB_FUNC
     {
-        HelpID = "sc:MultiListBox:RID_SCDLG_DPDATAFIELD:LB_FUNC";
+        HelpID = "sc:ListBox:RID_SCDLG_DPDATAFIELD:LB_FUNC";
         Border = TRUE ;
         Pos = MAP_APPFONT ( 12 , 14 ) ;
         Size = MAP_APPFONT ( 140 , 65 ) ;
         TabStop = TRUE ;
         AutoHScroll = TRUE ;
-        SimpleMode = TRUE ;
     };
     FixedText FT_NAMELABEL
     {
diff --git a/sc/source/ui/inc/pvfundlg.hxx b/sc/source/ui/inc/pvfundlg.hxx
index e76329b..8ccbe9c 100644
--- a/sc/source/ui/inc/pvfundlg.hxx
+++ b/sc/source/ui/inc/pvfundlg.hxx
@@ -53,13 +53,13 @@ class ScDPObject;
 
 // ============================================================================
 
-class ScDPFunctionListBox : public MultiListBox
+class ScDPFunctionListBox : public ListBox
 {
 public:
     explicit            ScDPFunctionListBox( Window* pParent, const ResId& rResId );
 
     void                SetSelection( sal_uInt16 nFuncMask );
-    sal_uInt16              GetSelection() const;
+    sal_uInt16          GetSelection() const;
 
 private:
     void                FillFunctionNames();
commit 3c870ad0ce6836546526aba45c07f34bfeacf804
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 23:33:20 2012 -0500

    Use SUM function by default in case nothing is selected.

diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index 0052a44..1955be7 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -478,6 +478,8 @@ void ScDPLayoutDlg::AddField( size_t nFromIndex, ScDPFieldType eToType, const Po
         ScDPLabelData* p = GetLabelData(fData.mnCol);
         OUString aStr = p->maLayoutName;
         sal_uInt16 nMask = fData.mnFuncMask;
+        if (nMask == PIVOT_FUNC_NONE)
+            nMask = PIVOT_FUNC_SUM; // Use SUM by default.
         if (aStr.isEmpty())
         {
             aStr = GetFuncString(nMask);
commit 780436aaf7cb3675bed8277f0b0069b43a25b908
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 20:19:04 2012 -0500

    ???

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index bb988f5..bd28f39 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -1971,7 +1971,7 @@ bool ScDPObject::FillLabelData(ScPivotParam& rParam)
 {
     rParam.maLabelArray.clear();
 
-    ((ScDPObject*)this)->CreateObjects();
+    CreateObjects();
     if (!xSource.is())
         return false;
 
commit 34ff598994a52e8058e34074cb18a993e8c82157
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 20:14:08 2012 -0500

    Use a dedicated method instead of manually removing trailing '*'s.
    
    Also, caption shouldn't have a leading ' any more. We have a dedicated
    flag for that.

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 25f2c60..bb988f5 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -52,6 +52,7 @@
 #include "dpglobal.hxx"
 #include "globstr.hrc"
 #include "queryentry.hxx"
+#include "dputil.hxx"
 
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/sdb/XCompletedExecution.hpp>
@@ -2016,7 +2017,7 @@ bool ScDPObject::FillLabelData(ScPivotParam& rParam)
             xDimProp, OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_FIELD_SUBTOTALNAME)), OUString());
 
         bool bIsValue = true;                               //! check
-        aFieldName = comphelper::string::stripEnd(aFieldName, sal_Unicode('*'));
+        aFieldName = ScDPUtil::getSourceDimensionName(aFieldName);
 
         std::auto_ptr<ScDPLabelData> pNewLabel(
             new ScDPLabelData(aFieldName, static_cast<SCCOL>(nDim), bIsValue));
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index 690d5b6..37f0970 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -54,6 +54,7 @@
 #include "unonames.hxx"
 #include "sc.hrc"
 #include "stringutil.hxx"
+#include "dputil.hxx"
 
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
@@ -1481,7 +1482,7 @@ bool ScDPOutput::GetDataResultPositionData(vector<sheet::DataPilotFieldFilter>&
 //  helper functions for ScDPOutput::GetPivotData
 //
 
-bool lcl_IsNamedDataField( const ScDPGetPivotDataField& rTarget, const String& rSourceName, const String& rGivenName )
+bool lcl_IsNamedDataField( const ScDPGetPivotDataField& rTarget, const rtl::OUString& rSourceName, const rtl::OUString& rGivenName )
 {
     // match one of the names, ignoring case
     return ScGlobal::GetpTransliteration()->isEqual( rTarget.maFieldName, rSourceName ) ||
@@ -1740,13 +1741,10 @@ void lcl_FilterInclude( std::vector< sal_Bool >& rResult, std::vector< sal_Int32
                 {
                     // Asterisks are added in ScDPSaveData::WriteToSource to create unique names.
                     //! preserve original name there?
-                    String aSourceName( aResultEntry.Name );
-                    aSourceName.EraseTrailingChars( '*' );
+                    rtl::OUString aSourceName = ScDPUtil::getSourceDimensionName(aResultEntry.Name);
 
-                    String aGivenName( aResultEntry.Caption );  //! Should use a stored name when available
-                    aGivenName.EraseLeadingChars( '\'' );
-
-                    rResult[j] = lcl_IsNamedDataField( rTarget, aSourceName, aGivenName );
+                    rResult[j] = lcl_IsNamedDataField(
+                        rTarget, aSourceName, aResultEntry.Caption);
                 }
             }
             else if ( bHasFilter )
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 7dbb122..22f17ef 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -58,6 +58,7 @@
 #include "miscuno.hxx"
 #include "unonames.hxx"
 #include "dpitemdata.hxx"
+#include "dputil.hxx"
 
 #include <com/sun/star/beans/PropertyAttribute.hpp>
 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
@@ -824,10 +825,9 @@ void ScDPSource::CreateRes_Impl()
 
         aDataNames[i] = pDim->getName();
 
-        //  asterisk is added to duplicated dimension names by ScDPSaveData::WriteToSource
         //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
 
-        aDataNames[i] = comphelper::string::removeTrailingChars(aDataNames[i], '*');
+        aDataNames[i] = ScDPUtil::getSourceDimensionName(aDataNames[i]);
 
         //! if the name is overridden by user, a flag must be set
         //! so the user defined name replaces the function string and field name.
commit d473a3699befc388d49bdba491a543d88bcf0778
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 18:41:44 2012 -0500

    Modify dup count correctly when dimensions are removed.
    
    Though normally dimensions don't get removed, since the entire save data
    gets re-built whenever the pivot model is modified.  So, this is probably
    for limited use cases...

diff --git a/sc/inc/dputil.hxx b/sc/inc/dputil.hxx
index d33d344..46ffa6b 100644
--- a/sc/inc/dputil.hxx
+++ b/sc/inc/dputil.hxx
@@ -37,6 +37,8 @@ public:
     static bool isDuplicateDimension(const rtl::OUString& rName);
 
     static rtl::OUString getSourceDimensionName(const rtl::OUString& rName);
+
+    static rtl::OUString createDuplicateDimensionName(const rtl::OUString& rOriginal, size_t nDupCount);
 };
 
 #endif
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index ef8cb5e..ec46604 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -1277,12 +1277,7 @@ void ScDPSaveData::CheckDuplicateName(ScDPSaveDimension& rDim)
     DupNameCountType::iterator it = maDupNameCounts.find(aName);
     if (it != maDupNameCounts.end())
     {
-        it->second = it->second + 1;
-        // This is a duplicate name.  Up the counter and append '*' to make the name unique.
-        rtl::OUStringBuffer aBuf(aName);
-        for (size_t i = 0, n = it->second; i < n; ++i)
-            aBuf.append(sal_Unicode('*'));
-        rDim.SetName(aBuf.makeStringAndClear());
+        rDim.SetName(ScDPUtil::createDuplicateDimensionName(aName, ++it->second));
         rDim.SetDupFlag(true);
     }
     else
@@ -1292,6 +1287,22 @@ void ScDPSaveData::CheckDuplicateName(ScDPSaveDimension& rDim)
 
 void ScDPSaveData::RemoveDuplicateNameCount(const rtl::OUString& rName)
 {
+    rtl::OUString aCoreName = rName;
+    if (ScDPUtil::isDuplicateDimension(rName))
+        aCoreName = ScDPUtil::getSourceDimensionName(rName);
+
+    DupNameCountType::iterator it = maDupNameCounts.find(aCoreName);
+    if (it == maDupNameCounts.end())
+        return;
+
+    if (!it->second)
+    {
+        maDupNameCounts.erase(it);
+        return;
+    }
+
+    --it->second;
+    return;
 }
 
 ScDPSaveDimension* ScDPSaveData::AppendNewDimension(const rtl::OUString& rName, bool bDataLayout)
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
index f04a587..65a1ee5 100644
--- a/sc/source/core/data/dputil.cxx
+++ b/sc/source/core/data/dputil.cxx
@@ -44,4 +44,16 @@ rtl::OUString ScDPUtil::getSourceDimensionName(const rtl::OUString& rName)
     return comphelper::string::removeTrailingChars(rName, sal_Unicode('*'));
 }
 
+rtl::OUString ScDPUtil::createDuplicateDimensionName(const rtl::OUString& rOriginal, size_t nDupCount)
+{
+    if (!nDupCount)
+        return rOriginal;
+
+    rtl::OUStringBuffer aBuf(rOriginal);
+    for (size_t i = 0; i < nDupCount; ++i)
+        aBuf.append(sal_Unicode('*'));
+
+    return aBuf.makeStringAndClear();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 513edaa41ddb4dfdf6e3ec1efd44f56ff959ef26
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 15:52:15 2012 -0500

    Properly tally original/duplicate dimension name counts.
    
    Else the duplicated data fields would disappear after clicking OK in
    the layout dialog.

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 656aa82..a643b7a 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -116,6 +116,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/core/data/dptablecache \
 	sc/source/core/data/dptabres \
 	sc/source/core/data/dptabsrc \
+	sc/source/core/data/dputil \
 	sc/source/core/data/drawpage \
 	sc/source/core/data/drwlayer \
 	sc/source/core/data/fillinfo \
diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx
index 3107da8..a699d61 100644
--- a/sc/inc/dpsave.hxx
+++ b/sc/inc/dpsave.hxx
@@ -357,6 +357,19 @@ public:
 private:
     void CheckDuplicateName(ScDPSaveDimension& rDim);
     void RemoveDuplicateNameCount(const rtl::OUString& rName);
+
+    /**
+     * Append a new original dimension. Not to be called to insert a duplicate
+     * dimension.
+     *
+     * @param rName Dimension name. The name must be the original dimension
+     *              name; not a duplicate dimension name.
+     * @param bDataLayout true if this is a data layout dimension, false
+     *                    otherwise.
+     *
+     * @return pointer to the new dimension just inserted.
+     */
+    ScDPSaveDimension* AppendNewDimension(const rtl::OUString& rName, bool bDataLayout);
 };
 
 #endif
diff --git a/sc/inc/dputil.hxx b/sc/inc/dputil.hxx
new file mode 100644
index 0000000..d33d344
--- /dev/null
+++ b/sc/inc/dputil.hxx
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ *   Copyright (C) 2012 Kohei Yoshida <kohei.yoshida at suse.com>
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef __SC_DPUTIL_HXX__
+#define __SC_DPUTIL_HXX__
+
+#include "rtl/ustring.hxx"
+
+class ScDPUtil
+{
+public:
+    static bool isDuplicateDimension(const rtl::OUString& rName);
+
+    static rtl::OUString getSourceDimensionName(const rtl::OUString& rName);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 5d4e8bc..25f2c60 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2124,7 +2124,7 @@ bool ScDPObject::GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, uno::Reference<
 
 namespace {
 
-String lcl_GetDimName( const uno::Reference<sheet::XDimensionsSupplier>& xSource, long nDim )
+rtl::OUString lcl_GetDimName( const uno::Reference<sheet::XDimensionsSupplier>& xSource, long nDim )
 {
     rtl::OUString aName;
     if ( xSource.is() )
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index 00ff289..ef8cb5e 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -35,6 +35,8 @@
 #include "scerrors.hxx"
 #include "unonames.hxx"
 #include "global.hxx"
+#include "dptabsrc.hxx"
+#include "dputil.hxx"
 
 #include <sal/types.h>
 #include "comphelper/string.hxx"
@@ -52,7 +54,6 @@
 #include <com/sun/star/sheet/XMembersSupplier.hpp>
 #include <com/sun/star/container/XNamed.hpp>
 #include <com/sun/star/util/XCloneable.hpp>
-#include "dptabsrc.hxx"
 
 #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
@@ -864,9 +865,7 @@ ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const ::rtl::OUString& rName
             return const_cast<ScDPSaveDimension*>(&(*iter));
     }
 
-    ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, false );
-    aDimList.push_back(pNew);
-    return pNew;
+    return AppendNewDimension(rName, false);
 }
 
 ScDPSaveDimension* ScDPSaveData::GetExistingDimensionByName(const ::rtl::OUString& rName) const
@@ -889,9 +888,7 @@ ScDPSaveDimension* ScDPSaveData::GetNewDimensionByName(const ::rtl::OUString& rN
             return DuplicateDimension(rName);
     }
 
-    ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, false );
-    aDimList.push_back(pNew);
-    return pNew;
+    return AppendNewDimension(rName, false);
 }
 
 ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension()
@@ -900,9 +897,7 @@ ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension()
     if (pDim)
         return pDim;
 
-    ScDPSaveDimension* pNew = new ScDPSaveDimension( ::rtl::OUString(), true );
-    aDimList.push_back(pNew);
-    return pNew;
+    return AppendNewDimension(rtl::OUString(), true);
 }
 
 ScDPSaveDimension* ScDPSaveData::GetExistingDataLayoutDimension() const
@@ -1124,7 +1119,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
         for (long i = 0; iter != aDimList.end(); ++iter, ++i)
         {
             rtl::OUString aName = iter->GetName();
-            rtl::OUString aCoreName = comphelper::string::removeTrailingChars(aName, sal_Unicode('*'));
+            rtl::OUString aCoreName = ScDPUtil::getSourceDimensionName(aName);
 
             OSL_TRACE( "%s", aName.getStr() );
 
@@ -1278,13 +1273,13 @@ bool ScDPSaveData::HasInvisibleMember(const OUString& rDimName) const
 
 void ScDPSaveData::CheckDuplicateName(ScDPSaveDimension& rDim)
 {
-    const rtl::OUString aName = comphelper::string::removeTrailingChars(rDim.GetName(), sal_Unicode('*'));
+    const rtl::OUString aName = ScDPUtil::getSourceDimensionName(rDim.GetName());
     DupNameCountType::iterator it = maDupNameCounts.find(aName);
     if (it != maDupNameCounts.end())
     {
+        it->second = it->second + 1;
         // This is a duplicate name.  Up the counter and append '*' to make the name unique.
         rtl::OUStringBuffer aBuf(aName);
-        it->second = it->second + 1;
         for (size_t i = 0, n = it->second; i < n; ++i)
             aBuf.append(sal_Unicode('*'));
         rDim.SetName(aBuf.makeStringAndClear());
@@ -1299,6 +1294,20 @@ void ScDPSaveData::RemoveDuplicateNameCount(const rtl::OUString& rName)
 {
 }
 
+ScDPSaveDimension* ScDPSaveData::AppendNewDimension(const rtl::OUString& rName, bool bDataLayout)
+{
+    if (ScDPUtil::isDuplicateDimension(rName))
+        // This call is for original dimensions only.
+        return NULL;
+
+    ScDPSaveDimension* pNew = new ScDPSaveDimension(rName, bDataLayout);
+    aDimList.push_back(pNew);
+    if (!maDupNameCounts.count(rName))
+        maDupNameCounts.insert(DupNameCountType::value_type(rName, 0));
+
+    return pNew;
+}
+
 void ScDPSaveDimension::Refresh( const com::sun::star::uno::Reference<
                                 com::sun::star::sheet::XDimensionsSupplier>& xSource ,
                                 const std::list<rtl::OUString>& deletedDims)
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
new file mode 100644
index 0000000..f04a587
--- /dev/null
+++ b/sc/source/core/data/dputil.cxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ *   Copyright (C) 2012 Kohei Yoshida <kohei.yoshida at suse.com>
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "dputil.hxx"
+
+#include "comphelper/string.hxx"
+
+bool ScDPUtil::isDuplicateDimension(const rtl::OUString& rName)
+{
+    if (rName.isEmpty())
+        return false;
+
+    sal_Unicode cLast = rName[rName.getLength()-1];
+    return cLast == sal_Unicode('*');
+}
+
+rtl::OUString ScDPUtil::getSourceDimensionName(const rtl::OUString& rName)
+{
+    return comphelper::string::removeTrailingChars(rName, sal_Unicode('*'));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 57875110e3365988bb01cfef42d8094cb076002d
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 15:02:28 2012 -0500

    Ensure that the save dimension and regular dimension have identical name.
    
    This was not the case previously, for duplicated dimensions.  Without this,
    setting layout names (aka custom names) to data fields would not work
    properly especially when the data fields are duplicated.

diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx
index 65d0498..3107da8 100644
--- a/sc/inc/dpsave.hxx
+++ b/sc/inc/dpsave.hxx
@@ -237,10 +237,13 @@ public:
 
 class ScDPSaveData
 {
+    typedef boost::unordered_map<rtl::OUString, size_t, rtl::OUStringHash> DupNameCountType;
 public:
     typedef boost::ptr_vector<ScDPSaveDimension> DimsType;
+
 private:
     DimsType aDimList;
+    DupNameCountType maDupNameCounts; /// keep track of number of duplicates in each name.
     ScDPDimensionSaveData* pDimensionData; // settings that create new dimensions
     sal_uInt16 nColumnGrandMode;
     sal_uInt16 nRowGrandMode;
@@ -281,8 +284,7 @@ public:
         com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
         std::vector<const ScDPSaveDimension*>& rDims) const;
 
-    void AddDimension(ScDPSaveDimension* pDim)
-        { aDimList.push_back(pDim); }
+    void AddDimension(ScDPSaveDimension* pDim);
 
     /**
      * Get a dimension object by its name.  <i>If one doesn't exist for the
@@ -351,6 +353,10 @@ public:
      * @param rDimName dimension name
      */
     SC_DLLPUBLIC bool HasInvisibleMember(const ::rtl::OUString& rDimName) const;
+
+private:
+    void CheckDuplicateName(ScDPSaveDimension& rDim);
+    void RemoveDuplicateNameCount(const rtl::OUString& rName);
 };
 
 #endif
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index a16732c..00ff289 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -37,6 +37,7 @@
 #include "global.hxx"
 
 #include <sal/types.h>
+#include "comphelper/string.hxx"
 
 #include <com/sun/star/sheet/GeneralFunction.hpp>
 #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
@@ -845,6 +846,15 @@ void ScDPSaveData::GetAllDimensionsByOrientation(
     rDims.swap(aDims);
 }
 
+void ScDPSaveData::AddDimension(ScDPSaveDimension* pDim)
+{
+    if (!pDim)
+        return;
+
+    CheckDuplicateName(*pDim);
+    aDimList.push_back(pDim);
+}
+
 ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const ::rtl::OUString& rName)
 {
     boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
@@ -915,7 +925,7 @@ ScDPSaveDimension* ScDPSaveData::DuplicateDimension(const ::rtl::OUString& rName
         return NULL;
 
     ScDPSaveDimension* pNew = new ScDPSaveDimension( *pOld );
-    pNew->SetDupFlag( true );
+    CheckDuplicateName(*pNew);
     aDimList.push_back(pNew);
     return pNew;
 }
@@ -925,18 +935,19 @@ void ScDPSaveData::RemoveDimensionByName(const ::rtl::OUString& rName)
     boost::ptr_vector<ScDPSaveDimension>::iterator iter;
     for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
     {
-        if ( iter->GetName() == rName && !iter->IsDataLayout() )
-        {
-            aDimList.erase(iter);
-            break;
-        }
+        if (iter->GetName() != rName || iter->IsDataLayout())
+            continue;
+
+        aDimList.erase(iter);
+        RemoveDuplicateNameCount(rName);
+        return;
     }
 }
 
 ScDPSaveDimension& ScDPSaveData::DuplicateDimension( const ScDPSaveDimension& rDim )
 {
     ScDPSaveDimension* pNew = new ScDPSaveDimension( rDim );
-    pNew->SetDupFlag( true );
+    CheckDuplicateName(*pNew);
     aDimList.push_back(pNew);
     return *pNew;
 }
@@ -1113,6 +1124,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
         for (long i = 0; iter != aDimList.end(); ++iter, ++i)
         {
             rtl::OUString aName = iter->GetName();
+            rtl::OUString aCoreName = comphelper::string::removeTrailingChars(aName, sal_Unicode('*'));
 
             OSL_TRACE( "%s", aName.getStr() );
 
@@ -1137,30 +1149,24 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
                 else
                 {
                     uno::Reference<container::XNamed> xDimName( xIntDim, uno::UNO_QUERY );
-                    if ( xDimName.is() && xDimName->getName() == aName )
+                    if (xDimName.is() && xDimName->getName() == aCoreName)
                         bFound = true;
                 }
 
-                if ( bFound )
+                if (bFound)
                 {
-                    if ( iter->GetDupFlag() )
+                    if (iter->GetDupFlag())
                     {
-                        OUStringBuffer aBuf(iter->GetName());
-
-                        // different name for each duplication of a (real) dimension...
-                        for (long j=0; j<=i; ++j) //! Test !!!!!!
-                            aBuf.append(sal_Unicode('*')); //! modify name at creation of SaveDimension
-
-                        uno::Reference<util::XCloneable> xCloneable( xIntDim, uno::UNO_QUERY );
-                        OSL_ENSURE( xCloneable.is(), "cannot clone dimension" );
+                        uno::Reference<util::XCloneable> xCloneable(xIntDim, uno::UNO_QUERY);
+                        OSL_ENSURE(xCloneable.is(), "cannot clone dimension");
                         if (xCloneable.is())
                         {
                             uno::Reference<util::XCloneable> xNew = xCloneable->createClone();
-                            uno::Reference<container::XNamed> xNewName( xNew, uno::UNO_QUERY );
+                            uno::Reference<container::XNamed> xNewName(xNew, uno::UNO_QUERY);
                             if (xNewName.is())
                             {
-                                xNewName->setName(aBuf.makeStringAndClear());
-                                iter->WriteToSource( xNew );
+                                xNewName->setName(aName);
+                                iter->WriteToSource(xNew);
                             }
                         }
                     }
@@ -1270,6 +1276,29 @@ bool ScDPSaveData::HasInvisibleMember(const OUString& rDimName) const
     return pDim->HasInvisibleMember();
 }
 
+void ScDPSaveData::CheckDuplicateName(ScDPSaveDimension& rDim)
+{
+    const rtl::OUString aName = comphelper::string::removeTrailingChars(rDim.GetName(), sal_Unicode('*'));
+    DupNameCountType::iterator it = maDupNameCounts.find(aName);
+    if (it != maDupNameCounts.end())
+    {
+        // This is a duplicate name.  Up the counter and append '*' to make the name unique.
+        rtl::OUStringBuffer aBuf(aName);
+        it->second = it->second + 1;
+        for (size_t i = 0, n = it->second; i < n; ++i)
+            aBuf.append(sal_Unicode('*'));
+        rDim.SetName(aBuf.makeStringAndClear());
+        rDim.SetDupFlag(true);
+    }
+    else
+        // New name.
+        maDupNameCounts.insert(DupNameCountType::value_type(aName, 0));
+}
+
+void ScDPSaveData::RemoveDuplicateNameCount(const rtl::OUString& rName)
+{
+}
+
 void ScDPSaveDimension::Refresh( const com::sun::star::uno::Reference<
                                 com::sun::star::sheet::XDimensionsSupplier>& xSource ,
                                 const std::list<rtl::OUString>& deletedDims)
commit efae4424c0f9381e6050541784358bfe1095189a
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 01:03:18 2012 -0500

    More scope reduction by early bail-out.

diff --git a/sc/inc/dptabsrc.hxx b/sc/inc/dptabsrc.hxx
index fd704ed..7db245e 100644
--- a/sc/inc/dptabsrc.hxx
+++ b/sc/inc/dptabsrc.hxx
@@ -129,7 +129,7 @@ private:
     com::sun::star::uno::Sequence<com::sun::star::sheet::MemberResult>* pRowResults;
     std::vector<ScDPLevel*> aColLevelList;
     std::vector<ScDPLevel*> aRowLevelList;
-    sal_Bool                    bResultOverflow;
+    bool                    bResultOverflow;
     bool                    bPageFiltered;      // set if page field filters have been applied to cache table
 
     SAL_WNODEPRECATED_DECLARATIONS_PUSH
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 0515eec..7dbb122 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -910,61 +910,58 @@ void ScDPSource::CreateRes_Impl()
         //  (this relies on late init, so no members are allocated in InitFrom above)
 
         bResultOverflow = true;
+        return;
     }
-    else
-    {
-        FilterCacheTableByPageDimensions();
 
-        aInfo.aPageDims.reserve(nPageDimCount);
-        for (i = 0; i < nPageDimCount; ++i)
-            aInfo.aPageDims.push_back(nPageDims[i]);
+    FilterCacheTableByPageDimensions();
 
-        aInfo.pInitState = &aInitState;
-        aInfo.pColRoot   = pColResRoot;
-        aInfo.pRowRoot   = pRowResRoot;
-        pData->CalcResults(aInfo, false);
+    aInfo.aPageDims.reserve(nPageDimCount);
+    for (i = 0; i < nPageDimCount; ++i)
+        aInfo.aPageDims.push_back(nPageDims[i]);
 
-        pColResRoot->CheckShowEmpty();
-        pRowResRoot->CheckShowEmpty();
-        // ----------------------------------------------------------------
-        //  With all data processed, calculate the final results:
+    aInfo.pInitState = &aInitState;
+    aInfo.pColRoot   = pColResRoot;
+    aInfo.pRowRoot   = pRowResRoot;
+    pData->CalcResults(aInfo, false);
 
-        //  UpdateDataResults calculates all original results from the collected values,
-        //  and stores them as reference values if needed.
-        pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
-
-        if ( bHasAutoShow )     // do the double calculation only if AutoShow is used
-        {
-            //  Find the desired members and set bAutoHidden flag for the others
-            pRowResRoot->DoAutoShow( pColResRoot );
+    pColResRoot->CheckShowEmpty();
+    pRowResRoot->CheckShowEmpty();
+    // ----------------------------------------------------------------
+    //  With all data processed, calculate the final results:
 
-            //  Reset all results to empty, so they can be built again with data for the
-            //  desired members only.
-            pColResRoot->ResetResults( sal_True );
-            pRowResRoot->ResetResults( sal_True );
-            pData->CalcResults(aInfo, true);
+    //  UpdateDataResults calculates all original results from the collected values,
+    //  and stores them as reference values if needed.
+    pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
 
-            //  Call UpdateDataResults again, with the new (limited) values.
-            pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
-        }
-
-        //  SortMembers does the sorting by a result dimension, using the orginal results,
-        //  but not running totals etc.
-        pRowResRoot->SortMembers( pColResRoot );
+    if ( bHasAutoShow )     // do the double calculation only if AutoShow is used
+    {
+        //  Find the desired members and set bAutoHidden flag for the others
+        pRowResRoot->DoAutoShow( pColResRoot );
 
-        //  UpdateRunningTotals calculates running totals along column/row dimensions,
-        //  differences from other members (named or relative), and column/row percentages
-        //  or index values.
-        //  Running totals and relative differences need to be done using the sorted values.
-        //  Column/row percentages and index values must be done after sorting, because the
-        //  results may no longer be in the right order (row total for percentage of row is
-        //  always 1).
-        ScDPRunningTotalState aRunning( pColResRoot, pRowResRoot );
-        ScDPRowTotals aTotals;
-        pRowResRoot->UpdateRunningTotals( pColResRoot, pResData->GetRowStartMeasure(), aRunning, aTotals );
+        //  Reset all results to empty, so they can be built again with data for the
+        //  desired members only.
+        pColResRoot->ResetResults( sal_True );
+        pRowResRoot->ResetResults( sal_True );
+        pData->CalcResults(aInfo, true);
 
-        // ----------------------------------------------------------------
+        //  Call UpdateDataResults again, with the new (limited) values.
+        pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
     }
+
+    //  SortMembers does the sorting by a result dimension, using the orginal results,
+    //  but not running totals etc.
+    pRowResRoot->SortMembers( pColResRoot );
+
+    //  UpdateRunningTotals calculates running totals along column/row dimensions,
+    //  differences from other members (named or relative), and column/row percentages
+    //  or index values.
+    //  Running totals and relative differences need to be done using the sorted values.
+    //  Column/row percentages and index values must be done after sorting, because the
+    //  results may no longer be in the right order (row total for percentage of row is
+    //  always 1).
+    ScDPRunningTotalState aRunning( pColResRoot, pRowResRoot );
+    ScDPRowTotals aTotals;
+    pRowResRoot->UpdateRunningTotals( pColResRoot, pResData->GetRowStartMeasure(), aRunning, aTotals );
 }
 
 
commit 346332125f2caf5551c0ac575efdcc70a0262442
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Thu Feb 23 00:58:16 2012 -0500

    Scope reduction.

diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 5ee5325..0515eec 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -750,220 +750,220 @@ void ScDPSource::FilterCacheTableByPageDimensions()
 
 void ScDPSource::CreateRes_Impl()
 {
-    if ( !pResData )
+    if (pResData)
+        return;
+
+    sal_uInt16 nDataOrient = GetDataLayoutOrientation();
+    if ( nDataDimCount > 1 && ( nDataOrient != sheet::DataPilotFieldOrientation_COLUMN &&
+                                nDataOrient != sheet::DataPilotFieldOrientation_ROW ) )
     {
-        sal_uInt16 nDataOrient = GetDataLayoutOrientation();
-        if ( nDataDimCount > 1 && ( nDataOrient != sheet::DataPilotFieldOrientation_COLUMN &&
-                                    nDataOrient != sheet::DataPilotFieldOrientation_ROW ) )
-        {
-            //  if more than one data dimension, data layout orientation must be set
-            SetOrientation( pData->GetColumnCount(), sheet::DataPilotFieldOrientation_ROW );
-            nDataOrient = sheet::DataPilotFieldOrientation_ROW;
-        }
+        //  if more than one data dimension, data layout orientation must be set
+        SetOrientation( pData->GetColumnCount(), sheet::DataPilotFieldOrientation_ROW );
+        nDataOrient = sheet::DataPilotFieldOrientation_ROW;
+    }
 
-        // TODO: Aggreate pDataNames, pDataRefValues, nDataRefOrient, and
-        // eDataFunctions into a structure and use vector instead of static
-        // or pointer arrays.
-        vector<rtl::OUString> aDataNames;
-        sheet::DataPilotFieldReference* pDataRefValues = NULL;
-        ScSubTotalFunc eDataFunctions[SC_DP_MAX_FIELDS];
-        sal_uInt16 nDataRefOrient[SC_DP_MAX_FIELDS];
-        if (nDataDimCount)
-        {
-            aDataNames.resize(nDataDimCount);
-            pDataRefValues = new sheet::DataPilotFieldReference[nDataDimCount];
-        }
+    // TODO: Aggreate pDataNames, pDataRefValues, nDataRefOrient, and
+    // eDataFunctions into a structure and use vector instead of static
+    // or pointer arrays.
+    vector<rtl::OUString> aDataNames;
+    sheet::DataPilotFieldReference* pDataRefValues = NULL;
+    ScSubTotalFunc eDataFunctions[SC_DP_MAX_FIELDS];
+    sal_uInt16 nDataRefOrient[SC_DP_MAX_FIELDS];
+    if (nDataDimCount)
+    {
+        aDataNames.resize(nDataDimCount);
+        pDataRefValues = new sheet::DataPilotFieldReference[nDataDimCount];
+    }
 
-        ScDPTableData::CalcInfo aInfo;
+    ScDPTableData::CalcInfo aInfo;
 
 
-        //  LateInit (initialize only those rows/children that are used) can be used unless
-        //  any data dimension needs reference values from column/row dimensions
-        sal_Bool bLateInit = sal_True;
+    //  LateInit (initialize only those rows/children that are used) can be used unless
+    //  any data dimension needs reference values from column/row dimensions
+    bool bLateInit = true;
 
-        // Go through all data dimensions (i.e. fields) and build their meta data
-        // so that they can be passed on to ScDPResultData instance later.
-        // TODO: aggregate all of data dimension info into a structure.
-        long i;
-        for (i=0; i<nDataDimCount; i++)
+    // Go through all data dimensions (i.e. fields) and build their meta data
+    // so that they can be passed on to ScDPResultData instance later.
+    // TODO: aggregate all of data dimension info into a structure.
+    long i;
+    for (i=0; i<nDataDimCount; i++)
+    {
+        // Get function for each data field.
+        long nDimIndex = nDataDims[i];
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nDimIndex);
+        sheet::GeneralFunction eUser = (sheet::GeneralFunction)pDim->getFunction();
+        if (eUser == sheet::GeneralFunction_AUTO)
         {
-            // Get function for each data field.
-            long nDimIndex = nDataDims[i];
-            ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nDimIndex);
-            sheet::GeneralFunction eUser = (sheet::GeneralFunction)pDim->getFunction();
-            if (eUser == sheet::GeneralFunction_AUTO)
-            {
-                //! test for numeric data
-                eUser = sheet::GeneralFunction_SUM;
-            }
+            //! test for numeric data
+            eUser = sheet::GeneralFunction_SUM;
+        }
 
-            // Map UNO's enum to internal enum ScSubTotalFunc.
-            eDataFunctions[i] = ScDataUnoConversion::GeneralToSubTotal( eUser );
-
-            // Get reference field/item information.
-            pDataRefValues[i] = pDim->GetReferenceValue();
-            nDataRefOrient[i] = sheet::DataPilotFieldOrientation_HIDDEN;    // default if not used
-            sal_Int32 eRefType = pDataRefValues[i].ReferenceType;
-            if ( eRefType == sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE ||
-                 eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE ||
-                 eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE ||
-                 eRefType == sheet::DataPilotFieldReferenceType::RUNNING_TOTAL )
+        // Map UNO's enum to internal enum ScSubTotalFunc.
+        eDataFunctions[i] = ScDataUnoConversion::GeneralToSubTotal( eUser );
+
+        // Get reference field/item information.
+        pDataRefValues[i] = pDim->GetReferenceValue();
+        nDataRefOrient[i] = sheet::DataPilotFieldOrientation_HIDDEN;    // default if not used
+        sal_Int32 eRefType = pDataRefValues[i].ReferenceType;
+        if ( eRefType == sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE ||
+             eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE ||
+             eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE ||
+             eRefType == sheet::DataPilotFieldReferenceType::RUNNING_TOTAL )
+        {
+            long nColumn = lcl_GetIndexFromName( pDataRefValues[i].ReferenceField,
+                                    GetDimensionsObject()->getElementNames() );
+            if ( nColumn >= 0 )
             {
-                long nColumn = lcl_GetIndexFromName( pDataRefValues[i].ReferenceField,
-                                        GetDimensionsObject()->getElementNames() );
-                if ( nColumn >= 0 )
-                {
-                    nDataRefOrient[i] = GetOrientation( nColumn );
-                    //  need fully initialized results to find reference values
-                    //  (both in column or row dimensions), so updated values or
-                    //  differences to 0 can be displayed even for empty results.
-                    bLateInit = false;
-                }
+                nDataRefOrient[i] = GetOrientation( nColumn );
+                //  need fully initialized results to find reference values
+                //  (both in column or row dimensions), so updated values or
+                //  differences to 0 can be displayed even for empty results.
+                bLateInit = false;
             }
+        }
 
-            aDataNames[i] = pDim->getName();
+        aDataNames[i] = pDim->getName();
 
-            //  asterisk is added to duplicated dimension names by ScDPSaveData::WriteToSource
-            //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
+        //  asterisk is added to duplicated dimension names by ScDPSaveData::WriteToSource
+        //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
 
-            aDataNames[i] = comphelper::string::removeTrailingChars(aDataNames[i], '*');
+        aDataNames[i] = comphelper::string::removeTrailingChars(aDataNames[i], '*');
 
-            //! if the name is overridden by user, a flag must be set
-            //! so the user defined name replaces the function string and field name.
+        //! if the name is overridden by user, a flag must be set
+        //! so the user defined name replaces the function string and field name.
 
-            //! the complete name (function and field) must be stored at the dimension
+        //! the complete name (function and field) must be stored at the dimension
 
-            long nSource = ((ScDPDimension*)pDim)->GetSourceDim();
-            if (nSource >= 0)
-                aInfo.aDataSrcCols.push_back(nSource);
-            else
-                aInfo.aDataSrcCols.push_back(nDimIndex);
-        }
+        long nSource = ((ScDPDimension*)pDim)->GetSourceDim();
+        if (nSource >= 0)
+            aInfo.aDataSrcCols.push_back(nSource);
+        else
+            aInfo.aDataSrcCols.push_back(nDimIndex);
+    }
 
-        pResData = new ScDPResultData( this );
-        pResData->SetMeasureData( nDataDimCount, eDataFunctions, pDataRefValues, nDataRefOrient, aDataNames );
-        pResData->SetDataLayoutOrientation(nDataOrient);
-        pResData->SetLateInit( bLateInit );
+    pResData = new ScDPResultData( this );
+    pResData->SetMeasureData( nDataDimCount, eDataFunctions, pDataRefValues, nDataRefOrient, aDataNames );
+    pResData->SetDataLayoutOrientation(nDataOrient);
+    pResData->SetLateInit( bLateInit );
 
-        delete[] pDataRefValues;
+    delete[] pDataRefValues;
 
-        bool bHasAutoShow = false;
+    bool bHasAutoShow = false;
 
-        ScDPInitState aInitState;
+    ScDPInitState aInitState;
 
-        // Page field selections restrict the members shown in related fields
-        // (both in column and row fields). aInitState is filled with the page
-        // field selections, they are kept across the data iterator loop.
+    // Page field selections restrict the members shown in related fields
+    // (both in column and row fields). aInitState is filled with the page
+    // field selections, they are kept across the data iterator loop.
 
-        for (i=0; i<nPageDimCount; i++)
-        {
-            ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] );
-            if ( pDim->HasSelectedPage() )
-                aInitState.AddMember( nPageDims[i], GetMemberId( nPageDims[i],  pDim->GetSelectedData() ) );
-        }
+    for (i=0; i<nPageDimCount; i++)
+    {
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] );
+        if ( pDim->HasSelectedPage() )
+            aInitState.AddMember( nPageDims[i], GetMemberId( nPageDims[i],  pDim->GetSelectedData() ) );
+    }
 
-        pColResRoot = new ScDPResultMember( pResData, bColumnGrand );
-        pRowResRoot = new ScDPResultMember( pResData, bRowGrand );
+    pColResRoot = new ScDPResultMember( pResData, bColumnGrand );
+    pRowResRoot = new ScDPResultMember( pResData, bRowGrand );
 
-        FillCalcInfo(false, aInfo, bHasAutoShow);
-        long nColLevelCount = aInfo.aColLevels.size();
+    FillCalcInfo(false, aInfo, bHasAutoShow);
+    long nColLevelCount = aInfo.aColLevels.size();
 
-        pColResRoot->InitFrom( aInfo.aColDims, aInfo.aColLevels, 0, aInitState );
-        pColResRoot->SetHasElements();
+    pColResRoot->InitFrom( aInfo.aColDims, aInfo.aColLevels, 0, aInitState );
+    pColResRoot->SetHasElements();
 
-        FillCalcInfo(true, aInfo, bHasAutoShow);
-        long nRowLevelCount = aInfo.aRowLevels.size();
+    FillCalcInfo(true, aInfo, bHasAutoShow);
+    long nRowLevelCount = aInfo.aRowLevels.size();
 
-        if ( nRowLevelCount > 0 )
-        {
-            // disable layout flags for the innermost row field (level)
-            aInfo.aRowLevels[nRowLevelCount-1]->SetEnableLayout( false );
-        }
+    if ( nRowLevelCount > 0 )
+    {
+        // disable layout flags for the innermost row field (level)
+        aInfo.aRowLevels[nRowLevelCount-1]->SetEnableLayout( false );
+    }
 
-        pRowResRoot->InitFrom( aInfo.aRowDims, aInfo.aRowLevels, 0, aInitState );
-        pRowResRoot->SetHasElements();
+    pRowResRoot->InitFrom( aInfo.aRowDims, aInfo.aRowLevels, 0, aInitState );
+    pRowResRoot->SetHasElements();
 
-        // initialize members object also for all page dimensions (needed for numeric groups)
-        for (i=0; i<nPageDimCount; i++)
-        {
-            ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] );
-            long nHierarchy = pDim->getUsedHierarchy();
-            if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() )
-                nHierarchy = 0;
-
-            ScDPLevels* pLevels = pDim->GetHierarchiesObject()->getByIndex(nHierarchy)->GetLevelsObject();
-            long nCount = pLevels->getCount();
-            for (long j=0; j<nCount; j++)
-                pLevels->getByIndex(j)->GetMembersObject();             // initialize for groups
-        }
+    // initialize members object also for all page dimensions (needed for numeric groups)
+    for (i=0; i<nPageDimCount; i++)
+    {
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] );
+        long nHierarchy = pDim->getUsedHierarchy();
+        if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() )
+            nHierarchy = 0;
 
-        //  pre-check: calculate minimum number of result columns / rows from
-        //  levels that have the "show all" flag set
+        ScDPLevels* pLevels = pDim->GetHierarchiesObject()->getByIndex(nHierarchy)->GetLevelsObject();
+        long nCount = pLevels->getCount();
+        for (long j=0; j<nCount; j++)
+            pLevels->getByIndex(j)->GetMembersObject();             // initialize for groups
+    }
 
-        long nMinColMembers = lcl_CountMinMembers( aInfo.aColDims, aInfo.aColLevels, nColLevelCount );
-        long nMinRowMembers = lcl_CountMinMembers( aInfo.aRowDims, aInfo.aRowLevels, nRowLevelCount );
+    //  pre-check: calculate minimum number of result columns / rows from
+    //  levels that have the "show all" flag set
 
-        if ( nMinColMembers > MAXCOLCOUNT/*SC_MINCOUNT_LIMIT*/ || nMinRowMembers > SC_MINCOUNT_LIMIT )
-        {
-            //  resulting table is too big -> abort before calculating
-            //  (this relies on late init, so no members are allocated in InitFrom above)
+    long nMinColMembers = lcl_CountMinMembers( aInfo.aColDims, aInfo.aColLevels, nColLevelCount );
+    long nMinRowMembers = lcl_CountMinMembers( aInfo.aRowDims, aInfo.aRowLevels, nRowLevelCount );
 
-            bResultOverflow = sal_True;
-        }
-        else
-        {
-            FilterCacheTableByPageDimensions();
+    if ( nMinColMembers > MAXCOLCOUNT/*SC_MINCOUNT_LIMIT*/ || nMinRowMembers > SC_MINCOUNT_LIMIT )
+    {
+        //  resulting table is too big -> abort before calculating
+        //  (this relies on late init, so no members are allocated in InitFrom above)
 
-            aInfo.aPageDims.reserve(nPageDimCount);
-            for (i = 0; i < nPageDimCount; ++i)
-                aInfo.aPageDims.push_back(nPageDims[i]);
+        bResultOverflow = true;
+    }
+    else
+    {
+        FilterCacheTableByPageDimensions();
 
-            aInfo.pInitState = &aInitState;
-            aInfo.pColRoot   = pColResRoot;
-            aInfo.pRowRoot   = pRowResRoot;
-            pData->CalcResults(aInfo, false);
+        aInfo.aPageDims.reserve(nPageDimCount);
+        for (i = 0; i < nPageDimCount; ++i)
+            aInfo.aPageDims.push_back(nPageDims[i]);
 
-            pColResRoot->CheckShowEmpty();
-            pRowResRoot->CheckShowEmpty();
-            // ----------------------------------------------------------------
-            //  With all data processed, calculate the final results:
+        aInfo.pInitState = &aInitState;
+        aInfo.pColRoot   = pColResRoot;
+        aInfo.pRowRoot   = pRowResRoot;
+        pData->CalcResults(aInfo, false);
 
-            //  UpdateDataResults calculates all original results from the collected values,
-            //  and stores them as reference values if needed.
-            pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
+        pColResRoot->CheckShowEmpty();
+        pRowResRoot->CheckShowEmpty();
+        // ----------------------------------------------------------------
+        //  With all data processed, calculate the final results:
 
-            if ( bHasAutoShow )     // do the double calculation only if AutoShow is used
-            {
-                //  Find the desired members and set bAutoHidden flag for the others
-                pRowResRoot->DoAutoShow( pColResRoot );
+        //  UpdateDataResults calculates all original results from the collected values,
+        //  and stores them as reference values if needed.
+        pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
 
-                //  Reset all results to empty, so they can be built again with data for the
-                //  desired members only.
-                pColResRoot->ResetResults( sal_True );
-                pRowResRoot->ResetResults( sal_True );
-                pData->CalcResults(aInfo, true);
+        if ( bHasAutoShow )     // do the double calculation only if AutoShow is used
+        {
+            //  Find the desired members and set bAutoHidden flag for the others
+            pRowResRoot->DoAutoShow( pColResRoot );
 
-                //  Call UpdateDataResults again, with the new (limited) values.
-                pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
-            }
+            //  Reset all results to empty, so they can be built again with data for the
+            //  desired members only.
+            pColResRoot->ResetResults( sal_True );
+            pRowResRoot->ResetResults( sal_True );
+            pData->CalcResults(aInfo, true);
 
-            //  SortMembers does the sorting by a result dimension, using the orginal results,
-            //  but not running totals etc.
-            pRowResRoot->SortMembers( pColResRoot );
-
-            //  UpdateRunningTotals calculates running totals along column/row dimensions,
-            //  differences from other members (named or relative), and column/row percentages
-            //  or index values.
-            //  Running totals and relative differences need to be done using the sorted values.
-            //  Column/row percentages and index values must be done after sorting, because the
-            //  results may no longer be in the right order (row total for percentage of row is
-            //  always 1).
-            ScDPRunningTotalState aRunning( pColResRoot, pRowResRoot );
-            ScDPRowTotals aTotals;
-            pRowResRoot->UpdateRunningTotals( pColResRoot, pResData->GetRowStartMeasure(), aRunning, aTotals );
-
-            // ----------------------------------------------------------------
+            //  Call UpdateDataResults again, with the new (limited) values.
+            pRowResRoot->UpdateDataResults( pColResRoot, pResData->GetRowStartMeasure() );
         }
+
+        //  SortMembers does the sorting by a result dimension, using the orginal results,
+        //  but not running totals etc.
+        pRowResRoot->SortMembers( pColResRoot );
+
+        //  UpdateRunningTotals calculates running totals along column/row dimensions,
+        //  differences from other members (named or relative), and column/row percentages
+        //  or index values.
+        //  Running totals and relative differences need to be done using the sorted values.
+        //  Column/row percentages and index values must be done after sorting, because the
+        //  results may no longer be in the right order (row total for percentage of row is
+        //  always 1).
+        ScDPRunningTotalState aRunning( pColResRoot, pRowResRoot );
+        ScDPRowTotals aTotals;
+        pRowResRoot->UpdateRunningTotals( pColResRoot, pResData->GetRowStartMeasure(), aRunning, aTotals );
+
+        // ----------------------------------------------------------------
     }
 }
 


More information about the Libreoffice-commits mailing list