sc/inc/column.hxx | 1 + sc/inc/document.hxx | 8 +++++++- sc/inc/mtvcellfunc.hxx | 7 +++++++ sc/inc/table.hxx | 1 + sc/qa/unit/data/ods/single-note.ods |binary sc/qa/unit/subsequent_export-test.cxx | 31 +++++++++++++++++++++++++++++++ sc/source/core/data/column2.cxx | 23 +++++++++++++++++++++++ sc/source/core/data/document.cxx | 11 +++++++++++ sc/source/core/data/table2.cxx | 6 ++++++ sc/source/filter/xml/xmlwrap.cxx | 2 ++ 10 files changed, 89 insertions(+), 1 deletion(-)
New commits: commit 018500a73f3b1082b6662b7c123dfe5158ae5752 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sun Feb 2 13:21:35 2014 -0500 fdo#74325: Ensure that all note objects have an sdr object before exporting. Otherwise, if a note hasn't been displayed at least once before saving that note would not get saved. In the future, we should modify the export code to not rely on SdrObject to check the presence of note. Change-Id: Ib7ca3ac00a0c9cdd3a01facda7af479ef172afbe diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 835daa8..34cef91 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -515,6 +515,7 @@ public: bool IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const; size_t GetNoteCount() const; + void CreateAllNoteCaptions(); SCROW GetNotePosition( size_t nIndex ) const; void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const; void GetNotesInRange( SCROW nStartRow, SCROW nEndRow, std::vector<sc::NoteEntry>& rNotes ) const; diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 551557d..ded209c 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -913,6 +913,12 @@ public: size_t CountNotes() const; size_t GetNoteCount( SCTAB nTab, SCCOL nCol ) const; + /** + * Ensure that all note objects have an associated sdr object. The export + * code uses sdr objects to export note data. + */ + void CreateAllNoteCaptions(); + ScAddress GetNotePosition( size_t nIndex ) const; SCROW GetNotePosition( SCTAB nTab, SCCOL nCol, size_t nIndex ) const; diff --git a/sc/inc/mtvcellfunc.hxx b/sc/inc/mtvcellfunc.hxx index c54d02e..793f2db 100644 --- a/sc/inc/mtvcellfunc.hxx +++ b/sc/inc/mtvcellfunc.hxx @@ -159,6 +159,13 @@ FindFormulaEditText(const CellStoreType& rStore, SCROW nRow1, SCROW nRow2, _Func return FindElement2<CellStoreType, edittext_block, formula_block, _Func, _Func>(rStore, nRow1, nRow2, rFunc, rFunc); } +template<typename _Func> +void ProcessNote(CellNoteStoreType& rStore, _Func& rFunc) +{ + FuncElseNoOp<size_t> aElse; + ProcessElements1<CellNoteStoreType, cellnote_block, _Func, FuncElseNoOp<size_t> >(rStore, rFunc, aElse); +} + } #endif diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 548c6cc..eb17a18 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -388,6 +388,7 @@ public: size_t GetNoteCount( SCCOL nCol ) const; SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const; + void CreateAllNoteCaptions(); void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const; void GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const; diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 510ad17..7a58377 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1227,6 +1227,29 @@ size_t ScColumn::GetNoteCount() const return nCount; } +namespace { + +class NoteCaptionCreator +{ + ScAddress maPos; +public: + NoteCaptionCreator( SCTAB nTab, SCCOL nCol ) : maPos(nCol,0,nTab) {} + + void operator() ( size_t nRow, ScPostIt* p ) + { + maPos.SetRow(nRow); + p->GetOrCreateCaption(maPos); + } +}; + +} + +void ScColumn::CreateAllNoteCaptions() +{ + NoteCaptionCreator aFunc(nTab, nCol); + sc::ProcessNote(maCellNotes, aFunc); +} + SCROW ScColumn::GetNotePosition( size_t nIndex ) const { // Return the row position of the nth note in the column. diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 432888b..eab2594 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -6224,6 +6224,17 @@ size_t ScDocument::GetNoteCount( SCTAB nTab, SCCOL nCol ) const return pTab->GetNoteCount(nCol); } +void ScDocument::CreateAllNoteCaptions() +{ + TableContainer::iterator it = maTabs.begin(), itEnd = maTabs.end(); + for (; it != itEnd; ++it) + { + ScTable* p = *it; + if (p) + p->CreateAllNoteCaptions(); + } +} + ScAddress ScDocument::GetNotePosition( size_t nIndex ) const { for (size_t nTab = 0; nTab < maTabs.size(); ++nTab) diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 8a16e49..d8cfbfe 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1511,6 +1511,12 @@ SCROW ScTable::GetNotePosition( SCCOL nCol, size_t nIndex ) const return aCol[nCol].GetNotePosition(nIndex); } +void ScTable::CreateAllNoteCaptions() +{ + for (SCCOL i = 0; i <= MAXCOL; ++i) + aCol[i].CreateAllNoteCaptions(); +} + void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const { for (SCCOL nCol = 0; nCol < MAXCOLCOUNT; ++nCol) diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx index 4e2ef7d..b965888 100644 --- a/sc/source/filter/xml/xmlwrap.cxx +++ b/sc/source/filter/xml/xmlwrap.cxx @@ -759,6 +759,8 @@ sal_Bool ScXMLImportWrapper::ExportToComponent(const uno::Reference<uno::XCompon sal_Bool ScXMLImportWrapper::Export(sal_Bool bStylesOnly) { + rDoc.CreateAllNoteCaptions(); + uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); uno::Reference<xml::sax::XWriter> xWriter = xml::sax::Writer::create(xContext); commit 31973b54efb1c607d7a53b0728264f8dd13bef0f Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sun Feb 2 10:48:57 2014 -0500 fdo#74325: Write unit test for cell note export to ods. Change-Id: Ic145781a6c2d7fefb4e80b3a84735e0fb505b0e7 diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 2d84ecd..551557d 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -902,7 +902,7 @@ public: SC_DLLPUBLIC ScPostIt* GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab); void SetNote(const ScAddress& rPos, ScPostIt* pNote); void SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, ScPostIt* pNote); - bool HasNote(const ScAddress& rPos); + SC_DLLPUBLIC bool HasNote(const ScAddress& rPos); bool HasNote(SCCOL nCol, SCROW nRow, SCTAB nTab); SC_DLLPUBLIC bool HasColNotes(SCCOL nCol, SCTAB nTab); SC_DLLPUBLIC bool HasTabNotes(SCTAB nTab); diff --git a/sc/qa/unit/data/ods/single-note.ods b/sc/qa/unit/data/ods/single-note.ods new file mode 100644 index 0000000..3a0c8e3 Binary files /dev/null and b/sc/qa/unit/data/ods/single-note.ods differ diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index ad2e2ee..5e67df9 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -31,6 +31,7 @@ #include "editutil.hxx" #include "scopetools.hxx" #include "cellvalue.hxx" +#include <postit.hxx> #include "svx/svdoole2.hxx" #include "tabprotection.hxx" @@ -67,6 +68,7 @@ public: void testRichTextExportODS(); void testCellValuesExportODS(); + void testCellNoteExportODS(); void testFormatExportODS(); void testInlineArrayXLS(); @@ -87,6 +89,7 @@ public: CPPUNIT_TEST(testNamedRangeBugfdo62729); CPPUNIT_TEST(testRichTextExportODS); CPPUNIT_TEST(testCellValuesExportODS); + CPPUNIT_TEST(testCellNoteExportODS); CPPUNIT_TEST(testFormatExportODS); CPPUNIT_TEST(testInlineArrayXLS); CPPUNIT_TEST(testEmbeddedChartXLS); @@ -661,6 +664,34 @@ void ScExportTest::testCellValuesExportODS() xNewDocSh->DoClose(); } +void ScExportTest::testCellNoteExportODS() +{ + ScDocShellRef xOrigDocSh = loadDoc("single-note.", ODS); + ScDocument* pDoc = xOrigDocSh->GetDocument(); + + ScAddress aPos(0,0,0); // Start with A1. + CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", pDoc->HasNote(aPos)); + + aPos.IncRow(); // Move to A2. + ScPostIt* pNote = pDoc->GetOrCreateNote(aPos); + pNote->SetText(aPos, "Note One"); + pNote->SetAuthor("Author One"); + CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", pDoc->HasNote(aPos)); + + // save and reload + ScDocShellRef xNewDocSh = saveAndReload(xOrigDocSh, ODS); + xOrigDocSh->DoClose(); + CPPUNIT_ASSERT(xNewDocSh.Is()); + pDoc = xNewDocSh->GetDocument(); + + aPos.SetRow(0); // Move back to A1. + CPPUNIT_ASSERT_MESSAGE("There should be a note at A1.", pDoc->HasNote(aPos)); + aPos.IncRow(); // Move to A2. + CPPUNIT_ASSERT_MESSAGE("There should be a note at A2.", pDoc->HasNote(aPos)); + + xNewDocSh->DoClose(); +} + namespace { void checkMatrixRange(ScDocument& rDoc, const ScRange& rRange) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits