[Libreoffice-commits] .: 23 commits - sc/inc sc/qa sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Jan 21 21:16:11 PST 2011


 sc/inc/dpshttab.hxx                         |   64 +++++-
 sc/qa/unit/ucalc.cxx                        |   11 -
 sc/source/core/data/dpobject.cxx            |   77 ++++---
 sc/source/core/data/dpshttab.cxx            |  171 +++++++++++-----
 sc/source/filter/excel/read.cxx             |    1 
 sc/source/filter/excel/xepivot.cxx          |   23 +-
 sc/source/filter/excel/xipivot.cxx          |   67 +++++-
 sc/source/filter/inc/xepivot.hxx            |    3 
 sc/source/filter/inc/xipivot.hxx            |   10 
 sc/source/filter/xml/XMLExportDataPilot.cxx |  291 ++++++++++++++--------------
 sc/source/filter/xml/xmldpimp.cxx           |  157 +++++++--------
 sc/source/filter/xml/xmldpimp.hxx           |    2 
 sc/source/filter/xml/xmlimprt.cxx           |    3 
 sc/source/filter/xml/xmlimprt.hxx           |    3 
 sc/source/ui/dbgui/pvlaydlg.cxx             |  134 +++++++++++-
 sc/source/ui/docshell/dbdocfun.cxx          |   45 ++++
 sc/source/ui/docshell/docsh5.cxx            |    2 
 sc/source/ui/inc/pvlaydlg.hxx               |    7 
 sc/source/ui/unoobj/dapiuno.cxx             |   11 -
 sc/source/ui/unoobj/datauno.cxx             |    6 
 sc/source/ui/view/cellsh2.cxx               |    4 
 sc/source/ui/view/gridwin2.cxx              |    8 
 sc/source/ui/view/pivotsh.cxx               |    8 
 23 files changed, 735 insertions(+), 373 deletions(-)

New commits:
commit 34cc4a426661a8e6fa9760f0b7ec17f16a646623
Merge: 16f4248... df17b73...
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Sat Jan 22 00:13:59 2011 -0500

    Merge branch 'feature/dp-named-range-source'
    
    This change implements named range support for data pilot tables.
    (n#654526)

commit df17b73a6c2d647587c6329f8c2f46c3aa0c47cd
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Sat Jan 22 00:08:46 2011 -0500

    Comment for the new method.

diff --git a/sc/source/filter/inc/xepivot.hxx b/sc/source/filter/inc/xepivot.hxx
index 281bd16..993812c 100644
--- a/sc/source/filter/inc/xepivot.hxx
+++ b/sc/source/filter/inc/xepivot.hxx
@@ -224,6 +224,7 @@ private:
 
     /** Writes the DCONREF record containing the source range. */
     void                WriteDconref( XclExpStream& rStrm ) const;
+    /** DCONNAME record contains range name source. */
     void                WriteDConName( XclExpStream& rStrm ) const;
 
     /** Creates the pivot cache storage stream and writes the cache. */
commit 5d6de3aaa7650ed0bfe8040f680eb57899d94414
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Sat Jan 22 00:02:26 2011 -0500

    Export range name data source back to xls document.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index d08984f..8125a04 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -71,7 +71,7 @@ public:
      */
     SC_DLLPUBLIC const ScRange& GetSourceRange() const;
     SC_DLLPUBLIC void SetRangeName(const ::rtl::OUString& rName);
-    const ::rtl::OUString& GetRangeName() const;
+    SC_DLLPUBLIC const ::rtl::OUString& GetRangeName() const;
     bool HasRangeName() const;
     void SetQueryParam(const ScQueryParam& rParam);
     const ScQueryParam& GetQueryParam() const;
diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx
index 11e679f..3244a45 100644
--- a/sc/source/filter/excel/xepivot.cxx
+++ b/sc/source/filter/excel/xepivot.cxx
@@ -641,6 +641,7 @@ XclExpPivotCache::XclExpPivotCache( const XclExpRoot& rRoot, const ScDPObject& r
                 This range may be shorter than maExpSrcRange to improve export
                 performance (#i22541#). */
         maOrigSrcRange = maExpSrcRange = maDocSrcRange = pSrcDesc->GetSourceRange();
+        maSrcRangeName = pSrcDesc->GetRangeName();
 
         // internal sheet data only
         SCTAB nScTab = maExpSrcRange.aStart.Tab();
@@ -728,8 +729,14 @@ void XclExpPivotCache::Save( XclExpStream& rStrm )
     XclExpUInt16Record( EXC_ID_SXIDSTM, maPCInfo.mnStrmId ).Save( rStrm );
     // SXVS
     XclExpUInt16Record( EXC_ID_SXVS, EXC_SXVS_SHEET ).Save( rStrm );
-    // DCONREF
-    WriteDconref( rStrm );
+
+    if (maSrcRangeName.getLength())
+        // DCONNAME
+        WriteDConName(rStrm);
+    else
+        // DCONREF
+        WriteDconref(rStrm);
+
     // create the pivot cache storage stream
     WriteCacheStream();
 }
@@ -855,6 +862,14 @@ void XclExpPivotCache::WriteDconref( XclExpStream& rStrm ) const
     rStrm.EndRecord();
 }
 
+void XclExpPivotCache::WriteDConName( XclExpStream& rStrm ) const
+{
+    XclExpString aName(maSrcRangeName);
+    rStrm.StartRecord(EXC_ID_DCONNAME, aName.GetSize() + 2);
+    rStrm << aName << sal_uInt16(0);
+    rStrm.EndRecord();
+}
+
 void XclExpPivotCache::WriteCacheStream()
 {
     SotStorageRef xSvStrg = OpenStorage( EXC_STORAGE_PTCACHE );
diff --git a/sc/source/filter/inc/xepivot.hxx b/sc/source/filter/inc/xepivot.hxx
index 97df866..281bd16 100644
--- a/sc/source/filter/inc/xepivot.hxx
+++ b/sc/source/filter/inc/xepivot.hxx
@@ -224,6 +224,7 @@ private:
 
     /** Writes the DCONREF record containing the source range. */
     void                WriteDconref( XclExpStream& rStrm ) const;
+    void                WriteDConName( XclExpStream& rStrm ) const;
 
     /** Creates the pivot cache storage stream and writes the cache. */
     void                WriteCacheStream();
@@ -241,6 +242,7 @@ private:
     XclPCInfo           maPCInfo;           /// Pivot cache settings (SXDB record).
     XclExpPCFieldList   maFieldList;        /// List of all pivot cache fields.
     String              maTabName;          /// Name of source data sheet.
+    ::rtl::OUString     maSrcRangeName;     /// Range name for source data.
     ScRange             maOrigSrcRange;     /// The original sheet source range.
     ScRange             maExpSrcRange;      /// The exported sheet source range.
     ScRange             maDocSrcRange;      /// The range used to build the cache fields and items.
commit 9f49336d7df0b051cd60217fe9e929125650da4d
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 23:39:01 2011 -0500

    Take care of importing pivot tables with range name from xls docs.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index c1ce6c0..d08984f 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -70,7 +70,7 @@ public:
      * @return source range.
      */
     SC_DLLPUBLIC const ScRange& GetSourceRange() const;
-    void SetRangeName(const ::rtl::OUString& rName);
+    SC_DLLPUBLIC void SetRangeName(const ::rtl::OUString& rName);
     const ::rtl::OUString& GetRangeName() const;
     bool HasRangeName() const;
     void SetQueryParam(const ScQueryParam& rParam);
diff --git a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx
index 2a299d4..1ed46a3 100644
--- a/sc/source/filter/excel/read.cxx
+++ b/sc/source/filter/excel/read.cxx
@@ -1020,6 +1020,7 @@ FltError ImportExcel8::Read( void )
                     case EXC_ID_SXIDSTM:        rPTableMgr.ReadSxidstm( maStrm );   break;
                     case EXC_ID_SXVS:           rPTableMgr.ReadSxvs( maStrm );      break;
                     case EXC_ID_DCONREF:        rPTableMgr.ReadDconref( maStrm );   break;
+                    case EXC_ID_DCONNAME:       rPTableMgr.ReadDConName( maStrm );  break;
                 }
 
             }
diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx
index 16109c2..a860353 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -659,6 +659,22 @@ void XclImpPivotCache::ReadDconref( XclImpStream& rStrm )
         GetAddressConverter().ConvertRange( maSrcRange, aXclRange, 0, 0, true );
 }
 
+void XclImpPivotCache::ReadDConName( XclImpStream& rStrm )
+{
+    maSrcRangeName = rStrm.ReadUniString();
+
+    // This 2-byte value equals the length of string that follows, or if 0 it
+    // indicates that the name has a workbook scope.  For now, we only support
+    // internal defined name with a workbook scope.
+    sal_uInt16 nFlag;
+    rStrm >> nFlag;
+    mbSelfRef = (nFlag == 0);
+
+    if (!mbSelfRef)
+        // External name is not supported yet.
+        maSrcRangeName = OUString();
+}
+
 void XclImpPivotCache::ReadPivotCacheStream( XclImpStream& rStrm )
 {
     if( (mnSrcType != EXC_SXVS_SHEET) && (mnSrcType != EXC_SXVS_EXTERN) )
@@ -672,18 +688,21 @@ void XclImpPivotCache::ReadPivotCacheStream( XclImpStream& rStrm )
 
     if( mbSelfRef )
     {
-        // try to find internal sheet containing the source data
-        nScTab = GetTabInfo().GetScTabFromXclName( maTabName );
-        if( rDoc.HasTable( nScTab ) )
+        if (!maSrcRangeName.getLength())
         {
-            // set sheet index to source range
-            maSrcRange.aStart.SetTab( nScTab );
-            maSrcRange.aEnd.SetTab( nScTab );
-        }
-        else
-        {
-            // create dummy sheet for deleted internal sheet
-            bGenerateSource = true;
+            // try to find internal sheet containing the source data
+            nScTab = GetTabInfo().GetScTabFromXclName( maTabName );
+            if( rDoc.HasTable( nScTab ) )
+            {
+                // set sheet index to source range
+                maSrcRange.aStart.SetTab( nScTab );
+                maSrcRange.aEnd.SetTab( nScTab );
+            }
+            else
+            {
+                // create dummy sheet for deleted internal sheet
+                bGenerateSource = true;
+            }
         }
     }
     else
@@ -856,6 +875,14 @@ bool XclImpPivotCache::IsRefreshOnLoad() const
     return static_cast<bool>(maPCInfo.mnFlags & 0x0004);
 }
 
+bool XclImpPivotCache::IsValid() const
+{
+    if (maSrcRangeName.getLength())
+        return true;
+
+    return maSrcRange.IsValid();
+}
+
 // ============================================================================
 // Pivot table
 // ============================================================================
@@ -1346,7 +1373,7 @@ void XclImpPivotTable::ReadSxViewEx9( XclImpStream& rStrm )
 
 void XclImpPivotTable::Convert()
 {
-    if( !mxPCache || !mxPCache->GetSourceRange().IsValid() )
+    if( !mxPCache || !mxPCache->IsValid() )
         return;
 
     ScDPSaveData aSaveData;
@@ -1396,7 +1423,13 @@ void XclImpPivotTable::Convert()
 
     // create source descriptor
     ScSheetSourceDesc aDesc(GetDocPtr());
-    aDesc.SetSourceRange(mxPCache->GetSourceRange());
+    const OUString& rSrcName = mxPCache->GetSourceRangeName();
+    if (rSrcName.getLength())
+        // Range name is the data source.
+        aDesc.SetRangeName(rSrcName);
+    else
+        // Normal cell range.
+        aDesc.SetSourceRange(mxPCache->GetSourceRange());
 
     // adjust output range to include the page fields
     ScRange aOutRange( maOutScRange );
@@ -1558,6 +1591,12 @@ void XclImpPivotTableManager::ReadDconref( XclImpStream& rStrm )
         maPCaches.back()->ReadDconref( rStrm );
 }
 
+void XclImpPivotTableManager::ReadDConName( XclImpStream& rStrm )
+{
+    if( !maPCaches.empty() )
+        maPCaches.back()->ReadDConName( rStrm );
+}
+
 // pivot table records --------------------------------------------------------
 
 void XclImpPivotTableManager::ReadSxview( XclImpStream& rStrm )
diff --git a/sc/source/filter/inc/xipivot.hxx b/sc/source/filter/inc/xipivot.hxx
index 9b26509..e4ad832 100644
--- a/sc/source/filter/inc/xipivot.hxx
+++ b/sc/source/filter/inc/xipivot.hxx
@@ -169,6 +169,8 @@ public:
     /** Returns the data source range read from the DCONREF record. */
     inline const ScRange& GetSourceRange() const { return maSrcRange; }
 
