[Libreoffice-commits] .: Branch 'feature/gsoc-calc-perf' - 8 commits - sc/qa sc/source
Daniel Bankston
dbank at kemper.freedesktop.org
Wed Jun 6 23:49:44 PDT 2012
sc/qa/unit/data/contentCSV/merged1.csv | 16
sc/qa/unit/data/contentCSV/merged2.csv | 4
sc/qa/unit/data/contentCSV/repeatedColumns.csv | 1
sc/qa/unit/data/contentCSV/repeatedColumns1.csv | 1
sc/qa/unit/data/contentCSV/repeatedColumns2.csv | 1
sc/qa/unit/data/ods/merged.ods |binary
sc/qa/unit/data/ods/repeatedColumns.ods |binary
sc/qa/unit/subsequent_filters-test.cxx | 66 ++
sc/source/filter/xml/xmlcelli.cxx | 607 ++++++++++++------------
sc/source/filter/xml/xmlcelli.hxx | 16
10 files changed, 422 insertions(+), 290 deletions(-)
New commits:
commit 15491fd393508e25b4516f6c50b52b54052ea0ce
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Thu Jun 7 01:46:52 2012 -0500
Add ODS unittest that checks merged cells and their content on multiple sheets
Existing unit tests did not check if cells were merged correctly on more than
one sheet.
Change-Id: Ibd4d29abd7345afc95fede2a17c7e498d8cac3d9
diff --git a/sc/qa/unit/data/contentCSV/merged1.csv b/sc/qa/unit/data/contentCSV/merged1.csv
new file mode 100644
index 0000000..708ab3a
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/merged1.csv
@@ -0,0 +1,16 @@
+merged,,,,,,,
+,,,,,,,
+,,,,,,,another merged
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,yet another merged,,,,
diff --git a/sc/qa/unit/data/contentCSV/merged2.csv b/sc/qa/unit/data/contentCSV/merged2.csv
new file mode 100644
index 0000000..68eef28
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/merged2.csv
@@ -0,0 +1,4 @@
+,,,,
+,,,,
+,,,,
+,,,,merged on another sheet
diff --git a/sc/qa/unit/data/ods/merged.ods b/sc/qa/unit/data/ods/merged.ods
new file mode 100644
index 0000000..2474571
Binary files /dev/null and b/sc/qa/unit/data/ods/merged.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index e006aac..7cc3f6d 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -112,6 +112,7 @@ public:
void testBugFixesXLS();
void testBugFixesXLSX();
void testBrokenQuotesCSV();
+ void testMergedCellsODS();
void testRepeatedColumnsODS();
//change this test file only in excel and not in calc
@@ -138,6 +139,7 @@ public:
CPPUNIT_TEST(testBugFixesODS);
CPPUNIT_TEST(testBugFixesXLS);
CPPUNIT_TEST(testBugFixesXLSX);
+ CPPUNIT_TEST(testMergedCellsODS);
CPPUNIT_TEST(testRepeatedColumnsODS);
#if 0
CPPUNIT_TEST(testBrokenQuotesCSV);
@@ -631,6 +633,58 @@ void ScFiltersTest::testBugFixesXLSX()
xDocSh->DoClose();
}
+namespace {
+
+void checkMergedCells( ScDocument* pDoc, const ScAddress& rStartAddress,
+ const ScAddress& rExpectedEndAddress )
+{
+ SCCOL nActualEndCol = rStartAddress.Col();
+ SCROW nActualEndRow = rStartAddress.Row();
+ pDoc->ExtendMerge( rStartAddress.Col(), rStartAddress.Row(),
+ nActualEndCol, nActualEndRow, rStartAddress.Tab(), false );
+ rtl::OString sTab = rtl::OString::valueOf( static_cast<sal_Int32>(rStartAddress.Tab() + 1) );
+ rtl::OString sExpectedEndCol = rtl::OString::valueOf( static_cast<sal_Int32>(rExpectedEndAddress.Col()) );
+ rtl::OString sExpectedEndRow = rtl::OString::valueOf( static_cast<sal_Int32>(rExpectedEndAddress.Row()) );
+ rtl::OString sActualEndCol = rtl::OString::valueOf( static_cast<sal_Int32>(nActualEndCol) );
+ rtl::OString sActualEndRow = rtl::OString::valueOf( static_cast<sal_Int32>(nActualEndRow) );
+ rtl::OString msg = "Merged cells are not correctly imported on sheet" + sTab + "\n" +
+ " Expected EndCol, EndRow: " + sExpectedEndCol + ", " + sExpectedEndRow + "\n" +
+ " Actual EndCol, EndRow: " + sActualEndCol + ", " + sActualEndRow;
+ CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer,
+ nActualEndCol == rExpectedEndAddress.Col() &&
+ nActualEndRow == rExpectedEndAddress.Row() );
+}
+
+}
+
+void ScFiltersTest::testMergedCellsODS()
+{
+ const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("merged."));
+ ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+
+ //check sheet1 content
+ rtl::OUString aCSVFileName1;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("merged1.")), aCSVFileName1);
+ testFile(aCSVFileName1, pDoc, 0);
+
+ //check sheet1 merged cells
+ checkMergedCells( pDoc, ScAddress( 0, 0, 0 ), ScAddress( 5, 11, 0 ) );
+ checkMergedCells( pDoc, ScAddress( 7, 2, 0 ), ScAddress( 9, 12, 0 ) );
+ checkMergedCells( pDoc, ScAddress( 3, 15, 0 ), ScAddress( 7, 23, 0 ) );
+
+ //check sheet2 content
+ rtl::OUString aCSVFileName2;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("merged2.")), aCSVFileName2);
+ testFile(aCSVFileName2, pDoc, 1);
+
+ //check sheet2 merged cells
+ checkMergedCells( pDoc, ScAddress( 4, 3, 1 ), ScAddress( 6, 15, 1 ) );
+
+ xDocSh->DoClose();
+}
+
void ScFiltersTest::testRepeatedColumnsODS()
{
const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns."));
commit f2a1bd4cd13fdf115fcab68c60975f05febf2345
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 21:10:38 2012 -0500
Move logic in AddFormulaCell() that adds non-formula cells into its own method
Change-Id: Icc607e48f5d7bb538c8549b40f21d5e0a75a1511
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 2ba1003..69b3936 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -978,9 +978,72 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos,
}
}
+void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rScCellPos )
+{
+ LockSolarMutex();
+
+ ScDocument* pDoc = rXMLImport.GetDocument();
+
+ rtl::OUString aText = pOUFormula->first;
+ rtl::OUString aFormulaNmsp = pOUFormula->second;
+
+ ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
+ pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
+
+ ScBaseCell* pNewCell = NULL;
+
+ if ( !aText.isEmpty() )
+ {
+ if ( aText[0] == '=' && aText.getLength() > 1 )
+ {
+ // temporary formula string as string tokens
+ ScTokenArray* pCode = new ScTokenArray;
+ pCode->AddStringXML( aText );
+ if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
+ pCode->AddStringXML( aFormulaNmsp );
+
+ pDoc->IncXMLImportedFormulaCount( aText.getLength() );
+ pNewCell = new ScFormulaCell( pDoc, rScCellPos, pCode, eGrammar, MM_NONE );
+ delete pCode;
+ }
+ else if ( aText[0] == '\'' && aText.getLength() > 1 )
+ {
+ // for bEnglish, "'" at the beginning is always interpreted as text
+ // marker and stripped
+ pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
+ }
+ else
+ {
+ SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+ sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
+ double fVal;
+ if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
+ {
+ pNewCell = new ScValueCell( fVal );
+ }
+ else
+ pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
+ // das (englische) Zahlformat wird nicht gesetzt
+ //! passendes lokales Format suchen und setzen???
+ }
+
+ if( pNewCell )
+ pDoc->PutCell( rScCellPos, pNewCell );
+
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCellPos );
+ if( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
+ {
+ if( bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty() )
+ static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
+ else
+ static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
+ }
+ }
+}
+
void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
{
- if (scCellExists(rScCellPos))
+ if( scCellExists(rScCellPos) )
{
uno::Reference <table::XCell> xCell;
try
@@ -991,73 +1054,13 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
{
OSL_FAIL("It seems here are to many columns or rows");
}
- if (xCell.is())
+ if( xCell.is() )
{
SetCellProperties(xCell); // set now only the validation
OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
if (!bIsMatrix)
- {
- LockSolarMutex();
-
- ScDocument* pDoc = rXMLImport.GetDocument();
-
- rtl::OUString aText = pOUFormula->first;
- rtl::OUString aFormulaNmsp = pOUFormula->second;
-
- ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
- pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
-
- ScBaseCell* pNewCell = NULL;
-
- if ( !aText.isEmpty() )
- {
- if ( aText[0] == '=' && aText.getLength() > 1 )
- {
- // temporary formula string as string tokens
- ScTokenArray* pCode = new ScTokenArray;
- pCode->AddStringXML( aText );
- if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
- pCode->AddStringXML( aFormulaNmsp );
-
- pDoc->IncXMLImportedFormulaCount( aText.getLength() );
- pNewCell = new ScFormulaCell( pDoc, rScCellPos, pCode, eGrammar, MM_NONE );
- delete pCode;
- }
- else if ( aText[0] == '\'' && aText.getLength() > 1 )
- {
- // for bEnglish, "'" at the beginning is always interpreted as text
- // marker and stripped
- pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
- }
- else
- {
- SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
- sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
- double fVal;
- if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
- {
- pNewCell = new ScValueCell( fVal );
- }
- else
- pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
- // das (englische) Zahlformat wird nicht gesetzt
- //! passendes lokales Format suchen und setzen???
- }
-
- if (pNewCell)
- pDoc->PutCell( rScCellPos, pNewCell );
-
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCellPos );
- if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
- {
- if (bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty())
- static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
- else
- static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
- }
- }
- }
+ AddNonMatrixFormulaCell( rScCellPos );
else
{
if (nMatrixCols > 0 && nMatrixRows > 0)
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 6bd22a5..6ba5ebd 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -98,15 +98,16 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
bool ContextIsEmpty() const;
bool CellsAreRepeated() const;
- void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
- const ::boost::optional< rtl::OUString >& pOUText );
- void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
- void AddCellsToTable ( const ScAddress& rScCellPos,
- const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
- void AddNonFormulaCells ( const ScAddress& rScCellPos,
- const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
- void AddFormulaCell ( const ScAddress& rScCellPos,
- const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
+ void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
+ const ::boost::optional< rtl::OUString >& pOUText );
+ void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
+ void AddCellsToTable ( const ScAddress& rScCellPos,
+ const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
+ void AddNonFormulaCells ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
+ void AddNonMatrixFormulaCell ( const ScAddress& rScCurrentPos );
+ void AddFormulaCell ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
public:
commit db124705d353983886eb80d3d7235155e358d73f
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 20:57:38 2012 -0500
Put logic that adds nonformula cells into its own method
Change-Id: Ieb8d806e8890166c7ccb2188a79368873aaf42a7
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 1dc35da..2ba1003 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -925,6 +925,59 @@ void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
}
}
+bool ScXMLTableRowCellContext::ContextIsEmpty() const
+{
+ return !( (pContentValidationName && !pContentValidationName->isEmpty()) ||
+ mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource );
+}
+
+bool ScXMLTableRowCellContext::CellsAreRepeated() const
+{
+ return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
+}
+
+void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+{
+ ::boost::optional< rtl::OUString > pOUText;
+
+ if( nCellType == util::NumberFormat::TEXT )
+ {
+ if( xLockable.is() )
+ xLockable->removeActionLock();
+
+ // #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
+ // so it can't be used after calling removeActionLock (getString always uses the document).
+
+ if( scCellExists(rScCellPos) && CellsAreRepeated() )
+ pOUText.reset( getOutputString(rXMLImport.GetDocument(), rScCellPos) );
+
+ if( !pOUTextContent && !pOUText && !pOUTextValue )
+ bIsEmpty = true;
+ }
+
+ ScAddress aScCurrentPos( rScCellPos );
+ if( !ContextIsEmpty() )
+ bIsEmpty = false;
+
+ AddCellsToTable( rScCellPos, pOUText, aScCurrentPos );
+
+ if( CellsAreRepeated() )
+ {
+ SetCellProperties(xCellRange, rScCellPos); // set now only the validation for the complete range with the given cell as start cell
+ SCCOL nStartCol( rScCellPos.Col() < MAXCOL ? rScCellPos.Col() : MAXCOL );
+ SCROW nStartRow( rScCellPos.Row() < MAXROW ? rScCellPos.Row() : MAXROW );
+ SCCOL nEndCol( rScCellPos.Col() + nColsRepeated - 1 < MAXCOL ? rScCellPos.Col() + nColsRepeated - 1 : MAXCOL );
+ SCROW nEndRow( rScCellPos.Row() + nRepeatedRows - 1 < MAXROW ? rScCellPos.Row() + nRepeatedRows - 1 : MAXROW );
+ ScRange aScRange( nStartCol, nStartRow, rScCellPos.Tab(), nEndCol, nEndRow, rScCellPos.Tab() );
+ rXMLImport.GetStylesImportHelper()->AddRange(aScRange);
+ }
+ else if( scCellExists(rScCellPos) )
+ {
+ rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
+ SetCellProperties(xCellRange, rScCellPos);
+ }
+}
+
void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
{
if (scCellExists(rScCellPos))
@@ -1031,17 +1084,6 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
}
}
-bool ScXMLTableRowCellContext::ContextIsEmpty() const
-{
- return !( (pContentValidationName && !pContentValidationName->isEmpty()) ||
- mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource );
-}
-
-bool ScXMLTableRowCellContext::CellsAreRepeated() const
-{
- return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
-}
-
void ScXMLTableRowCellContext::EndElement()
{
if( !bHasSubTable )
@@ -1054,68 +1096,25 @@ void ScXMLTableRowCellContext::EndElement()
if( aTextImport->GetCursor()->goLeft(1, true) )
{
aTextImport->GetText()->insertString(
- aTextImport->GetCursorAsRange(), rtl::OUString(),
- true );
+ aTextImport->GetCursorAsRange(), rtl::OUString(), true );
}
aTextImport->ResetCursor();
}
}
- ScMyTables& rTables = rXMLImport.GetTables();
- ScAddress aScCellPos = rTables.GetRealScCellPos();
+ ScAddress aScCellPos = rXMLImport.GetTables().GetRealScCellPos();
if( aScCellPos.Col() > 0 && nRepeatedRows > 1 )
aScCellPos.SetRow( aScCellPos.Row() - (nRepeatedRows - 1) );
- uno::Reference<table::XCellRange> xCellRange(rTables.GetCurrentXCellRange());
+ uno::Reference<table::XCellRange> xCellRange( rXMLImport.GetTables().GetCurrentXCellRange() );
if( xCellRange.is() )
{
if( bIsMerged )
DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
if( !pOUFormula )
- {
- ::boost::optional< rtl::OUString > pOUText;
-
- if( nCellType == util::NumberFormat::TEXT )
- {
- if( xLockable.is() )
- xLockable->removeActionLock();
-
- // #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
- // so it can't be used after calling removeActionLock (getString always uses the document).
-
- if( scCellExists(aScCellPos) && CellsAreRepeated() )
- pOUText.reset( getOutputString(rXMLImport.GetDocument(), aScCellPos) );
-
- if( !pOUTextContent && !pOUText && !pOUTextValue )
- bIsEmpty = true;
- }
-
- ScAddress aScCurrentPos( aScCellPos );
- if( !ContextIsEmpty() )
- bIsEmpty = false;
-
- AddCellsToTable( aScCellPos, pOUText, aScCurrentPos );
-
- if( CellsAreRepeated() )
- {
- SetCellProperties(xCellRange, aScCellPos); // set now only the validation for the complete range with the given cell as start cell
- SCCOL nStartCol( aScCellPos.Col() < MAXCOL ? aScCellPos.Col() : MAXCOL );
- SCROW nStartRow( aScCellPos.Row() < MAXROW ? aScCellPos.Row() : MAXROW );
- SCCOL nEndCol( aScCellPos.Col() + nColsRepeated - 1 < MAXCOL ? aScCellPos.Col() + nColsRepeated - 1 : MAXCOL );
- SCROW nEndRow( aScCellPos.Row() + nRepeatedRows - 1 < MAXROW ? aScCellPos.Row() + nRepeatedRows - 1 : MAXROW );
- ScRange aScRange( nStartCol, nStartRow, aScCellPos.Tab(), nEndCol, nEndRow, aScCellPos.Tab() );
- rXMLImport.GetStylesImportHelper()->AddRange(aScRange);
- }
- else if( scCellExists(aScCellPos) )
- {
- rXMLImport.GetStylesImportHelper()->AddCell(aScCellPos);
- SetCellProperties(xCellRange, aScCellPos);
- }
- }
+ AddNonFormulaCells( aScCellPos, xCellRange );
else // if ( pOUFormula )
- {
AddFormulaCell( aScCellPos, xCellRange );
- }
}
UnlockSolarMutex();
}
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index bc7f49f..6bd22a5 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -103,6 +103,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
void AddCellsToTable ( const ScAddress& rScCellPos,
const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
+ void AddNonFormulaCells ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
void AddFormulaCell ( const ScAddress& rScCellPos,
const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
commit 514797046f9b632f62da88132ca91d3610c49a63
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 20:04:15 2012 -0500
Put some conditional statements into readable methods and do minor formatting
Change-Id: I82d6349db5e7e3afdc36d893155539129f9d120c
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 3b4e4e7..1dc35da 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -117,7 +117,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
nMergedRows(1),
nRepeatedRows(nTempRepeatedRows),
nMergedCols(1),
- nCellsRepeated(1),
+ nColsRepeated(1),
rXMLImport((ScXMLImport&)rImport),
eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
nCellType(util::NumberFormat::TEXT),
@@ -171,7 +171,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
nMatrixRows = static_cast<SCROW>(sValue.toInt32());
break;
case XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED:
- nCellsRepeated = static_cast<SCCOL>(std::max( sValue.toInt32(), (sal_Int32) 1 ));
+ nColsRepeated = static_cast<SCCOL>(std::max( sValue.toInt32(), (sal_Int32) 1 ));
break;
case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE:
nCellType = GetScImport().GetCellType(sValue);
@@ -547,7 +547,7 @@ void ScXMLTableRowCellContext::SetCellProperties(const uno::Reference<table::XCe
if (CellExists(aCellAddress) && pContentValidationName && !pContentValidationName->isEmpty())
{
sal_Int32 nBottom = aCellAddress.Row + static_cast<sal_Int32>(nRepeatedRows) - 1;
- sal_Int32 nRight = aCellAddress.Column + static_cast<sal_Int32>(nCellsRepeated) - 1;
+ sal_Int32 nRight = aCellAddress.Column + static_cast<sal_Int32>(nColsRepeated) - 1;
if (nBottom > MAXROW)
nBottom = MAXROW;
if (nRight > MAXCOL)
@@ -846,7 +846,7 @@ void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
{
ScMyTables& rTables = rXMLImport.GetTables();
bool bWasEmpty = bIsEmpty;
- for (SCCOL i = 0; i < nCellsRepeated; ++i)
+ for (SCCOL i = 0; i < nColsRepeated; ++i)
{
rScCurrentPos.SetCol( rScCellPos.Col() + i );
if (i > 0)
@@ -941,7 +941,7 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
if (xCell.is())
{
SetCellProperties(xCell); // set now only the validation
- OSL_ENSURE(((nCellsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
+ OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
if (!bIsMatrix)
{
@@ -1031,16 +1031,27 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
}
}
+bool ScXMLTableRowCellContext::ContextIsEmpty() const
+{
+ return !( (pContentValidationName && !pContentValidationName->isEmpty()) ||
+ mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource );
+}
+
+bool ScXMLTableRowCellContext::CellsAreRepeated() const
+{
+ return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
+}
+
void ScXMLTableRowCellContext::EndElement()
{
- if (!bHasSubTable)
+ if( !bHasSubTable )
{
- if (bHasTextImport && rXMLImport.GetRemoveLastChar())
+ if( bHasTextImport && rXMLImport.GetRemoveLastChar() )
{
UniReference< XMLTextImportHelper > aTextImport = rXMLImport.GetTextImport();
- if (aTextImport->GetCursor().is())
+ if( aTextImport->GetCursor().is() )
{
- if( aTextImport->GetCursor()->goLeft( 1, true ) )
+ if( aTextImport->GetCursor()->goLeft(1, true) )
{
aTextImport->GetText()->insertString(
aTextImport->GetCursorAsRange(), rtl::OUString(),
@@ -1052,49 +1063,47 @@ void ScXMLTableRowCellContext::EndElement()
ScMyTables& rTables = rXMLImport.GetTables();
ScAddress aScCellPos = rTables.GetRealScCellPos();
- if (aScCellPos.Col() > 0 && nRepeatedRows > 1)
+ if( aScCellPos.Col() > 0 && nRepeatedRows > 1 )
aScCellPos.SetRow( aScCellPos.Row() - (nRepeatedRows - 1) );
uno::Reference<table::XCellRange> xCellRange(rTables.GetCurrentXCellRange());
- if (xCellRange.is())
+ if( xCellRange.is() )
{
- if (bIsMerged)
- DoMerge(aScCellPos, nMergedCols - 1, nMergedRows - 1);
- if ( !pOUFormula )
+ if( bIsMerged )
+ DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
+ if( !pOUFormula )
{
::boost::optional< rtl::OUString > pOUText;
- if(nCellType == util::NumberFormat::TEXT)
+ if( nCellType == util::NumberFormat::TEXT )
{
- if (xLockable.is())
+ if( xLockable.is() )
xLockable->removeActionLock();
// #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
// so it can't be used after calling removeActionLock (getString always uses the document).
- if (scCellExists(aScCellPos) && ((nCellsRepeated > 1) || (nRepeatedRows > 1)))
+ if( scCellExists(aScCellPos) && CellsAreRepeated() )
pOUText.reset( getOutputString(rXMLImport.GetDocument(), aScCellPos) );
- if (!pOUTextContent && !pOUText && !pOUTextValue)
+ if( !pOUTextContent && !pOUText && !pOUTextValue )
bIsEmpty = true;
}
ScAddress aScCurrentPos( aScCellPos );
- if ((pContentValidationName && !pContentValidationName->isEmpty()) ||
- mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource)
+ if( !ContextIsEmpty() )
bIsEmpty = false;
AddCellsToTable( aScCellPos, pOUText, aScCurrentPos );
- if (nCellsRepeated > 1 || nRepeatedRows > 1)
+ if( CellsAreRepeated() )
{
SetCellProperties(xCellRange, aScCellPos); // set now only the validation for the complete range with the given cell as start cell
SCCOL nStartCol( aScCellPos.Col() < MAXCOL ? aScCellPos.Col() : MAXCOL );
SCROW nStartRow( aScCellPos.Row() < MAXROW ? aScCellPos.Row() : MAXROW );
- SCCOL nEndCol( aScCellPos.Col() + nCellsRepeated - 1 < MAXCOL ? aScCellPos.Col() + nCellsRepeated - 1 : MAXCOL );
+ SCCOL nEndCol( aScCellPos.Col() + nColsRepeated - 1 < MAXCOL ? aScCellPos.Col() + nColsRepeated - 1 : MAXCOL );
SCROW nEndRow( aScCellPos.Row() + nRepeatedRows - 1 < MAXROW ? aScCellPos.Row() + nRepeatedRows - 1 : MAXROW );
- ScRange aScRange( nStartCol, nStartRow, aScCellPos.Tab(),
- nEndCol, nEndRow, aScCellPos.Tab() );
+ ScRange aScRange( nStartCol, nStartRow, aScCellPos.Tab(), nEndCol, nEndRow, aScCellPos.Tab() );
rXMLImport.GetStylesImportHelper()->AddRange(aScRange);
}
else if( scCellExists(aScCellPos) )
@@ -1106,8 +1115,7 @@ void ScXMLTableRowCellContext::EndElement()
else // if ( pOUFormula )
{
AddFormulaCell( aScCellPos, xCellRange );
-
- } // if ( pOUFormula )
+ }
}
UnlockSolarMutex();
}
@@ -1115,7 +1123,7 @@ void ScXMLTableRowCellContext::EndElement()
bHasSubTable = false;
nMergedCols = 1;
nMergedRows = 1;
- nCellsRepeated = 1;
+ nColsRepeated = 1;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 3e7e46e..bc7f49f 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -61,7 +61,7 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
ScMyImpCellRangeSource* pCellRangeSource;
double fValue;
SCROW nMergedRows, nMatrixRows, nRepeatedRows;
- SCCOL nMergedCols, nMatrixCols, nCellsRepeated;
+ SCCOL nMergedCols, nMatrixCols, nColsRepeated;
ScXMLImport& rXMLImport;
formula::FormulaGrammar::Grammar eGrammar;
sal_Int16 nCellType;
@@ -95,6 +95,9 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
return (aCellPos.Column <= MAXCOL && aCellPos.Row <= MAXROW);
}
+ bool ContextIsEmpty() const;
+ bool CellsAreRepeated() const;
+
void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
const ::boost::optional< rtl::OUString >& pOUText );
void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
commit 9a148fa9bb8349ede02346209fd669092ff75ef2
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 19:10:09 2012 -0500
Move EndElement()'s logic (that adds formula cell to doc) into its own method
Change-Id: Idd88d66856e5b9ec5e63e238434902daaa4e7f3e
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 0871c4f..3b4e4e7 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -925,6 +925,112 @@ void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
}
}
+void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+{
+ if (scCellExists(rScCellPos))
+ {
+ uno::Reference <table::XCell> xCell;
+ try
+ {
+ xCell.set(xCellRange->getCellByPosition(rScCellPos.Col() , rScCellPos.Row()));
+ }
+ catch (lang::IndexOutOfBoundsException&)
+ {
+ OSL_FAIL("It seems here are to many columns or rows");
+ }
+ if (xCell.is())
+ {
+ SetCellProperties(xCell); // set now only the validation
+ OSL_ENSURE(((nCellsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
+ rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
+ if (!bIsMatrix)
+ {
+ LockSolarMutex();
+
+ ScDocument* pDoc = rXMLImport.GetDocument();
+
+ rtl::OUString aText = pOUFormula->first;
+ rtl::OUString aFormulaNmsp = pOUFormula->second;
+
+ ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
+ pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
+
+ ScBaseCell* pNewCell = NULL;
+
+ if ( !aText.isEmpty() )
+ {
+ if ( aText[0] == '=' && aText.getLength() > 1 )
+ {
+ // temporary formula string as string tokens
+ ScTokenArray* pCode = new ScTokenArray;
+ pCode->AddStringXML( aText );
+ if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
+ pCode->AddStringXML( aFormulaNmsp );
+
+ pDoc->IncXMLImportedFormulaCount( aText.getLength() );
+ pNewCell = new ScFormulaCell( pDoc, rScCellPos, pCode, eGrammar, MM_NONE );
+ delete pCode;
+ }
+ else if ( aText[0] == '\'' && aText.getLength() > 1 )
+ {
+ // for bEnglish, "'" at the beginning is always interpreted as text
+ // marker and stripped
+ pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
+ }
+ else
+ {
+ SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+ sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
+ double fVal;
+ if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
+ {
+ pNewCell = new ScValueCell( fVal );
+ }
+ else
+ pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
+ // das (englische) Zahlformat wird nicht gesetzt
+ //! passendes lokales Format suchen und setzen???
+ }
+
+ if (pNewCell)
+ pDoc->PutCell( rScCellPos, pNewCell );
+
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCellPos );
+ if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
+ {
+ if (bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty())
+ static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
+ else
+ static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
+ }
+ }
+ }
+ else
+ {
+ if (nMatrixCols > 0 && nMatrixRows > 0)
+ {
+ rXMLImport.GetTables().AddMatrixRange(
+ rScCellPos.Col(), rScCellPos.Row(),
+ rScCellPos.Col() + nMatrixCols - 1,
+ rScCellPos.Row() + nMatrixRows - 1,
+ pOUFormula->first, pOUFormula->second, eGrammar);
+ }
+ }
+ SetAnnotation( rScCellPos );
+ SetDetectiveObj( rScCellPos );
+ SetCellRangeSource( rScCellPos );
+ rXMLImport.ProgressBarIncrement(false);
+ }
+ }
+ else
+ {
+ if (rScCellPos.Row() > MAXROW)
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
+ else
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
+ }
+}
+
void ScXMLTableRowCellContext::EndElement()
{
if (!bHasSubTable)
@@ -997,112 +1103,11 @@ void ScXMLTableRowCellContext::EndElement()
SetCellProperties(xCellRange, aScCellPos);
}
}
- else // if ( !pOUFormula )
+ else // if ( pOUFormula )
{
- if (scCellExists(aScCellPos))
- {
- uno::Reference <table::XCell> xCell;
- try
- {
- xCell.set(xCellRange->getCellByPosition(aScCellPos.Col() , aScCellPos.Row()));
- }
- catch (lang::IndexOutOfBoundsException&)
- {
- OSL_FAIL("It seems here are to many columns or rows");
- }
- if (xCell.is())
- {
- SetCellProperties(xCell); // set now only the validation
- OSL_ENSURE(((nCellsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
- rXMLImport.GetStylesImportHelper()->AddCell(aScCellPos);
- if (!bIsMatrix)
- {
- LockSolarMutex();
-
- ScDocument* pDoc = rXMLImport.GetDocument();
-
- rtl::OUString aText = pOUFormula->first;
- rtl::OUString aFormulaNmsp = pOUFormula->second;
-
- ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
- pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
-
- ScBaseCell* pNewCell = NULL;
-
- if ( !aText.isEmpty() )
- {
- if ( aText[0] == '=' && aText.getLength() > 1 )
- {
- // temporary formula string as string tokens
- ScTokenArray* pCode = new ScTokenArray;
- pCode->AddStringXML( aText );
- if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
- pCode->AddStringXML( aFormulaNmsp );
-
- pDoc->IncXMLImportedFormulaCount( aText.getLength() );
- pNewCell = new ScFormulaCell( pDoc, aScCellPos, pCode, eGrammar, MM_NONE );
- delete pCode;
- }
- else if ( aText[0] == '\'' && aText.getLength() > 1 )
- {
- // for bEnglish, "'" at the beginning is always interpreted as text
- // marker and stripped
- pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
- }
- else
- {
- SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
- sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
- double fVal;
- if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
- {
- pNewCell = new ScValueCell( fVal );
- }
- else
- pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
- // das (englische) Zahlformat wird nicht gesetzt
- //! passendes lokales Format suchen und setzen???
- }
-
- if (pNewCell)
- pDoc->PutCell( aScCellPos, pNewCell );
-
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( aScCellPos );
- if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
- {
- if (bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty())
- static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
- else
- static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
- }
- }
- }
- else
- {
- if (nMatrixCols > 0 && nMatrixRows > 0)
- {
- rTables.AddMatrixRange(
- aScCellPos.Col(), aScCellPos.Row(),
- aScCellPos.Col() + nMatrixCols - 1,
- aScCellPos.Row() + nMatrixRows - 1,
- pOUFormula->first, pOUFormula->second, eGrammar);
- }
- }
- SetAnnotation( aScCellPos );
- SetDetectiveObj( aScCellPos );
- SetCellRangeSource( aScCellPos );
- rXMLImport.ProgressBarIncrement(false);
- }
- }
- else
- {
- if (aScCellPos.Row() > MAXROW)
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
- else
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
- }
+ AddFormulaCell( aScCellPos, xCellRange );
- } // if ( !pOUFormula )
+ } // if ( pOUFormula )
}
UnlockSolarMutex();
}
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 0a0e8c2..3e7e46e 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -100,6 +100,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
void AddCellsToTable ( const ScAddress& rScCellPos,
const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
+ void AddFormulaCell ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
public:
commit 8b8b075b5471e4ff42a13d159f03831fb8bb278e
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 17:45:18 2012 -0500
Put EndElement()'s long for-loop into its own method
Moved EndElements()'s long for-loop (where rows and columns are added to the
table) to is own method.
Renamed sub-methods to more appropriately reflect the work being done.
Change-Id: Iab9bdc2deb50577af164c8a210a32557e9708d67
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index f15478c..0871c4f 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -767,8 +767,8 @@ rtl::OUString getOutputString(ScDocument* pDoc, const ScAddress& aCellPos)
} // anon namespace
-void ScXMLTableRowCellContext::DoNumberFormatTextWork( const ScAddress& rScCurrentPos,
- const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
+void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rScCurrentPos,
+ const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
{
bool bDoIncrement = true;
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
@@ -813,7 +813,7 @@ void ScXMLTableRowCellContext::DoNumberFormatTextWork( const ScAddress& rScCurre
rXMLImport.ProgressBarIncrement(false);
}
-void ScXMLTableRowCellContext::DoNumberFormatOtherWork( const ScAddress& rScCurrentPos )
+void ScXMLTableRowCellContext::AddNumberCellToDoc( const ScAddress& rScCurrentPos )
{
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
{
@@ -841,6 +841,90 @@ void ScXMLTableRowCellContext::DoNumberFormatOtherWork( const ScAddress& rScCurr
rXMLImport.ProgressBarIncrement(false);
}
+void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
+ const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos )
+{
+ ScMyTables& rTables = rXMLImport.GetTables();
+ bool bWasEmpty = bIsEmpty;
+ for (SCCOL i = 0; i < nCellsRepeated; ++i)
+ {
+ rScCurrentPos.SetCol( rScCellPos.Col() + i );
+ if (i > 0)
+ rTables.AddColumn(false);
+ if (!bIsEmpty)
+ {
+ for (SCROW j = 0; j < nRepeatedRows; ++j)
+ {
+ rScCurrentPos.SetRow( rScCellPos.Row() + j );
+ if( (rScCurrentPos.Col() == 0) && (j > 0) )
+ {
+ rTables.AddRow();
+ rTables.AddColumn(false);
+ }
+ if( scCellExists(rScCurrentPos) )
+ {
+ if( ( !(bIsCovered) || lcl_IsEmptyOrNote(rXMLImport.GetDocument(), rScCurrentPos) ) )
+ {
+ switch (nCellType)
+ {
+ case util::NumberFormat::TEXT:
+ {
+ AddTextCellToDoc( rScCurrentPos, i, pOUText );
+ }
+ break;
+ case util::NumberFormat::NUMBER:
+ case util::NumberFormat::PERCENT:
+ case util::NumberFormat::CURRENCY:
+ case util::NumberFormat::TIME:
+ case util::NumberFormat::DATETIME:
+ case util::NumberFormat::LOGICAL:
+ {
+ AddNumberCellToDoc( rScCurrentPos );
+ }
+ break;
+ default:
+ {
+ OSL_FAIL("no cell type given");
+ }
+ break;
+ }
+ }
+
+ SetAnnotation( rScCurrentPos );
+ SetDetectiveObj( rScCurrentPos );
+ SetCellRangeSource( rScCurrentPos );
+ }
+ else
+ {
+ if (!bWasEmpty || mxAnnotationData.get())
+ {
+ if (rScCurrentPos.Row() > MAXROW)
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
+ else
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
+ }
+ }
+ }
+ }
+ else
+ {
+ // #i56027# If the child context put formatted text into the cell,
+ // bIsEmpty is true and ProgressBarIncrement has to be called
+ // with bEditCell = TRUE.
+ if (bHasTextImport)
+ rXMLImport.ProgressBarIncrement(true);
+ if ((i == 0) && (rScCellPos.Col() == 0))
+ {
+ for (sal_Int32 j = 1; j < nRepeatedRows; ++j)
+ {
+ rTables.AddRow();
+ rTables.AddColumn(false);
+ }
+ }
+ }
+ }
+}
+
void ScXMLTableRowCellContext::EndElement()
{
if (!bHasSubTable)
@@ -888,88 +972,14 @@ void ScXMLTableRowCellContext::EndElement()
if (!pOUTextContent && !pOUText && !pOUTextValue)
bIsEmpty = true;
}
- bool bWasEmpty = bIsEmpty;
ScAddress aScCurrentPos( aScCellPos );
if ((pContentValidationName && !pContentValidationName->isEmpty()) ||
mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource)
bIsEmpty = false;
- for (SCCOL i = 0; i < nCellsRepeated; ++i)
- {
- aScCurrentPos.SetCol( aScCellPos.Col() + i );
- if (i > 0)
- rTables.AddColumn(false);
- if (!bIsEmpty)
- {
- for (SCROW j = 0; j < nRepeatedRows; ++j)
- {
- aScCurrentPos.SetRow( aScCellPos.Row() + j );
- if( (aScCurrentPos.Col() == 0) && (j > 0) )
- {
- rTables.AddRow();
- rTables.AddColumn(false);
- }
- if( scCellExists(aScCurrentPos) )
- {
- if( ( !(bIsCovered) || lcl_IsEmptyOrNote(rXMLImport.GetDocument(), aScCurrentPos) ) )
- {
- switch (nCellType)
- {
- case util::NumberFormat::TEXT:
- {
- DoNumberFormatTextWork( aScCurrentPos, i, pOUText );
- }
- break;
- case util::NumberFormat::NUMBER:
- case util::NumberFormat::PERCENT:
- case util::NumberFormat::CURRENCY:
- case util::NumberFormat::TIME:
- case util::NumberFormat::DATETIME:
- case util::NumberFormat::LOGICAL:
- {
- DoNumberFormatOtherWork( aScCurrentPos );
- }
- break;
- default:
- {
- OSL_FAIL("no cell type given");
- }
- break;
- }
- }
+ AddCellsToTable( aScCellPos, pOUText, aScCurrentPos );
- SetAnnotation( aScCurrentPos );
- SetDetectiveObj( aScCurrentPos );
- SetCellRangeSource( aScCurrentPos );
- }
- else
- {
- if (!bWasEmpty || mxAnnotationData.get())
- {
- if (aScCurrentPos.Row() > MAXROW)
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
- else
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
- }
- }
- }
- }
- else
- {
- // #i56027# If the child context put formatted text into the cell,
- // bIsEmpty is true and ProgressBarIncrement has to be called
- // with bEditCell = TRUE.
- if (bHasTextImport)
- rXMLImport.ProgressBarIncrement(true);
- if ((i == 0) && (aScCellPos.Col() == 0))
- for (sal_Int32 j = 1; j < nRepeatedRows; ++j)
- {
- rTables.AddRow();
- rTables.AddColumn(false);
- }
- }
- }
if (nCellsRepeated > 1 || nRepeatedRows > 1)
{
SetCellProperties(xCellRange, aScCellPos); // set now only the validation for the complete range with the given cell as start cell
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 845dacd..0a0e8c2 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -95,9 +95,11 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
return (aCellPos.Column <= MAXCOL && aCellPos.Row <= MAXROW);
}
- void DoNumberFormatTextWork( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
- const ::boost::optional< rtl::OUString >& pOUText );
- void DoNumberFormatOtherWork( const ScAddress& rScCurrentPos );
+ void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
+ const ::boost::optional< rtl::OUString >& pOUText );
+ void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
+ void AddCellsToTable ( const ScAddress& rScCellPos,
+ const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
public:
commit 82bcfd816376846c76cf25ff859c23f6c4340402
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 16:55:27 2012 -0500
Break contents EndElement()'s switch statement into smaller sub functions
Change-Id: Id39e3a4bee4739b988d190a288849e0482b8e52c
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 9e309f7..f15478c 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -287,7 +287,8 @@ namespace {
bool scCellExists( const ScAddress& rCellPos )
{
- return( rCellPos.Col() <= MAXCOL && rCellPos.Row() <= MAXROW );
+ return( rCellPos.Col() >= 0 && rCellPos.Row() >= 0 &&
+ rCellPos.Col() <= MAXCOL && rCellPos.Row() <= MAXROW );
}
}
@@ -764,6 +765,80 @@ rtl::OUString getOutputString(ScDocument* pDoc, const ScAddress& aCellPos)
return aVal;
}
+} // anon namespace
+
+void ScXMLTableRowCellContext::DoNumberFormatTextWork( const ScAddress& rScCurrentPos,
+ const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
+{
+ bool bDoIncrement = true;
+ if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
+ {
+ LockSolarMutex();
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
+ bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA );
+ if ( bDoIncrement )
+ {
+ ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+ if (pOUTextValue && !pOUTextValue->isEmpty())
+ pFCell->SetHybridString( *pOUTextValue );
+ else if (pOUTextContent && !pOUTextContent->isEmpty())
+ pFCell->SetHybridString( *pOUTextContent );
+ else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
+ pFCell->SetHybridString( *pOUText );
+ else
+ bDoIncrement = false;
+ }
+ }
+ else
+ {
+ LockSolarMutex();
+ ScBaseCell* pNewCell = NULL;
+ ScDocument* pDoc = rXMLImport.GetDocument();
+ if (pOUTextValue && !pOUTextValue->isEmpty())
+ pNewCell = ScBaseCell::CreateTextCell( *pOUTextValue, pDoc );
+ else if (pOUTextContent && !pOUTextContent->isEmpty())
+ pNewCell = ScBaseCell::CreateTextCell( *pOUTextContent, pDoc );
+ else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
+ pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc );
+
+ bDoIncrement = pNewCell != NULL;
+ if ( bDoIncrement )
+ pDoc->PutCell( rScCurrentPos, pNewCell );
+ }
+ // #i56027# This is about setting simple text, not edit cells,
+ // so ProgressBarIncrement must be called with bEditCell = FALSE.
+ // Formatted text that is put into the cell by the child context
+ // is handled below (bIsEmpty is true then).
+ if (bDoIncrement || bHasTextImport)
+ rXMLImport.ProgressBarIncrement(false);
+}
+
+void ScXMLTableRowCellContext::DoNumberFormatOtherWork( const ScAddress& rScCurrentPos )
+{
+ if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
+ {
+ LockSolarMutex();
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
+ if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
+ static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
+ }
+ else
+ {
+ LockSolarMutex();
+
+ // #i62435# Initialize the value cell's script type
+ // if the default style's number format is latin-only.
+ // If the cell uses a different format, the script type
+ // will be reset when the style is applied.
+
+ ScBaseCell* pNewCell = new ScValueCell(fValue);
+ if ( rXMLImport.IsLatinDefaultStyle() )
+ pNewCell->SetScriptType( SCRIPTTYPE_LATIN );
+ rXMLImport.GetDocument()->PutCell(
+ rScCurrentPos.Col(), rScCurrentPos.Row(),
+ rScCurrentPos.Tab(), pNewCell );
+ }
+ rXMLImport.ProgressBarIncrement(false);
}
void ScXMLTableRowCellContext::EndElement()
@@ -843,47 +918,7 @@ void ScXMLTableRowCellContext::EndElement()
{
case util::NumberFormat::TEXT:
{
- bool bDoIncrement = true;
- if( rTables.IsPartOfMatrix(aScCurrentPos.Col(), aScCurrentPos.Row()) )
- {
- LockSolarMutex();
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( aScCurrentPos );
- bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA );
- if ( bDoIncrement )
- {
- ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
- if (pOUTextValue && !pOUTextValue->isEmpty())
- pFCell->SetHybridString( *pOUTextValue );
- else if (pOUTextContent && !pOUTextContent->isEmpty())
- pFCell->SetHybridString( *pOUTextContent );
- else if ( i > 0 && pOUText && !pOUText->isEmpty() )
- pFCell->SetHybridString( *pOUText );
- else
- bDoIncrement = false;
- }
- }
- else
- {
- LockSolarMutex();
- ScBaseCell* pNewCell = NULL;
- ScDocument* pDoc = rXMLImport.GetDocument();
- if (pOUTextValue && !pOUTextValue->isEmpty())
- pNewCell = ScBaseCell::CreateTextCell( *pOUTextValue, pDoc );
- else if (pOUTextContent && !pOUTextContent->isEmpty())
- pNewCell = ScBaseCell::CreateTextCell( *pOUTextContent, pDoc );
- else if ( i > 0 && pOUText && !pOUText->isEmpty() )
- pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc );
-
- bDoIncrement = pNewCell != NULL;
- if ( bDoIncrement )
- pDoc->PutCell( aScCurrentPos, pNewCell );
- }
- // #i56027# This is about setting simple text, not edit cells,
- // so ProgressBarIncrement must be called with bEditCell = FALSE.
- // Formatted text that is put into the cell by the child context
- // is handled below (bIsEmpty is true then).
- if (bDoIncrement || bHasTextImport)
- rXMLImport.ProgressBarIncrement(false);
+ DoNumberFormatTextWork( aScCurrentPos, i, pOUText );
}
break;
case util::NumberFormat::NUMBER:
@@ -893,30 +928,7 @@ void ScXMLTableRowCellContext::EndElement()
case util::NumberFormat::DATETIME:
case util::NumberFormat::LOGICAL:
{
- if( rTables.IsPartOfMatrix(aScCurrentPos.Col(), aScCurrentPos.Row()) )
- {
- LockSolarMutex();
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( aScCurrentPos );
- if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
- static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
- }
- else
- {
- LockSolarMutex();
-
- // #i62435# Initialize the value cell's script type
- // if the default style's number format is latin-only.
- // If the cell uses a different format, the script type
- // will be reset when the style is applied.
-
- ScBaseCell* pNewCell = new ScValueCell(fValue);
- if ( rXMLImport.IsLatinDefaultStyle() )
- pNewCell->SetScriptType( SCRIPTTYPE_LATIN );
- rXMLImport.GetDocument()->PutCell(
- aScCurrentPos.Col(), aScCurrentPos.Row(),
- aScCurrentPos.Tab(), pNewCell );
- }
- rXMLImport.ProgressBarIncrement(false);
+ DoNumberFormatOtherWork( aScCurrentPos );
}
break;
default:
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 3e624ee..845dacd 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -95,6 +95,10 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
return (aCellPos.Column <= MAXCOL && aCellPos.Row <= MAXROW);
}
+ void DoNumberFormatTextWork( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
+ const ::boost::optional< rtl::OUString >& pOUText );
+ void DoNumberFormatOtherWork( const ScAddress& rScCurrentPos );
+
public:
ScXMLTableRowCellContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
commit df27c101fd3645f3c5fde89b510d6c3139cd469f
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 16:13:19 2012 -0500
Extend repeated columns unit test to check both text and numbers
Change-Id: I7d261958f81f73dfce44f27c0130f68c5c4b233f
diff --git a/sc/qa/unit/data/contentCSV/repeatedColumns.csv b/sc/qa/unit/data/contentCSV/repeatedColumns.csv
deleted file mode 100644
index ffcf6c2..0000000
--- a/sc/qa/unit/data/contentCSV/repeatedColumns.csv
+++ /dev/null
@@ -1 +0,0 @@
-test,test,test,test,test,test
diff --git a/sc/qa/unit/data/contentCSV/repeatedColumns1.csv b/sc/qa/unit/data/contentCSV/repeatedColumns1.csv
new file mode 100644
index 0000000..ffcf6c2
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/repeatedColumns1.csv
@@ -0,0 +1 @@
+test,test,test,test,test,test
diff --git a/sc/qa/unit/data/contentCSV/repeatedColumns2.csv b/sc/qa/unit/data/contentCSV/repeatedColumns2.csv
new file mode 100644
index 0000000..e0020ad
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/repeatedColumns2.csv
@@ -0,0 +1 @@
+5,5,5,5,5
diff --git a/sc/qa/unit/data/ods/repeatedColumns.ods b/sc/qa/unit/data/ods/repeatedColumns.ods
index f1e7b69..3b55057 100644
Binary files a/sc/qa/unit/data/ods/repeatedColumns.ods and b/sc/qa/unit/data/ods/repeatedColumns.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index cfe32e0..e006aac 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -638,9 +638,15 @@ void ScFiltersTest::testRepeatedColumnsODS()
ScDocument* pDoc = xDocSh->GetDocument();
- rtl::OUString aCSVFileName;
- createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns.")), aCSVFileName);
- testFile(aCSVFileName, pDoc, 0);
+ //text
+ rtl::OUString aCSVFileName1;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns1.")), aCSVFileName1);
+ testFile(aCSVFileName1, pDoc, 0);
+
+ //numbers
+ rtl::OUString aCSVFileName2;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns2.")), aCSVFileName2);
+ testFile(aCSVFileName2, pDoc, 1);
xDocSh->DoClose();
}
More information about the Libreoffice-commits
mailing list