[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/inc sc/qa sc/source
Laurent Godard
lgodard.libre at laposte.net
Wed Oct 2 09:10:40 PDT 2013
sc/inc/column.hxx | 7 +-
sc/qa/unit/ucalc.cxx | 111 ++++++++++++++++++++++++++++++++++++++++
sc/qa/unit/ucalc.hxx | 2
sc/source/core/data/column2.cxx | 31 ++++++++++-
sc/source/core/data/table1.cxx | 73 ++++++++++++--------------
5 files changed, 184 insertions(+), 40 deletions(-)
New commits:
commit 6669f4c85ce3b59c24b78f89c408650c7b26c1b9
Author: Laurent Godard <lgodard.libre at laposte.net>
Date: Wed Oct 2 18:08:20 2013 +0200
refactor area calculations with notes
- add ScColumn::GetCellNotesMaxRow helper
- add ScColumn::GetCellNotesMinRow helper
Change-Id: I0513d89d39fd45d4f6127658a39d17f716fb3d11
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index d73e97a..24ba203 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -495,8 +495,11 @@ public:
void DeleteCellNote( SCROW nRow );
bool HasCellNotes() const;
void SetCellNote( SCROW nRow, ScPostIt* pNote);
- // cell notes
- void CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest=0);
+
+ SCROW GetCellNotesMaxRow() const;
+ SCROW GetCellNotesMinRow() const;
+
+ void CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest=0) const;
void DuplicateNotes(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol, sc::ColumnBlockPosition& maDestBlockPos, SCROW nRowOffsetDest=0 ) const;
void InterpretDirtyCells( SCROW nRow1, SCROW nRow2 );
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 3f45bef..ebfe925 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -4051,6 +4051,117 @@ void Test::testNoteDeleteCol()
pDoc->DeleteTab(0);
}
+void Test::testNotesRowMinMax()
+{
+
+ ScDocument* pDoc = getDocShell().GetDocument();
+ OUString aSheet1("Sheet1");
+ pDoc->InsertTab(0, aSheet1);
+
+ OUString aHello("Hello");
+ OUString aJimBob("Jim Bob");
+ ScAddress rAddr(1, 5, 0);
+ ScPostIt* pNote = m_pDoc->GetOrCreateNote(rAddr);
+ pNote->SetText(rAddr, aHello);
+ pNote->SetAuthor(aJimBob);
+ ScAddress rAddrMin(2, 2, 0);
+ ScPostIt* pNoteMin = m_pDoc->GetOrCreateNote(rAddrMin);
+ pNoteMin->SetText(rAddrMin, aHello);
+
+ SCCOL col;
+ SCROW row;
+ bool dataFound = false;
+
+ // only cell notes (empty content)
+
+ dataFound = pDoc->GetDataStart(0,col,row);
+
+ CPPUNIT_ASSERT_MESSAGE("No DataStart found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("DataStart wrong col for notes", col == 1);
+ CPPUNIT_ASSERT_MESSAGE("DataStart wrong row for notes", row == 2);
+
+ dataFound = pDoc->GetCellArea(0,col,row);
+
+ CPPUNIT_ASSERT_MESSAGE("No CellArea found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("CellArea wrong col for notes", col == 2);
+ CPPUNIT_ASSERT_MESSAGE("CellArea wrong row for notes", row == 5);
+
+ bool bNotes = true;
+ dataFound = pDoc->GetPrintArea(0,col,row, bNotes);
+
+ CPPUNIT_ASSERT_MESSAGE("No PrintArea found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintArea wrong col for notes", col == 2);
+ CPPUNIT_ASSERT_MESSAGE("PrintArea wrong row for notes", row == 5);
+
+ bNotes = false;
+ dataFound = pDoc->GetPrintArea(0,col,row, bNotes);
+ CPPUNIT_ASSERT_MESSAGE("No PrintArea should be found", !dataFound);
+
+ bNotes = true;
+ dataFound = pDoc->GetPrintAreaVer(0,0,1,row, bNotes); // cols 0 & 1
+ CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintAreaVer wrong row for notes", row == 5);
+
+ dataFound = pDoc->GetPrintAreaVer(0,2,3,row, bNotes); // cols 2 & 3
+ CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintAreaVer wrong row for notes", row == 2);
+
+ bNotes = false;
+ dataFound = pDoc->GetPrintAreaVer(0,0,1,row, bNotes); // col 0 & 1
+ CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer should be found", !dataFound);
+
+ // now add cells with value, check that notes are taken into accompt in good cases
+
+ OUString aTestVal("Some Text");
+ m_pDoc->SetString(0, 3, 0, aTestVal);
+ m_pDoc->SetString(3, 3, 0, aTestVal);
+
+ dataFound = pDoc->GetDataStart(0,col,row);
+
+ CPPUNIT_ASSERT_MESSAGE("No DataStart found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("DataStart wrong col", col == 0);
+ CPPUNIT_ASSERT_MESSAGE("DataStart wrong row", row == 2);
+
+ dataFound = pDoc->GetCellArea(0,col,row);
+
+ CPPUNIT_ASSERT_MESSAGE("No CellArea found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("CellArea wrong col", col == 3);
+ CPPUNIT_ASSERT_MESSAGE("CellArea wrong row", row == 5);
+
+ bNotes = true;
+ dataFound = pDoc->GetPrintArea(0,col,row, bNotes);
+
+ CPPUNIT_ASSERT_MESSAGE("No PrintArea found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintArea wrong col", col == 3);
+ CPPUNIT_ASSERT_MESSAGE("PrintArea wrong row", row == 5);
+
+ bNotes = false;
+ dataFound = pDoc->GetPrintArea(0,col,row, bNotes);
+ CPPUNIT_ASSERT_MESSAGE("No PrintArea found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintArea wrong col", col == 3);
+ CPPUNIT_ASSERT_MESSAGE("PrintArea wrong row", row == 3);
+
+ bNotes = true;
+ dataFound = pDoc->GetPrintAreaVer(0,0,1,row, bNotes); // cols 0 & 1
+ CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintAreaVer wrong row", row == 5);
+
+ dataFound = pDoc->GetPrintAreaVer(0,2,3,row, bNotes); // cols 2 & 3
+ CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintAreaVer wrong row", row == 3);
+
+ bNotes = false;
+ dataFound = pDoc->GetPrintAreaVer(0,0,1,row, bNotes); // cols 0 & 1
+ CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer found", dataFound);
+ CPPUNIT_ASSERT_MESSAGE("PrintAreaVer wrong row", row == 3);
+
+
+ std::cout << "cell area col " << col << std::endl;
+ std::cout << "cell area row " << row << std::endl;
+
+ pDoc->DeleteTab(0);
+
+}
/* TODO : notes - these are private methods :(
void Test::testSwapCells()
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index ed2ae1f..f44d309 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -269,6 +269,7 @@ public:
void testShiftCells();
void testNoteDeleteRow();
void testNoteDeleteCol();
+ void testNotesRowMinMax();
// void testSwapCells();
void testAnchoredRotatedShape();
void testCellTextWidth();
@@ -372,6 +373,7 @@ public:
CPPUNIT_TEST(testShiftCells);
CPPUNIT_TEST(testNoteDeleteRow);
CPPUNIT_TEST(testNoteDeleteCol);
+ CPPUNIT_TEST(testNotesRowMinMax);
// CPPUNIT_TEST(testSwapCells);
CPPUNIT_TEST(testAnchoredRotatedShape);
CPPUNIT_TEST(testCellTextWidth);
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 56de103..7c2c565 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1617,7 +1617,7 @@ void ScColumn::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& r
}
//void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const
-void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest) // TODO : notes promising factorisation
+void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest) const // TODO : notes promising factorisation
{
rDestCol.maCellNotes.set_empty(nRow1, nRow2); // Empty the destination range first.
@@ -1911,6 +1911,35 @@ bool ScColumn::HasCellNotes() const
return false;
}
+SCROW ScColumn::GetCellNotesMaxRow() const
+{
+ // hypothesis : the column has cell notes (should be checked before)
+ SCROW maxRow = 0;
+ sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
+ for (; it != itEnd; ++it)
+ {
+ if (it->type == sc::element_type_cellnote)
+ maxRow = it->position + it->size -1;
+ }
+ return maxRow;
+}
+SCROW ScColumn::GetCellNotesMinRow() const
+{
+ // hypothesis : the column has cell notes (should be checked before)
+ SCROW minRow = 0;
+ bool bFound = false;
+ sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
+ for (; it != itEnd && !bFound; ++it)
+ {
+ if (it->type == sc::element_type_cellnote)
+ {
+ bFound = true;
+ minRow = it->position;
+ }
+ }
+ return minRow;
+}
+
sal_uInt16 ScColumn::GetTextWidth(SCROW nRow) const
{
return maCellTextAttrs.get<sc::CellTextAttr>(nRow).mnTextWidth;
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 8823d6c..184177c 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -528,20 +528,20 @@ bool ScTable::GetCellArea( SCCOL& rEndCol, SCROW& rEndRow ) const
if (nRow > nMaxY)
nMaxY = nRow;
}
- if ( pDocument->HasColNotes(i, nTab) )
+ if ( aCol[i].HasCellNotes() )
{
- sc::CellNoteStoreType& maCellNotes = pDocument->GetColNotes(i, nTab);
- for (SCROW r=nMaxY; r <=MAXROW; r++) // TODO : notes suboptimal ?
+ SCROW maxNoteRow = aCol[i].GetCellNotesMaxRow();
+ if (maxNoteRow >= nMaxY)
{
- ScPostIt* pNote = maCellNotes.get<ScPostIt*>(r);
- if (pNote)
- {
- nMaxY = r;
- if (i>nMaxX)
- nMaxX = i;
- }
+ bFound = true;
+ nMaxY = maxNoteRow;
+ }
+ if (i>nMaxX)
+ {
+ bFound = true;
+ nMaxX = i;
}
- }
+ }
}
rEndCol = nMaxX;
@@ -584,18 +584,18 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes, bool bF
}
if (bNotes)
{
- if ( pDocument->HasColNotes(i, nTab) )
+ if ( aCol[i].HasCellNotes() )
{
- sc::CellNoteStoreType& maCellNotes = pDocument->GetColNotes(i, nTab);
- for (SCROW r=nMaxY; r <=MAXROW; r++) // TODO : notes suboptimal ?
+ SCROW maxNoteRow = aCol[i].GetCellNotesMaxRow();
+ if (maxNoteRow >= nMaxY)
{
- ScPostIt* pNote = maCellNotes.get<ScPostIt*>(r);
- if (pNote)
- {
- nMaxY = r;
- if (i>nMaxX)
- nMaxX = i;
- }
+ bFound = true;
+ nMaxY = maxNoteRow;
+ }
+ if (i>nMaxX)
+ {
+ bFound = true;
+ nMaxX = i;
}
}
}
@@ -720,14 +720,13 @@ bool ScTable::GetPrintAreaVer( SCCOL nStartCol, SCCOL nEndCol,
}
if (bNotes)
{
- if ( pDocument->HasColNotes(i, nTab) )
+ if ( aCol[i].HasCellNotes() )
{
- sc::CellNoteStoreType& maCellNotes = pDocument->GetColNotes(i, nTab);
- for (SCROW r=nMaxY; r <=MAXROW; r++) // TODO : notes suboptimal ?
+ SCROW maxNoteRow =aCol[i].GetCellNotesMaxRow();
+ if (maxNoteRow > nMaxY)
{
- ScPostIt* pNote = maCellNotes.get<ScPostIt*>(r);
- if (pNote)
- nMaxY = r;
+ bFound = true;
+ nMaxY = maxNoteRow;
}
}
}
@@ -779,18 +778,18 @@ bool ScTable::GetDataStart( SCCOL& rStartCol, SCROW& rStartRow ) const
if (nRow < nMinY)
nMinY = nRow;
}
- if ( pDocument->HasColNotes(i, nTab) )
+ if ( aCol[i].HasCellNotes() )
{
- sc::CellNoteStoreType& maCellNotes = pDocument->GetColNotes(i, nTab);
- for (SCROW r=0; r < nMinY; r++) // TODO : notes suboptimal ?
+ SCROW minNoteRow = aCol[i].GetCellNotesMinRow();
+ if (minNoteRow <= nMinY)
{
- ScPostIt* pNote = maCellNotes.get<ScPostIt*>(r);
- if (pNote)
- {
- nMinY = r;
- if (i<nMinX)
- nMinX = i;
- }
+ bFound = true;
+ nMinY = minNoteRow;
+ }
+ if (i<nMinX)
+ {
+ bFound = true;
+ nMinX = i;
}
}
}
More information about the Libreoffice-commits
mailing list