+    const ::rtl::OUString& GetSourceRangeName() const { return maSrcRangeName; }
+
     /** Returns the number of pivot cache fields. */
     sal_uInt16          GetFieldCount() const;
     /** Returns read-only access to a pivot cache field. */
@@ -182,10 +184,16 @@ public:
     void                ReadSxvs( XclImpStream& rStrm );
     /** Reads a DCONREF record containing the source range of the pivot cache. */
     void                ReadDconref( XclImpStream& rStrm );
+    /**
+     * Read DECONNAME record which contains the defined name of the source
+     * range.
+     */
+    void                ReadDConName( XclImpStream& rStrm );
     /** Reads the entire pivot cache stream. Uses decrypter from passed stream. */
     void                ReadPivotCacheStream( XclImpStream& rStrm );
 
     bool                IsRefreshOnLoad() const;
+    bool                IsValid() const;
 
 private:
     typedef ::std::vector< XclImpPCFieldRef > XclImpPCFieldVec;
@@ -195,6 +203,7 @@ private:
     ScRange             maSrcRange;         /// Source range in the spreadsheet.
     String              maUrl;              /// URL of the source data.
     String              maTabName;          /// Sheet name of the source data.
+    ::rtl::OUString     maSrcRangeName;     /// Name of the source data range.
     sal_uInt16          mnStrmId;           /// Pivot cache stream identifier.
     sal_uInt16          mnSrcType;          /// Source data type.
     bool                mbSelfRef;          /// true = Source data from own document.
@@ -413,6 +422,7 @@ public:
     void                ReadSxvs( XclImpStream& rStrm );
     /** Reads a DCONREF record containing the source range of a pivot cache. */
     void                ReadDconref( XclImpStream& rStrm );
+    void                ReadDConName( XclImpStream& rStrm );
 
     // pivot table records ----------------------------------------------------
 
commit 6a7304ee5777b404f0de160d9c29d0aa9564a3b6
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 22:19:00 2011 -0500

    Import source range name properly from ods document.

diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index d28a82d..dc644dc 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -447,7 +447,11 @@ void ScXMLDataPilotTableContext::EndElement()
             if (bSourceCellRange)
             {
                 ScSheetSourceDesc aSheetDesc(pDoc);
-                aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
+                if (sSourceRangeName.getLength())
+                    // Range name takes precedence.
+                    aSheetDesc.SetRangeName(sSourceRangeName);
+                else
+                    aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
                 aSheetDesc.SetQueryParam(aSourceQueryParam);
                 pDPObject->SetSheetDesc(aSheetDesc);
             }
@@ -856,6 +860,9 @@ ScXMLSourceCellRangeContext::ScXMLSourceCellRangeContext( ScXMLImport& rImport,
                     pDataPilotTable->SetSourceCellRangeAddress(aSourceRangeAddress);
             }
             break;
+            case XML_TOK_SOURCE_CELL_RANGE_ATTR_NAME:
+                pDataPilotTable->SetSourceRangeName(sValue);
+            break;
         }
     }
 }
diff --git a/sc/source/filter/xml/xmldpimp.hxx b/sc/source/filter/xml/xmldpimp.hxx
index 1e9ac07..311c82e 100644
--- a/sc/source/filter/xml/xmldpimp.hxx
+++ b/sc/source/filter/xml/xmldpimp.hxx
@@ -106,6 +106,7 @@ class ScXMLDataPilotTableContext : public SvXMLImportContext
     rtl::OUString	sServiceUsername;
     rtl::OUString	sServicePassword;
     rtl::OUString	sButtons;
+    rtl::OUString   sSourceRangeName;
     ScRange			aSourceCellRangeAddress;
     ScRange			aTargetRangeAddress;
     ScRange			aFilterSourceRange;
@@ -157,6 +158,7 @@ public:
     void SetServiceSourceObject(const rtl::OUString& sValue) { sServiceSourceObject = sValue; }
     void SetServiceUsername(const rtl::OUString& sValue) { sServiceUsername = sValue; }
     void SetServicePassword(const rtl::OUString& sValue) { sServicePassword = sValue; }
