summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Nebel <nn@openoffice.org>2010-06-07 19:26:06 +0200
committerNiklas Nebel <nn@openoffice.org>2010-06-07 19:26:06 +0200
commit3de4d76f48fcde2915c94ba6a3541eb6cff69332 (patch)
treeecf9846040d0a27920a24c918e340264c328089c
parentba5ea750b1c821f7f2edc14061334d44d86bb8e1 (diff)
#i94570# keep DataPilot table names unique, get document from DocShell in RefreshDPObject
-rw-r--r--sc/inc/dpobject.hxx1
-rwxr-xr-xsc/source/core/data/dpobject.cxx8
-rw-r--r--sc/source/filter/xml/xmldpimp.cxx5
-rw-r--r--sc/source/ui/docshell/dbdocfun.cxx7
-rw-r--r--sc/source/ui/docshell/docsh.cxx14
-rwxr-xr-xsc/source/ui/view/dbfunc3.cxx3
6 files changed, 38 insertions, 0 deletions
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 65e89ec75d41..44aa1daa9a92 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -276,6 +276,7 @@ public:
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,
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 44c998fb4ede..b9eb7d88a44d 100755
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2429,6 +2429,14 @@ void ScDPCollection::WriteRefsTo( ScDPCollection& r ) const
}
}
+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"));
diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index 93e529c4ceca..ba107347b46a 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -464,6 +464,11 @@ void ScXMLDataPilotTableContext::EndElement()
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);
}
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 9895f0f43610..bc0b71d8e47b 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1275,6 +1275,13 @@ BOOL ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
// 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) )
{
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 9d37d417ec06..1e832427dc54 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -354,6 +354,20 @@ void ScDocShell::AfterXMLLoading(sal_Bool bRet)
// 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;
}
diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index 35befa8f7a36..dbdeae1ae0b1 100755
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -694,6 +694,9 @@ ULONG RefreshDPObject( ScDPObject *pDPObj, ScDocument *pDoc, ScDocShell *pDocSh,
if( !pDPObj )
return STR_PIVOT_NOTFOUND;
+ if ( pDocSh && !pDoc )
+ pDoc = pDocSh->GetDocument();
+
if( !pDoc )
return static_cast<ULONG>(-1);