[Libreoffice-commits] .: 11 commits - sc/inc sc/qa sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Jan 11 20:37:11 PST 2013
sc/inc/dpobject.hxx | 7
sc/qa/unit/ucalc.cxx | 1
sc/source/core/data/dpobject.cxx | 12
sc/source/filter/excel/xipivot.cxx | 1
sc/source/filter/xml/xmldpimp.cxx | 1
sc/source/ui/dbgui/pvlaydlg.cxx | 1
sc/source/ui/docshell/dbdocfun.cxx | 573 +++++++++++++++++++------------------
sc/source/ui/docshell/docsh5.cxx | 32 --
sc/source/ui/inc/dbdocfun.hxx | 2
sc/source/ui/undo/undodat.cxx | 1
sc/source/ui/unoobj/dapiuno.cxx | 5
sc/source/ui/view/dbfunc3.cxx | 2
12 files changed, 315 insertions(+), 323 deletions(-)
New commits:
commit fbc389bf17b7a2259380ade43fe15fd952c13eef
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 23:22:22 2013 -0500
Remove more duplicated code blocks.
Change-Id: I4b392a10b324ba082764df92a8640edb3e225666
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 1a20f6a..e25dda0 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1231,6 +1231,49 @@ SAL_WNODEPRECATED_DECLARATIONS_POP
pDoc->CopyToDocument(rRange, IDF_ALL, false, pUndoDoc.get());
}
+bool checkNewOutputRange(ScDPObject& rDPObj, ScDocShell& rDocShell, ScRange& rNewOut, bool bApi)
+{
+ ScDocument* pDoc = rDocShell.GetDocument();
+
+ bool bOverflow = false;
+ rNewOut = rDPObj.GetNewOutputRange(bOverflow);
+
+ // Test for overlap with source data range.
+ // TODO: Check with other pivot tables as well.
+ const ScSheetSourceDesc* pSheetDesc = rDPObj.GetSheetDesc();
+ if (pSheetDesc && pSheetDesc->GetSourceRange().Intersects(rNewOut))
+ {
+ // New output range intersepts with the source data. Move it up to
+ // where the old range is and see if that works.
+ ScRange aOldRange = rDPObj.GetOutRange();
+ SCsROW nDiff = aOldRange.aStart.Row() - rNewOut.aStart.Row();
+ rNewOut.aStart.SetRow(aOldRange.aStart.Row());
+ rNewOut.aEnd.IncRow(nDiff);
+ if (!ValidRow(rNewOut.aStart.Row()) || !ValidRow(rNewOut.aEnd.Row()))
+ bOverflow = true;
+ }
+
+ if (bOverflow)
+ {
+ if (!bApi)
+ rDocShell.ErrorMessage(STR_PIVOT_ERROR);
+
+ return false;
+ }
+
+ ScEditableTester aTester(pDoc, rNewOut);
+ if (!aTester.IsEditable())
+ {
+ // destination area isn't editable
+ if (!bApi)
+ rDocShell.ErrorMessage(aTester.GetMessageId());
+
+ return false;
+ }
+
+ return true;
+}
+
}
bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj,
@@ -1294,44 +1337,13 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
if (pOldObj->GetName().isEmpty())
pOldObj->SetName( pDoc->GetDPCollection()->CreateNewName() );
- bool bOverflow = false;
- ScRange aNewOut = pOldObj->GetNewOutputRange(bOverflow);
-
- //! test for overlap with other data pilot tables
- const ScSheetSourceDesc* pSheetDesc = pOldObj->GetSheetDesc();
- if (pSheetDesc && pSheetDesc->GetSourceRange().Intersects(aNewOut))
- {
- ScRange aOldRange = pOldObj->GetOutRange();
- SCsROW nDiff = aOldRange.aStart.Row() - aNewOut.aStart.Row();
- aNewOut.aStart.SetRow(aOldRange.aStart.Row());
- aNewOut.aEnd.SetRow(aNewOut.aEnd.Row() + nDiff);
- if (!ValidRow(aNewOut.aStart.Row()) || !ValidRow(aNewOut.aEnd.Row()))
- bOverflow = true;
- }
-
- if (bOverflow)
+ ScRange aNewOut;
+ if (!checkNewOutputRange(*pOldObj, rDocShell, aNewOut, bApi))
{
*pOldObj = aUndoDPObj;
-
- if (!bApi)
- rDocShell.ErrorMessage(STR_PIVOT_ERROR);
-
return false;
}
- {
- ScEditableTester aTester(pDoc, aNewOut);
- if (!aTester.IsEditable())
- {
- // destination area isn't editable
- //! reverse everything done so far, don't proceed
- if (!bApi)
- rDocShell.ErrorMessage(aTester.GetMessageId());
-
- return false;
- }
- }
-
// test if new output area is empty except for old area
if (!bApi)
{
@@ -1350,12 +1362,7 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
}
if (bRecord)
- {
- SCTAB nTab = aNewOut.aStart.Tab();
- pNewUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
- pNewUndoDoc->InitUndo(pDoc, nTab, nTab);
- pDoc->CopyToDocument(aNewOut, IDF_ALL, false, pNewUndoDoc.get());
- }
+ createUndoDoc(pNewUndoDoc, pDoc, aNewOut);
pOldObj->Output(aNewOut.aStart);
rDocShell.PostPaintGridAll(); //! only necessary parts
@@ -1514,12 +1521,7 @@ bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool
}
if (bRecord)
- {
- SCTAB nTab = aNewOut.aStart.Tab();
- pNewUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
- pNewUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument(aNewOut, IDF_ALL, false, pNewUndoDoc.get());
- }
+ createUndoDoc(pNewUndoDoc, pDoc, aNewOut);
rDestObj.Output(aNewOut.aStart);
rDocShell.PostPaintGridAll(); //! only necessary parts
@@ -1570,45 +1572,13 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
if (rDPObj.GetName().isEmpty())
rDPObj.SetName( pDoc->GetDPCollection()->CreateNewName() );
- bool bOverflow = false;
- ScRange aNewOut = rDPObj.GetNewOutputRange(bOverflow);
-
- //! test for overlap with other data pilot tables
- const ScSheetSourceDesc* pSheetDesc = rDPObj.GetSheetDesc();
- if (pSheetDesc && pSheetDesc->GetSourceRange().Intersects(aNewOut))
- {
- ScRange aOldRange = rDPObj.GetOutRange();
- SCsROW nDiff = aOldRange.aStart.Row()-aNewOut.aStart.Row();
- aNewOut.aStart.SetRow( aOldRange.aStart.Row() );
- aNewOut.aEnd.SetRow( aNewOut.aEnd.Row()+nDiff );
- if (!ValidRow(aNewOut.aStart.Row()) || !ValidRow(aNewOut.aEnd.Row()))
- bOverflow = true;
- }
-
- if (bOverflow)
+ ScRange aNewOut;
+ if (!checkNewOutputRange(rDPObj, rDocShell, aNewOut, bApi))
{
- if (!bApi)
- rDocShell.ErrorMessage(STR_PIVOT_ERROR);
-
rDPObj = aUndoDPObj;
return false;
}
- {
- ScEditableTester aTester(pDoc, aNewOut);
- if (!aTester.IsEditable())
- {
- // destination area isn't editable
- //! reverse everything done so far, don't proceed
-
- if (!bApi)
- rDocShell.ErrorMessage(aTester.GetMessageId());
-
- rDPObj = aUndoDPObj;
- return false;
- }
- }
-
// test if new output area is empty except for old area
if (!bApi)
{
@@ -1625,12 +1595,7 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
}
if (bRecord)
- {
- SCTAB nTab = aNewOut.aStart.Tab();
- pNewUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
- pNewUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument(aNewOut, IDF_ALL, false, pNewUndoDoc.get());
- }
+ createUndoDoc(pNewUndoDoc, pDoc, aNewOut);
rDPObj.Output(aNewOut.aStart);
rDocShell.PostPaintGridAll(); //! only necessary parts
commit 7eca12e396766dcf6ad7bf76ee3c0dfa49ac99c4
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 21:49:58 2013 -0500
Remove duplicate blocks.
Change-Id: If994ea2505078ea7133c162c95df4f89a3c5ba99
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 7ae010a..1a20f6a 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1221,6 +1221,16 @@ bool isEditable(ScDocShell& rDocShell, const ScRangeList& rRanges, bool bApi)
return true;
}
+SAL_WNODEPRECATED_DECLARATIONS_PUSH
+void createUndoDoc(std::auto_ptr<ScDocument>& pUndoDoc, ScDocument* pDoc, const ScRange& rRange)
+SAL_WNODEPRECATED_DECLARATIONS_POP
+{
+ SCTAB nTab = rRange.aStart.Tab();
+ pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
+ pUndoDoc->InitUndo(pDoc, nTab, nTab);
+ pDoc->CopyToDocument(rRange, IDF_ALL, false, pUndoDoc.get());
+}
+
}
bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj,
@@ -1266,13 +1276,7 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
bRecord = false;
if (bRecord)
- {
- ScRange aRange = pOldObj->GetOutRange();
- SCTAB nTab = aRange.aStart.Tab();
- pOldUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
- pOldUndoDoc->InitUndo(pDoc, nTab, nTab);
- pDoc->CopyToDocument(aRange, IDF_ALL, false, pOldUndoDoc.get());
- }
+ createUndoDoc(pOldUndoDoc, pDoc, pOldObj->GetOutRange());
pNewObj->WriteSourceDataTo(*pOldObj); // copy source data
@@ -1396,11 +1400,7 @@ bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
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());
- }
+ createUndoDoc(pOldUndoDoc, pDoc, aRange);
pDoc->DeleteAreaTab( aRange.aStart.Col(), aRange.aStart.Row(),
aRange.aEnd.Col(), aRange.aEnd.Row(),
@@ -1557,13 +1557,7 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
bRecord = false;
if (bRecord)
- {
- ScRange aRange = rDPObj.GetOutRange();
- SCTAB nTab = aRange.aStart.Tab();
- pOldUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
- pOldUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument(aRange, IDF_ALL, false, pOldUndoDoc.get());
- }
+ createUndoDoc(pOldUndoDoc, pDoc, rDPObj.GetOutRange());
rDPObj.SetAllowMove(false);
rDPObj.ReloadGroupTableData();
commit cb5be2219787ad7c0a50c5daaaca217179c6811b
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 21:39:54 2013 -0500
Redo DataPilotUpdate() as well.
Change-Id: I8c53c233f42b6640ef8d77982082945e07882979
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 2be91364..7ae010a 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1254,156 +1254,120 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
if (!isEditable(rDocShell, aRanges, bApi))
return false;
- bool bDone = false;
- bool bUndoSelf = false;
- sal_uInt16 nErrId = 0;
+ SAL_WNODEPRECATED_DECLARATIONS_PUSH
+ std::auto_ptr<ScDocument> pOldUndoDoc;
+ std::auto_ptr<ScDocument> pNewUndoDoc;
+ SAL_WNODEPRECATED_DECLARATIONS_POP
- ScDocument* pOldUndoDoc = NULL;
- ScDocument* pNewUndoDoc = NULL;
- ScDPObject* pUndoDPObj = NULL;
- if ( bRecord && pOldObj )
- pUndoDPObj = new ScDPObject( *pOldObj ); // copy old settings for undo
+ ScDPObject aUndoDPObj(*pOldObj); // for undo or revert on failure
ScDocument* pDoc = rDocShell.GetDocument();
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- ScDPObject* pDestObj = NULL;
- if ( !nErrId )
+ if (bRecord)
{
- if ( bRecord )
- {
- ScRange aRange = pOldObj->GetOutRange();
- SCTAB nTab = aRange.aStart.Tab();
- pOldUndoDoc = new ScDocument( SCDOCMODE_UNDO );
- pOldUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument( aRange, IDF_ALL, false, pOldUndoDoc );
- }
+ ScRange aRange = pOldObj->GetOutRange();
+ SCTAB nTab = aRange.aStart.Tab();
+ pOldUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
+ pOldUndoDoc->InitUndo(pDoc, nTab, nTab);
+ pDoc->CopyToDocument(aRange, IDF_ALL, false, pOldUndoDoc.get());
+ }
- pNewObj->WriteSourceDataTo( *pOldObj ); // copy source data
+ pNewObj->WriteSourceDataTo(*pOldObj); // copy source data
- ScDPSaveData* pData = pNewObj->GetSaveData();
- OSL_ENSURE( pData, "no SaveData from living DPObject" );
- if ( pData )
- pOldObj->SetSaveData( *pData ); // copy SaveData
+ ScDPSaveData* pData = pNewObj->GetSaveData();
+ OSL_ENSURE( pData, "no SaveData from living DPObject" );
+ if (pData)
+ pOldObj->SetSaveData(*pData); // copy SaveData
- pDestObj = pOldObj;
- pDestObj->SetAllowMove(bAllowMove);
- pDestObj->ReloadGroupTableData();
- pDestObj->SyncAllDimensionMembers();
- pDestObj->InvalidateData(); // before getting the new output area
+ pOldObj->SetAllowMove(bAllowMove);
+ pOldObj->ReloadGroupTableData();
+ pOldObj->SyncAllDimensionMembers();
+ pOldObj->InvalidateData(); // before getting the new output area
- // make sure the table has a name (not set by dialog)
- if (pDestObj->GetName().isEmpty())
- pDestObj->SetName( pDoc->GetDPCollection()->CreateNewName() );
+ // make sure the table has a name (not set by dialog)
+ if (pOldObj->GetName().isEmpty())
+ pOldObj->SetName( pDoc->GetDPCollection()->CreateNewName() );
- bool bOverflow = false;
- ScRange aNewOut = pDestObj->GetNewOutputRange( bOverflow );
+ bool bOverflow = false;
+ ScRange aNewOut = pOldObj->GetNewOutputRange(bOverflow);
- //! test for overlap with other data pilot tables
- const ScSheetSourceDesc* pSheetDesc = pOldObj->GetSheetDesc();
- if( pSheetDesc && pSheetDesc->GetSourceRange().Intersects( aNewOut ) )
- {
- ScRange aOldRange = pOldObj->GetOutRange();
- SCsROW nDiff = aOldRange.aStart.Row()-aNewOut.aStart.Row();
- aNewOut.aStart.SetRow( aOldRange.aStart.Row() );
- aNewOut.aEnd.SetRow( aNewOut.aEnd.Row()+nDiff );
- if( !ValidRow( aNewOut.aStart.Row() ) || !ValidRow( aNewOut.aEnd.Row() ) )
- bOverflow = sal_True;
- }
+ //! test for overlap with other data pilot tables
+ const ScSheetSourceDesc* pSheetDesc = pOldObj->GetSheetDesc();
+ if (pSheetDesc && pSheetDesc->GetSourceRange().Intersects(aNewOut))
+ {
+ ScRange aOldRange = pOldObj->GetOutRange();
+ SCsROW nDiff = aOldRange.aStart.Row() - aNewOut.aStart.Row();
+ aNewOut.aStart.SetRow(aOldRange.aStart.Row());
+ aNewOut.aEnd.SetRow(aNewOut.aEnd.Row() + nDiff);
+ if (!ValidRow(aNewOut.aStart.Row()) || !ValidRow(aNewOut.aEnd.Row()))
+ bOverflow = true;
+ }
- if ( bOverflow )
- {
- // like with STR_PROTECTIONERR, use undo to reverse everything
- OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
- bUndoSelf = true;
- nErrId = STR_PIVOT_ERROR;
- }
- else
- {
- ScEditableTester aTester( pDoc, aNewOut );
- if ( !aTester.IsEditable() )
- {
- // destination area isn't editable
- //! reverse everything done so far, don't proceed
-
- // quick solution: proceed to end, use undo action
- // to reverse everything:
- OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
- bUndoSelf = sal_True;
- nErrId = aTester.GetMessageId();
- }
- }
+ if (bOverflow)
+ {
+ *pOldObj = aUndoDPObj;
- // test if new output area is empty except for old area
- if ( !bApi )
- {
- // OutRange of pOldObj (pDestObj) is still old area
- bool bEmpty = lcl_EmptyExcept( pDoc, aNewOut, pOldObj->GetOutRange() );
+ if (!bApi)
+ rDocShell.ErrorMessage(STR_PIVOT_ERROR);
- if ( !bEmpty )
- {
- QueryBox aBox( rDocShell.GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
- ScGlobal::GetRscString(STR_PIVOT_NOTEMPTY) );
- if (aBox.Execute() == RET_NO)
- {
- //! like above (not editable), use undo to reverse everything
- OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
- bUndoSelf = true;
- }
- }
- }
+ return false;
+ }
- if ( bRecord )
+ {
+ ScEditableTester aTester(pDoc, aNewOut);
+ if (!aTester.IsEditable())
{
- SCTAB nTab = aNewOut.aStart.Tab();
- pNewUndoDoc = new ScDocument( SCDOCMODE_UNDO );
- pNewUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument( aNewOut, IDF_ALL, false, pNewUndoDoc );
- }
-
- pDestObj->Output( aNewOut.aStart );
+ // destination area isn't editable
+ //! reverse everything done so far, don't proceed
+ if (!bApi)
+ rDocShell.ErrorMessage(aTester.GetMessageId());
- rDocShell.PostPaintGridAll(); //! only necessary parts
- bDone = true;
+ return false;
+ }
}
- if ( bRecord && bDone )
+ // test if new output area is empty except for old area
+ if (!bApi)
{
- SfxUndoAction* pAction = new ScUndoDataPilot( &rDocShell,
- pOldUndoDoc, pNewUndoDoc, pUndoDPObj, pDestObj, bAllowMove );
- pOldUndoDoc = NULL;
- pNewUndoDoc = NULL; // pointers are used in undo action
- // pUndoDPObj is copied
-
- if (bUndoSelf)
+ // OutRange of pOldObj (pDestObj) is still old area
+ if (!lcl_EmptyExcept(pDoc, aNewOut, pOldObj->GetOutRange()))
{
- // use undo action to restore original state
- //! prevent setting the document modified? (ScDocShellModificator)
-
- pAction->Undo();
- delete pAction;
- bDone = false;
+ QueryBox aBox( rDocShell.GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
+ ScGlobal::GetRscString(STR_PIVOT_NOTEMPTY) );
+ if (aBox.Execute() == RET_NO)
+ {
+ //! like above (not editable)
+ *pOldObj = aUndoDPObj;
+ return false;
+ }
}
- else
- rDocShell.GetUndoManager()->AddUndoAction( pAction );
}
- delete pOldUndoDoc; // if not used for undo
- delete pNewUndoDoc;
- delete pUndoDPObj;
+ if (bRecord)
+ {
+ SCTAB nTab = aNewOut.aStart.Tab();
+ pNewUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
+ pNewUndoDoc->InitUndo(pDoc, nTab, nTab);
+ pDoc->CopyToDocument(aNewOut, IDF_ALL, false, pNewUndoDoc.get());
+ }
- if (bDone)
+ pOldObj->Output(aNewOut.aStart);
+ rDocShell.PostPaintGridAll(); //! only necessary parts
+
+ if (bRecord)
{
- // notify API objects
- pDoc->BroadcastUno( ScDataPilotModifiedHint( pDestObj->GetName() ) );
- aModificator.SetDocumentModified();
+ rDocShell.GetUndoManager()->AddUndoAction(
+ new ScUndoDataPilot(
+ &rDocShell, pOldUndoDoc.release(), pNewUndoDoc.release(), &aUndoDPObj, pOldObj, bAllowMove));
}
- if ( nErrId && !bApi )
- rDocShell.ErrorMessage( nErrId );
+ // notify API objects
+ pDoc->BroadcastUno( ScDataPilotModifiedHint(pOldObj->GetName()) );
+ aModificator.SetDocumentModified();
- return bDone;
+ return true;
}
bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
@@ -1629,9 +1593,6 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
if (bOverflow)
{
- // like with STR_PROTECTIONERR, use undo to reverse everything
- OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
-
if (!bApi)
rDocShell.ErrorMessage(STR_PIVOT_ERROR);
@@ -1682,11 +1643,9 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
if (bRecord)
{
- SfxUndoAction *const pAction(
+ rDocShell.GetUndoManager()->AddUndoAction(
new ScUndoDataPilot(
&rDocShell, pOldUndoDoc.release(), pNewUndoDoc.release(), &aUndoDPObj, &rDPObj, false));
-
- rDocShell.GetUndoManager()->AddUndoAction(pAction);
}
// notify API objects
commit 4dbce30757f3cbe8e083e2c85c2456554ba81402
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 20:55:48 2013 -0500
Actually let's do these earlier so we can bail out early.
Change-Id: I1903efe4dba876e4d373cc329c66595840d7be81
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 26071c0..2be91364 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1411,6 +1411,9 @@ bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
ScDocShellModificator aModificator(rDocShell);
WaitObject aWait(rDocShell.GetActiveDialogParent());
+ if (!isEditable(rDocShell, rDPObj.GetOutRange(), bApi))
+ return false;
+
SAL_WNODEPRECATED_DECLARATIONS_PUSH
std::auto_ptr<ScDocument> pOldUndoDoc;
std::auto_ptr<ScDPObject> pUndoDPObj;
@@ -1423,9 +1426,6 @@ bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- if (!isEditable(rDocShell, rDPObj.GetOutRange(), bApi))
- return false;
-
// delete table
ScRange aRange = rDPObj.GetOutRange();
@@ -1468,6 +1468,10 @@ bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool
ScDocShellModificator aModificator(rDocShell);
WaitObject aWait(rDocShell.GetActiveDialogParent());
+ // At least one cell in the output range should be editable. Check in advance.
+ if (!isEditable(rDocShell, ScRange(rDPObj.GetOutRange().aStart), bApi))
+ return false;
+
SAL_WNODEPRECATED_DECLARATIONS_PUSH
std::auto_ptr<ScDocument> pNewUndoDoc;
SAL_WNODEPRECATED_DECLARATIONS_POP
@@ -1476,10 +1480,6 @@ bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- // At least one cell in the output range should be editable. Check in advance.
- if (!isEditable(rDocShell, ScRange(rDPObj.GetOutRange().aStart), bApi))
- return false;
-
// output range must be set at pNewObj
SAL_WNODEPRECATED_DECLARATIONS_PUSH
std::auto_ptr<ScDPObject> pDestObj(new ScDPObject(rDPObj));
@@ -1578,6 +1578,9 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
ScDocShellModificator aModificator( rDocShell );
WaitObject aWait( rDocShell.GetActiveDialogParent() );
+ if (!isEditable(rDocShell, rDPObj.GetOutRange(), bApi))
+ return false;
+
SAL_WNODEPRECATED_DECLARATIONS_PUSH
std::auto_ptr<ScDocument> pOldUndoDoc;
std::auto_ptr<ScDocument> pNewUndoDoc;
@@ -1589,9 +1592,6 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- if (!isEditable(rDocShell, rDPObj.GetOutRange(), bApi))
- return false;
-
if (bRecord)
{
ScRange aRange = rDPObj.GetOutRange();
commit 676c5a2a9235459a948eddf5bb93ebeb6c23dac3
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 20:41:21 2013 -0500
Check this first before instantiating heap objects.
To prevent memory leak.
Change-Id: Ia4a5bb3fbad8bdd5646bc92c405458b929b5f7da
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index cf962c2..26071c0 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1248,6 +1248,12 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
ScDocShellModificator aModificator( rDocShell );
WaitObject aWait( rDocShell.GetActiveDialogParent() );
+ ScRangeList aRanges;
+ aRanges.Append(pOldObj->GetOutRange());
+ aRanges.Append(pNewObj->GetOutRange().aStart); // at least one cell in the output position must be editable.
+ if (!isEditable(rDocShell, aRanges, bApi))
+ return false;
+
bool bDone = false;
bool bUndoSelf = false;
sal_uInt16 nErrId = 0;
@@ -1262,12 +1268,6 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- ScRangeList aRanges;
- aRanges.Append(pOldObj->GetOutRange());
- aRanges.Append(pNewObj->GetOutRange().aStart); // at least one cell in the output position must be editable.
- if (!isEditable(rDocShell, aRanges, bApi))
- return false;
-
ScDPObject* pDestObj = NULL;
if ( !nErrId )
{
commit 37cdf01c4e6de756c3ea3e05f9a648dc32c8e3d3
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 20:35:43 2013 -0500
Remove duplicate code blocks.
Change-Id: I403b6a1e3639c221b007f38ad07daf19dfd8e643
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 6882942..cf962c2 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1174,9 +1174,9 @@ sal_Bool ScDBDocFunc::DoSubTotals( SCTAB nTab, const ScSubTotalParam& rParam,
return bRet;
}
-//==================================================================
+namespace {
-static sal_Bool lcl_EmptyExcept( ScDocument* pDoc, const ScRange& rRange, const ScRange& rExcept )
+bool lcl_EmptyExcept( ScDocument* pDoc, const ScRange& rRange, const ScRange& rExcept )
{
ScCellIterator aIter( pDoc, rRange );
ScBaseCell* pCell = aIter.GetFirst();
@@ -1190,7 +1190,37 @@ static sal_Bool lcl_EmptyExcept( ScDocument* pDoc, const ScRange& rRange, const
pCell = aIter.GetNext();
}
- return sal_True; // nothing found - empty
+ return true; // nothing found - empty
+}
+
+bool isEditable(ScDocShell& rDocShell, const ScRangeList& rRanges, bool bApi)
+{
+ ScDocument* pDoc = rDocShell.GetDocument();
+ if (!rDocShell.IsEditable() || pDoc->GetChangeTrack())
+ {
+ // not recorded -> disallow
+ if (!bApi)
+ rDocShell.ErrorMessage(STR_PROTECTIONERR);
+
+ return false;
+ }
+
+ for (size_t i = 0, n = rRanges.size(); i < n; ++i)
+ {
+ const ScRange* p = rRanges[i];
+ ScEditableTester aTester(pDoc, *p);
+ if (!aTester.IsEditable())
+ {
+ if (!bApi)
+ rDocShell.ErrorMessage(aTester.GetMessageId());
+
+ return false;
+ }
+ }
+
+ return true;
+}
+
}
bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj,
@@ -1231,31 +1261,12 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
ScDocument* pDoc = rDocShell.GetDocument();
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- if ( !rDocShell.IsEditable() || pDoc->GetChangeTrack() )
- {
- // not recorded -> disallow
- //! different error messages?
- nErrId = STR_PROTECTIONERR;
- }
- if (!nErrId)
- {
- ScRange aOldOut = pOldObj->GetOutRange();
- ScEditableTester aTester( pDoc, aOldOut );
- if ( !aTester.IsEditable() )
- nErrId = aTester.GetMessageId();
- }
- if (!nErrId)
- {
- // at least one cell at the output position must be editable
- // -> check in advance
- // (start of output range in pNewObj is valid)
-
- ScRange aNewStart( pNewObj->GetOutRange().aStart );
- ScEditableTester aTester( pDoc, aNewStart );
- if ( !aTester.IsEditable() )
- nErrId = aTester.GetMessageId();
- }
+ ScRangeList aRanges;
+ aRanges.Append(pOldObj->GetOutRange());
+ aRanges.Append(pNewObj->GetOutRange().aStart); // at least one cell in the output position must be editable.
+ if (!isEditable(rDocShell, aRanges, bApi))
+ return false;
ScDPObject* pDestObj = NULL;
if ( !nErrId )
@@ -1411,25 +1422,9 @@ bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
ScDocument* pDoc = rDocShell.GetDocument();
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- if ( !rDocShell.IsEditable() || pDoc->GetChangeTrack() )
- {
- // not recorded -> disallow
- if (!bApi)
- rDocShell.ErrorMessage(STR_PROTECTIONERR);
+ if (!isEditable(rDocShell, rDPObj.GetOutRange(), bApi))
return false;
- }
-
- {
- ScEditableTester aTester(pDoc, rDPObj.GetOutRange());
- if (!aTester.IsEditable())
- {
- if (!bApi)
- rDocShell.ErrorMessage(aTester.GetMessageId());
-
- return false;
- }
- }
// delete table
@@ -1481,28 +1476,9 @@ bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- if (!rDocShell.IsEditable() || pDoc->GetChangeTrack())
- {
- // not recorded -> disallow
- if (!bApi)
- rDocShell.ErrorMessage(STR_PROTECTIONERR);
-
+ // At least one cell in the output range should be editable. Check in advance.
+ if (!isEditable(rDocShell, ScRange(rDPObj.GetOutRange().aStart), bApi))
return false;
- }
-
- {
- // at least one cell at the output position must be editable
- // -> check in advance
- // (start of output range in pNewObj is valid)
- ScEditableTester aTester(pDoc, rDPObj.GetOutRange().aStart);
- if (!aTester.IsEditable())
- {
- if (!bApi)
- rDocShell.ErrorMessage(aTester.GetMessageId());
-
- return false;
- }
- }
// output range must be set at pNewObj
SAL_WNODEPRECATED_DECLARATIONS_PUSH
@@ -1613,26 +1589,8 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi)
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- if (!rDocShell.IsEditable() || pDoc->GetChangeTrack())
- {
- // not recorded -> disallow
- //! different error messages?
- if (!bApi)
- rDocShell.ErrorMessage(STR_PROTECTIONERR);
-
+ if (!isEditable(rDocShell, rDPObj.GetOutRange(), bApi))
return false;
- }
-
- {
- ScEditableTester aTester(pDoc, rDPObj.GetOutRange());
- if (!aTester.IsEditable())
- {
- if (!bApi)
- rDocShell.ErrorMessage(aTester.GetMessageId());
-
- return false;
- }
- }
if (bRecord)
{
commit 5ae038858f9e54516f376571de8c10c35d9d65db
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 19:20:54 2013 -0500
Remove all checks for NULL pointers from DataPilotUpdate().
Now we can safely assume that both pOldObj and pNewObj are non-NULL,
and they are not equal. Remove unnecessary checks to make the code
simpler.
Change-Id: I263dc377aeb245dc9261b40ee0605e2cb54c28f2
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 58b9a21..6882942 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1238,14 +1238,14 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
nErrId = STR_PROTECTIONERR;
}
- if ( pOldObj && !nErrId )
+ if (!nErrId)
{
ScRange aOldOut = pOldObj->GetOutRange();
ScEditableTester aTester( pDoc, aOldOut );
if ( !aTester.IsEditable() )
nErrId = aTester.GetMessageId();
}
- if ( pNewObj && !nErrId )
+ if (!nErrId)
{
// at least one cell at the output position must be editable
// -> check in advance
@@ -1260,171 +1260,101 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
ScDPObject* pDestObj = NULL;
if ( !nErrId )
{
- if ( pOldObj && !pNewObj )
+ if ( bRecord )
{
- // delete table
-
ScRange aRange = pOldObj->GetOutRange();
SCTAB nTab = aRange.aStart.Tab();
+ pOldUndoDoc = new ScDocument( SCDOCMODE_UNDO );
+ pOldUndoDoc->InitUndo( pDoc, nTab, nTab );
+ pDoc->CopyToDocument( aRange, IDF_ALL, false, pOldUndoDoc );
+ }
- if ( bRecord )
- {
- pOldUndoDoc = new ScDocument( SCDOCMODE_UNDO );
- pOldUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument( aRange, IDF_ALL, false, pOldUndoDoc );
- }
+ pNewObj->WriteSourceDataTo( *pOldObj ); // copy source data
- 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 );
+ ScDPSaveData* pData = pNewObj->GetSaveData();
+ OSL_ENSURE( pData, "no SaveData from living DPObject" );
+ if ( pData )
+ pOldObj->SetSaveData( *pData ); // copy SaveData
- pDoc->GetDPCollection()->FreeTable( pOldObj ); // object is deleted here
+ pDestObj = pOldObj;
+ pDestObj->SetAllowMove(bAllowMove);
+ pDestObj->ReloadGroupTableData();
+ pDestObj->SyncAllDimensionMembers();
+ pDestObj->InvalidateData(); // before getting the new output area
- rDocShell.PostPaintGridAll(); //! only necessary parts
- rDocShell.PostPaint(aRange, PAINT_GRID);
- bDone = true;
- }
- else if ( pNewObj )
- {
- if ( pOldObj )
- {
- if ( bRecord )
- {
- ScRange aRange = pOldObj->GetOutRange();
- SCTAB nTab = aRange.aStart.Tab();
- pOldUndoDoc = new ScDocument( SCDOCMODE_UNDO );
- pOldUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument( aRange, IDF_ALL, false, pOldUndoDoc );
- }
+ // make sure the table has a name (not set by dialog)
+ if (pDestObj->GetName().isEmpty())
+ pDestObj->SetName( pDoc->GetDPCollection()->CreateNewName() );
- if ( pNewObj == pOldObj )
- {
- // refresh only - no settings modified
- }
- else
- {
- pNewObj->WriteSourceDataTo( *pOldObj ); // copy source data
+ bool bOverflow = false;
+ ScRange aNewOut = pDestObj->GetNewOutputRange( bOverflow );
- ScDPSaveData* pData = pNewObj->GetSaveData();
- OSL_ENSURE( pData, "no SaveData from living DPObject" );
- if ( pData )
- pOldObj->SetSaveData( *pData ); // copy SaveData
- }
+ //! test for overlap with other data pilot tables
+ const ScSheetSourceDesc* pSheetDesc = pOldObj->GetSheetDesc();
+ if( pSheetDesc && pSheetDesc->GetSourceRange().Intersects( aNewOut ) )
+ {
+ ScRange aOldRange = pOldObj->GetOutRange();
+ SCsROW nDiff = aOldRange.aStart.Row()-aNewOut.aStart.Row();
+ aNewOut.aStart.SetRow( aOldRange.aStart.Row() );
+ aNewOut.aEnd.SetRow( aNewOut.aEnd.Row()+nDiff );
+ if( !ValidRow( aNewOut.aStart.Row() ) || !ValidRow( aNewOut.aEnd.Row() ) )
+ bOverflow = sal_True;
+ }
- pDestObj = pOldObj;
- pDestObj->SetAllowMove( bAllowMove );
- }
- else
+ if ( bOverflow )
+ {
+ // like with STR_PROTECTIONERR, use undo to reverse everything
+ OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
+ bUndoSelf = true;
+ nErrId = STR_PIVOT_ERROR;
+ }
+ else
+ {
+ ScEditableTester aTester( pDoc, aNewOut );
+ if ( !aTester.IsEditable() )
{
- // 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
-
- if ( !pDoc->GetDPCollection()->InsertNewTable(pDestObj) )
- {
- OSL_FAIL("cannot insert DPObject");
- DELETEZ( pDestObj );
- }
+ // destination area isn't editable
+ //! reverse everything done so far, don't proceed
+
+ // quick solution: proceed to end, use undo action
+ // to reverse everything:
+ OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
+ bUndoSelf = sal_True;
+ nErrId = aTester.GetMessageId();
}
- if ( pDestObj )
- {
- pDestObj->ReloadGroupTableData();
- pDestObj->SyncAllDimensionMembers();
- pDestObj->InvalidateData(); // before getting the new output area
-
- // make sure the table has a name (not set by dialog)
- if (pDestObj->GetName().isEmpty())
- pDestObj->SetName( pDoc->GetDPCollection()->CreateNewName() );
-
- bool bOverflow = false;
- ScRange aNewOut = pDestObj->GetNewOutputRange( bOverflow );
+ }
- //! test for overlap with other data pilot tables
- if( pOldObj )
- {
- const ScSheetSourceDesc* pSheetDesc = pOldObj->GetSheetDesc();
- if( pSheetDesc && pSheetDesc->GetSourceRange().Intersects( aNewOut ) )
- {
- ScRange aOldRange = pOldObj->GetOutRange();
- SCsROW nDiff = aOldRange.aStart.Row()-aNewOut.aStart.Row();
- aNewOut.aStart.SetRow( aOldRange.aStart.Row() );
- aNewOut.aEnd.SetRow( aNewOut.aEnd.Row()+nDiff );
- if( !ValidRow( aNewOut.aStart.Row() ) || !ValidRow( aNewOut.aEnd.Row() ) )
- bOverflow = sal_True;
- }
- }
+ // test if new output area is empty except for old area
+ if ( !bApi )
+ {
+ // OutRange of pOldObj (pDestObj) is still old area
+ bool bEmpty = lcl_EmptyExcept( pDoc, aNewOut, pOldObj->GetOutRange() );
- if ( bOverflow )
+ if ( !bEmpty )
+ {
+ QueryBox aBox( rDocShell.GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
+ ScGlobal::GetRscString(STR_PIVOT_NOTEMPTY) );
+ if (aBox.Execute() == RET_NO)
{
- // like with STR_PROTECTIONERR, use undo to reverse everything
+ //! like above (not editable), use undo to reverse everything
OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
bUndoSelf = true;
- nErrId = STR_PIVOT_ERROR;
- }
- else
- {
- ScEditableTester aTester( pDoc, aNewOut );
- if ( !aTester.IsEditable() )
- {
- // destination area isn't editable
- //! reverse everything done so far, don't proceed
-
- // quick solution: proceed to end, use undo action
- // to reverse everything:
- OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
- bUndoSelf = sal_True;
- nErrId = aTester.GetMessageId();
- }
- }
-
- // test if new output area is empty except for old area
- if ( !bApi )
- {
- bool bEmpty;
- if ( pOldObj ) // OutRange of pOldObj (pDestObj) is still old area
- bEmpty = lcl_EmptyExcept( pDoc, aNewOut, pOldObj->GetOutRange() );
- else
- bEmpty = pDoc->IsBlockEmpty( aNewOut.aStart.Tab(),
- aNewOut.aStart.Col(), aNewOut.aStart.Row(),
- aNewOut.aEnd.Col(), aNewOut.aEnd.Row() );
-
- if ( !bEmpty )
- {
- QueryBox aBox( rDocShell.GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
- ScGlobal::GetRscString(STR_PIVOT_NOTEMPTY) );
- if (aBox.Execute() == RET_NO)
- {
- //! like above (not editable), use undo to reverse everything
- OSL_ENSURE( bRecord, "DataPilotUpdate: can't undo" );
- bUndoSelf = true;
- }
- }
}
+ }
+ }
- if ( bRecord )
- {
- SCTAB nTab = aNewOut.aStart.Tab();
- pNewUndoDoc = new ScDocument( SCDOCMODE_UNDO );
- pNewUndoDoc->InitUndo( pDoc, nTab, nTab );
- pDoc->CopyToDocument( aNewOut, IDF_ALL, false, pNewUndoDoc );
- }
+ if ( bRecord )
+ {
+ SCTAB nTab = aNewOut.aStart.Tab();
+ pNewUndoDoc = new ScDocument( SCDOCMODE_UNDO );
+ pNewUndoDoc->InitUndo( pDoc, nTab, nTab );
+ pDoc->CopyToDocument( aNewOut, IDF_ALL, false, pNewUndoDoc );
+ }
- pDestObj->Output( aNewOut.aStart );
+ pDestObj->Output( aNewOut.aStart );
- rDocShell.PostPaintGridAll(); //! only necessary parts
- bDone = true;
- }
- }
- // else nothing (no old, no new)
+ rDocShell.PostPaintGridAll(); //! only necessary parts
+ bDone = true;
}
if ( bRecord && bDone )
@@ -1455,8 +1385,7 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
if (bDone)
{
// notify API objects
- if (pDestObj)
- pDoc->BroadcastUno( ScDataPilotModifiedHint( pDestObj->GetName() ) );
+ pDoc->BroadcastUno( ScDataPilotModifiedHint( pDestObj->GetName() ) );
aModificator.SetDocumentModified();
}
commit 4932e51c77b18935d0ed562258b44404abac6817
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 19:13:09 2013 -0500
A little cleaning of RefreshPivotTables().
Change-Id: I0cc99d68545f5b7e27132930626afa830fc86633
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index 6fa69bb..4e32bca 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -431,30 +431,20 @@ void ScDocShell::UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore )
void ScDocShell::RefreshPivotTables( const ScRange& rSource )
{
- //! rename to RefreshDataPilotTables?
-
ScDPCollection* pColl = aDocument.GetDPCollection();
- if ( pColl )
+ if (!pColl)
+ return;
+
+ ScDBDocFunc aFunc(*this);
+ for (size_t i = 0, n = pColl->GetCount(); i < n; ++i)
{
- // DataPilotUpdate doesn't modify the collection order like PivotUpdate did,
- // so a simple loop can be used.
+ ScDPObject* pOld = (*pColl)[i];
+ if (!pOld)
+ continue;
- sal_uInt16 nCount = pColl->GetCount();
- for ( sal_uInt16 i=0; i<nCount; i++ )
- {
- ScDPObject* pOld = (*pColl)[i];
- if ( pOld )
- {
- const ScSheetSourceDesc* pSheetDesc = pOld->GetSheetDesc();
- if ( pSheetDesc && pSheetDesc->GetSourceRange().Intersects( rSource ) )
- {
- ScDPObject* pNew = new ScDPObject( *pOld );
- ScDBDocFunc aFunc( *this );
- aFunc.DataPilotUpdate( pOld, pNew, sal_True, false );
- delete pNew; // DataPilotUpdate copies settings from "new" object
- }
- }
- }
+ const ScSheetSourceDesc* pSheetDesc = pOld->GetSheetDesc();
+ if (pSheetDesc && pSheetDesc->GetSourceRange().Intersects(rSource))
+ aFunc.UpdatePivotTable(*pOld, true, false);
}
}
commit f1a08de8483342400b39b3c0a0f37da00a6109fb
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 19:00:34 2013 -0500
Add a variant of DataPilotUpdate that removes pivot table.
This one became pretty small.
Change-Id: Ic1e1e2b7afc35e5d1141a34722a6fe395832d936
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 4cd2eef..58b9a21 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 71fbbb5..ebd9747 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 23313e7..ac9293f 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 ff768cf..714230a 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
commit 12ff4cc60a87c0e9eddb1f354fd02e59d480b2de
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 16:18:05 2013 -0500
Create another variant of DataPilotUpdate() for new table creation.
Again, this version has much less branching.
Change-Id: I9138471261f2d4df14b64e603a88d4495b6ea45e
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 18527d6..4cd2eef 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1196,6 +1196,14 @@ static sal_Bool lcl_EmptyExcept( ScDocument* pDoc, const ScRange& rRange, const
bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj,
bool bRecord, bool bApi, bool bAllowMove )
{
+ if (!pOldObj)
+ {
+ if (!pNewObj)
+ return false;
+
+ return CreatePivotTable(*pNewObj, bRecord, bApi);
+ }
+
ScDocShellModificator aModificator( rDocShell );
WaitObject aWait( rDocShell.GetActiveDialogParent() );
@@ -1447,6 +1455,135 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
return bDone;
}
+bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool bApi)
+{
+ ScDocShellModificator aModificator(rDocShell);
+ WaitObject aWait(rDocShell.GetActiveDialogParent());
+
+ SAL_WNODEPRECATED_DECLARATIONS_PUSH
+ std::auto_ptr<ScDocument> pNewUndoDoc;
+ SAL_WNODEPRECATED_DECLARATIONS_POP
+
+ 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;
+ }
+
+ {
+ // at least one cell at the output position must be editable
+ // -> check in advance
+ // (start of output range in pNewObj is valid)
+ ScEditableTester aTester(pDoc, rDPObj.GetOutRange().aStart);
+ if (!aTester.IsEditable())
+ {
+ if (!bApi)
+ rDocShell.ErrorMessage(aTester.GetMessageId());
+
+ return false;
+ }
+ }
+
+ // output range must be set at pNewObj
+ SAL_WNODEPRECATED_DECLARATIONS_PUSH
+ std::auto_ptr<ScDPObject> pDestObj(new ScDPObject(rDPObj));
+ SAL_WNODEPRECATED_DECLARATIONS_POP
+
+ ScDPObject& rDestObj = *pDestObj;
+
+ // #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(rDestObj.GetName()))
+ rDestObj.SetName(OUString()); // ignore the invalid name, create a new name below
+
+ if (!pDoc->GetDPCollection()->InsertNewTable(pDestObj.release()))
+ // Insertion into collection failed.
+ return false;
+
+ rDestObj.ReloadGroupTableData();
+ rDestObj.SyncAllDimensionMembers();
+ rDestObj.InvalidateData(); // before getting the new output area
+
+ // make sure the table has a name (not set by dialog)
+ if (rDestObj.GetName().isEmpty())
+ rDestObj.SetName(pDoc->GetDPCollection()->CreateNewName());
+
+ bool bOverflow = false;
+ ScRange aNewOut = rDestObj.GetNewOutputRange(bOverflow);
+
+ if (bOverflow)
+ {
+ if (!bApi)
+ rDocShell.ErrorMessage(STR_PIVOT_ERROR);
+
+ return false;
+ }
+
+ {
+ ScEditableTester aTester(pDoc, aNewOut);
+ if (!aTester.IsEditable())
+ {
+ // destination area isn't editable
+ if (!bApi)
+ rDocShell.ErrorMessage(aTester.GetMessageId());
+
+ return false;
+ }
+ }
+
+ // test if new output area is empty except for old area
+ if (!bApi)
+ {
+ bool bEmpty = pDoc->IsBlockEmpty(
+ aNewOut.aStart.Tab(), aNewOut.aStart.Col(), aNewOut.aStart.Row(),
+ aNewOut.aEnd.Col(), aNewOut.aEnd.Row());
+
+ if (!bEmpty)
+ {
+ QueryBox aBox(
+ rDocShell.GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
+ ScGlobal::GetRscString(STR_PIVOT_NOTEMPTY));
+
+ if (aBox.Execute() == RET_NO)
+ {
+ //! like above (not editable)
+ return false;
+ }
+ }
+ }
+
+ if (bRecord)
+ {
+ SCTAB nTab = aNewOut.aStart.Tab();
+ pNewUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
+ pNewUndoDoc->InitUndo( pDoc, nTab, nTab );
+ pDoc->CopyToDocument(aNewOut, IDF_ALL, false, pNewUndoDoc.get());
+ }
+
+ rDestObj.Output(aNewOut.aStart);
+ rDocShell.PostPaintGridAll(); //! only necessary parts
+
+ if (bRecord)
+ {
+ rDocShell.GetUndoManager()->AddUndoAction(
+ new ScUndoDataPilot(&rDocShell, NULL, pNewUndoDoc.release(), NULL, &rDestObj, false));
+ }
+
+ // notify API objects
+ pDoc->BroadcastUno(ScDataPilotModifiedHint(rDestObj.GetName()));
+ aModificator.SetDocumentModified();
+
+ return true;
+}
+
bool ScDBDocFunc::UpdatePivotTable(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 c302d5c..71fbbb5 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 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 d3d2637..23313e7 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -440,7 +440,7 @@ void SAL_CALL ScDataPilotTablesObj::insertNewByName( const OUString& aNewName,
// todo: handle double fields (for more information see ScDPObject
ScDBDocFunc aFunc(*pDocShell);
- bDone = aFunc.DataPilotUpdate( NULL, pNewObj, sal_True, sal_True );
+ bDone = aFunc.CreatePivotTable(*pNewObj, true, true);
}
}
commit ecb7b8b698e47015b23cd4f7f7812df55c682a1f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jan 11 15:33:23 2013 -0500
Let's remove this underused bAlive flag....
It's no longer that useful in today's pivot table design.
Change-Id: I665a7707126793dfde17a2221ba563d22a59aad1
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index b74db73..fc8d066 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -100,7 +100,6 @@ private:
long nHeaderRows; // page fields plus filter button
bool mbHeaderLayout:1; // true : grid, false : standard
bool bAllowMove:1;
- bool bAlive:1; // false if only used to hold settings
bool bSettingsChanged:1;
bool mbEnableGetPivotData:1;
@@ -120,12 +119,6 @@ public:
void EnableGetPivotData(bool b);
- /**
- * When a DP object is "alive", it has table output on a sheet. This flag
- * doesn't really change the behavior of the object, but is used only for
- * testing purposes.
- */
- void SetAlive(bool bSet);
void SetAllowMove(bool bSet);
void InvalidateData();
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 14d0da1..2d736de 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1817,7 +1817,6 @@ ScDPObject* createDPFromSourceDesc(
pDim->SetShowEmpty(true);
pDPObj->SetSaveData(aSaveData);
- pDPObj->SetAlive(true);
pDPObj->InvalidateData();
return pDPObj;
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 69e7901..d86a012 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -315,7 +315,6 @@ ScDPObject::ScDPObject( ScDocument* pD ) :
nHeaderRows( 0 ),
mbHeaderLayout(false),
bAllowMove(false),
- bAlive(false),
bSettingsChanged(false),
mbEnableGetPivotData(true)
{
@@ -336,7 +335,6 @@ ScDPObject::ScDPObject(const ScDPObject& r) :
nHeaderRows( r.nHeaderRows ),
mbHeaderLayout( r.mbHeaderLayout ),
bAllowMove(false),
- bAlive(false),
bSettingsChanged(false),
mbEnableGetPivotData(r.mbEnableGetPivotData)
{
@@ -366,11 +364,6 @@ void ScDPObject::EnableGetPivotData(bool b)
mbEnableGetPivotData = b;
}
-void ScDPObject::SetAlive(bool bSet)
-{
- bAlive = bSet;
-}
-
void ScDPObject::SetAllowMove(bool bSet)
{
bAllowMove = bSet;
@@ -628,10 +621,6 @@ void ScDPObject::CreateObjects()
{
if (!xSource.is())
{
- //! cache DPSource and/or Output?
-
- OSL_ENSURE( bAlive, "CreateObjects on non-inserted DPObject" );
-
DELETEZ( pOutput ); // not valid when xSource is changed
if ( pServDesc )
@@ -3295,7 +3284,6 @@ void ScDPCollection::WriteRefsTo( ScDPCollection& r ) const
// none found, re-insert deleted object (see ScUndoDataPilot::Undo)
ScDPObject* pDestObj = new ScDPObject(rSrcObj);
- pDestObj->SetAlive(true);
r.InsertNewTable(pDestObj);
}
}
diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx
index f205502..7d06426 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -1438,7 +1438,6 @@ void XclImpPivotTable::Convert()
pDPObj->SetSaveData( aSaveData );
pDPObj->SetSheetDesc( aDesc );
pDPObj->SetOutRange( aOutRange );
- pDPObj->SetAlive(true);
pDPObj->SetHeaderLayout( maPTViewEx9Info.mnGridLayout == 0 );
GetDoc().GetDPCollection()->InsertNewTable(pDPObj);
diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index 229db29..ac42282 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -551,7 +551,6 @@ void ScXMLDataPilotTableContext::EndElement()
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();
diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index 9f01ab2..cc6f6f6 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -133,7 +133,6 @@ ScPivotLayoutDlg::ScPivotLayoutDlg( SfxBindings* pB, SfxChildWindow* pCW, Window
mnOffset(0),
mbRefInputMode( false )
{
- mxDlgDPObject->SetAlive( true ); // needed to get structure information
mxDlgDPObject->FillOldParam( maPivotData );
mxDlgDPObject->FillLabelData( maPivotData );
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 1f09610..18527d6 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1310,7 +1310,6 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
if ( pDoc->GetDPCollection()->GetByName(pDestObj->GetName()) )
pDestObj->SetName( String() ); // ignore the invalid name, create a new name below
- pDestObj->SetAlive(sal_True);
if ( !pDoc->GetDPCollection()->InsertNewTable(pDestObj) )
{
OSL_FAIL("cannot insert DPObject");
diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx
index 19f60ef..ee81052 100644
--- a/sc/source/ui/undo/undodat.cxx
+++ b/sc/source/ui/undo/undodat.cxx
@@ -1640,7 +1640,6 @@ void ScUndoDataPilot::Undo()
// re-insert deleted object
ScDPObject* pDestObj = new ScDPObject( *pOldDPObject );
- pDestObj->SetAlive(sal_True);
if ( !pDoc->GetDPCollection()->InsertNewTable(pDestObj) )
{
OSL_FAIL("cannot insert DPObject");
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index 07c2693..d3d2637 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -1413,7 +1413,6 @@ ScDataPilotDescriptor::ScDataPilotDescriptor(ScDocShell* pDocSh) :
ScDataPilotDescriptorBase( pDocSh ),
mpDPObject(new ScDPObject(pDocSh ? pDocSh->GetDocument() : NULL) )
{
- mpDPObject->SetAlive(sal_True);
ScDPSaveData aSaveData;
// set defaults like in ScPivotParam constructor
aSaveData.SetColumnGrand( sal_True );
More information about the Libreoffice-commits
mailing list