+    void SetSourceRangeName(const rtl::OUString& sValue) { sSourceRangeName = sValue; bSourceCellRange = true; }
     void SetSourceCellRangeAddress(const ScRange& aValue) { aSourceCellRangeAddress = aValue; bSourceCellRange = sal_True; }
     void SetSourceQueryParam(const ScQueryParam& aValue) { aSourceQueryParam = aValue; }
 //	void SetFilterUseRegularExpressions(const sal_Bool bValue) { aSourceQueryParam.bRegExp = bValue; }
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index fb39fbe..27d661b 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -1430,7 +1430,8 @@ const SvXMLTokenMap& ScXMLImport::GetDataPilotTableSourceCellRangeAttrTokenMap()
     {
         static SvXMLTokenMapEntry aDataPilotTableSourceCellRangeAttrTokenMap[] =
         {
-            { XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS,		XML_TOK_SOURCE_CELL_RANGE_ATTR_CELL_RANGE_ADDRESS},
+            { XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, XML_TOK_SOURCE_CELL_RANGE_ATTR_CELL_RANGE_ADDRESS },
+            { XML_NAMESPACE_TABLE, XML_NAME, XML_TOK_SOURCE_CELL_RANGE_ATTR_NAME },
             XML_TOKEN_MAP_END
         };
 
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 1ec6ef5..6a53601 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -530,7 +530,8 @@ enum ScXMLDataPilotTableSourceCellRangeElemTokens
 
 enum ScXMLDataPilotTableSourceCellRangeAttrTokens
 {
-    XML_TOK_SOURCE_CELL_RANGE_ATTR_CELL_RANGE_ADDRESS
+    XML_TOK_SOURCE_CELL_RANGE_ATTR_CELL_RANGE_ADDRESS,
+    XML_TOK_SOURCE_CELL_RANGE_ATTR_NAME
 };
 
 enum ScXMLDataPilotFieldAttrTokens
commit cbaf9eb3d076e9e7b3c42d398ad429e06535e177
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 21:57:16 2011 -0500

    Reduced indent levels again.

diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index 09659e0..d28a82d 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -398,90 +398,90 @@ void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension& aGrou
 
 void ScXMLDataPilotTableContext::EndElement()
 {
-    if (bTargetRangeAddress)
+    if (!bTargetRangeAddress)
+        return;
+
+    pDPObject->SetName(sDataPilotTableName);
+    pDPObject->SetTag(sApplicationData);
+    pDPObject->SetOutRange(aTargetRangeAddress);
+    pDPObject->SetHeaderLayout(bHeaderGridLayout);
+    switch (nSourceType)
     {
-        pDPObject->SetName(sDataPilotTableName);
-        pDPObject->SetTag(sApplicationData);
-        pDPObject->SetOutRange(aTargetRangeAddress);
-        pDPObject->SetHeaderLayout(bHeaderGridLayout);
-        switch (nSourceType)
+        case SQL :
         {
-            case SQL :
-            {
-                ScImportSourceDesc aImportDesc;
-                aImportDesc.aDBName = sDatabaseName;
-                aImportDesc.aObject = sSourceObject;
-                aImportDesc.nType = sheet::DataImportMode_SQL;
-                aImportDesc.bNative = bIsNative;
-                pDPObject->SetImportDesc(aImportDesc);
-            }
-            break;
-            case TABLE :
-            {
-                ScImportSourceDesc aImportDesc;
-                aImportDesc.aDBName = sDatabaseName;
-                aImportDesc.aObject = sSourceObject;
-                aImportDesc.nType = sheet::DataImportMode_TABLE;
-                pDPObject->SetImportDesc(aImportDesc);
-            }
-            break;
-            case QUERY :
-            {
-                ScImportSourceDesc aImportDesc;
-                aImportDesc.aDBName = sDatabaseName;
-                aImportDesc.aObject = sSourceObject;
-                aImportDesc.nType = sheet::DataImportMode_QUERY;
-                pDPObject->SetImportDesc(aImportDesc);
-            }
-            break;
-            case SERVICE :
-            {
-                ScDPServiceDesc aServiceDesk(sServiceName, sServiceSourceName, sServiceSourceObject,
-                                    sServiceUsername, sServicePassword);
-                pDPObject->SetServiceData(aServiceDesk);
-            }
-            break;
-            case CELLRANGE :
+            ScImportSourceDesc aImportDesc;
+            aImportDesc.aDBName = sDatabaseName;
+            aImportDesc.aObject = sSourceObject;
+            aImportDesc.nType = sheet::DataImportMode_SQL;
+            aImportDesc.bNative = bIsNative;
+            pDPObject->SetImportDesc(aImportDesc);
+        }
+        break;
+        case TABLE :
+        {
+            ScImportSourceDesc aImportDesc;
+            aImportDesc.aDBName = sDatabaseName;
+            aImportDesc.aObject = sSourceObject;
+            aImportDesc.nType = sheet::DataImportMode_TABLE;
+            pDPObject->SetImportDesc(aImportDesc);
+        }
+        break;
+        case QUERY :
+        {
+            ScImportSourceDesc aImportDesc;
+            aImportDesc.aDBName = sDatabaseName;
+            aImportDesc.aObject = sSourceObject;
+            aImportDesc.nType = sheet::DataImportMode_QUERY;
+            pDPObject->SetImportDesc(aImportDesc);
+        }
+        break;
+        case SERVICE :
+        {
+            ScDPServiceDesc aServiceDesk(sServiceName, sServiceSourceName, sServiceSourceObject,
+                                sServiceUsername, sServicePassword);
+            pDPObject->SetServiceData(aServiceDesk);
+        }
+        break;
+        case CELLRANGE :
+        {
+            if (bSourceCellRange)
             {
-                if (bSourceCellRange)
-                {
-                    ScSheetSourceDesc aSheetDesc(pDoc);
-                    aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
-                    aSheetDesc.SetQueryParam(aSourceQueryParam);
-                    pDPObject->SetSheetDesc(aSheetDesc);
-                }
+                ScSheetSourceDesc aSheetDesc(pDoc);
+                aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
+                aSheetDesc.SetQueryParam(aSourceQueryParam);
+                pDPObject->SetSheetDesc(aSheetDesc);
             }
-            break;
         }
+        break;
+    }
 
-        pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
-        pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
-        if (maRowGrandTotal.maDisplayName.getLength())
-            // TODO: Right now, we only support one grand total name for both 
-            // column and row totals.  Take the value from the row total for
-            // now.
-            pDPSave->SetGrandTotalName(maRowGrandTotal.maDisplayName);
-
-        pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
-        pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
-        pDPSave->SetFilterButton(bShowFilter);
-        pDPSave->SetDrillDown(bDrillDown);
-        if (pDPDimSaveData)
-            pDPSave->SetDimensionData(pDPDimSaveData);
-        pDPObject->SetSaveData(*pDPSave);
-        if (pDoc)
-        {
-            ScDPCollection* pDPCollection = pDoc->GetDPCollection();
+    pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
+    pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
+    if (maRowGrandTotal.maDisplayName.getLength())
+        // TODO: Right now, we only support one grand total name for both
+        // column and row totals.  Take the value from the row total for
+        // now.
+        pDPSave->SetGrandTotalName(maRowGrandTotal.maDisplayName);
+
+    pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
+    pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
+    pDPSave->SetFilterButton(bShowFilter);
+    pDPSave->SetDrillDown(bDrillDown);
+    if (pDPDimSaveData)
+        pDPSave->SetDimensionData(pDPDimSaveData);
+    pDPObject->SetSaveData(*pDPSave);
+    if (pDoc)
+    {
+        ScDPCollection* pDPCollection = pDoc->GetDPCollection();
 
-            // #i94570# Names have to be unique, or the tables can't be accessed by API.
-            if ( pDPCollection->GetByName(pDPObject->GetName()) )
-                pDPObject->SetName( String() );     // ignore the invalid name, create a new name in AfterXMLLoading
+        // #i94570# Names have to be unique, or the tables can't be accessed by API.
+        if ( pDPCollection->GetByName(pDPObject->GetName()) )
+            pDPObject->SetName( String() );     // ignore the invalid name, create a new name in AfterXMLLoading
 
-            pDPObject->SetAlive(sal_True);
-            pDPCollection->InsertNewTable(pDPObject);
-        }
-        SetButtons();
+        pDPObject->SetAlive(sal_True);
+        pDPCollection->InsertNewTable(pDPObject);
     }
+    SetButtons();
 }
 
 void ScXMLDataPilotTableContext::SetGrandTotal(
commit 2a8e03313c52c4c1fe793a85caf2d444149fa6c1
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 21:53:06 2011 -0500

    Save range name to ODF 1.2 extended.

diff --git a/sc/source/filter/xml/XMLExportDataPilot.cxx b/sc/source/filter/xml/XMLExportDataPilot.cxx
index 842d96a..9710e7f 100644
--- a/sc/source/filter/xml/XMLExportDataPilot.cxx
+++ b/sc/source/filter/xml/XMLExportDataPilot.cxx
@@ -844,8 +844,19 @@ void ScXMLExportDataPilot::WriteDataPilots(const uno::Reference <sheet::XSpreads
         if ((*pDPs)[i]->IsSheetData())
         {
             const ScSheetSourceDesc* pSheetSource = (*pDPs)[i]->GetSheetDesc();
-            rtl::OUString sCellRangeAddress;
-            ScRangeStringConverter::GetStringFromRange( sCellRangeAddress, pSheetSource->GetSourceRange(), pDoc, ::formula::FormulaGrammar::CONV_OOO );
+
+            if (rExport.getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST)
+            {
+                if (pSheetSource->HasRangeName())
+                    rExport.AddAttribute(
+                        XML_NAMESPACE_TABLE, XML_NAME, pSheetSource->GetRangeName());
+            }
+
+            OUString sCellRangeAddress;
+            ScRangeStringConverter::GetStringFromRange(
+                sCellRangeAddress, pSheetSource->GetSourceRange(), pDoc,
+                ::formula::FormulaGrammar::CONV_OOO);
+
             rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sCellRangeAddress);
             SvXMLElementExport aElemSCR(rExport, XML_NAMESPACE_TABLE, XML_SOURCE_CELL_RANGE, sal_True, sal_True);
             rExport.CheckAttrList();
commit f7d439573c61df684bb7e08ca9b5cb10acefec1a
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 21:11:56 2011 -0500

    Reduce indent levels by early bail out.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 918e32b..c1ce6c0 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -72,6 +72,7 @@ public:
     SC_DLLPUBLIC const ScRange& GetSourceRange() const;
     void SetRangeName(const ::rtl::OUString& rName);
     const ::rtl::OUString& GetRangeName() const;
+    bool HasRangeName() const;
     void SetQueryParam(const ScQueryParam& rParam);
     const ScQueryParam& GetQueryParam() const;
 
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 73d7b18..dae4266 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -285,6 +285,11 @@ const OUString& ScSheetSourceDesc::GetRangeName() const
     return maRangeName;
 }
 
+bool ScSheetSourceDesc::HasRangeName() const
+{
+    return maRangeName.getLength() > 0;
+}
+
 void ScSheetSourceDesc::SetQueryParam(const ScQueryParam& rParam)
 {
     maQueryParam = rParam;
diff --git a/sc/source/filter/xml/XMLExportDataPilot.cxx b/sc/source/filter/xml/XMLExportDataPilot.cxx
index 4eab2ba..842d96a 100644
--- a/sc/source/filter/xml/XMLExportDataPilot.cxx
+++ b/sc/source/filter/xml/XMLExportDataPilot.cxx
@@ -750,154 +750,154 @@ void ScXMLExportDataPilot::WriteGrandTotal(::xmloff::token::XMLTokenEnum eOrient
 void ScXMLExportDataPilot::WriteDataPilots(const uno::Reference <sheet::XSpreadsheetDocument>& /* xSpreadDoc */)
 {
     pDoc = rExport.GetDocument();
-    if (pDoc)
+    if (!pDoc)
+        return;
+
+    ScDPCollection* pDPs = pDoc->GetDPCollection();
+    if (!pDPs)
+        return;
+
+    size_t nDPCount = pDPs->GetCount();
+    if (!nDPCount)
+        return;
+
+    SvXMLElementExport aElemDPs(rExport, XML_NAMESPACE_TABLE, XML_DATA_PILOT_TABLES, sal_True, sal_True);
+    rExport.CheckAttrList();
+    for (size_t i = 0; i < nDPCount; ++i)
     {
-        ScDPCollection* pDPs = pDoc->GetDPCollection();
-        if (pDPs)
+        ScDPSaveData* pDPSave = (*pDPs)[i]->GetSaveData();
+        if (!pDPSave)
+            continue;
+
+        ScRange aOutRange((*pDPs)[i]->GetOutRange());
+        rtl::OUString sTargetRangeAddress;
+        ScRangeStringConverter::GetStringFromRange( sTargetRangeAddress, aOutRange, pDoc, ::formula::FormulaGrammar::CONV_OOO );
+        ScDocAttrIterator aAttrItr(pDoc, aOutRange.aStart.Tab(),
+            aOutRange.aStart.Col(), aOutRange.aStart.Row(),
+            aOutRange.aEnd.Col(), aOutRange.aEnd.Row());
+        SCCOL nCol;
+        SCROW nRow1, nRow2;
+        rtl::OUString sOUButtonList;
+        const ScPatternAttr* pAttr = aAttrItr.GetNext(nCol, nRow1, nRow2);
+        while (pAttr)
         {
-            size_t nDPCount = pDPs->GetCount();
-            if (nDPCount > 0)
+            ScMergeFlagAttr& rItem = (ScMergeFlagAttr&)pAttr->GetItem(ATTR_MERGE_FLAG);
+            if (rItem.HasButton())
             {
-                SvXMLElementExport aElemDPs(rExport, XML_NAMESPACE_TABLE, XML_DATA_PILOT_TABLES, sal_True, sal_True);
-                rExport.CheckAttrList();
-                for (size_t i = 0; i < nDPCount; ++i)
+                for (SCROW nButtonRow = nRow1; nButtonRow <= nRow2; ++nButtonRow)
                 {
-                    ScDPSaveData* pDPSave = (*pDPs)[i]->GetSaveData();
-                    if (pDPSave)
-                    {
-                        ScRange aOutRange((*pDPs)[i]->GetOutRange());
-                        rtl::OUString sTargetRangeAddress;
-                        ScRangeStringConverter::GetStringFromRange( sTargetRangeAddress, aOutRange, pDoc, ::formula::FormulaGrammar::CONV_OOO );
-                        ScDocAttrIterator aAttrItr(pDoc, aOutRange.aStart.Tab(),
-                            aOutRange.aStart.Col(), aOutRange.aStart.Row(),
-                            aOutRange.aEnd.Col(), aOutRange.aEnd.Row());
-                        SCCOL nCol;
-                        SCROW nRow1, nRow2;
-                        rtl::OUString sOUButtonList;
-                        const ScPatternAttr* pAttr = aAttrItr.GetNext(nCol, nRow1, nRow2);
-                        while (pAttr)
-                        {
-                            ScMergeFlagAttr& rItem = (ScMergeFlagAttr&)pAttr->GetItem(ATTR_MERGE_FLAG);
-                            if (rItem.HasButton())
-                            {
-                                for (SCROW nButtonRow = nRow1; nButtonRow <= nRow2; ++nButtonRow)
-                                {
-                                    ScAddress aButtonAddr(nCol, nButtonRow, aOutRange.aStart.Tab());
-                                    ScRangeStringConverter::GetStringFromAddress(
-                                        sOUButtonList, aButtonAddr, pDoc, ::formula::FormulaGrammar::CONV_OOO, ' ', sal_True );
-                                }
-                            }
-                            pAttr = aAttrItr.GetNext(nCol, nRow1, nRow2);
-                        }
-                        rtl::OUString sName((*pDPs)[i]->GetName());
-                        rtl::OUString sApplicationData((*pDPs)[i]->GetTag());
-                        sal_Bool bRowGrand = pDPSave->GetRowGrand();
-                        sal_Bool bColumnGrand = pDPSave->GetColumnGrand();
-                        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, sName);
-                        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_APPLICATION_DATA, sApplicationData);
-                        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TARGET_RANGE_ADDRESS, sTargetRangeAddress);
-                        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_BUTTONS, sOUButtonList);
-                        if (!(bRowGrand && bColumnGrand))
-                        {
-                            if (bRowGrand)
-                                rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_GRAND_TOTAL, XML_ROW);
-                            else if (bColumnGrand)
-                                rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_GRAND_TOTAL, XML_COLUMN);
-                            else
-                                rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_GRAND_TOTAL, XML_NONE);
-                        }
-                        if (pDPSave->GetIgnoreEmptyRows())
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_IGNORE_EMPTY_ROWS, XML_TRUE);
-                        if (pDPSave->GetRepeatIfEmpty())
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_IDENTIFY_CATEGORIES, XML_TRUE);
-                        if (!pDPSave->GetFilterButton())
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_SHOW_FILTER_BUTTON, XML_FALSE);
-                        if (!pDPSave->GetDrillDown())
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DRILL_DOWN_ON_DOUBLE_CLICK, XML_FALSE);
-                        if ((*pDPs)[i]->GetHeaderLayout())
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_HEADER_GRID_LAYOUT, XML_TRUE);
-
-                        SvXMLElementExport aElemDP(rExport, XML_NAMESPACE_TABLE, XML_DATA_PILOT_TABLE, sal_True, sal_True);
-
-                        // grand total elements.
-
-                        const OUString* pGrandTotalName = pDPSave->GetGrandTotalName();
-                        if (pGrandTotalName && rExport.getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST)
-                        {
-                            // Use the new data-pilot-grand-total element.
-                            if (bRowGrand && bColumnGrand)
-                            {
-                                WriteGrandTotal(XML_BOTH, true, pGrandTotalName);
-                            }
-                            else
-                            {
-                                WriteGrandTotal(XML_ROW, bRowGrand, pGrandTotalName);
-                                WriteGrandTotal(XML_COLUMN, bColumnGrand, pGrandTotalName);
-                            }
-                        }
+                    ScAddress aButtonAddr(nCol, nButtonRow, aOutRange.aStart.Tab());
+                    ScRangeStringConverter::GetStringFromAddress(
+                        sOUButtonList, aButtonAddr, pDoc, ::formula::FormulaGrammar::CONV_OOO, ' ', sal_True );
+                }
+            }
+            pAttr = aAttrItr.GetNext(nCol, nRow1, nRow2);
+        }
+        rtl::OUString sName((*pDPs)[i]->GetName());
+        rtl::OUString sApplicationData((*pDPs)[i]->GetTag());
+        sal_Bool bRowGrand = pDPSave->GetRowGrand();
+        sal_Bool bColumnGrand = pDPSave->GetColumnGrand();
+        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, sName);
+        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_APPLICATION_DATA, sApplicationData);
+        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TARGET_RANGE_ADDRESS, sTargetRangeAddress);
+        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_BUTTONS, sOUButtonList);
+        if (!(bRowGrand && bColumnGrand))
+        {
+            if (bRowGrand)
+                rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_GRAND_TOTAL, XML_ROW);
+            else if (bColumnGrand)
+                rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_GRAND_TOTAL, XML_COLUMN);
+            else
+                rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_GRAND_TOTAL, XML_NONE);
+        }
+        if (pDPSave->GetIgnoreEmptyRows())
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_IGNORE_EMPTY_ROWS, XML_TRUE);
+        if (pDPSave->GetRepeatIfEmpty())
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_IDENTIFY_CATEGORIES, XML_TRUE);
+        if (!pDPSave->GetFilterButton())
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_SHOW_FILTER_BUTTON, XML_FALSE);
+        if (!pDPSave->GetDrillDown())
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DRILL_DOWN_ON_DOUBLE_CLICK, XML_FALSE);
+        if ((*pDPs)[i]->GetHeaderLayout())
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_HEADER_GRID_LAYOUT, XML_TRUE);
+
+        SvXMLElementExport aElemDP(rExport, XML_NAMESPACE_TABLE, XML_DATA_PILOT_TABLE, sal_True, sal_True);
+
+        // grand total elements.
+
+        const OUString* pGrandTotalName = pDPSave->GetGrandTotalName();
+        if (pGrandTotalName && rExport.getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST)
+        {
+            // Use the new data-pilot-grand-total element.
+            if (bRowGrand && bColumnGrand)
+            {
+                WriteGrandTotal(XML_BOTH, true, pGrandTotalName);
+            }
+            else
+            {
+                WriteGrandTotal(XML_ROW, bRowGrand, pGrandTotalName);
+                WriteGrandTotal(XML_COLUMN, bColumnGrand, pGrandTotalName);
+            }
+        }
 
