sc/inc/table.hxx | 2 - sc/qa/unit/ucalc.cxx | 68 +++++++++++++++++++++++++++++++++++++ sc/qa/unit/ucalc.hxx | 2 + sc/source/core/data/table3.cxx | 23 +++++------- sc/source/ui/docshell/dbdocfun.cxx | 4 +- 5 files changed, 84 insertions(+), 15 deletions(-)
New commits: commit bda3a2375f8ef581d12da54a4905392d1504b2f0 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Jul 12 22:09:10 2014 -0400 Add another test case. Change-Id: I1664bc3faf44abc978391d0f97820c468f4419b0 diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index c834766..8e88ee4 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -5059,6 +5059,38 @@ void Test::testSortSingleRow() bool bSorted = aFunc.Sort(0, aSortData, true, true, true); CPPUNIT_ASSERT(bSorted); + // Another test case - single row horizontal sort with header column. + clearSheet(m_pDoc, 0); + + // A1:G1 + m_pDoc->SetString(ScAddress(0,0,0), "Header"); + m_pDoc->SetValue(ScAddress(1,0,0), 1.0); + m_pDoc->SetValue(ScAddress(2,0,0), 10.0); + m_pDoc->SetValue(ScAddress(3,0,0), 3.0); + m_pDoc->SetValue(ScAddress(4,0,0), 9.0); + m_pDoc->SetValue(ScAddress(5,0,0), 12.0); + m_pDoc->SetValue(ScAddress(6,0,0), 2.0); + + // Define A1:G1 as sheet-local anonymous database range. + m_pDoc->SetAnonymousDBData( + 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 6, 0, false, true)); + + // Update the sort data. + aSortData.nCol1 = 0; + aSortData.nCol2 = 6; + aSortData.bByRow = false; + bSorted = aFunc.Sort(0, aSortData, true, true, true); + CPPUNIT_ASSERT(bSorted); + + // Check the result. + CPPUNIT_ASSERT_EQUAL(OUString("Header"), m_pDoc->GetString(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(1,0,0))); + CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(ScAddress(2,0,0))); + CPPUNIT_ASSERT_EQUAL( 3.0, m_pDoc->GetValue(ScAddress(3,0,0))); + CPPUNIT_ASSERT_EQUAL( 9.0, m_pDoc->GetValue(ScAddress(4,0,0))); + CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(5,0,0))); + CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(ScAddress(6,0,0))); + m_pDoc->DeleteTab(0); } commit f565bd8e0597ccbc2b525c03ea430bcc1abce9ee Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Jul 12 21:55:59 2014 -0400 fdo#80462: Write test for this. Change-Id: Icdc83c0264fd76239e8c8772c207cc22ce969a76 diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index ac66506..c834766 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -5026,6 +5026,42 @@ void Test::testSortHorizontal() m_pDoc->DeleteTab(0); } +void Test::testSortSingleRow() +{ + // This test case is from fdo#80462. + + m_pDoc->InsertTab(0, "Test"); + + // Sort range consists of only one row. + m_pDoc->SetString(ScAddress(0,0,0), "X"); + m_pDoc->SetString(ScAddress(1,0,0), "Y"); + + // Define A1:B1 as sheet-local anonymous database range. + m_pDoc->SetAnonymousDBData( + 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 0)); + + // Sort A1:B1 horizontally, ascending by row 1. + ScDBDocFunc aFunc(getDocShell()); + + ScSortParam aSortData; + aSortData.nCol1 = 0; + aSortData.nCol2 = 1; + aSortData.nRow1 = 0; + aSortData.nRow2 = 0; + aSortData.bHasHeader = true; + aSortData.bByRow = true; + aSortData.bIncludePattern = true; + aSortData.maKeyState[0].bDoSort = true; + aSortData.maKeyState[0].nField = 0; + aSortData.maKeyState[0].bAscending = true; + + // Do the sorting. This should not crash. + bool bSorted = aFunc.Sort(0, aSortData, true, true, true); + CPPUNIT_ASSERT(bSorted); + + m_pDoc->DeleteTab(0); +} + void Test::testSortInFormulaGroup() { static struct { diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 2df47c0..c592e69 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -341,6 +341,7 @@ public: void testFindAreaPosColRight(); void testSort(); void testSortHorizontal(); + void testSortSingleRow(); void testSortWithFormulaRefs(); void testSortWithStrings(); void testSortInFormulaGroup(); @@ -509,6 +510,7 @@ public: CPPUNIT_TEST(testFindAreaPosColRight); CPPUNIT_TEST(testSort); CPPUNIT_TEST(testSortHorizontal); + CPPUNIT_TEST(testSortSingleRow); CPPUNIT_TEST(testSortWithFormulaRefs); CPPUNIT_TEST(testSortWithStrings); CPPUNIT_TEST(testSortInFormulaGroup); commit 6fb4cbb860652c780dbb56cec92fc93e769e97a5 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Jul 12 21:46:13 2014 -0400 fdo#80462: Don't always increment the start row position. Sometimes someone might attempt to sort only a single row. Change-Id: Ie29d4cf7ec0bd3a5c945997083368b6ef6074268 diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 5398042..187621d 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -485,7 +485,9 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, WaitObject aWait( rDocShell.GetActiveDialogParent() ); - SCROW nStartRow = aLocalParam.nRow1 + (aLocalParam.bHasHeader ? 1 : 0); + SCROW nStartRow = aLocalParam.nRow1; + if (aLocalParam.bByRow && aLocalParam.bHasHeader && nStartRow < aLocalParam.nRow2) + ++nStartRow; // Calculate the script types for all cells in the sort range beforehand. // This will speed up the row height adjustment that takes place after the commit d257651526ccdbfb3e821dc3f7d18d77f3b0c7c6 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Jul 12 18:08:44 2014 -0400 SortReorderByColumn() to not access aSortParam member. Change-Id: I9b66f42e49873b732caba727432a472a07fb43f4 diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 452e171..44c4951 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -1024,7 +1024,7 @@ private: ScSortInfoArray* CreateSortInfoArray( const sc::ReorderParam& rParam ); ScSortInfoArray* CreateSortInfoArray( const ScSortParam& rSortParam, SCCOLROW nInd1, SCCOLROW nInd2, bool bKeepQuery ); void QuickSort( ScSortInfoArray*, SCsCOLROW nLo, SCsCOLROW nHi); - void SortReorderByColumn( ScSortInfoArray* pArray, ScProgress* pProgress ); + void SortReorderByColumn( ScSortInfoArray* pArray, SCROW nRow1, SCROW nRow2, bool bPattern, ScProgress* pProgress ); void SortReorderByRow( ScSortInfoArray* pArray, SCCOL nCol1, SCCOL nCol2, ScProgress* pProgress ); bool CreateExcelQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam); diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index e15f1b9..061dd56 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -654,7 +654,8 @@ public: } -void ScTable::SortReorderByColumn( ScSortInfoArray* pArray, ScProgress* pProgress ) +void ScTable::SortReorderByColumn( + ScSortInfoArray* pArray, SCROW nRow1, SCROW nRow2, bool bPattern, ScProgress* pProgress ) { size_t nCount = pArray->GetCount(); SCCOLROW nStart = pArray->GetStart(); @@ -668,7 +669,7 @@ void ScTable::SortReorderByColumn( ScSortInfoArray* pArray, ScProgress* pProgres aTable[ppInfo[nPos]->nOrg - nStart] = ppInfo[nPos]; // Cut formula grouping at row and reference boundaries before the reordering. - ScRange aSortRange(nStart, aSortParam.nRow1, nTab, nLast, aSortParam.nRow2, nTab); + ScRange aSortRange(nStart, nRow1, nTab, nLast, nRow2, nTab); for (SCCOL nCol = nStart; nCol <= nLast; ++nCol) aCol[nCol].SplitFormulaGroupByRelativeRef(aSortRange); @@ -678,7 +679,7 @@ void ScTable::SortReorderByColumn( ScSortInfoArray* pArray, ScProgress* pProgres SCCOLROW nOrg = ppInfo[nPos]->nOrg; if ( nDest != nOrg ) { - aCol[nDest].Swap(aCol[nOrg], aSortParam.nRow1, aSortParam.nRow2, aSortParam.bIncludePattern); + aCol[nDest].Swap(aCol[nOrg], nRow1, nRow2, bPattern); // neue Position des weggeswapten eintragen ScSortInfo* p = ppInfo[nPos]; @@ -694,7 +695,7 @@ void ScTable::SortReorderByColumn( ScSortInfoArray* pArray, ScProgress* pProgres // Reset formula cell positions which became out-of-sync after column reordering. for (SCCOL nCol = nStart; nCol <= nLast; ++nCol) - aCol[nCol].ResetFormulaCellPositions(aSortParam.nRow1, aSortParam.nRow2); + aCol[nCol].ResetFormulaCellPositions(nRow1, nRow2); // Set up column reorder map (for later broadcasting of reference updates). sc::ColRowReorderMapType aColMap; @@ -709,14 +710,14 @@ void ScTable::SortReorderByColumn( ScSortInfoArray* pArray, ScProgress* pProgres // Collect all listeners within sorted range ahead of time. std::vector<SvtListener*> aListeners; for (SCCOL nCol = nStart; nCol <= nLast; ++nCol) - aCol[nCol].CollectListeners(aListeners, aSortParam.nRow1, aSortParam.nRow2); + aCol[nCol].CollectListeners(aListeners, nRow1, nRow2); // Remove any duplicate listener entries and notify all listeners // afterward. We must ensure that we notify each unique listener only // once. std::sort(aListeners.begin(), aListeners.end()); aListeners.erase(std::unique(aListeners.begin(), aListeners.end()), aListeners.end()); - ColReorderNotifier aFunc(aColMap, nTab, aSortParam.nRow1, aSortParam.nRow2); + ColReorderNotifier aFunc(aColMap, nTab, nRow1, nRow2); std::for_each(aListeners.begin(), aListeners.end(), aFunc); // Re-join formulas at row boundaries now that all the references have @@ -724,9 +725,9 @@ void ScTable::SortReorderByColumn( ScSortInfoArray* pArray, ScProgress* pProgres for (SCCOL nCol = nStart; nCol <= nLast; ++nCol) { sc::CellStoreType& rCells = aCol[nCol].maCells; - sc::CellStoreType::position_type aPos = rCells.position(aSortParam.nRow1); + sc::CellStoreType::position_type aPos = rCells.position(nRow1); sc::SharedFormulaUtil::joinFormulaCellAbove(aPos); - aPos = rCells.position(aPos.first, aSortParam.nRow2+1); + aPos = rCells.position(aPos.first, nRow2+1); sc::SharedFormulaUtil::joinFormulaCellAbove(aPos); } } @@ -1230,8 +1231,6 @@ void ScTable::Sort( pUndo->maSortRange = ScRange(rSortParam.nCol1, nRow1, nTab, rSortParam.nCol2, nLastRow, nTab); pUndo->maPosIndices = pArray->GetOldIndices(); } - - // #i59745# update position of caption objects of cell notes --> reported at (SortReorder) ScColumn::SwapCellNotes level } } else @@ -1251,15 +1250,13 @@ void ScTable::Sort( boost::scoped_ptr<ScSortInfoArray> pArray(CreateSortInfoArray(aSortParam, nCol1, nLastCol, bKeepQuery)); QuickSort(pArray.get(), nCol1, nLastCol); - SortReorderByColumn(pArray.get(), pProgress); + SortReorderByColumn(pArray.get(), aSortParam.nRow1, aSortParam.nRow2, aSortParam.bIncludePattern, pProgress); if (pUndo) { pUndo->maSortRange = ScRange(nCol1, aSortParam.nRow1, nTab, nLastCol, aSortParam.nRow2, nTab); pUndo->maPosIndices = pArray->GetOldIndices(); } - - // #i59745# update position of caption objects of cell notes --> reported at (SortReorder) ScColumn::SwapCellNotes level } } DestroySortCollator(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits