Commits

Anonymous committed d32695d

#i94570# keep DataPilot table names unique, get document from DocShell in RefreshDPObject

Comments (0)

Files changed (6)

sc/inc/dpobject.hxx

 	virtual	ScDataObject*	Clone() const;
 
 	ScDPObject*	operator[](USHORT nIndex) const {return (ScDPObject*)At(nIndex);}
+    ScDPObject*	GetByName(const String& rName) const;
 
     void        DeleteOnTab( SCTAB nTab );
 	void		UpdateReference( UpdateRefMode eUpdateRefMode,

sc/source/core/data/dpobject.cxx

     }
 }
 
+ScDPObject* ScDPCollection::GetByName(const String& rName) const
+{
+    for (USHORT i=0; i<nCount; i++)
+        if (static_cast<const ScDPObject*>(pItems[i])->GetName() == rName)
+            return static_cast<ScDPObject*>(pItems[i]);
+    return NULL;
+}
+
 String ScDPCollection::CreateNewName( USHORT nMin ) const
 {
 	String aBase = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("DataPilot"));

sc/source/filter/xml/xmldpimp.cxx

 		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
+
 			pDPObject->SetAlive(sal_True);
             pDPCollection->InsertNewTable(pDPObject);
 		}

sc/source/ui/docshell/dbdocfun.cxx

 				//	output range must be set at pNewObj
 
 				pDestObj = new ScDPObject( *pNewObj );
+
+                // #i94570# When changing the output position in the dialog, a new table is created
+                // with the settings from the old table, including the name.
+                // So we have to check for duplicate names here (before inserting).
+                if ( pDoc->GetDPCollection()->GetByName(pDestObj->GetName()) )
+                    pDestObj->SetName( String() );      // ignore the invalid name, create a new name below
+
 				pDestObj->SetAlive(TRUE);
                 if ( !pDoc->GetDPCollection()->InsertNewTable(pDestObj) )
 				{

sc/source/ui/docshell/docsh.cxx

 					// else;  nothing has to happen, because it is a user given name
 				}
 			}
+
+            // #i94570# DataPilot table names have to be unique, or the tables can't be accessed by API.
+            // If no name (or an invalid name, skipped in ScXMLDataPilotTableContext::EndElement) was set, create a new name.
+            ScDPCollection* pDPCollection = aDocument.GetDPCollection();
+            if ( pDPCollection )
+            {
+                USHORT nDPCount = pDPCollection->GetCount();
+                for (USHORT nDP=0; nDP<nDPCount; nDP++)
+                {
+                    ScDPObject* pDPObj = (*pDPCollection)[nDP];
+                    if ( !pDPObj->GetName().Len() )
+                        pDPObj->SetName( pDPCollection->CreateNewName() );
+                }
+            }
 		}
 		ScColumn::bDoubleAlloc = sal_False;
     }

sc/source/ui/view/dbfunc3.cxx

 	if( !pDPObj )
 		return STR_PIVOT_NOTFOUND;
 
+    if ( pDocSh && !pDoc )
+        pDoc = pDocSh->GetDocument();
+
 	if( !pDoc  )
         return static_cast<ULONG>(-1);