[Libreoffice-commits] core.git: Branch 'private/kohei/sort-ref-update' - sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Fri Jun 27 09:39:46 PDT 2014
sc/source/ui/docshell/dbdocfun.cxx | 117 ++++---------------------------------
sc/source/ui/inc/undodat.hxx | 4 -
sc/source/ui/undo/undodat.cxx | 18 -----
3 files changed, 16 insertions(+), 123 deletions(-)
New commits:
commit 9e47c4d1947ef57182a7cb48a37dbe12b168c65a
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Fri Jun 27 12:38:20 2014 -0400
Make sort a two step process when "copy to range" is specified.
First step is to copy the range from A to B, then sort on B. This will
be handled as two commands rather than one.
Change-Id: Ibb1ad7384a3a25337b2b15c67ece90b3d61a6632
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 3e5c6e1..b422213 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -473,7 +473,7 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
ScDocument& rDoc = rDocShell.GetDocument();
if (bRecord && !rDoc.IsUndoEnabled())
bRecord = false;
- SCTAB nSrcTab = nTab;
+
ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
ScDBData* pDBData = rDoc.GetDBAtArea( nTab, rSortParam.nCol1, rSortParam.nRow1,
@@ -484,28 +484,25 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
return false;
}
- ScDBData* pDestData = NULL;
- ScRange aOldDest;
bool bCopy = !rSortParam.bInplace;
if ( bCopy && rSortParam.nDestCol == rSortParam.nCol1 &&
rSortParam.nDestRow == rSortParam.nRow1 && rSortParam.nDestTab == nTab )
bCopy = false;
+
ScSortParam aLocalParam( rSortParam );
if ( bCopy )
{
- aLocalParam.MoveToDest();
- if ( !ValidColRow( aLocalParam.nCol2, aLocalParam.nRow2 ) )
- {
- if (!bApi)
- rDocShell.ErrorMessage(STR_PASTE_FULL);
+ // Copy the data range to the destination then move the sort range to it.
+ ScRange aSrcRange(rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab);
+ ScAddress aDestPos(rSortParam.nDestCol,rSortParam.nDestRow,rSortParam.nDestTab);
+
+ ScDocFunc& rDocFunc = rDocShell.GetDocFunc();
+ bool bRet = rDocFunc.MoveBlock(aSrcRange, aDestPos, false, bRecord, bPaint, bApi);
+
+ if (!bRet)
return false;
- }
- nTab = rSortParam.nDestTab;
- pDestData = rDoc.GetDBAtCursor( rSortParam.nDestCol, rSortParam.nDestRow,
- rSortParam.nDestTab, true );
- if (pDestData)
- pDestData->GetArea(aOldDest);
+ aLocalParam.MoveToDest();
}
ScEditableTester aTester( &rDoc, nTab, aLocalParam.nCol1,aLocalParam.nRow1,
@@ -552,15 +549,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
if ( aQueryParam.GetEntry(0).bDoQuery )
bRepeatQuery = true;
- if (bRepeatQuery && bCopy)
- {
- if ( aQueryParam.bInplace ||
- aQueryParam.nDestCol != rSortParam.nDestCol ||
- aQueryParam.nDestRow != rSortParam.nDestRow ||
- aQueryParam.nDestTab != rSortParam.nDestTab ) // Query auf selben Zielbereich?
- bRepeatQuery = false;
- }
-
ScUndoSort* pUndoAction = 0;
if ( bRecord )
{
@@ -580,19 +568,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
aLocalParam.nCol2, aLocalParam.nRow2, nTab,
IDF_ALL|IDF_NOCAPTIONS, false, pUndoDoc );
- const ScRange* pR = 0;
- if (pDestData)
- {
- /* #i59745# Do not copy note captions from destination range to
- undo document. All existing caption objects will be removed
- which is tracked in drawing undo. When undo is executed, the
- caption objects are reinserted with drawing undo, and the cells
- with the old notes (which still refer to the existing captions)
- will be copied back into the source document. */
- rDoc.CopyToDocument( aOldDest, IDF_ALL|IDF_NOCAPTIONS, false, pUndoDoc );
- pR = &aOldDest;
- }
-
// Zeilenhoehen immer (wegen automatischer Anpassung)
//! auf ScBlockUndo umstellen
// if (bRepeatQuery)
@@ -604,7 +579,7 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
if (!pDocDB->empty())
pUndoDB = new ScDBCollection( *pDocDB );
- pUndoAction = new ScUndoSort( &rDocShell, nTab, rSortParam, pUndoDoc, pUndoDB, pR );
+ pUndoAction = new ScUndoSort(&rDocShell, nTab, rSortParam, pUndoDoc, pUndoDB);
rDocShell.GetUndoManager()->AddUndoAction( pUndoAction );
// #i59745# collect all drawing undo actions affecting cell note captions
@@ -612,18 +587,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
pDrawLayer->BeginCalcUndo(false);
}
- if ( bCopy )
- {
- if (pDestData)
- rDoc.DeleteAreaTab(aOldDest, IDF_CONTENTS); // Zielbereich vorher loeschen
-
- ScRange aSource( rSortParam.nCol1,rSortParam.nRow1,nSrcTab,
- rSortParam.nCol2,rSortParam.nRow2,nSrcTab );
- ScAddress aDest( rSortParam.nDestCol, rSortParam.nDestRow, rSortParam.nDestTab );
-
- rDocShell.GetDocFunc().MoveBlock( aSource, aDest, false, false, false, true );
- }
-
// don't call ScDocument::Sort with an empty SortParam (may be empty here if bCopy is set)
if (aLocalParam.GetSortKeyCount() && aLocalParam.maKeyState[0].bDoSort)
{
@@ -631,54 +594,7 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
rDoc.Sort( nTab, aLocalParam, bRepeatQuery, &aProgress );
}
- bool bSave = true;
- if (bCopy)
- {
- ScSortParam aOldSortParam;
- pDBData->GetSortParam( aOldSortParam );
- if (aOldSortParam.GetSortKeyCount() &&
- aOldSortParam.maKeyState[0].bDoSort && aOldSortParam.bInplace)
- {
- bSave = false;
- aOldSortParam.nDestCol = rSortParam.nDestCol;
- aOldSortParam.nDestRow = rSortParam.nDestRow;
- aOldSortParam.nDestTab = rSortParam.nDestTab;
- pDBData->SetSortParam( aOldSortParam ); // dann nur DestPos merken
- }
- }
- if (bSave) // Parameter merken
- {
- pDBData->SetSortParam( rSortParam );
- pDBData->SetHeader( rSortParam.bHasHeader ); //! ???
- pDBData->SetByRow( rSortParam.bByRow ); //! ???
- }
-
- if (bCopy) // neuen DB-Bereich merken
- {
- // Tabelle umschalten von aussen (View)
- //! SetCursor ??!?!
-
- ScRange aDestPos( aLocalParam.nCol1, aLocalParam.nRow1, nTab,
- aLocalParam.nCol2, aLocalParam.nRow2, nTab );
- ScDBData* pNewData;
- if (pDestData)
- pNewData = pDestData; // Bereich vorhanden -> anpassen
- else // Bereich ab Cursor/Markierung wird angelegt
- pNewData = rDocShell.GetDBData(aDestPos, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );
- if (pNewData)
- {
- pNewData->SetArea( nTab,
- aLocalParam.nCol1,aLocalParam.nRow1,
- aLocalParam.nCol2,aLocalParam.nRow2 );
- pNewData->SetSortParam( aLocalParam );
- pNewData->SetHeader( aLocalParam.bHasHeader ); //! ???
- pNewData->SetByRow( aLocalParam.bByRow );
- }
- else
- {
- OSL_FAIL("Zielbereich nicht da");
- }
- }
+ pDBData->SetSortParam(rSortParam);
ScRange aDirtyRange(
aLocalParam.nCol1, nStartRow, nTab,
@@ -698,13 +614,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
nStartX = 0;
nEndX = MAXCOL;
}
- if (pDestData)
- {
- if ( nEndX < aOldDest.aEnd.Col() )
- nEndX = aOldDest.aEnd.Col();
- if ( nEndY < aOldDest.aEnd.Row() )
- nEndY = aOldDest.aEnd.Row();
- }
rDocShell.PostPaint(ScRange(nStartX, nStartY, nTab, nEndX, nEndY, nTab), nPaint);
}
diff --git a/sc/source/ui/inc/undodat.hxx b/sc/source/ui/inc/undodat.hxx
index 00388d7..cbe1152 100644
--- a/sc/source/ui/inc/undodat.hxx
+++ b/sc/source/ui/inc/undodat.hxx
@@ -231,7 +231,7 @@ public:
ScUndoSort( ScDocShell* pNewDocShell, SCTAB nNewTab,
const ScSortParam& rParam,
ScDocument* pNewUndoDoc,
- ScDBCollection* pNewUndoDB, const ScRange* pDest = NULL );
+ ScDBCollection* pNewUndoDB );
virtual ~ScUndoSort();
virtual void Undo() SAL_OVERRIDE;
@@ -246,8 +246,6 @@ private:
ScSortParam aSortParam;
ScDocument* pUndoDoc;
ScDBCollection* pUndoDB; // due to source and target range
- bool bDestArea;
- ScRange aDestRange;
};
class ScUndoQuery: public ScDBFuncUndo
diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx
index 4d6111b..4621fcd 100644
--- a/sc/source/ui/undo/undodat.cxx
+++ b/sc/source/ui/undo/undodat.cxx
@@ -739,21 +739,14 @@ bool ScUndoSubTotals::CanRepeat(SfxRepeatTarget& /* rTarget */) const
ScUndoSort::ScUndoSort( ScDocShell* pNewDocShell,
SCTAB nNewTab, const ScSortParam& rParam,
- ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
- const ScRange* pDest ) :
+ ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB ) :
ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
rParam.nCol2, rParam.nRow2, nNewTab ) ),
nTab( nNewTab ),
aSortParam( rParam ),
pUndoDoc( pNewUndoDoc ),
- pUndoDB( pNewUndoDB ),
- bDestArea( false )
+ pUndoDB( pNewUndoDB )
{
- if ( pDest )
- {
- bDestArea = true;
- aDestRange = *pDest;
- }
}
ScUndoSort::~ScUndoSort()
@@ -796,13 +789,6 @@ void ScUndoSort::Undo()
pUndoDoc->CopyToDocument( nStartCol, nStartRow, nSortTab, nEndCol, nEndRow, nSortTab,
IDF_ALL|IDF_NOCAPTIONS, false, &rDoc );
- if (bDestArea)
- {
- // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo)
- rDoc.DeleteAreaTab( aDestRange, IDF_ALL|IDF_NOCAPTIONS );
- pUndoDoc->CopyToDocument( aDestRange, IDF_ALL|IDF_NOCAPTIONS, false, &rDoc );
- }
-
// Row heights always (due to automatic adjustment)
// TODO change to use ScBlockUndo
pUndoDoc->CopyToDocument( 0, nStartRow, nSortTab, MAXCOL, nEndRow, nSortTab,
More information about the Libreoffice-commits
mailing list