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 | |
parent | 12ff4cc60a87c0e9eddb1f354fd02e59d480b2de (diff) |
Add a variant of DataPilotUpdate that removes pivot table.
This one became pretty small.
Change-Id: Ic1e1e2b7afc35e5d1141a34722a6fe395832d936
-rw-r--r-- | sc/source/ui/docshell/dbdocfun.cxx | 84 | ||||
-rw-r--r-- | sc/source/ui/inc/dbdocfun.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/unoobj/dapiuno.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/dbfunc3.cxx | 2 |
4 files changed, 87 insertions, 2 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); diff --git a/sc/source/ui/inc/dbdocfun.hxx b/sc/source/ui/inc/dbdocfun.hxx index 71fbbb5c5761..ebd97473c75f 100644 --- a/sc/source/ui/inc/dbdocfun.hxx +++ b/sc/source/ui/inc/dbdocfun.hxx @@ -92,6 +92,7 @@ public: bool DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj, bool bRecord, bool bApi, bool bAllowMove = false ); + bool RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi); bool CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool bApi); bool UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi); diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx index 23313e722941..ac9293f5f63f 100644 --- a/sc/source/ui/unoobj/dapiuno.cxx +++ b/sc/source/ui/unoobj/dapiuno.cxx @@ -457,7 +457,7 @@ void SAL_CALL ScDataPilotTablesObj::removeByName( const OUString& aName ) if (pDPObj && pDocShell) { ScDBDocFunc aFunc(*pDocShell); - aFunc.DataPilotUpdate( pDPObj, NULL, sal_True, sal_True ); // remove - incl. undo etc. + aFunc.RemovePivotTable(*pDPObj, true, true); // remove - incl. undo etc. } else throw RuntimeException(); // no other exceptions specified diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index ff768cf501eb..714230a1c5c7 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -661,7 +661,7 @@ void ScDBFunc::DeletePivotTable() if ( pDPObj ) { ScDBDocFunc aFunc( *pDocSh ); - aFunc.DataPilotUpdate( pDPObj, NULL, sal_True, false ); + aFunc.RemovePivotTable(*pDPObj, true, false); CursorPosChanged(); // shells may be switched } else |