sc/inc/document.hxx | 2 - sc/inc/table.hxx | 4 +-- sc/qa/unit/ucalc.cxx | 45 +++++++++++++++++++++++++++++++++++++ sc/source/core/data/documen3.cxx | 4 +-- sc/source/core/data/table3.cxx | 19 ++++++++------- sc/source/ui/docshell/dbdocfun.cxx | 5 +++- 6 files changed, 64 insertions(+), 15 deletions(-)
New commits: commit 332451bea5ebe08136de2d51e0e29cac88f89e8c Author: Markus Mohrhard <[email protected]> Date: Wed Aug 29 19:42:02 2012 +0200 add unit test for basic sorting with cell note Change-Id: I997f96e0a9f6aa4c2ed7f2d3811a84fdfda05683 diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 63b3b00..a6d5115 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -224,6 +224,7 @@ public: void testFindAreaPosRowDown(); void testFindAreaPosColRight(); + void testSort(); CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(testCollator); @@ -271,6 +272,7 @@ public: CPPUNIT_TEST(testCopyPasteFormulasExternalDoc); CPPUNIT_TEST(testFindAreaPosRowDown); CPPUNIT_TEST(testFindAreaPosColRight); + CPPUNIT_TEST(testSort); CPPUNIT_TEST_SUITE_END(); private: @@ -4881,6 +4883,49 @@ void Test::testFindAreaPosColRight() pDoc->DeleteTab(0); } +void Test::testSort() +{ + ScDocument* pDoc = m_xDocShRef->GetDocument(); + rtl::OUString aTabName1("test1"); + pDoc->InsertTab(0, aTabName1); + + const char* aData[][2] = { + { "2", "4" }, + { "4", "1" }, + { "1", "2" } + }; + + clearRange( pDoc, ScRange(0, 0, 0, 1, SAL_N_ELEMENTS(aData), 0)); + ScAddress aPos(0,0,0); + ScRange aDataRange = insertRangeData( pDoc, aPos, aData, SAL_N_ELEMENTS(aData)); + CPPUNIT_ASSERT_MESSAGE("failed to insert range data at correct position", aDataRange.aStart == aPos); + + rtl::OUString aHello("Hello"); + rtl::OUString aJimBob("Jim Bob"); + ScAddress rAddr(1, 1, 0); + ScPostIt* pNote = m_pDoc->GetNotes(rAddr.Tab())->GetOrCreateNote(rAddr); + pNote->SetText(rAddr, aHello); + pNote->SetAuthor(aJimBob); + + ScSortParam aSortData; + aSortData.nCol1 = 1; + aSortData.nCol2 = 1; + aSortData.nRow1 = 0; + aSortData.nRow2 = 2; + aSortData.maKeyState[0].bDoSort = true; + aSortData.maKeyState[0].nField = 1; + + pDoc->Sort(0, aSortData, false, NULL); + double nVal = pDoc->GetValue(1,0,0); + CPPUNIT_ASSERT_DOUBLES_EQUAL(nVal, 1.0, 1e-8); + + // check that note is also moved + pNote = m_pDoc->GetNotes(0)->findByAddress( 1, 0 ); + CPPUNIT_ASSERT(pNote); + + pDoc->DeleteTab(0); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } commit b705c6b4bd080dd0f7713286a1b19ce95850eb49 Author: Markus Mohrhard <[email protected]> Date: Wed Aug 29 19:35:06 2012 +0200 move ScProgress construction out of ScTable::Sort Change-Id: I8e523fbb53b9c40075b62ee32d79eee0b408168e diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index a2db35f..efe8814 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1471,7 +1471,7 @@ public: SC_DLLPUBLIC SvNumberFormatter* GetFormatTable() const; - void Sort( SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery ); + void Sort( SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress ); SCSIZE Query( SCTAB nTab, const ScQueryParam& rQueryParam, bool bKeepSub ); SC_DLLPUBLIC bool CreateQueryParam( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, ScQueryParam& rQueryParam ); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 223d38c..2b205e5 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -753,7 +753,7 @@ public: void StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 ); void ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 ); - void Sort(const ScSortParam& rSortParam, bool bKeepQuery); + void Sort(const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress); bool ValidQuery( SCROW nRow, const ScQueryParam& rQueryParam, ScBaseCell* pCell = NULL, bool* pbTestEqualCondition = NULL); @@ -863,7 +863,7 @@ private: short Compare( ScSortInfoArray*, SCCOLROW nIndex1, SCCOLROW nIndex2) const; ScSortInfoArray* CreateSortInfoArray( SCCOLROW nInd1, SCCOLROW nInd2 ); void QuickSort( ScSortInfoArray*, SCsCOLROW nLo, SCsCOLROW nHi); - void SortReorder( ScSortInfoArray*, ScProgress& ); + void SortReorder( ScSortInfoArray*, ScProgress* ); bool CreateExcelQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam); bool CreateStarQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam); diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 20a6127..209ba19 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1335,13 +1335,13 @@ bool ScDocument::UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, b return false; } -void ScDocument::Sort(SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery) +void ScDocument::Sort(SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress) { if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) { bool bOldDisableIdle = IsIdleDisabled(); DisableIdle( true ); - maTabs[nTab]->Sort(rSortParam, bKeepQuery); + maTabs[nTab]->Sort(rSortParam, bKeepQuery, pProgress); DisableIdle( bOldDisableIdle ); } } diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 1ea61fb..7688b4e 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -343,7 +343,7 @@ void ScTable::DestroySortCollator() } -void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress& rProgress ) +void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress ) { bool bByRow = aSortParam.bByRow; SCSIZE nCount = pArray->GetCount(); @@ -372,7 +372,8 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress& rProgress ) ::std::swap(p, aTable[nOrg-nStart]); OSL_ENSURE( p == ppInfo[nPos], "SortReorder: nOrg MisMatch" ); } - rProgress.SetStateOnPercent( nPos ); + if(pProgress) + pProgress->SetStateOnPercent( nPos ); } } @@ -742,7 +743,7 @@ void ScTable::DecoladeRow( ScSortInfoArray* pArray, SCROW nRow1, SCROW nRow2 ) } } -void ScTable::Sort(const ScSortParam& rSortParam, bool bKeepQuery) +void ScTable::Sort(const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* pProgress) { aSortParam = rSortParam; InitSortCollator( rSortParam ); @@ -757,13 +758,13 @@ void ScTable::Sort(const ScSortParam& rSortParam, bool bKeepQuery) aSortParam.nRow1 + 1 : aSortParam.nRow1); if (!IsSorted(nRow1, nLastRow)) { - ScProgress aProgress( pDocument->GetDocumentShell(), - ScGlobal::GetRscString(STR_PROGRESS_SORTING), nLastRow - nRow1 ); + if(pProgress) + pProgress->SetState( 0, nLastRow-nRow1 ); ScSortInfoArray* pArray = CreateSortInfoArray( nRow1, nLastRow ); if ( nLastRow - nRow1 > 255 ) DecoladeRow( pArray, nRow1, nLastRow ); QuickSort( pArray, nRow1, nLastRow ); - SortReorder( pArray, aProgress ); + SortReorder( pArray, pProgress ); delete pArray; // #i59745# update position of caption objects of cell notes ScNoteUtil::UpdateCaptionPositions( *pDocument, ScRange( aSortParam.nCol1, nRow1, nTab, aSortParam.nCol2, nLastRow, nTab ) ); @@ -780,11 +781,11 @@ void ScTable::Sort(const ScSortParam& rSortParam, bool bKeepQuery) aSortParam.nCol1 + 1 : aSortParam.nCol1); if (!IsSorted(nCol1, nLastCol)) { - ScProgress aProgress( pDocument->GetDocumentShell(), - ScGlobal::GetRscString(STR_PROGRESS_SORTING), nLastCol - nCol1 ); + if(pProgress) + pProgress->SetState( 0, nLastCol-nCol1 ); ScSortInfoArray* pArray = CreateSortInfoArray( nCol1, nLastCol ); QuickSort( pArray, nCol1, nLastCol ); - SortReorder( pArray, aProgress ); + SortReorder( pArray, pProgress ); delete pArray; // #i59745# update position of caption objects of cell notes ScNoteUtil::UpdateCaptionPositions( *pDocument, ScRange( nCol1, aSortParam.nRow1, nTab, nLastCol, aSortParam.nRow2, nTab ) ); diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index c5ac760..d7cff63 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -582,7 +582,10 @@ sal_Bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, // don't call ScDocument::Sort with an empty SortParam (may be empty here if bCopy is set) if (aLocalParam.GetSortKeyCount() && aLocalParam.maKeyState[0].bDoSort) - pDoc->Sort( nTab, aLocalParam, bRepeatQuery ); + { + ScProgress aProgress(&rDocShell, ScGlobal::GetRscString(STR_PROGRESS_SORTING), 0); + pDoc->Sort( nTab, aLocalParam, bRepeatQuery, &aProgress ); + } sal_Bool bSave = sal_True; if (bCopy) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
