[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - 2 commits - sc/inc sc/qa sc/source
Laurent Godard
lgodard.libre at laposte.net
Fri Sep 20 10:20:50 PDT 2013
Rebased ref, commits from common ancestor:
commit 4398cb1dccb7f024256dfad654e58164bbd5a7ce
Author: Laurent Godard <lgodard.libre at laposte.net>
Date: Fri Sep 20 19:18:55 2013 +0200
sync notes captions on sort
Change-Id: Ib63ded7e1516a5a4ed8e7d17c3f0480e5ed5b50e
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index 8640ebf..c632817 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -160,8 +160,6 @@ private:
class SC_DLLPUBLIC ScNoteUtil
{
public:
- /** Tries to update the position of note caption objects in the specified range. */
- static void UpdateCaptionPositions( ScDocument& rDoc, const ScRange& rRange );
/** Creates and returns a caption object for a temporary caption. */
static SdrCaptionObj* CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 9fede25..d34d2c9 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -3853,16 +3853,15 @@ void Test::testSort()
aSortData.maKeyState[0].nField = 1;
aSortData.maKeyState[0].bAscending = true;
-/* TODO : notes crash
- m_pDoc->Sort(0, aSortData, false, NULL); // TODO : notes crash
+ m_pDoc->Sort(0, aSortData, false, NULL);
double nVal = m_pDoc->GetValue(1,0,0);
ASSERT_DOUBLES_EQUAL(nVal, 1.0);
// check that note is also moved after sorting
- pNote = m_pDoc->GetNote(1, 0, 0); //TODO : notes GetNotes
+ pNote = m_pDoc->GetNote(1, 0, 0);
CPPUNIT_ASSERT(pNote);
-*/
+
clearRange(m_pDoc, ScRange(0, 0, 0, 1, 9, 0)); // Clear A1:B10.
{
// 0 = empty cell
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index d7433a4..f38ce5a 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1722,6 +1722,8 @@ void ScColumn::SwapCellNotes( SCROW nRow1, SCROW nRow2 )
if (aPos2.first == maCellNotes.end())
return;
+ ScPostIt* aNote;
+
sc::CellNoteStoreType::iterator it1 = aPos1.first, it2 = aPos2.first;
if (it1->type == it2->type)
{
@@ -1734,6 +1736,12 @@ void ScColumn::SwapCellNotes( SCROW nRow1, SCROW nRow2 )
sc::cellnote_block::at(*it1->data, aPos1.second),
sc::cellnote_block::at(*it2->data, aPos2.second));
+ //update captions
+ aNote = sc::cellnote_block::at(*it1->data, aPos1.second);
+ aNote->UpdateCaptionPos(ScAddress(nCol,nRow2,nTab));
+ aNote = sc::cellnote_block::at(*it2->data, aPos2.second);
+ aNote->UpdateCaptionPos(ScAddress(nCol,nRow1,nTab));
+
return;
}
@@ -1741,16 +1749,23 @@ void ScColumn::SwapCellNotes( SCROW nRow1, SCROW nRow2 )
if (it1->type == sc::element_type_empty)
{
// row 1 is empty while row 2 is non-empty.
- const ScPostIt* rVal2 = sc::cellnote_block::at(*it2->data, aPos2.second);
- it1 = maCellNotes.set(it1, nRow1, rVal2);
+ ScPostIt* pVal2 = sc::cellnote_block::at(*it2->data, aPos2.second);
+ it1 = maCellNotes.set(it1, nRow1, pVal2);
maCellNotes.set_empty(it1, nRow2, nRow2);
+
+ //update captions
+ pVal2->UpdateCaptionPos(ScAddress(nCol,nRow1,nTab));
+
return;
}
// row 1 is non-empty while row 2 is empty.
- ScPostIt* aVal1 = sc::cellnote_block::at(*it1->data, aPos1.second); // make a copy.
+ ScPostIt* pVal1 = sc::cellnote_block::at(*it1->data, aPos1.second); // make a copy.
it1 = maCellNotes.set_empty(it1, nRow1, nRow1);
- maCellNotes.set(it1, nRow2, aVal1);
+ maCellNotes.set(it1, nRow2, pVal1);
+
+ //update captions
+ pVal1->UpdateCaptionPos(ScAddress(nCol,nRow1,nTab));
CellStorageModified();
}
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index a39794c..9896034 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -794,16 +794,6 @@ void ScPostIt::RemoveCaption()
// ============================================================================
-void ScNoteUtil::UpdateCaptionPositions( ScDocument& rDoc, const ScRange& rRange )
-{
- // do not use ScCellIterator, it skips filtered and subtotal cells
- for( ScAddress aPos( rRange.aStart ); aPos.Tab() <= rRange.aEnd.Tab(); aPos.IncTab() )
- for( aPos.SetCol( rRange.aStart.Col() ); aPos.Col() <= rRange.aEnd.Col(); aPos.IncCol() )
- for( aPos.SetRow( rRange.aStart.Row() ); aPos.Row() <= rRange.aEnd.Row(); aPos.IncRow() )
- if( ScPostIt* pNote = rDoc.GetNote(aPos) )
- pNote->UpdateCaptionPos( aPos );
-}
-
SdrCaptionObj* ScNoteUtil::CreateTempCaption(
ScDocument& rDoc, const ScAddress& rPos, SdrPage& rDrawPage,
const OUString& rUserText, const Rectangle& rVisRect, bool bTailFront )
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 3e2b78f..a8877d9 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -666,8 +666,7 @@ void ScTable::Sort(const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* p
QuickSort( pArray, nRow1, nLastRow );
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 ) );
+ // #i59745# update position of caption objects of cell notes --> reported at (SortReorder) ScColumn::SwapCellNotes level
}
}
else
@@ -687,8 +686,7 @@ void ScTable::Sort(const ScSortParam& rSortParam, bool bKeepQuery, ScProgress* p
QuickSort( pArray, nCol1, nLastCol );
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 ) );
+ // #i59745# update position of caption objects of cell notes --> reported at (SortReorder) ScColumn::SwapCellNotes level
}
}
DestroySortCollator();
commit 8527feb67223778618b85610b45dadaeea36fbc3
Author: Laurent Godard <lgodard.libre at laposte.net>
Date: Fri Sep 20 18:09:36 2013 +0200
a new unit test project for testing row/col swapping with notes
- does not work as the methods are private
Change-Id: I4d48167cee3e9dff9bc64d2a6f3c7d79f1e7cad4
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 69f44c6..9fede25 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -513,6 +513,8 @@ void Test::testCopyToDocument()
m_pDoc->SetString(0, 4, 0, "=4/2");
m_pDoc->CalcAll();
+ //TODO : notes
+
// Copy statically to another document.
ScDocument aDestDoc(SCDOCMODE_DOCUMENT);
@@ -3975,6 +3977,93 @@ void Test::testNoteDeleteCol()
pDoc->DeleteTab(0);
}
+/* TODO : notes - these are private methods :(
+
+void Test::testSwapCells()
+{
+ ScDocument* pDoc = getDocShell().GetDocument();
+ OUString aSheet1("Sheet1");
+ pDoc->InsertTab(0, aSheet1);
+
+ OUString aString;
+
+ OUString aStringA1("originally A1");
+ OUString aStringA2("originally A2");
+ OUString aStringA3("originally A3");
+ OUString aStringB1("originally B1");
+ OUString aStringB2("originally B2");
+ OUString aStringB3("originally B3");
+
+
+ m_pDoc->SetString(0, 0, 0, aStringA1);
+ m_pDoc->SetString(0, 1, 0, aStringA2);
+ m_pDoc->SetString(0, 2, 0, aStringA3);
+
+ m_pDoc->SetString(1, 0, 0, aStringB1);
+ m_pDoc->SetString(1, 1, 0, aStringB2);
+ m_pDoc->SetString(1, 2, 0, aStringB3);
+
+ ScTable* pTab = pDoc->GetTable[0];
+
+ // swap rows
+ pTab->SwapRow(0,1);
+
+ aString = m_pDoc->GetString(0,0,0);
+ CPPUNIT_ASSERT_MESSAGE("A1 should contain aStringA2", aString == aStringA2);
+ aString = m_pDoc->GetString(0,1,0);
+ CPPUNIT_ASSERT_MESSAGE("A2 should contain aStringA1", aString == aStringA1);
+ aString = m_pDoc->GetString(1,0,0);
+ CPPUNIT_ASSERT_MESSAGE("B1 should contain aStringB2", aString == aStringB2);
+ aString = m_pDoc->GetString(1,1,0);
+ CPPUNIT_ASSERT_MESSAGE("B2 should contain aStringB1", aString == aStringB1);
+ aString = m_pDoc->GetString(0,2,0);
+ CPPUNIT_ASSERT_MESSAGE("A3 should contain aStringA3", aString == aStringA3);
+
+ // back to orginal state
+ pTab->SwapRow(1,0);
+
+ aString = m_pDoc->GetString(0,0,0);
+ CPPUNIT_ASSERT_MESSAGE("A1 should contain aStringA1", aString == aStringA1);
+ aString = m_pDoc->GetString(0,1,0);
+ CPPUNIT_ASSERT_MESSAGE("A2 should contain aStringA1", aString == aStringA2);
+ aString = m_pDoc->GetString(1,0,0);
+ CPPUNIT_ASSERT_MESSAGE("B1 should contain aStringB1", aString == aStringB1);
+ aString = m_pDoc->GetString(1,1,0);
+ CPPUNIT_ASSERT_MESSAGE("B2 should contain aStringB2", aString == aStringB2);
+ aString = m_pDoc->GetString(0,2,0);
+ CPPUNIT_ASSERT_MESSAGE("A3 should contain aStringA3", aString == aStringA3);
+
+ // swap cols
+ pTab->SwapCol(0,1);
+
+ aString = m_pDoc->GetString(0,0,0);
+ CPPUNIT_ASSERT_MESSAGE("A1 should contain aStringB1", aString == aStringB1);
+ aString = m_pDoc->GetString(1,0,0);
+ CPPUNIT_ASSERT_MESSAGE("B1 should contain aStringA1", aString == aStringA1);
+ aString = m_pDoc->GetString(0,1,0);
+ CPPUNIT_ASSERT_MESSAGE("A2 should contain aStringB2", aString == aStringB2);
+ aString = m_pDoc->GetString(1,1,0);
+ CPPUNIT_ASSERT_MESSAGE("B2 should contain aStringA2", aString == aStringA2);
+ aString = m_pDoc->GetString(0,2,0);
+ CPPUNIT_ASSERT_MESSAGE("A3 should contain aStringA3", aString == aStringA3);
+
+ // back to orginal state
+ pTab->SwapRow(1,0);
+
+ aString = m_pDoc->GetString(0,0,0);
+ CPPUNIT_ASSERT_MESSAGE("A1 should contain aStringA1", aString == aStringA1);
+ aString = m_pDoc->GetString(0,1,0);
+ CPPUNIT_ASSERT_MESSAGE("A2 should contain aStringA1", aString == aStringA2);
+ aString = m_pDoc->GetString(1,0,0);
+ CPPUNIT_ASSERT_MESSAGE("B1 should contain aStringB1", aString == aStringB1);
+ aString = m_pDoc->GetString(1,1,0);
+ CPPUNIT_ASSERT_MESSAGE("B2 should contain aStringB2", aString == aStringB2);
+ aString = m_pDoc->GetString(0,2,0);
+ CPPUNIT_ASSERT_MESSAGE("A3 should contain aStringA3", aString == aStringA3);
+
+}
+*/
+
void Test::testAnchoredRotatedShape()
{
OUString aTabName("TestTab");
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 31e1ddc..1273241 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -268,6 +268,7 @@ public:
void testShiftCells();
void testNoteDeleteRow();
void testNoteDeleteCol();
+// void testSwapCells();
void testAnchoredRotatedShape();
void testCellTextWidth();
void testEditTextIterator();
@@ -369,6 +370,7 @@ public:
CPPUNIT_TEST(testShiftCells);
CPPUNIT_TEST(testNoteDeleteRow);
CPPUNIT_TEST(testNoteDeleteCol);
+// CPPUNIT_TEST(testSwapCells);
CPPUNIT_TEST(testAnchoredRotatedShape);
CPPUNIT_TEST(testCellTextWidth);
CPPUNIT_TEST(testEditTextIterator);
More information about the Libreoffice-commits
mailing list