[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/source
Laurent Godard
lgodard.libre at laposte.net
Wed Sep 18 05:28:32 PDT 2013
sc/source/core/data/column.cxx | 159 +++++++++++++++++++++++++++++++++-------
sc/source/core/data/column3.cxx | 143 ++++++++---------------------------
2 files changed, 166 insertions(+), 136 deletions(-)
New commits:
commit aba27154d984f0793bef38ab19bb64b2f92bbb25
Author: Laurent Godard <lgodard.libre at laposte.net>
Date: Wed Sep 18 14:26:55 2013 +0200
notes & clipboard : copyTo an copyFrom clipboards handler refactoring
a unit test segfault though
Change-Id: I90623a2ed127e84b14eeb8f909b41d921b82cb8f
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index bbeafdc..2d67b27 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1302,6 +1302,35 @@ class CopyToClipHandler
}
}
+ void duplicateNotes(SCROW nStartRow, size_t nOffset, size_t nDataSize )
+ {
+ sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
+ std::vector<ScPostIt*> aNotes;
+ aNotes.reserve(nDataSize);
+ SCROW nRow = nStartRow;
+
+ sc::CellNoteStoreType::const_iterator itNote = maSrcCellNotes.begin();
+ std::advance(itNote, nOffset);
+ sc::CellNoteStoreType::const_iterator itNoteEnd = itNote;
+ std::advance(itNoteEnd, nDataSize);
+
+ for (; itNote != itNoteEnd; ++itNote, ++nRow)
+ {
+ ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
+ if (pSrcNote)
+ {
+ ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
+ ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
+ mrDestCol.GetDoc(),
+ aDestPos, true );
+ aNotes.push_back(pClonedNote);
+ }
+ }
+
+ maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(
+ maDestPos.miCellNotePos, nStartRow, aNotes.begin(), aNotes.end());
+ }
+
public:
CopyToClipHandler(const ScColumn& rSrcCol, ScColumn& rDestCol, sc::ColumnBlockPosition* pDestPos, bool bCopyNotes) :
mrSrcCol(rSrcCol), mrDestCol(rDestCol), mpDestPos(pDestPos), mbCopyNotes(bCopyNotes)
@@ -1342,6 +1371,7 @@ public:
sc::string_block::const_iterator itEnd = it;
std::advance(itEnd, nDataSize);
maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nTopRow, it, itEnd);
+
}
break;
case sc::element_type_edittext:
@@ -1401,35 +1431,14 @@ public:
}
break;
default:
- bSet = true;
- ;
+ bSet = false;
}
if (bSet)
- {
setDefaultAttrsToDest(nTopRow, nDataSize);
- if (mbCopyNotes)
- {
- //maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(maDestPos.miCellNotePos, nTopRow, it, itEnd);
- sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
- sc::CellNoteStoreType::position_type aPosNotes = maSrcCellNotes.position(nTopRow);
- sc::CellNoteStoreType::iterator itNotes = aPosNotes.first;
- if (itNotes->type == sc::element_type_cellnote)
- {
- ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nTopRow);
- if (pSrcNote)
- {
- ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nTopRow, mrDestCol.GetTab());
- ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nTopRow, mrSrcCol.GetTab() ),
- mrDestCol.GetDoc(),
- aDestPos, true );
- mrDestCol.GetDoc().ReleaseNote(aDestPos);
- mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
- }
- }
- }
- }
+ if (mbCopyNotes)
+ duplicateNotes(nTopRow, nOffset, nDataSize );
}
};
@@ -1885,6 +1894,31 @@ public:
maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, *it);
setDefaultAttrToDest(nRow);
+
+ // TODO : notes - copy notes
+ bool mbCopyNotes = true;
+ if (mbCopyNotes)
+ {
+ //maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(maDestPos.miCellNotePos, nTopRow, it, itEnd);
+ sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
+ sc::CellNoteStoreType::position_type aPosNotes = maSrcCellNotes.position(nRow);
+ sc::CellNoteStoreType::iterator itNotes = aPosNotes.first;
+ if (itNotes->type == sc::element_type_cellnote)
+ {
+ ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
+ if (pSrcNote)
+ {
+ ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
+ ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
+ mrDestCol.GetDoc(),
+ aDestPos, true );
+ mrDestCol.GetDoc().ReleaseNote(aDestPos);
+ mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
+ }
+ }
+ }
+
+
}
}
break;
@@ -1915,6 +1949,30 @@ public:
mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, rStr);
setDefaultAttrToDest(nRow);
}
+
+ // TODO : notes - copy notes
+ bool mbCopyNotes = true;
+ if (mbCopyNotes)
+ {
+ //maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(maDestPos.miCellNotePos, nTopRow, it, itEnd);
+ sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
+ sc::CellNoteStoreType::position_type aPosNotes = maSrcCellNotes.position(nRow);
+ sc::CellNoteStoreType::iterator itNotes = aPosNotes.first;
+ if (itNotes->type == sc::element_type_cellnote)
+ {
+ ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
+ if (pSrcNote)
+ {
+ ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
+ ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
+ mrDestCol.GetDoc(),
+ aDestPos, true );
+ mrDestCol.GetDoc().ReleaseNote(aDestPos);
+ mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
+ }
+ }
+ }
+
}
}
break;
@@ -1930,13 +1988,39 @@ public:
std::vector<EditTextObject*> aCloned;
aCloned.reserve(nDataSize);
- for (; it != itEnd; ++it)
+ for (; it != itEnd; ++it, ++nRow)
+ {
aCloned.push_back(ScEditUtil::Clone(**it, mrDestCol.GetDoc()));
+ // TODO : notes - copy notes
+ bool mbCopyNotes = true;
+ if (mbCopyNotes)
+ {
+ //maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(maDestPos.miCellNotePos, nTopRow, it, itEnd);
+ sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
+ sc::CellNoteStoreType::position_type aPosNotes = maSrcCellNotes.position(nRow);
+ sc::CellNoteStoreType::iterator itNotes = aPosNotes.first;
+ if (itNotes->type == sc::element_type_cellnote)
+ {
+ ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
+ if (pSrcNote)
+ {
+ ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
+ ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
+ mrDestCol.GetDoc(),
+ aDestPos, true );
+ mrDestCol.GetDoc().ReleaseNote(aDestPos);
+ mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
+ }
+ }
+ }
+ }
maDestPos.miCellPos = mrDestCol.GetCellStore().set(
maDestPos.miCellPos, nRow, aCloned.begin(), aCloned.end());
setDefaultAttrsToDest(nRow, nDataSize);
+
+
}
break;
case sc::element_type_formula:
@@ -1947,10 +2031,35 @@ public:
std::advance(itEnd, nDataSize);
for (; it != itEnd; ++it, ++nRow)
+ {
cloneFormulaCell(nRow, const_cast<ScFormulaCell&>(**it));
+ // TODO : notes - copy notes
+ bool mbCopyNotes = true;
+ if (mbCopyNotes)
+ {
+ //maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(maDestPos.miCellNotePos, nTopRow, it, itEnd);
+ sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
+ sc::CellNoteStoreType::position_type aPosNotes = maSrcCellNotes.position(nRow);
+ sc::CellNoteStoreType::iterator itNotes = aPosNotes.first;
+ if (itNotes->type == sc::element_type_cellnote)
+ {
+ ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
+ if (pSrcNote)
+ {
+ ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
+ ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
+ mrDestCol.GetDoc(),
+ aDestPos, true );
+ mrDestCol.GetDoc().ReleaseNote(aDestPos);
+ mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
+ }
+ }
+ }
+ }
}
break;
default:
+ // TODO : notes - copy notes from empty cells
;
}
}
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index ed3c382..e8076fb 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -697,6 +697,35 @@ class CopyCellsFromClipHandler
maDestBlockPos, nDestRow, new ScFormulaCell(&mrDestCol.GetDoc(), aDestPos, &aArr));
}
+ void duplicateNotes(SCROW nStartRow, size_t nOffset, size_t nDataSize )
+ {
+ sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
+ std::vector<ScPostIt*> aNotes;
+ aNotes.reserve(nDataSize);
+ SCROW nRow = nStartRow;
+
+ sc::CellNoteStoreType::const_iterator itNote = maSrcCellNotes.begin();
+ std::advance(itNote, nOffset);
+ sc::CellNoteStoreType::const_iterator itNoteEnd = itNote;
+ std::advance(itNoteEnd, nDataSize);
+
+ for (; itNote != itNoteEnd; ++itNote, ++nRow)
+ {
+ ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
+ if (pSrcNote)
+ {
+ ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow+mnRowOffset, mrDestCol.GetTab());
+ ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
+ mrDestCol.GetDoc(),
+ aDestPos, true );
+ aNotes.push_back(pClonedNote);
+ }
+ }
+
+ maDestBlockPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(
+ maDestBlockPos.miCellNotePos, nStartRow+mnRowOffset, aNotes.begin(), aNotes.end());
+ }
+
public:
CopyCellsFromClipHandler(sc::CopyFromClipContext& rCxt, ScColumn& rSrcCol, ScColumn& rDestCol, SCTAB nDestTab, SCCOL nDestCol, long nRowOffset) :
mrCxt(rCxt),
@@ -759,29 +788,8 @@ public:
insertRefCell(nSrcRow, nSrcRow + mnRowOffset);
else
mrDestCol.SetValue(maDestBlockPos, nSrcRow + mnRowOffset, *it);
-
- if (bCopyCellNotes)
- {
- sc::CellNoteStoreType& maCellNotesSrc = mrSrcCol.GetCellNoteStore();
- sc::CellNoteStoreType::position_type aPos = maCellNotesSrc.position(nSrcRow);
- sc::CellNoteStoreType::iterator itNotes = aPos.first;
- if (itNotes->type == sc::element_type_cellnote)
- {
- ScPostIt* pSrcNote = maCellNotesSrc.get<ScPostIt*>(nSrcRow);
- if (pSrcNote)
- {
- ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nSrcRow+mnRowOffset, mrDestCol.GetTab());
- ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nSrcRow, mrSrcCol.GetTab() ),
- mrDestCol.GetDoc(),
- aDestPos, true );
- mrDestCol.GetDoc().ReleaseNote(aDestPos);
- mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
- }
- }
- }
}
}
-
break;
case sc::element_type_string:
{
@@ -798,26 +806,6 @@ public:
insertRefCell(nSrcRow, nSrcRow + mnRowOffset);
else
mrDestCol.SetRawString(maDestBlockPos, nSrcRow + mnRowOffset, *it);
-
- if (bCopyCellNotes)
- {
- sc::CellNoteStoreType& maCellNotesSrc = mrSrcCol.GetCellNoteStore();
- sc::CellNoteStoreType::position_type aPos = maCellNotesSrc.position(nSrcRow);
- sc::CellNoteStoreType::iterator itNotes = aPos.first;
- if (itNotes->type == sc::element_type_cellnote)
- {
- ScPostIt* pSrcNote = maCellNotesSrc.get<ScPostIt*>(nSrcRow);
- if (pSrcNote)
- {
- ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nSrcRow+mnRowOffset, mrDestCol.GetTab());
- ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nSrcRow, mrSrcCol.GetTab() ),
- mrDestCol.GetDoc(),
- aDestPos, true );
- mrDestCol.GetDoc().ReleaseNote(aDestPos);
- mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
- }
- }
- }
}
}
break;
@@ -837,26 +825,6 @@ public:
insertRefCell(nSrcRow, nSrcRow + mnRowOffset);
else
mrDestCol.SetEditText(maDestBlockPos, nSrcRow + mnRowOffset, **it);
-
- if (bCopyCellNotes)
- {
- sc::CellNoteStoreType& maCellNotesSrc = mrSrcCol.GetCellNoteStore();
- sc::CellNoteStoreType::position_type aPos = maCellNotesSrc.position(nSrcRow);
- sc::CellNoteStoreType::iterator itNotes = aPos.first;
- if (itNotes->type == sc::element_type_cellnote)
- {
- ScPostIt* pSrcNote = maCellNotesSrc.get<ScPostIt*>(nSrcRow);
- if (pSrcNote)
- {
- ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nSrcRow+mnRowOffset, mrDestCol.GetTab());
- ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nSrcRow, mrSrcCol.GetTab() ),
- mrDestCol.GetDoc(),
- aDestPos, true );
- mrDestCol.GetDoc().ReleaseNote(aDestPos);
- mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
- }
- }
- }
}
}
break;
@@ -948,61 +916,14 @@ public:
mrDestCol.SetRawString(maDestBlockPos, nSrcRow + mnRowOffset, aStr);
}
}
-
- if (bCopyCellNotes)
- {
- sc::CellNoteStoreType& maCellNotesSrc = mrSrcCol.GetCellNoteStore();
- sc::CellNoteStoreType::position_type aPos = maCellNotesSrc.position(nSrcRow);
- sc::CellNoteStoreType::iterator itNotes = aPos.first;
- if (itNotes->type == sc::element_type_cellnote)
- {
- ScPostIt* pSrcNote = maCellNotesSrc.get<ScPostIt*>(nSrcRow);
- if (pSrcNote)
- {
- ScAddress aDestPosNotes = ScAddress(mrDestCol.GetCol(), nSrcRow+mnRowOffset, mrDestCol.GetTab());
- ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nSrcRow, mrSrcCol.GetTab() ),
- mrDestCol.GetDoc(),
- aDestPosNotes, true );
- mrDestCol.GetDoc().ReleaseNote(aDestPosNotes);
- mrDestCol.GetDoc().SetNote(aDestPosNotes, pClonedNote);
- }
- }
- }
}
}
break;
default:
- /* TODO : notes - notes of empty cell are note copied */
- /* the following code does not solve it */
- {
- if (bCopyCellNotes)
- {
- sc::formula_block::const_iterator it = sc::formula_block::begin(*node.data);
- std::advance(it, nOffset);
- sc::formula_block::const_iterator itEnd = it;
- std::advance(itEnd, nDataSize);
- for (SCROW nSrcRow = nSrcRow1; it != itEnd; ++it, ++nSrcRow)
- {
- sc::CellNoteStoreType& maCellNotesSrc = mrSrcCol.GetCellNoteStore();
- sc::CellNoteStoreType::position_type aPos = maCellNotesSrc.position(nSrcRow);
- sc::CellNoteStoreType::iterator itNotes = aPos.first;
- if (itNotes->type == sc::element_type_cellnote)
- {
- ScPostIt* pSrcNote = maCellNotesSrc.get<ScPostIt*>(nSrcRow);
- if (pSrcNote)
- {
- ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nSrcRow+mnRowOffset, mrDestCol.GetTab());
- ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nSrcRow, mrSrcCol.GetTab() ),
- mrDestCol.GetDoc(),
- aDestPos, true );
- mrDestCol.GetDoc().ReleaseNote(aDestPos);
- mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
- }
- }
- }
- }
- }
+ ;
}
+ if (bCopyCellNotes)
+ duplicateNotes(nSrcRow1, nOffset, nDataSize );
}
};
More information about the Libreoffice-commits
mailing list