-                        rExport.CheckAttrList();
-                        if ((*pDPs)[i]->IsSheetData())
-                        {
-                            const ScSheetSourceDesc* pSheetSource = (*pDPs)[i]->GetSheetDesc();
-                            rtl::OUString sCellRangeAddress;
-                            ScRangeStringConverter::GetStringFromRange( sCellRangeAddress, pSheetSource->GetSourceRange(), pDoc, ::formula::FormulaGrammar::CONV_OOO );
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sCellRangeAddress);
-                            SvXMLElementExport aElemSCR(rExport, XML_NAMESPACE_TABLE, XML_SOURCE_CELL_RANGE, sal_True, sal_True);
-                            rExport.CheckAttrList();
-                            WriteDPFilter(pSheetSource->GetQueryParam());
-                        }
-                        else if ((*pDPs)[i]->IsImportData())
-                        {
-                            const ScImportSourceDesc* pImpSource = (*pDPs)[i]->GetImportSourceDesc();
-                            switch (pImpSource->nType)
-                            {
-                                case sheet::DataImportMode_NONE : break;
-                                case sheet::DataImportMode_QUERY :
-                                {
-                                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, rtl::OUString(pImpSource->aDBName));
-                                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_QUERY_NAME, rtl::OUString(pImpSource->aObject));
-                                    SvXMLElementExport aElemID(rExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_QUERY, sal_True, sal_True);
-                                    rExport.CheckAttrList();
-                                }
-                                break;
-                                case sheet::DataImportMode_TABLE :
-                                {
-                                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, rtl::OUString(pImpSource->aDBName));
-                                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_NAME, rtl::OUString(pImpSource->aObject));
-                                    SvXMLElementExport aElemID(rExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_TABLE, sal_True, sal_True);
-                                    rExport.CheckAttrList();
-                                }
-                                break;
-                                case sheet::DataImportMode_SQL :
-                                {
-                                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, rtl::OUString(pImpSource->aDBName));
-                                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_SQL_STATEMENT, rtl::OUString(pImpSource->aObject));
-                                    if (!pImpSource->bNative)
-                                        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_PARSE_SQL_STATEMENT, XML_TRUE);
-                                    SvXMLElementExport aElemID(rExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_SQL, sal_True, sal_True);
-                                    rExport.CheckAttrList();
-                                }
-                                break;
-                            }
-                        }
-                        else if ((*pDPs)[i]->IsServiceData())
-                        {
-                            const ScDPServiceDesc* pServSource = (*pDPs)[i]->GetDPServiceDesc();
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, rtl::OUString(pServSource->aServiceName));
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_SOURCE_NAME, rtl::OUString(pServSource->aParSource));
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_OBJECT_NAME, rtl::OUString(pServSource->aParName));
-                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_USER_NAME, rtl::OUString(pServSource->aParUser));
-                            // #i111754# leave out password attribute as long as DataPilotSource doesn't specify the content
-                            // rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_PASSWORD, rtl::OUString(pServSource->aParPass));
-                            SvXMLElementExport aElemSD(rExport, XML_NAMESPACE_TABLE, XML_SOURCE_SERVICE, sal_True, sal_True);
-                            rExport.CheckAttrList();
-                        }
-                        WriteDimensions(pDPSave);
-                    }
+        rExport.CheckAttrList();
+        if ((*pDPs)[i]->IsSheetData())
+        {
+            const ScSheetSourceDesc* pSheetSource = (*pDPs)[i]->GetSheetDesc();
+            rtl::OUString sCellRangeAddress;
+            ScRangeStringConverter::GetStringFromRange( sCellRangeAddress, pSheetSource->GetSourceRange(), pDoc, ::formula::FormulaGrammar::CONV_OOO );
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sCellRangeAddress);
+            SvXMLElementExport aElemSCR(rExport, XML_NAMESPACE_TABLE, XML_SOURCE_CELL_RANGE, sal_True, sal_True);
+            rExport.CheckAttrList();
+            WriteDPFilter(pSheetSource->GetQueryParam());
+        }
+        else if ((*pDPs)[i]->IsImportData())
+        {
+            const ScImportSourceDesc* pImpSource = (*pDPs)[i]->GetImportSourceDesc();
+            switch (pImpSource->nType)
+            {
+                case sheet::DataImportMode_NONE : break;
+                case sheet::DataImportMode_QUERY :
+                {
+                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, rtl::OUString(pImpSource->aDBName));
+                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_QUERY_NAME, rtl::OUString(pImpSource->aObject));
+                    SvXMLElementExport aElemID(rExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_QUERY, sal_True, sal_True);
+                    rExport.CheckAttrList();
+                }
+                break;
+                case sheet::DataImportMode_TABLE :
+                {
+                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, rtl::OUString(pImpSource->aDBName));
+                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_NAME, rtl::OUString(pImpSource->aObject));
+                    SvXMLElementExport aElemID(rExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_TABLE, sal_True, sal_True);
+                    rExport.CheckAttrList();
                 }
+                break;
+                case sheet::DataImportMode_SQL :
+                {
+                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, rtl::OUString(pImpSource->aDBName));
+                    rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_SQL_STATEMENT, rtl::OUString(pImpSource->aObject));
+                    if (!pImpSource->bNative)
+                        rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_PARSE_SQL_STATEMENT, XML_TRUE);
+                    SvXMLElementExport aElemID(rExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_SQL, sal_True, sal_True);
+                    rExport.CheckAttrList();
+                }
+                break;
             }
         }
+        else if ((*pDPs)[i]->IsServiceData())
+        {
+            const ScDPServiceDesc* pServSource = (*pDPs)[i]->GetDPServiceDesc();
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, rtl::OUString(pServSource->aServiceName));
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_SOURCE_NAME, rtl::OUString(pServSource->aParSource));
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_OBJECT_NAME, rtl::OUString(pServSource->aParName));
+            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_USER_NAME, rtl::OUString(pServSource->aParUser));
+            // #i111754# leave out password attribute as long as DataPilotSource doesn't specify the content
+            // rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_PASSWORD, rtl::OUString(pServSource->aParPass));
+            SvXMLElementExport aElemSD(rExport, XML_NAMESPACE_TABLE, XML_SOURCE_SERVICE, sal_True, sal_True);
+            rExport.CheckAttrList();
+        }
+        WriteDimensions(pDPSave);
     }
 }
 
commit db6e01c44f61c3095c0368e32c5a24f2af420cf5
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 17:54:58 2011 -0500

    Properly display range name in the UI when appropriate.
    
    DataPilot main dialog now displays range name properly in lieu of
    the traditional raw range reference string if the source data range
    is referred to as a range name.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index c0fe2bd..918e32b 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -58,6 +58,17 @@ public:
     SC_DLLPUBLIC ScSheetSourceDesc(ScDocument* pDoc);
 
     SC_DLLPUBLIC void SetSourceRange(const ScRange& rRange);
+
+    /**
+     * Get the range that contains the source data.  In case the source data
+     * is referred to via a range name, it returns the range that the range
+     * name points to.
+     *
+     * <i>Note that currently only a single range is supported; if the
+     * range name contains multiple ranges, only the first range is used.</i>
+     *
+     * @return source range.
+     */
     SC_DLLPUBLIC const ScRange& GetSourceRange() const;
     void SetRangeName(const ::rtl::OUString& rName);
     const ::rtl::OUString& GetRangeName() const;
diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index d619c41..686c93e 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -247,9 +247,16 @@ void ScDPLayoutDlg::Init(bool bNewOutput)
     {
         aEdInPos.Enable();
         aRbInPos.Enable();
-        aOldRange = xDlgDPObject->GetSheetDesc()->GetSourceRange();
-        aOldRange.Format( inString, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
-        aEdInPos.SetText(inString);
+        const ScSheetSourceDesc* p = xDlgDPObject->GetSheetDesc();
+        OUString aRangeName = p->GetRangeName();
+        if (aRangeName.getLength())
+            aEdInPos.SetText(aRangeName);
+        else
+        {
+            aOldRange = p->GetSourceRange();
+            aOldRange.Format( inString, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
+            aEdInPos.SetText(inString);
+        }
     }
     else
     {
commit 6e6f818ebace4f62a82d3db3b2a5e541c6159613
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 17:41:08 2011 -0500

    Get source range from range name if exists.
    
    Now the data pilot table calculates result from a range name if
    it's there.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 19d009e..c0fe2bd 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -77,11 +77,11 @@ public:
      */
     ULONG CheckSourceRange() const;
     ScDPTableDataCache* GetCache(long nID) const;
-    ScDPTableDataCache* GetExistDPObjectCache () const;
+    ScDPTableDataCache* GetExistDPObjectCache() const;
     long GetCacheId(long nID) const;
 
 private:
-    ScRange         maSourceRange;
+    mutable ScRange maSourceRange;
     ::rtl::OUString maRangeName;
     ScQueryParam    maQueryParam;
     ScDocument*     mpDoc;
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 83c0dff..73d7b18 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -45,6 +45,8 @@
 #include "dpobject.hxx"
 #include "globstr.hrc"
 #include "dpglobal.hxx"
+#include "rangenam.hxx"
+
 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
 
 #include <vector>
@@ -61,7 +63,7 @@ using ::std::hash_set;
 // -----------------------------------------------------------------------
 
 ScSheetDPData::ScSheetDPData( ScDocument* pD, const ScSheetSourceDesc& rDesc , long nCacheId) :
-    ScDPTableData(pD, rDesc.GetCacheId(nCacheId) ), // DataPilot Migration - Cache&&Performance
+    ScDPTableData(pD, rDesc.GetCacheId(nCacheId) ),
     aQuery ( rDesc.GetQueryParam() ),
     pSpecial(NULL),
     bIgnoreEmptyRows( FALSE ),
@@ -247,7 +249,28 @@ const ScRange& ScSheetSourceDesc::GetSourceRange() const
     if (maRangeName.getLength())
     {
         // Obtain the source range from the range name first.
-
+        maSourceRange = ScRange();
+        ScRangeName* pRangeName = mpDoc->GetRangeName();
+        do
+        {
+            if (!pRangeName)
+                break;
+
+            OUString aUpper = ScGlobal::pCharClass->upper(maRangeName);
+            USHORT n;
+            if (!pRangeName->SearchNameUpper(aUpper, n))
+                break;
+
+            // range name found.  Fow now, we only use the first token and
+            // ignore the rest.
+            ScRangeData* pData = (*pRangeName)[n];
+            ScRange aRange;
+            if (!pData->IsReference(aRange))
+                break;
+
+            maSourceRange = aRange;
+        }
+        while (false);
     }
     return maSourceRange;
 }
@@ -306,7 +329,7 @@ ScDPTableDataCache* ScSheetSourceDesc::CreateCache(long nID) const
     return pCache;
 }
 
-ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache () const
+ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache() const
 {
     return mpDoc->GetDPCollection()->GetUsedDPObjectCache( GetSourceRange() );
 }
commit 7c67b616852a806d296d9a5866eb4c74ddcd1f66
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 16:56:06 2011 -0500

    Several of its methods now don't need to take ScDocument* as an arg.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 748b29a..19d009e 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -65,7 +65,7 @@ public:
     const ScQueryParam& GetQueryParam() const;
 
     bool operator== ( const ScSheetSourceDesc& rOther ) const;
-    ScDPTableDataCache* CreateCache( ScDocument* pDoc, long nID = -1) const;
+    ScDPTableDataCache* CreateCache(long nID = -1) const;
 
     /**
      * Check the sanity of the data source range.
@@ -75,10 +75,10 @@ public:
      * @return 0 if the source range is sane, otherwise an error message ID is
      *         returned.
      */
-    ULONG CheckSourceRange( ScDocument* pDoc ) const;
-    ScDPTableDataCache* GetCache( ScDocument* pDoc, long nID ) const;
-    ScDPTableDataCache* GetExistDPObjectCache ( ScDocument* pDoc ) const;
-    long GetCacheId( ScDocument* pDoc, long nID ) const;
+    ULONG CheckSourceRange() const;
+    ScDPTableDataCache* GetCache(long nID) const;
+    ScDPTableDataCache* GetExistDPObjectCache () const;
+    long GetCacheId(long nID) const;
 
 private:
     ScRange         maSourceRange;
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 6167768..48295c6 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2585,7 +2585,7 @@ ULONG ScDPObject::RefreshCache()
     CreateObjects();
     ULONG nErrId = 0;
     if ( pSheetDesc)
-        nErrId =  pSheetDesc->CheckSourceRange( pDoc );
+        nErrId =  pSheetDesc->CheckSourceRange();
     if ( nErrId == 0 )
     {
         // First remove the old cache if exists.
@@ -2598,9 +2598,9 @@ ULONG ScDPObject::RefreshCache()
         // Create a new cache.
         ScDPTableDataCache* pCache = NULL;
         if ( pSheetDesc )
-            pCache = pSheetDesc->CreateCache( pDoc, nNewId );
+            pCache = pSheetDesc->CreateCache(nNewId);
         else if ( pImpDesc )
-            pCache = pImpDesc->CreateCache( pDoc, nNewId );
+            pCache = pImpDesc->CreateCache(pDoc, nNewId);
 
         if ( pCache == NULL )
         {
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 91f3a44..83c0dff 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -61,12 +61,12 @@ using ::std::hash_set;
 // -----------------------------------------------------------------------
 
 ScSheetDPData::ScSheetDPData( ScDocument* pD, const ScSheetSourceDesc& rDesc , long nCacheId) :
-    ScDPTableData(pD, rDesc.GetCacheId( pD, nCacheId) ), // DataPilot Migration - Cache&&Performance
+    ScDPTableData(pD, rDesc.GetCacheId(nCacheId) ), // DataPilot Migration - Cache&&Performance
     aQuery ( rDesc.GetQueryParam() ),
     pSpecial(NULL),
     bIgnoreEmptyRows( FALSE ),
     bRepeatIfEmpty(FALSE),
-    aCacheTable( pD, rDesc.GetCacheId( pD, nCacheId))
+    aCacheTable( pD, rDesc.GetCacheId(nCacheId))
 {
     SCSIZE nEntryCount( aQuery.GetEntryCount());
     pSpecial = new bool[nEntryCount];
@@ -279,65 +279,65 @@ bool ScSheetSourceDesc::operator== (const ScSheetSourceDesc& rOther) const
         maQueryParam  == rOther.maQueryParam;
 }
 
-ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID ) const
+ScDPTableDataCache* ScSheetSourceDesc::CreateCache(long nID) const
 {
-    if (!pDoc)
+    if (!mpDoc)
         return NULL;
 
-    ScDPTableDataCache* pCache = GetExistDPObjectCache( pDoc );
+    ScDPTableDataCache* pCache = GetExistDPObjectCache();
     if ( pCache && ( nID < 0 || nID == pCache->GetId() ) )
         return pCache;
 
-    ULONG nErrId = CheckSourceRange( pDoc );
+    ULONG nErrId = CheckSourceRange();
     if (nErrId)
     {
         DBG_ERROR( "Error Create Cache\n" );
         return NULL;
     }
 
-    pCache = new ScDPTableDataCache( pDoc );
+    pCache = new ScDPTableDataCache(mpDoc);
 
-    pCache->InitFromDoc( pDoc, GetSourceRange() );
+    pCache->InitFromDoc(mpDoc, GetSourceRange());
     pCache->SetId( nID );
-    pDoc->GetDPCollection()->AddDPObjectCache( pCache );
+    mpDoc->GetDPCollection()->AddDPObjectCache(pCache);
 
-    DBG_TRACE1("Create a cache id = %d \n", pCache->GetId() );
+    DBG_TRACE1("Create a cache id = %d \n", pCache->GetId());
 
     return pCache;
 }
 
-ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache ( ScDocument* pDoc  ) const
+ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache () const
 {
-    return pDoc->GetDPCollection()->GetUsedDPObjectCache( GetSourceRange() );
+    return mpDoc->GetDPCollection()->GetUsedDPObjectCache( GetSourceRange() );
 }
 
-ScDPTableDataCache* ScSheetSourceDesc::GetCache( ScDocument* pDoc, long nID ) const
+ScDPTableDataCache* ScSheetSourceDesc::GetCache(long nID) const
 {
-    if (!pDoc)
+    if (!mpDoc)
         return NULL;
 
-    ScDPTableDataCache* pCache = pDoc->GetDPCollection()->GetDPObjectCache( nID );
+    ScDPTableDataCache* pCache = mpDoc->GetDPCollection()->GetDPObjectCache(nID);
     if (NULL == pCache)
-        pCache = GetExistDPObjectCache( pDoc );
+        pCache = GetExistDPObjectCache();
 
     if (NULL == pCache)
-        pCache = CreateCache( pDoc );
+        pCache = CreateCache();
 
     return pCache;
 }
 
-long ScSheetSourceDesc::GetCacheId( ScDocument* pDoc, long nID ) const
+long ScSheetSourceDesc::GetCacheId(long nID) const
 {
-    ScDPTableDataCache* pCache = GetCache( pDoc,  nID);
+    ScDPTableDataCache* pCache = GetCache(nID);
     if ( NULL == pCache )
         return -1;
     else 
         return pCache->GetId();
 }
 
-ULONG ScSheetSourceDesc::CheckSourceRange( ScDocument* pDoc ) const
+ULONG ScSheetSourceDesc::CheckSourceRange() const
 {
-    if (!pDoc)
+    if (!mpDoc)
         return STR_ERR_DATAPILOTSOURCE;
 
     const ScRange& aSrcRange = GetSourceRange();
@@ -345,11 +345,11 @@ ULONG ScSheetSourceDesc::CheckSourceRange( ScDocument* pDoc ) const
     const ScAddress& e = aSrcRange.aEnd;
     for (SCCOL nCol = aSrcRange.aStart.Col(); nCol <= e.Col(); ++nCol)
     {
-        if (pDoc->IsBlockEmpty(s.Tab(), nCol, s.Row(), nCol, s.Row()))
+        if (mpDoc->IsBlockEmpty(s.Tab(), nCol, s.Row(), nCol, s.Row()))
             return STR_PIVOT_FIRSTROWEMPTYERR; 
     }
 
-    if (pDoc->IsBlockEmpty(s.Tab(), s.Col(), s.Row()+1, e.Col(), e.Row()))
+    if (mpDoc->IsBlockEmpty(s.Tab(), s.Col(), s.Row()+1, e.Col(), e.Row()))
         return STR_PIVOT_ONLYONEROWERR;
 
     return 0;
commit 4176f290e0fcf5af57692498ddcfa5a405dc4846
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 16:46:47 2011 -0500

    Let's store ScDocument* in ScSheetSourceDesc.
    
    This class already uses ScDocument* a lot internally. Let's just
    take the pointer to the document instance in the ctor and store it
    inside.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 3f98e1c..748b29a 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -52,7 +52,10 @@ class ScDPItemData;
  */
 class ScSheetSourceDesc
 {
+    ScSheetSourceDesc(); // disabled
+
 public:
+    SC_DLLPUBLIC ScSheetSourceDesc(ScDocument* pDoc);
 
     SC_DLLPUBLIC void SetSourceRange(const ScRange& rRange);
     SC_DLLPUBLIC const ScRange& GetSourceRange() const;
@@ -81,6 +84,7 @@ private:
     ScRange         maSourceRange;
     ::rtl::OUString maRangeName;
     ScQueryParam    maQueryParam;
+    ScDocument*     mpDoc;
 };
 
 // --------------------------------------------------------------------
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 8132392..2417321 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -569,7 +569,7 @@ void Test::testDataPilot()
     printer.print("Data sheet content");
     printer.clear();
 
-    ScSheetSourceDesc aSheetDesc;
+    ScSheetSourceDesc aSheetDesc(m_pDoc);
     aSheetDesc.SetSourceRange(ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0));
     ScDPObject* pDPObj = new ScDPObject(m_pDoc);
     pDPObj->SetSheetDesc(aSheetDesc);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 9ad68b7..6167768 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -424,7 +424,7 @@ ScDPTableData* ScDPObject::GetTableData()
             if (!pSheetDesc)
             {
                 DBG_ERROR("no source descriptor");
-                pSheetDesc = new ScSheetSourceDesc;     // dummy defaults
+                pSheetDesc = new ScSheetSourceDesc(pDoc);     // dummy defaults
             }
             pData.reset(new ScSheetDPData(pDoc, *pSheetDesc, GetCacheId()));
         }
@@ -712,7 +712,7 @@ void ScDPObject::UpdateReference( UpdateRefMode eUpdateRefMode,
                 nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
         if ( eRes != UR_NOTHING )
         {
-            ScSheetSourceDesc aNewDesc;
+            ScSheetSourceDesc aNewDesc(pDoc);
             aNewDesc.SetSourceRange(ScRange(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2));
 
             SCsCOL nDiffX = nCol1 - (SCsCOL) pSheetDesc->GetSourceRange().aStart.Col();
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index ee121a3..91f3a44 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -233,6 +233,9 @@ const ScDPCacheTable& ScSheetDPData::GetCacheTable() const
     return aCacheTable;
 }
 
+ScSheetSourceDesc::ScSheetSourceDesc(ScDocument* pDoc) :
+    mpDoc(pDoc) {}
+
 void ScSheetSourceDesc::SetSourceRange(const ScRange& rRange)
 {
     maSourceRange = rRange;
@@ -241,6 +244,11 @@ void ScSheetSourceDesc::SetSourceRange(const ScRange& rRange)
 
 const ScRange& ScSheetSourceDesc::GetSourceRange() const
 {
+    if (maRangeName.getLength())
+    {
+        // Obtain the source range from the range name first.
+
+    }
     return maSourceRange;
 }
 
diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx
index daa19bd..16109c2 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -1395,7 +1395,7 @@ void XclImpPivotTable::Convert()
     // *** insert into Calc document ***
 
     // create source descriptor
-    ScSheetSourceDesc aDesc;
+    ScSheetSourceDesc aDesc(GetDocPtr());
     aDesc.SetSourceRange(mxPCache->GetSourceRange());
 
     // adjust output range to include the page fields
diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index 1a746ce..09659e0 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -445,7 +445,7 @@ void ScXMLDataPilotTableContext::EndElement()
             {
                 if (bSourceCellRange)
                 {
-                    ScSheetSourceDesc aSheetDesc;
+                    ScSheetSourceDesc aSheetDesc(pDoc);
                     aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
                     aSheetDesc.SetQueryParam(aSourceQueryParam);
                     pDPObject->SetSheetDesc(aSheetDesc);
diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index e15a40d..d619c41 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -188,7 +188,6 @@ ScDPLayoutDlg::ScDPLayoutDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pPar
                                 GetViewData() ),
         pDoc			( ((ScTabViewShell*)SfxViewShell::Current())->
                                 GetViewData()->GetDocument() ),
-        meSrcType(SRC_INVALID),
         bRefInputMode   (false)
 {
     xDlgDPObject->SetAlive( TRUE );     // needed to get structure information
@@ -1419,20 +1418,20 @@ bool ScDPLayoutDlg::GetPivotArrays(
 
 void ScDPLayoutDlg::UpdateSrcRange()
 {
-    String  theCurPosStr = aEdInPos.GetText();
-    USHORT  nResult = ScRange().Parse(theCurPosStr, pDoc, pDoc->GetAddressConvention());
-    meSrcType = SRC_INVALID;
-
+    String  aSrcStr = aEdInPos.GetText();
+    USHORT  nResult = ScRange().Parse(aSrcStr, pDoc, pDoc->GetAddressConvention());
+    DataSrcType eSrcType = SRC_INVALID;
     ScRange aNewRange;
+
     if (SCA_VALID == (nResult & SCA_VALID))
     {
         // Valid source range.  Take it.
         ScRefAddress start, end;
-        ConvertDoubleRef(pDoc, theCurPosStr, 1,  start, end, pDoc->GetAddressConvention());
+        ConvertDoubleRef(pDoc, aSrcStr, 1,  start, end, pDoc->GetAddressConvention());
         aNewRange.aStart = start.GetAddress();
         aNewRange.aEnd = end.GetAddress();
         aEdInPos.SetRefValid(true);
-        meSrcType = SRC_REF;
+        eSrcType = SRC_REF;
     }
     else
     {
@@ -1441,7 +1440,7 @@ void ScDPLayoutDlg::UpdateSrcRange()
         ScRangeName* pRangeName = pDoc->GetRangeName();
         if (pRangeName)
         {
-            OUString aUpper = ScGlobal::pCharClass->upper(theCurPosStr);
+            OUString aUpper = ScGlobal::pCharClass->upper(aSrcStr);
             USHORT n;
             bValid = pRangeName->SearchNameUpper(aUpper, n);
             if (bValid)
@@ -1460,22 +1459,37 @@ void ScDPLayoutDlg::UpdateSrcRange()
             return;
         }
 
-        meSrcType = SRC_NAME;
+        eSrcType = SRC_NAME;
     }
 
     aBtnOk.Enable();
+
+    // Now update the data src range or range name with the dp object.
     ScSheetSourceDesc inSheet = *xDlgDPObject->GetSheetDesc();
 
-    if (inSheet.GetSourceRange() == aNewRange)
-        // new range is identical to the current range.  Nothing to do.
-        return;
+    switch (eSrcType)
+    {
+        case SRC_REF:
+            // data source is a range reference.
+            if (inSheet.GetSourceRange() == aNewRange)
+                // new range is identical to the current range.  Nothing to do.
+                return;
+            inSheet.SetSourceRange(aNewRange);
+        break;
+        case SRC_NAME:
+            // data source is a range name.
+            inSheet.SetRangeName(aSrcStr);
+        break;
+        default:
+            OSL_ENSURE(false, "Unknown source type.");
+            return;
+    }
 
-    ScTabViewShell * pTabViewShell = pViewData->GetViewShell();
-    inSheet.SetSourceRange(aNewRange);
     xDlgDPObject->SetSheetDesc(inSheet);
     xDlgDPObject->FillOldParam( thePivotData, FALSE );
     xDlgDPObject->FillLabelData(thePivotData);
 
+    ScTabViewShell* pTabViewShell = pViewData->GetViewShell();
     pTabViewShell->SetDialogDPObject(xDlgDPObject.get());
     aLabelDataArr.clear();
     aWndSelect.ClearFields();
diff --git a/sc/source/ui/inc/pvlaydlg.hxx b/sc/source/ui/inc/pvlaydlg.hxx
index 14b1b61..9d0e215 100644
--- a/sc/source/ui/inc/pvlaydlg.hxx
+++ b/sc/source/ui/inc/pvlaydlg.hxx
@@ -185,7 +185,6 @@ private:
     ScPivotParam            thePivotData;
     ScViewData*             pViewData;
     ScDocument*             pDoc;
-    DataSrcType             meSrcType;
     bool                    bRefInputMode;
 
 private:
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index 76ef5b4..b9cb787 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -719,7 +719,7 @@ void SAL_CALL ScDataPilotDescriptorBase::setSourceRange( const CellRangeAddress&
     if (!pDPObject)
         throw RuntimeException();
 
-    ScSheetSourceDesc aSheetDesc;
+    ScSheetSourceDesc aSheetDesc(pDocShell->GetDocument());
     if (pDPObject->IsSheetData())
         aSheetDesc = *pDPObject->GetSheetDesc();
 
@@ -1418,7 +1418,7 @@ ScDataPilotDescriptor::ScDataPilotDescriptor(ScDocShell* pDocSh) :
     aSaveData.SetIgnoreEmptyRows( sal_False );
     aSaveData.SetRepeatIfEmpty( sal_False );
     mpDPObject->SetSaveData(aSaveData);
-    ScSheetSourceDesc aSheetDesc;
+    ScSheetSourceDesc aSheetDesc(pDocSh ? pDocSh->GetDocument() : NULL);
     mpDPObject->SetSheetDesc(aSheetDesc);
     mpDPObject->GetSource();
 }
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index 7d95014..1cbaa7c 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -1599,7 +1599,7 @@ void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam )
         ScDPObject* pDPObj = pParent->GetDPObject();
         if (pDPObj)
         {
-            ScSheetSourceDesc aSheetDesc;
+            ScSheetSourceDesc aSheetDesc(pParent->GetDocShell()->GetDocument());
             if (pDPObj->IsSheetData())
                 aSheetDesc = *pDPObj->GetSheetDesc();
             aSheetDesc.SetQueryParam(rParam);
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 9d3db62..1b036a5 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -849,7 +849,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                                 }
                                 if (bOK)
                                 {
-                                    ScSheetSourceDesc aShtDesc;
+                                    ScSheetSourceDesc aShtDesc(pDoc);
                                     aShtDesc.SetSourceRange(aRange);
                                     pNewDPObject = new ScDPObject( pDoc );
                                     pNewDPObject->SetSheetDesc( aShtDesc );
diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index aceda30..6a2a161 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -227,7 +227,7 @@ void ScGridWindow::DoPushButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt
             DBG_ASSERT(pDlg, "Dialog create fail!");
             if ( pDlg->Execute() == RET_OK )
             {
-                ScSheetSourceDesc aNewDesc;
+                ScSheetSourceDesc aNewDesc(pDoc);
                 if (pDesc)
                     aNewDesc = *pDesc;
 
diff --git a/sc/source/ui/view/pivotsh.cxx b/sc/source/ui/view/pivotsh.cxx
index c9d42a9..4bdfebe 100644
--- a/sc/source/ui/view/pivotsh.cxx
+++ b/sc/source/ui/view/pivotsh.cxx
@@ -134,7 +134,7 @@ void ScPivotShell::Execute( SfxRequest& rReq )
 
                 if( pDlg->Execute() == RET_OK )
                 {
-                    ScSheetSourceDesc aNewDesc;
+                    ScSheetSourceDesc aNewDesc(pViewData->GetDocument());
                     if( pDesc )
                         aNewDesc = *pDesc;
 
commit 42caa46f5e05c138df0fd28f5f7e51cb909139e2
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 16:01:07 2011 -0500

    Early bail out on error conditions, to reduce indent levels.

diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 0c7d33d..ee121a3 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -273,28 +273,29 @@ bool ScSheetSourceDesc::operator== (const ScSheetSourceDesc& rOther) const
 
 ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID ) const
 {
-    if ( pDoc )
+    if (!pDoc)
+        return NULL;
+
+    ScDPTableDataCache* pCache = GetExistDPObjectCache( pDoc );
+    if ( pCache && ( nID < 0 || nID == pCache->GetId() ) )
+        return pCache;
+
+    ULONG nErrId = CheckSourceRange( pDoc );
+    if (nErrId)
     {
-        ScDPTableDataCache* pCache =  GetExistDPObjectCache( pDoc );
-        if ( pCache && ( nID < 0 || nID == pCache->GetId() ) )
-            return pCache;
+        DBG_ERROR( "Error Create Cache\n" );
+        return NULL;
+    }
 
-        ULONG nErrId = CheckSourceRange( pDoc );
-        if ( !nErrId )
-        {
-            pCache = new ScDPTableDataCache( pDoc );
+    pCache = new ScDPTableDataCache( pDoc );
 
-            pCache->InitFromDoc( pDoc, GetSourceRange() );
-            pCache->SetId( nID );
-            pDoc->GetDPCollection()->AddDPObjectCache( pCache );
+    pCache->InitFromDoc( pDoc, GetSourceRange() );
+    pCache->SetId( nID );
+    pDoc->GetDPCollection()->AddDPObjectCache( pCache );
 
-            DBG_TRACE1("Create a cache id = %d \n", pCache->GetId() );
-        }
-        else
-            DBG_ERROR( "\n Error Create Cache" );
-        return pCache;
-    }
-    return NULL;
+    DBG_TRACE1("Create a cache id = %d \n", pCache->GetId() );
+
+    return pCache;
 }
 
 ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache ( ScDocument* pDoc  ) const
@@ -304,15 +305,20 @@ ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache ( ScDocument* pDoc
 
 ScDPTableDataCache* ScSheetSourceDesc::GetCache( ScDocument* pDoc, long nID ) const
 {
+    if (!pDoc)
+        return NULL;
+
     ScDPTableDataCache* pCache = pDoc->GetDPCollection()->GetDPObjectCache( nID );
-    if ( NULL == pCache && pDoc )
+    if (NULL == pCache)
         pCache = GetExistDPObjectCache( pDoc );
-    if ( NULL == pCache )
-        pCache = CreateCache( pDoc );    
+
+    if (NULL == pCache)
+        pCache = CreateCache( pDoc );
+
     return pCache;
 }
 
-long ScSheetSourceDesc:: GetCacheId( ScDocument* pDoc, long nID ) const
+long ScSheetSourceDesc::GetCacheId( ScDocument* pDoc, long nID ) const
 {
     ScDPTableDataCache* pCache = GetCache( pDoc,  nID);
     if ( NULL == pCache )
@@ -323,10 +329,10 @@ long ScSheetSourceDesc:: GetCacheId( ScDocument* pDoc, long nID ) const
 
 ULONG ScSheetSourceDesc::CheckSourceRange( ScDocument* pDoc ) const
 {
-    const ScRange& aSrcRange = GetSourceRange();
     if (!pDoc)
         return STR_ERR_DATAPILOTSOURCE;
 
+    const ScRange& aSrcRange = GetSourceRange();
     const ScAddress& s = aSrcRange.aStart;
     const ScAddress& e = aSrcRange.aEnd;
     for (SCCOL nCol = aSrcRange.aStart.Col(); nCol <= e.Col(); ++nCol)
commit 307e75d13ec1cbe0788dc2dfc1c5313c6d9e2e98
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 15:51:06 2011 -0500

    Now all its data members are private.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index d782157..3f98e1c 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -52,11 +52,7 @@ class ScDPItemData;
  */
 class ScSheetSourceDesc
 {
-private:
-    ScRange         aSourceRange;
-    ::rtl::OUString maRangeName;
 public:
-    ScQueryParam    aQueryParam;
 
     SC_DLLPUBLIC void SetSourceRange(const ScRange& rRange);
     SC_DLLPUBLIC const ScRange& GetSourceRange() const;
@@ -80,6 +76,11 @@ public:
     ScDPTableDataCache* GetCache( ScDocument* pDoc, long nID ) const;
     ScDPTableDataCache* GetExistDPObjectCache ( ScDocument* pDoc ) const;
     long GetCacheId( ScDocument* pDoc, long nID ) const;
+
+private:
+    ScRange         maSourceRange;
+    ::rtl::OUString maRangeName;
+    ScQueryParam    maQueryParam;
 };
 
 // --------------------------------------------------------------------
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 36c5aac..9ad68b7 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -277,11 +277,13 @@ void ScDPObject::SetSheetDesc(const ScSheetSourceDesc& rDesc)
     //	make valid QueryParam
 
     const ScRange& rSrcRange = pSheetDesc->GetSourceRange();
-    pSheetDesc->aQueryParam.nCol1 = rSrcRange.aStart.Col();
-    pSheetDesc->aQueryParam.nRow1 = rSrcRange.aStart.Row();
-    pSheetDesc->aQueryParam.nCol2 = rSrcRange.aEnd.Col();
-    pSheetDesc->aQueryParam.nRow2 = rSrcRange.aEnd.Row();;
-    pSheetDesc->aQueryParam.bHasHeader = TRUE;
+    ScQueryParam aParam = pSheetDesc->GetQueryParam();
+    aParam.nCol1 = rSrcRange.aStart.Col();
+    aParam.nRow1 = rSrcRange.aStart.Row();
+    aParam.nCol2 = rSrcRange.aEnd.Col();
+    aParam.nRow2 = rSrcRange.aEnd.Row();;
+    aParam.bHasHeader = true;
+    pSheetDesc->SetQueryParam(aParam);
 
     InvalidateSource();		// new source must be created
 }
@@ -716,16 +718,17 @@ void ScDPObject::UpdateReference( UpdateRefMode eUpdateRefMode,
             SCsCOL nDiffX = nCol1 - (SCsCOL) pSheetDesc->GetSourceRange().aStart.Col();
             SCsROW nDiffY = nRow1 - (SCsROW) pSheetDesc->GetSourceRange().aStart.Row();
 
-            aNewDesc.aQueryParam = pSheetDesc->aQueryParam;
-            aNewDesc.aQueryParam.nCol1 = sal::static_int_cast<SCCOL>( aNewDesc.aQueryParam.nCol1 + nDiffX );
-            aNewDesc.aQueryParam.nCol2 = sal::static_int_cast<SCCOL>( aNewDesc.aQueryParam.nCol2 + nDiffX );
-            aNewDesc.aQueryParam.nRow1 += nDiffY;	//! used?
-            aNewDesc.aQueryParam.nRow2 += nDiffY;	//! used?
-            SCSIZE nEC = aNewDesc.aQueryParam.GetEntryCount();
+            ScQueryParam aParam = pSheetDesc->GetQueryParam();
+            aParam.nCol1 = sal::static_int_cast<SCCOL>( aParam.nCol1 + nDiffX );
+            aParam.nCol2 = sal::static_int_cast<SCCOL>( aParam.nCol2 + nDiffX );
+            aParam.nRow1 += nDiffY;	//! used?
+            aParam.nRow2 += nDiffY;	//! used?
+            SCSIZE nEC = aParam.GetEntryCount();
             for (SCSIZE i=0; i<nEC; i++)
-                if (aNewDesc.aQueryParam.GetEntry(i).bDoQuery)
-                    aNewDesc.aQueryParam.GetEntry(i).nField += nDiffX;
+                if (aParam.GetEntry(i).bDoQuery)
+                    aParam.GetEntry(i).nField += nDiffX;
 
+            aNewDesc.SetQueryParam(aParam);
             SetSheetDesc( aNewDesc );		// allocates new pSheetDesc
         }
     }
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 176f917..0c7d33d 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -235,13 +235,13 @@ const ScDPCacheTable& ScSheetDPData::GetCacheTable() const
 
 void ScSheetSourceDesc::SetSourceRange(const ScRange& rRange)
 {
-    aSourceRange = rRange;
+    maSourceRange = rRange;
     maRangeName = OUString(); // overwrite existing range name if any.
 }
 
 const ScRange& ScSheetSourceDesc::GetSourceRange() const
 {
-    return aSourceRange;
+    return maSourceRange;
 }
 
 void ScSheetSourceDesc::SetRangeName(const OUString& rName)
@@ -256,19 +256,19 @@ const OUString& ScSheetSourceDesc::GetRangeName() const
 
 void ScSheetSourceDesc::SetQueryParam(const ScQueryParam& rParam)
 {
-    aQueryParam = rParam;
+    maQueryParam = rParam;
 }
 
 const ScQueryParam& ScSheetSourceDesc::GetQueryParam() const
 {
-    return aQueryParam;
+    return maQueryParam;
 }
 
 bool ScSheetSourceDesc::operator== (const ScSheetSourceDesc& rOther) const
 {
-    return aSourceRange == rOther.aSourceRange && 
+    return maSourceRange == rOther.maSourceRange &&
         maRangeName == rOther.maRangeName && 
-        aQueryParam  == rOther.aQueryParam;
+        maQueryParam  == rOther.maQueryParam;
 }
 
 ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID ) const
commit 3ffdf8c54889295f84aec2ba94c47bb66f496558
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 15:02:10 2011 -0500

    The range name data member can safely have private visibility.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 9584e89..d782157 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -54,8 +54,8 @@ class ScSheetSourceDesc
 {
 private:
     ScRange         aSourceRange;
-public:
     ::rtl::OUString maRangeName;
+public:
     ScQueryParam    aQueryParam;
 
     SC_DLLPUBLIC void SetSourceRange(const ScRange& rRange);
commit 3c796bd3a6ae37a47a2bf81fffe9bab5c703f4ae
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 14:59:06 2011 -0500

    Encapsulated access to aSourceRange.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 4b2d4df..9584e89 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -50,14 +50,16 @@ class ScDPItemData;
  * precedence over the source range when it's non-empty.</i>  When the range
  * name is empty, the source range gets used.
  */
-struct ScSheetSourceDesc
+class ScSheetSourceDesc
 {
+private:
     ScRange         aSourceRange;
+public:
     ::rtl::OUString maRangeName;
     ScQueryParam    aQueryParam;
 
-    void SetSourceRange(const ScRange& rRange);
-    const ScRange& GetSourceRange() const;
+    SC_DLLPUBLIC void SetSourceRange(const ScRange& rRange);
+    SC_DLLPUBLIC const ScRange& GetSourceRange() const;
     void SetRangeName(const ::rtl::OUString& rName);
     const ::rtl::OUString& GetRangeName() const;
     void SetQueryParam(const ScQueryParam& rParam);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 3f8510c..8132392 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -570,7 +570,7 @@ void Test::testDataPilot()
     printer.clear();
 
     ScSheetSourceDesc aSheetDesc;
-    aSheetDesc.aSourceRange = ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0);
+    aSheetDesc.SetSourceRange(ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0));
     ScDPObject* pDPObj = new ScDPObject(m_pDoc);
     pDPObj->SetSheetDesc(aSheetDesc);
     pDPObj->SetOutRange(ScAddress(0, 0, 1));
@@ -592,9 +592,10 @@ void Test::testDataPilot()
     aSaveData.SetDrillDown(true);
 
     // Check the sanity of the source range.
-    nCol1 = aSheetDesc.aSourceRange.aStart.Col();
-    nRow1 = aSheetDesc.aSourceRange.aStart.Row();
-    nRow2 = aSheetDesc.aSourceRange.aEnd.Row();
+    const ScRange& rSrcRange = aSheetDesc.GetSourceRange();
+    nCol1 = rSrcRange.aStart.Col();
+    nRow1 = rSrcRange.aStart.Row();
+    nRow2 = rSrcRange.aEnd.Row();
     CPPUNIT_ASSERT_MESSAGE("source range contains no data!", nRow2 - nRow1 > 1);
 
     // Set the dimension information.
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index d5d7a3a..36c5aac 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -276,10 +276,11 @@ void ScDPObject::SetSheetDesc(const ScSheetSourceDesc& rDesc)
 
     //	make valid QueryParam
 
-    pSheetDesc->aQueryParam.nCol1 = pSheetDesc->aSourceRange.aStart.Col();
-    pSheetDesc->aQueryParam.nRow1 = pSheetDesc->aSourceRange.aStart.Row();
-    pSheetDesc->aQueryParam.nCol2 = pSheetDesc->aSourceRange.aEnd.Col();
-    pSheetDesc->aQueryParam.nRow2 = pSheetDesc->aSourceRange.aEnd.Row();;
+    const ScRange& rSrcRange = pSheetDesc->GetSourceRange();
+    pSheetDesc->aQueryParam.nCol1 = rSrcRange.aStart.Col();
+    pSheetDesc->aQueryParam.nRow1 = rSrcRange.aStart.Row();
+    pSheetDesc->aQueryParam.nCol2 = rSrcRange.aEnd.Col();
+    pSheetDesc->aQueryParam.nRow2 = rSrcRange.aEnd.Row();;
     pSheetDesc->aQueryParam.bHasHeader = TRUE;
 
     InvalidateSource();		// new source must be created
@@ -695,12 +696,13 @@ void ScDPObject::UpdateReference( UpdateRefMode eUpdateRefMode,
 
     if ( pSheetDesc )
     {
-        nCol1 = pSheetDesc->aSourceRange.aStart.Col();
-        nRow1 = pSheetDesc->aSourceRange.aStart.Row();
-        nTab1 = pSheetDesc->aSourceRange.aStart.Tab();
-        nCol2 = pSheetDesc->aSourceRange.aEnd.Col();
-        nRow2 = pSheetDesc->aSourceRange.aEnd.Row();
-        nTab2 = pSheetDesc->aSourceRange.aEnd.Tab();
+        const ScRange& rSrcRange = pSheetDesc->GetSourceRange();
+        nCol1 = rSrcRange.aStart.Col();
+        nRow1 = rSrcRange.aStart.Row();
+        nTab1 = rSrcRange.aStart.Tab();
+        nCol2 = rSrcRange.aEnd.Col();
+        nRow2 = rSrcRange.aEnd.Row();
+        nTab2 = rSrcRange.aEnd.Tab();
 
         eRes = ScRefUpdate::Update( pDoc, eUpdateRefMode,
                 rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
@@ -709,10 +711,10 @@ void ScDPObject::UpdateReference( UpdateRefMode eUpdateRefMode,
         if ( eRes != UR_NOTHING )
         {
             ScSheetSourceDesc aNewDesc;
-            aNewDesc.aSourceRange = ScRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
+            aNewDesc.SetSourceRange(ScRange(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2));
 
-            SCsCOL nDiffX = nCol1 - (SCsCOL) pSheetDesc->aSourceRange.aStart.Col();
-            SCsROW nDiffY = nRow1 - (SCsROW) pSheetDesc->aSourceRange.aStart.Row();
+            SCsCOL nDiffX = nCol1 - (SCsCOL) pSheetDesc->GetSourceRange().aStart.Col();
+            SCsROW nDiffY = nRow1 - (SCsROW) pSheetDesc->GetSourceRange().aStart.Row();
 
             aNewDesc.aQueryParam = pSheetDesc->aQueryParam;
             aNewDesc.aQueryParam.nCol1 = sal::static_int_cast<SCCOL>( aNewDesc.aQueryParam.nCol1 + nDiffX );
@@ -736,7 +738,7 @@ BOOL ScDPObject::RefsEqual( const ScDPObject& r ) const
 
     if ( pSheetDesc && r.pSheetDesc )
     {
-        if ( pSheetDesc->aSourceRange != r.pSheetDesc->aSourceRange )
+        if ( pSheetDesc->GetSourceRange() != r.pSheetDesc->GetSourceRange() )
             return FALSE;
     }
     else if ( pSheetDesc || r.pSheetDesc )
@@ -1859,7 +1861,7 @@ BOOL ScDPObject::FillOldParam(ScPivotParam& rParam, BOOL bForFile) const
         // in old file format, columns are within document, not within source range
 
         DBG_ASSERT( pSheetDesc, "FillOldParam: bForFile, !pSheetDesc" );
-        nColAdd = pSheetDesc->aSourceRange.aStart.Col();
+        nColAdd = pSheetDesc->GetSourceRange().aStart.Col();
     }
 
     bool bAddData = ( lcl_GetDataGetOrientation( xSource ) == sheet::DataPilotFieldOrientation_HIDDEN );
@@ -2691,7 +2693,7 @@ ScDPTableDataCache* ScDPCollection::GetUsedDPObjectCache ( const ScRange& rRange
     for (size_t i=maTables.size(); i > 0 ; --i)
     {
         if ( const ScSheetSourceDesc* pUsedSheetDesc = maTables[i-1].GetSheetDesc() )
-            if ( rRange == pUsedSheetDesc->aSourceRange )
+            if ( rRange == pUsedSheetDesc->GetSourceRange() )
             {
                 long nID = maTables[i-1].GetCacheId();
                 if ( nID >= 0 )
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index dbb6cd2..176f917 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -284,7 +284,7 @@ ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID
         {
             pCache = new ScDPTableDataCache( pDoc );
 
-            pCache->InitFromDoc( pDoc, aSourceRange );
+            pCache->InitFromDoc( pDoc, GetSourceRange() );
             pCache->SetId( nID );
             pDoc->GetDPCollection()->AddDPObjectCache( pCache );
 
@@ -299,7 +299,7 @@ ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID
 
 ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache ( ScDocument* pDoc  ) const
 {
-    return pDoc->GetDPCollection()->GetUsedDPObjectCache( aSourceRange );
+    return pDoc->GetDPCollection()->GetUsedDPObjectCache( GetSourceRange() );
 }
 
 ScDPTableDataCache* ScSheetSourceDesc::GetCache( ScDocument* pDoc, long nID ) const
@@ -327,8 +327,8 @@ ULONG ScSheetSourceDesc::CheckSourceRange( ScDocument* pDoc ) const
     if (!pDoc)
         return STR_ERR_DATAPILOTSOURCE;
 
-    const ScAddress& s = aSrcRange.aStart();
-    const ScAddress& e = aSrcRange.aEnd();
+    const ScAddress& s = aSrcRange.aStart;
+    const ScAddress& e = aSrcRange.aEnd;
     for (SCCOL nCol = aSrcRange.aStart.Col(); nCol <= e.Col(); ++nCol)
     {
         if (pDoc->IsBlockEmpty(s.Tab(), nCol, s.Row(), nCol, s.Row()))
diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx
index 6b7f741..11e679f 100644
--- a/sc/source/filter/excel/xepivot.cxx
+++ b/sc/source/filter/excel/xepivot.cxx
@@ -640,7 +640,7 @@ XclExpPivotCache::XclExpPivotCache( const XclExpRoot& rRoot, const ScDPObject& r
             maDocSrcRange: Range used to get source data from Calc document.
                 This range may be shorter than maExpSrcRange to improve export
                 performance (#i22541#). */
-        maOrigSrcRange = maExpSrcRange = maDocSrcRange = pSrcDesc->aSourceRange;
+        maOrigSrcRange = maExpSrcRange = maDocSrcRange = pSrcDesc->GetSourceRange();
 
         // internal sheet data only
         SCTAB nScTab = maExpSrcRange.aStart.Tab();
@@ -717,7 +717,7 @@ bool XclExpPivotCache::HasEqualDataSource( const ScDPObject& rDPObj ) const
         compare the ScSheetSourceDesc. Later, there should be done more complicated
         comparisons regarding the source type of rDPObj and this cache. */
     if( const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc() )
-        return pSrcDesc->aSourceRange == maOrigSrcRange;
+        return pSrcDesc->GetSourceRange() == maOrigSrcRange;
     return false;
 }
 
diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx
index dc63f7e..daa19bd 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -1396,7 +1396,7 @@ void XclImpPivotTable::Convert()
 
     // create source descriptor
     ScSheetSourceDesc aDesc;
-    aDesc.aSourceRange = mxPCache->GetSourceRange();
+    aDesc.SetSourceRange(mxPCache->GetSourceRange());
 
     // adjust output range to include the page fields
     ScRange aOutRange( maOutScRange );
diff --git a/sc/source/filter/xml/XMLExportDataPilot.cxx b/sc/source/filter/xml/XMLExportDataPilot.cxx
index 42f0e31..4eab2ba 100644
--- a/sc/source/filter/xml/XMLExportDataPilot.cxx
+++ b/sc/source/filter/xml/XMLExportDataPilot.cxx
@@ -841,7 +841,7 @@ void ScXMLExportDataPilot::WriteDataPilots(const uno::Reference <sheet::XSpreads
                         {
                             const ScSheetSourceDesc* pSheetSource = (*pDPs)[i]->GetSheetDesc();
                             rtl::OUString sCellRangeAddress;
-                            ScRangeStringConverter::GetStringFromRange( sCellRangeAddress, pSheetSource->aSourceRange, pDoc, ::formula::FormulaGrammar::CONV_OOO );
+                            ScRangeStringConverter::GetStringFromRange( sCellRangeAddress, pSheetSource->GetSourceRange(), pDoc, ::formula::FormulaGrammar::CONV_OOO );
                             rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sCellRangeAddress);
                             SvXMLElementExport aElemSCR(rExport, XML_NAMESPACE_TABLE, XML_SOURCE_CELL_RANGE, sal_True, sal_True);
                             rExport.CheckAttrList();
diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index 774e622..1a746ce 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -446,7 +446,7 @@ void ScXMLDataPilotTableContext::EndElement()
                 if (bSourceCellRange)
                 {
                     ScSheetSourceDesc aSheetDesc;
-                    aSheetDesc.aSourceRange = aSourceCellRangeAddress;
+                    aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
                     aSheetDesc.SetQueryParam(aSourceQueryParam);
                     pDPObject->SetSheetDesc(aSheetDesc);
                 }
diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index 77dab61..e15a40d 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -248,7 +248,7 @@ void ScDPLayoutDlg::Init(bool bNewOutput)
     {
         aEdInPos.Enable();
         aRbInPos.Enable();
-        aOldRange = xDlgDPObject->GetSheetDesc()->aSourceRange;
+        aOldRange = xDlgDPObject->GetSheetDesc()->GetSourceRange();
         aOldRange.Format( inString, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
         aEdInPos.SetText(inString);
     }
@@ -1466,12 +1466,12 @@ void ScDPLayoutDlg::UpdateSrcRange()
     aBtnOk.Enable();
     ScSheetSourceDesc inSheet = *xDlgDPObject->GetSheetDesc();
 
-    if (inSheet.aSourceRange == aNewRange)
+    if (inSheet.GetSourceRange() == aNewRange)
         // new range is identical to the current range.  Nothing to do.
         return;
 
     ScTabViewShell * pTabViewShell = pViewData->GetViewShell();
-    inSheet.aSourceRange = aNewRange;
+    inSheet.SetSourceRange(aNewRange);
     xDlgDPObject->SetSheetDesc(inSheet);
     xDlgDPObject->FillOldParam( thePivotData, FALSE );
     xDlgDPObject->FillLabelData(thePivotData);
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index fe930d0..76206e2 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1355,7 +1355,7 @@ BOOL ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
                 if( pOldObj )
                 {   
                     const ScSheetSourceDesc* pSheetDesc = pOldObj->GetSheetDesc();
-                    if( pSheetDesc && pSheetDesc->aSourceRange.Intersects( aNewOut ) )
+                    if( pSheetDesc && pSheetDesc->GetSourceRange().Intersects( aNewOut ) )
                     {
                         ScRange aOldRange = pOldObj->GetOutRange();
                         SCsROW nDiff = aOldRange.aStart.Row()-aNewOut.aStart.Row();
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index 2bdad7c..0ac2822 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -486,7 +486,7 @@ void ScDocShell::RefreshPivotTables( const ScRange& rSource )
             if ( pOld )
             {
                 const ScSheetSourceDesc* pSheetDesc = pOld->GetSheetDesc();
-                if ( pSheetDesc && pSheetDesc->aSourceRange.Intersects( rSource ) )
+                if ( pSheetDesc && pSheetDesc->GetSourceRange().Intersects( rSource ) )
                 {
                     ScDPObject* pNew = new ScDPObject( *pOld );
                     ScDBDocFunc aFunc( *this );
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index 819a840..76ef5b4 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -707,7 +707,7 @@ CellRangeAddress SAL_CALL ScDataPilotDescriptorBase::getSourceRange()
 
     CellRangeAddress aRet;
     if (pDPObject->IsSheetData())
-        ScUnoConversion::FillApiRange( aRet, pDPObject->GetSheetDesc()->aSourceRange );
+        ScUnoConversion::FillApiRange( aRet, pDPObject->GetSheetDesc()->GetSourceRange() );
     return aRet;
 }
 
@@ -722,7 +722,10 @@ void SAL_CALL ScDataPilotDescriptorBase::setSourceRange( const CellRangeAddress&
     ScSheetSourceDesc aSheetDesc;
     if (pDPObject->IsSheetData())
         aSheetDesc = *pDPObject->GetSheetDesc();
-    ScUnoConversion::FillScRange( aSheetDesc.aSourceRange, aSourceRange );
+
+    ScRange aRange;
+    ScUnoConversion::FillScRange(aRange, aSourceRange);
+    aSheetDesc.SetSourceRange(aRange);
     pDPObject->SetSheetDesc( aSheetDesc );
     SetDPObject( pDPObject );
 }
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index bb4aea2..9d3db62 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -850,7 +850,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                                 if (bOK)
                                 {
                                     ScSheetSourceDesc aShtDesc;
-                                    aShtDesc.aSourceRange = aRange;
+                                    aShtDesc.SetSourceRange(aRange);
                                     pNewDPObject = new ScDPObject( pDoc );
                                     pNewDPObject->SetSheetDesc( aShtDesc );
 
diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index 1c018e2..aceda30 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -211,7 +211,7 @@ void ScGridWindow::DoPushButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt
             if (pDesc)
             {
                 aQueryParam = pDesc->GetQueryParam();
-                nSrcTab = pDesc->aSourceRange.aStart.Tab();
+                nSrcTab = pDesc->GetSourceRange().aStart.Tab();
             }
 
             SfxItemSet aArgSet( pViewData->GetViewShell()->GetPool(),
diff --git a/sc/source/ui/view/pivotsh.cxx b/sc/source/ui/view/pivotsh.cxx
index 9381b3a..c9d42a9 100644
--- a/sc/source/ui/view/pivotsh.cxx
+++ b/sc/source/ui/view/pivotsh.cxx
@@ -116,7 +116,7 @@ void ScPivotShell::Execute( SfxRequest& rReq )
                 if( pDesc )
                 {
                     aQueryParam = pDesc->GetQueryParam();
-                    nSrcTab = pDesc->aSourceRange.aStart.Tab();
+                    nSrcTab = pDesc->GetSourceRange().aStart.Tab();
                 }
 
                 ScViewData* pViewData = pViewShell->GetViewData();
commit cb3527334ebdb0f5d8b265a7335f17f37902d04b
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 14:45:11 2011 -0500

    renamed CheckValidate() to CheckSourceRange(), and cleaned it up.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 105a237..4b2d4df 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -65,7 +65,16 @@ struct ScSheetSourceDesc
 
     bool operator== ( const ScSheetSourceDesc& rOther ) const;
     ScDPTableDataCache* CreateCache( ScDocument* pDoc, long nID = -1) const;
-    ULONG CheckValidate( ScDocument* pDoc ) const;
+
+    /**
+     * Check the sanity of the data source range.
+     *
+     * @param pDoc document instance.
+     *
+     * @return 0 if the source range is sane, otherwise an error message ID is
+     *         returned.
+     */
+    ULONG CheckSourceRange( ScDocument* pDoc ) const;
     ScDPTableDataCache* GetCache( ScDocument* pDoc, long nID ) const;
     ScDPTableDataCache* GetExistDPObjectCache ( ScDocument* pDoc ) const;
     long GetCacheId( ScDocument* pDoc, long nID ) const;
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 5e1a43f..d5d7a3a 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2580,16 +2580,18 @@ ULONG ScDPObject::RefreshCache()
     CreateObjects();
     ULONG nErrId = 0;
     if ( pSheetDesc)
-        nErrId =  pSheetDesc->CheckValidate( pDoc );
+        nErrId =  pSheetDesc->CheckSourceRange( pDoc );
     if ( nErrId == 0 )
     {
+        // First remove the old cache if exists.
         ScDPCollection* pDPCollection = pDoc->GetDPCollection();
         long nOldId = GetCacheId();
         long nNewId = pDPCollection->GetNewDPObjectCacheId();
         if ( nOldId >= 0 )
             pDPCollection->RemoveDPObjectCache( nOldId );
 
-        ScDPTableDataCache* pCache  = NULL;
+        // Create a new cache.
+        ScDPTableDataCache* pCache = NULL;
         if ( pSheetDesc )
             pCache = pSheetDesc->CreateCache( pDoc, nNewId );
         else if ( pImpDesc )
@@ -2598,7 +2600,7 @@ ULONG ScDPObject::RefreshCache()
         if ( pCache == NULL )
         {
             //cache failed
-            DBG_ASSERT( pCache , " pCache == NULL" );
+            DBG_ASSERT( pCache , "pCache == NULL" );
             return STR_ERR_DATAPILOTSOURCE;
         }
 
@@ -2608,7 +2610,7 @@ ULONG ScDPObject::RefreshCache()
         size_t nCount = pDPCollection->GetCount();
         for (size_t i=0; i<nCount; ++i)
         { //set new cache id
-            if ( (*pDPCollection)[i]->GetCacheId() == nOldId  )
+            if ( (*pDPCollection)[i]->GetCacheId() == nOldId )
             {
                 (*pDPCollection)[i]->SetCacheId( nNewId );
                 (*pDPCollection)[i]->SetRefresh();
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 0e9a57e..dbb6cd2 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -279,7 +279,7 @@ ScDPTableDataCache* ScSheetSourceDesc::CreateCache( ScDocument* pDoc , long nID
         if ( pCache && ( nID < 0 || nID == pCache->GetId() ) )
             return pCache;
 
-        ULONG nErrId = CheckValidate( pDoc );
+        ULONG nErrId = CheckSourceRange( pDoc );
         if ( !nErrId )
         {
             pCache = new ScDPTableDataCache( pDoc );
@@ -301,6 +301,7 @@ ScDPTableDataCache* ScSheetSourceDesc::GetExistDPObjectCache ( ScDocument* pDoc
 {
     return pDoc->GetDPCollection()->GetUsedDPObjectCache( aSourceRange );
 }
+
 ScDPTableDataCache* ScSheetSourceDesc::GetCache( ScDocument* pDoc, long nID ) const
 {
     ScDPTableDataCache* pCache = pDoc->GetDPCollection()->GetDPObjectCache( nID );
@@ -320,30 +321,24 @@ long ScSheetSourceDesc:: GetCacheId( ScDocument* pDoc, long nID ) const
         return pCache->GetId();
 }
 
-ULONG ScSheetSourceDesc::CheckValidate( ScDocument* pDoc ) const
+ULONG ScSheetSourceDesc::CheckSourceRange( ScDocument* pDoc ) const
 {
-    ScRange aSrcRange( aSourceRange);
-    if ( !pDoc )
+    const ScRange& aSrcRange = GetSourceRange();
+    if (!pDoc)
         return STR_ERR_DATAPILOTSOURCE;
-    for(USHORT i= aSrcRange.aStart.Col();i <= aSrcRange.aEnd.Col();i++)
+
+    const ScAddress& s = aSrcRange.aStart();
+    const ScAddress& e = aSrcRange.aEnd();
+    for (SCCOL nCol = aSrcRange.aStart.Col(); nCol <= e.Col(); ++nCol)
     {
-        if ( pDoc->IsBlockEmpty( aSrcRange.aStart.Tab(),
-            i, aSrcRange.aStart.Row(),i, aSrcRange.aStart.Row()))
+        if (pDoc->IsBlockEmpty(s.Tab(), nCol, s.Row(), nCol, s.Row()))
             return STR_PIVOT_FIRSTROWEMPTYERR; 
     }
-    if( pDoc->IsBlockEmpty( aSrcRange.aStart.Tab(), aSrcRange.aStart.Col(), aSrcRange.aStart.Row()+1, aSrcRange.aEnd.Col(), aSrcRange.aEnd.Row() ) )
-    {
-        return STR_PIVOT_ONLYONEROWERR; 
-    }
-    return 0;
-}
-
-// -----------------------------------------------------------------------
-
-
-
-
 
+    if (pDoc->IsBlockEmpty(s.Tab(), s.Col(), s.Row()+1, e.Col(), e.Row()))
+        return STR_PIVOT_ONLYONEROWERR;
 
+    return 0;
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 4255ad871ab9566f00545278f873b295155df157
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 12:28:11 2011 -0500

    Fixed the failure to update table when hitting OK in the dialog.
    
    Modifying the source range of an existing data pilot table was not
    updating the table output because the data cache was not refereshed.

diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index c47055c..1878492 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -654,7 +654,10 @@ bool ScDBFunc::MakePivotTable( const ScDPSaveData& rData, const ScRange& rDest,
     else
         aObj.SetSaveData( rData );
 
-    BOOL bAllowMove = ( pDPObj != NULL );	// allow re-positioning when editing existing table
+    bool bAllowMove = (pDPObj != NULL);   // allow re-positioning when editing existing table
+
+    if (aObj.RefreshCache())
+        return false;
 
     ScDBDocFunc aFunc( *pDocSh );
     bool bSuccess = aFunc.DataPilotUpdate( pDPObj, &aObj, TRUE, FALSE, bAllowMove );
commit 0bf9e51919d131e7c9b03d5a781468b46d262c08
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jan 20 22:21:04 2011 -0500

    Store the data source type in the UI as we validate the string.

diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index 9a7114c..77dab61 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -188,8 +188,8 @@ ScDPLayoutDlg::ScDPLayoutDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pPar
                                 GetViewData() ),
         pDoc			( ((ScTabViewShell*)SfxViewShell::Current())->
                                 GetViewData()->GetDocument() ),
-        bRefInputMode   (false),

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list