diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-11 19:00:34 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-11 23:37:11 -0500 |
commit | f1a08de8483342400b39b3c0a0f37da00a6109fb (patch) | |
tree | d4ba2c6133715338fcda989c7cae66f005615c59 /sc/source/ui/docshell | |
parent | 12ff4cc60a87c0e9eddb1f354fd02e59d480b2de (diff) |
Add a variant of DataPilotUpdate that removes pivot table.
This one became pretty small.
Change-Id: Ic1e1e2b7afc35e5d1141a34722a6fe395832d936
Diffstat (limited to 'sc/source/ui/docshell')
-rw-r--r-- | sc/source/ui/docshell/dbdocfun.cxx | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 4cd2eefb6def..58b9a21b1a55 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -1204,6 +1204,17 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb return CreatePivotTable(*pNewObj, bRecord, bApi); } + if (pOldObj) + { + if (!pNewObj) + return RemovePivotTable(*pOldObj, bRecord, bApi); + + if (pOldObj == pNewObj) + return UpdatePivotTable(*pOldObj, bRecord, bApi); + } + + OSL_ASSERT(pOldObj && pNewObj && pOldObj != pNewObj); + ScDocShellModificator aModificator( rDocShell ); WaitObject aWait( rDocShell.GetActiveDialogParent() ); @@ -1455,6 +1466,79 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb return bDone; } +bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi) +{ + ScDocShellModificator aModificator(rDocShell); + WaitObject aWait(rDocShell.GetActiveDialogParent()); + + SAL_WNODEPRECATED_DECLARATIONS_PUSH + std::auto_ptr<ScDocument> pOldUndoDoc; + std::auto_ptr<ScDPObject> pUndoDPObj; + SAL_WNODEPRECATED_DECLARATIONS_POP + + if (bRecord) + pUndoDPObj.reset(new ScDPObject(rDPObj)); // copy old settings for undo + + ScDocument* pDoc = rDocShell.GetDocument(); + if (bRecord && !pDoc->IsUndoEnabled()) + bRecord = false; + if ( !rDocShell.IsEditable() || pDoc->GetChangeTrack() ) + { + // not recorded -> disallow + if (!bApi) + rDocShell.ErrorMessage(STR_PROTECTIONERR); + + return false; + } + + { + ScEditableTester aTester(pDoc, rDPObj.GetOutRange()); + if (!aTester.IsEditable()) + { + if (!bApi) + rDocShell.ErrorMessage(aTester.GetMessageId()); + + return false; + } + } + + // delete table + + ScRange aRange = rDPObj.GetOutRange(); + SCTAB nTab = aRange.aStart.Tab(); + + if (bRecord) + { + pOldUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO)); + pOldUndoDoc->InitUndo(pDoc, nTab, nTab); + pDoc->CopyToDocument(aRange, IDF_ALL, false, pOldUndoDoc.get()); + } + + pDoc->DeleteAreaTab( aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aEnd.Row(), + nTab, IDF_ALL ); + pDoc->RemoveFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aEnd.Row(), + nTab, SC_MF_AUTO ); + + pDoc->GetDPCollection()->FreeTable(&rDPObj); // object is deleted here + + rDocShell.PostPaintGridAll(); //! only necessary parts + rDocShell.PostPaint(aRange, PAINT_GRID); + + if (bRecord) + { + rDocShell.GetUndoManager()->AddUndoAction( + new ScUndoDataPilot( + &rDocShell, pOldUndoDoc.release(), NULL, pUndoDPObj.get(), NULL, false)); + + // pUndoDPObj is copied + } + + aModificator.SetDocumentModified(); + return true; +} + bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool bApi) { ScDocShellModificator aModificator(rDocShell); |