[Libreoffice-commits] .: Branch 'feature/gsoc-calc-perf' - 5 commits - sc/qa sc/source
Daniel Bankston
dbank at kemper.freedesktop.org
Sat Jun 9 04:56:37 PDT 2012
sc/qa/unit/data/contentCSV/dataValidity1.csv | 4
sc/qa/unit/data/contentCSV/dataValidity2.csv | 8
sc/qa/unit/data/ods/dataValidity.ods |binary
sc/qa/unit/subsequent_filters-test.cxx | 153 ++++++++++++++++
sc/source/filter/xml/xmlcelli.cxx | 256 ++++++++++++++-------------
sc/source/filter/xml/xmlcelli.hxx | 12 -
6 files changed, 311 insertions(+), 122 deletions(-)
New commits:
commit 8a7fce7e9f522c44d4207eef4becbd32a8148719
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 06:53:23 2012 -0500
Remove unused variables and parameters
Change-Id: I8691529e6260ea4d9e9d1d61ce3b1b28de7a676e
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index fa981c8..c1df37e 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -817,7 +817,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rScCurrentPos,
bool bDoIncrement = true;
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA );
if ( bDoIncrement )
@@ -835,7 +835,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rScCurrentPos,
}
else
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
ScBaseCell* pNewCell = NULL;
ScDocument* pDoc = rXMLImport.GetDocument();
if (pOUTextValue && !pOUTextValue->isEmpty())
@@ -861,14 +861,14 @@ void ScXMLTableRowCellContext::AddNumberCellToDoc( const ScAddress& rScCurrentPo
{
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
}
else
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
// #i62435# Initialize the value cell's script type
// if the default style's number format is latin-only.
@@ -980,13 +980,13 @@ bool ScXMLTableRowCellContext::CellsAreRepeated() const
return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
}
-void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos )
{
::boost::optional< rtl::OUString > pOUText;
if( nCellType == util::NumberFormat::TEXT )
{
- if( xLockable.is() )
+ if( xLockable.is() ) //is this still needed?
xLockable->removeActionLock();
// #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
@@ -1024,7 +1024,7 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos,
void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rScCellPos )
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed
ScDocument* pDoc = rXMLImport.GetDocument();
@@ -1085,42 +1085,30 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rScCell
}
}
-void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos )
{
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() )
+ SetContentValidation( rScCellPos );
+ OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
+ rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
+ if (!bIsMatrix)
+ AddNonMatrixFormulaCell( rScCellPos );
+ else
{
- SetContentValidation( rScCellPos );
- OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
- rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
- if (!bIsMatrix)
- AddNonMatrixFormulaCell( rScCellPos );
- else
+ if (nMatrixCols > 0 && nMatrixRows > 0)
{
- 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);
- }
+ 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);
}
+ SetAnnotation( rScCellPos );
+ SetDetectiveObj( rScCellPos );
+ SetCellRangeSource( rScCellPos );
+ rXMLImport.ProgressBarIncrement(false);
}
else
{
@@ -1152,18 +1140,14 @@ void ScXMLTableRowCellContext::EndElement()
ScAddress aScCellPos = rXMLImport.GetTables().GetRealScCellPos();
if( aScCellPos.Col() > 0 && nRepeatedRows > 1 )
aScCellPos.SetRow( aScCellPos.Row() - (nRepeatedRows - 1) );
-
- uno::Reference<table::XCellRange> xCellRange( rXMLImport.GetTables().GetCurrentXCellRange() );
- if( xCellRange.is() )
- {
- if( bIsMerged )
- DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
- if( !pOUFormula )
- AddNonFormulaCells( aScCellPos, xCellRange );
- else // if ( pOUFormula )
- AddFormulaCell( aScCellPos, xCellRange );
- }
- UnlockSolarMutex();
+ if( bIsMerged )
+ DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
+ if( !pOUFormula )
+ AddNonFormulaCells( aScCellPos );
+ else // if ( pOUFormula )
+ AddFormulaCell( aScCellPos );
+
+ UnlockSolarMutex(); //is this still needed?
}
bIsMerged = false;
bHasSubTable = false;
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 11914b2..978c9c1 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -101,11 +101,9 @@ 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 AddNonFormulaCells ( const ScAddress& rScCellPos );
void AddNonMatrixFormulaCell ( const ScAddress& rScCurrentPos );
- void AddFormulaCell ( const ScAddress& rScCellPos,
- const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
+ void AddFormulaCell ( const ScAddress& rScCellPos );
public:
commit 68f3467cb825eef86b86447cb5d33a69268e7ca2
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 06:34:06 2012 -0500
Fix regression that caused extra validation entries to be added to scdocument
Was adding duplicate validation entries that only had the
base cell address different.
Change-Id: I7cfe78c98cff350f2621cb4f321134ade04d0158
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 3a103a5..fa981c8 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -564,7 +564,7 @@ void ScXMLTableRowCellContext::SetContentValidation( const ScRange& rScRange )
ScValidationData aScValidationData(
validationTypeToMode(aValidation.aValidationType),
conditionOpToMode(aValidation.aOperator),
- aValidation.sFormula1, aValidation.sFormula2, pDoc, rScRange.aStart,
+ aValidation.sFormula1, aValidation.sFormula2, pDoc, ScAddress(),
aValidation.sFormulaNmsp1, aValidation.sFormulaNmsp2,
aValidation.eGrammar1, aValidation.eGrammar2
);
commit c47d99f20c62797e33f46d97bd4fb13ad242ac01
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 06:26:09 2012 -0500
Improve unit test for ODS import of data validity
-Test now ensures only the expected validation entries are tested against.
-Error output for cell validity check is improved. The error message now
displays each cell address that failed instead of just the first one that
fails.
Change-Id: Ic93de0dc3e465e914470634ffab2bfb5ccbe2da7
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index e987d56..63d12a3 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -720,18 +720,19 @@ struct ValDataTestParams
ScAddress aPosition;
String aErrorTitle, aErrorMessage;
ScValidErrorStyle eErrorStyle;
+ sal_uLong nExpectedIndex;
ValDataTestParams( ScValidationMode eMode, ScConditionMode eOp,
String aExpr1, String aExpr2, ScDocument* pDoc,
ScAddress aPos, String aETitle, String aEMsg,
- ScValidErrorStyle eEStyle ):
+ ScValidErrorStyle eEStyle, sal_uLong nIndex ):
eValMode(eMode), eCondOp(eOp), aStrVal1(aExpr1),
aStrVal2(aExpr2), pDocument(pDoc), aPosition(aPos),
aErrorTitle(aETitle), aErrorMessage(aEMsg),
- eErrorStyle(eEStyle) { };
+ eErrorStyle(eEStyle), nExpectedIndex(nIndex) { };
};
-void checkValiditationEntries( ValDataTestParams& rVDTParams )
+void checkValiditationEntries( const ValDataTestParams& rVDTParams )
{
ScDocument* pDoc = rVDTParams.pDocument;
@@ -747,23 +748,19 @@ void checkValiditationEntries( ValDataTestParams& rVDTParams )
aValData.SetError( rVDTParams.aErrorTitle, rVDTParams.aErrorMessage, rVDTParams.eErrorStyle );
aValData.SetSrcString( EMPTY_STRING );
- SCCOL nCol( rVDTParams.aPosition.Col() );
- SCROW nRow( rVDTParams.aPosition.Row() );
- SCTAB nTab( rVDTParams.aPosition.Tab() );
//get actual data validation entry from document
- const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(nCol, nRow, nTab, ATTR_VALIDDATA) );
- const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItem->GetValue() );
+ const ScValidationData* pValDataTest = pDoc->GetValidationEntry( rVDTParams.nExpectedIndex );
- rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(nCol)) );
- rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(nRow)) );
- rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
- rtl::OString msg( "Data Validation Entry with base-cell-address(Col,Row,Tab): (" +
+ rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Col())) );
+ rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Row())) );
+ rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Tab())) );
+ rtl::OString msg( "Data Validation Entry with base-cell-address: (" +
sCol + "," + sRow + "," + sTab + ") was not imported correctly." );
//check if expected and actual data validation entries are equal
CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && aValData.EqualEntries(*pValDataTest) );
}
-void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc )
+bool checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc, rtl::OString& sMsg )
{
SCCOL nBCol( rValBaseAddr.Col() );
SCTAB nBRow( rValBaseAddr.Row() );
@@ -772,6 +769,13 @@ void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, co
const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pDoc->GetAttr(nBCol, nBRow, nTab, ATTR_VALIDDATA) );
const ScValidationData* pValData = pDoc->GetValidationEntry( pItem->GetValue() );
+ rtl::OString sCol, sRow;
+ rtl::OString sBCol = rtl::OString::valueOf(static_cast<sal_Int32>(nBCol));
+ rtl::OString sBRow = rtl::OString::valueOf(static_cast<sal_Int32>(nBRow));
+ rtl::OString sTab = rtl::OString::valueOf(static_cast<sal_Int32>(nTab));
+ sMsg += "\nThe following cells failed to reference the data validation entry with base-cell-address: (" +
+ sBCol + "," + sBRow + "," + sTab + ")\n";
+ bool bPassed = true;
//check that each cell in the expected range is associated with the data validation entry
for(SCCOL i = rRange.aStart.Col(); i <= rRange.aEnd.Col(); ++i)
{
@@ -780,17 +784,26 @@ void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, co
const SfxUInt32Item* pItemTest = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(i, j, nTab, ATTR_VALIDDATA) );
const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItemTest->GetValue() );
- rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(i)) );
- rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(j)) );
- rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
- rtl::OString sBCol( rtl::OString::valueOf(static_cast<sal_Int32>(nBCol)) );
- rtl::OString sBRow( rtl::OString::valueOf(static_cast<sal_Int32>(nBRow)) );
- rtl::OString msg( "Cell at (" + sCol + "," + sRow + "," + sTab + ") does not reference " +
- "Data Validation Entry with base-cell-address: (" +
- sBCol + "," + sBRow + "," + sTab + ")." );
- CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && pValData->GetKey() == pValDataTest->GetKey() );
+ sCol = rtl::OString::valueOf(static_cast<sal_Int32>(i));
+ sRow = rtl::OString::valueOf(static_cast<sal_Int32>(j));
+ if(!(pValDataTest && pValData->GetKey() == pValDataTest->GetKey()))
+ {
+ bPassed = false;
+ rtl::OString sEntryKey = rtl::OString::valueOf(static_cast<sal_Int32>(pValData->GetKey()));
+ sMsg += "(" + sCol + "," + sRow + "," + sTab + "), expected key: " + sEntryKey + ", actual key: ";
+ if(pValDataTest)
+ {
+ rtl::OString sTestKey = rtl::OString::valueOf(static_cast<sal_Int32>(pValDataTest->GetKey()));
+ sMsg += sTestKey;
+ }
+ else sMsg += "none";
+ sMsg += "\n";
+ }
}
}
+ if(bPassed) sMsg += "None failed.\n";
+ sMsg += "\n";
+ return bPassed;
}
}
@@ -810,14 +823,14 @@ void ScFiltersTest::testDataValidityODS()
SC_VALID_DECIMAL, SC_COND_GREATER, String("3.14"), EMPTY_STRING, pDoc,
aValBaseAddr1, String("Too small"),
String("The number you are trying to enter is not greater than 3.14! Are you sure you want to enter it anyway?"),
- SC_VALERR_WARNING
+ SC_VALERR_WARNING, 1
);
//sheet2's expected Data Validation Entry values
ValDataTestParams aVDTParams2(
SC_VALID_WHOLE, SC_COND_BETWEEN, String("1"), String("10"), pDoc,
ScAddress(2,3,1), String("Error sheet 2"),
String("Must be a whole number between 1 and 10."),
- SC_VALERR_STOP
+ SC_VALERR_STOP, 2
);
//check each sheet's Data Validation Entries
checkValiditationEntries( aVDTParams1 );
@@ -828,8 +841,10 @@ void ScFiltersTest::testDataValidityODS()
ScRange aRange2( 2,3,1, 6,7,1 ); //sheet2
//check each sheet's cells for data validity
- checkCellValidity( aValBaseAddr1, aRange1, pDoc );
- checkCellValidity( aValBaseAddr2, aRange2, pDoc );
+ rtl::OString sMsg;
+ bool bPassed1 = checkCellValidity( aValBaseAddr1, aRange1, pDoc, sMsg );
+ bool bPassed2 = checkCellValidity( aValBaseAddr2, aRange2, pDoc, sMsg );
+ CPPUNIT_ASSERT_MESSAGE( sMsg.pData->buffer, bPassed1 && bPassed2 );
//check each sheet's content
rtl::OUString aCSVFileName1;
commit 7b8280d03e44a7aadf8f1382f47cf4708021d662
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 02:05:31 2012 -0500
Convert ODS import of Data Validaty to direct sc
Change-Id: Ia64c76d8e056b478fe4b6617fe262ac582008caa
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 69b3936..3a103a5 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -43,6 +43,10 @@
#include "sheetdata.hxx"
#include "docsh.hxx"
#include "cellform.hxx"
+#include "validat.hxx"
+#include "patattr.hxx"
+#include "scitems.hxx"
+#include "docpool.hxx"
#include "XMLTableShapeImportHelper.hxx"
#include "XMLTextPContext.hxx"
@@ -56,6 +60,7 @@
#include "editutil.hxx"
#include "cell.hxx"
+
#include <xmloff/xmltkmap.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/nmspmap.hxx>
@@ -88,10 +93,15 @@
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/text/ControlCharacter.hpp>
+#include <com/sun/star/sheet/ValidationType.hpp>
+#include <com/sun/star/sheet/ValidationAlertStyle.hpp>
+#include <com/sun/star/sheet/ConditionOperator.hpp>
+
#include <rtl/ustrbuf.hxx>
#include <tools/date.hxx>
#include <i18npool/lang.h>
#include <comphelper/extract.hxx>
+#include <tools/string.hxx>
#define SC_CURRENCYSYMBOL "CurrencySymbol"
@@ -488,49 +498,108 @@ void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScAddress, const SCCOL
}
}
-void ScXMLTableRowCellContext::SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet)
+namespace {
+
+ScValidationMode validationTypeToMode( const sheet::ValidationType eVType )
{
- if (pContentValidationName)
+ ScValidationMode eMode;
+ switch( eVType )
+ {
+ case sheet::ValidationType_WHOLE: eMode = SC_VALID_WHOLE; break;
+ case sheet::ValidationType_DECIMAL: eMode = SC_VALID_DECIMAL; break;
+ case sheet::ValidationType_DATE: eMode = SC_VALID_DATE; break;
+ case sheet::ValidationType_TIME: eMode = SC_VALID_TIME; break;
+ case sheet::ValidationType_TEXT_LEN: eMode = SC_VALID_TEXTLEN; break;
+ case sheet::ValidationType_LIST: eMode = SC_VALID_LIST; break;
+ case sheet::ValidationType_CUSTOM: eMode = SC_VALID_CUSTOM; break;
+ default: eMode = SC_VALID_ANY; break;
+ }
+ return eMode;
+}
+
+ScValidErrorStyle validAlertToValidError( const sheet::ValidationAlertStyle eVAlertStyle )
+{
+ ScValidErrorStyle eVErrStyle;
+ switch( eVAlertStyle )
+ {
+ case sheet::ValidationAlertStyle_STOP: eVErrStyle = SC_VALERR_STOP; break;
+ case sheet::ValidationAlertStyle_WARNING: eVErrStyle = SC_VALERR_WARNING; break;
+ case sheet::ValidationAlertStyle_MACRO: eVErrStyle = SC_VALERR_MACRO; break;
+ default: eVErrStyle = SC_VALERR_INFO; break;
+ //should INFO be the default? seems to be the most unobtrusive choice.
+ }
+ return eVErrStyle;
+}
+
+ScConditionMode conditionOpToMode( const sheet::ConditionOperator eOp )
+{
+ ScConditionMode eMode;
+ switch( eOp )
+ {
+ case sheet::ConditionOperator_EQUAL: eMode = SC_COND_EQUAL; break;
+ case sheet::ConditionOperator_NOT_EQUAL: eMode = SC_COND_NOTEQUAL; break;
+ case sheet::ConditionOperator_GREATER: eMode = SC_COND_GREATER; break;
+ case sheet::ConditionOperator_GREATER_EQUAL: eMode = SC_COND_EQGREATER; break;
+ case sheet::ConditionOperator_LESS: eMode = SC_COND_LESS; break;
+ case sheet::ConditionOperator_LESS_EQUAL: eMode = SC_COND_EQLESS; break;
+ case sheet::ConditionOperator_BETWEEN: eMode = SC_COND_BETWEEN; break;
+ case sheet::ConditionOperator_NOT_BETWEEN: eMode = SC_COND_NOTBETWEEN; break;
+ case sheet::ConditionOperator_FORMULA: eMode = SC_COND_DIRECT; break;
+ default: eMode = SC_COND_NONE; break;
+ }
+ return eMode;
+}
+
+}
+
+void ScXMLTableRowCellContext::SetContentValidation( const ScRange& rScRange )
+{
+ if( pContentValidationName && !pContentValidationName->isEmpty() )
{
+ ScDocument* pDoc = rXMLImport.GetDocument();
ScMyImportValidation aValidation;
- aValidation.eGrammar1 = aValidation.eGrammar2 = GetScImport().GetDocument()->GetStorageGrammar();
- if (rXMLImport.GetValidation(*pContentValidationName, aValidation))
+ aValidation.eGrammar1 = aValidation.eGrammar2 = pDoc->GetStorageGrammar();
+ if( rXMLImport.GetValidation(*pContentValidationName, aValidation) )
{
- uno::Reference<beans::XPropertySet> xPropertySet(xPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_VALIXML))), uno::UNO_QUERY);
- if (xPropertySet.is())
+ ScValidationData aScValidationData(
+ validationTypeToMode(aValidation.aValidationType),
+ conditionOpToMode(aValidation.aOperator),
+ aValidation.sFormula1, aValidation.sFormula2, pDoc, rScRange.aStart,
+ aValidation.sFormulaNmsp1, aValidation.sFormulaNmsp2,
+ aValidation.eGrammar1, aValidation.eGrammar2
+ );
+
+ aScValidationData.SetIgnoreBlank( aValidation.bIgnoreBlanks );
+ aScValidationData.SetListType( aValidation.nShowList );
+
+ // set strings for error / input even if disabled (and disable afterwards)
+ aScValidationData.SetInput( aValidation.sImputTitle, aValidation.sImputMessage );
+ if( !aValidation.bShowImputMessage )
+ aScValidationData.ResetInput();
+ aScValidationData.SetError( aValidation.sErrorTitle, aValidation.sErrorMessage, validAlertToValidError(aValidation.aAlertStyle) );
+ if( !aValidation.bShowErrorMessage )
+ aScValidationData.ResetError();
+
+ if( !aValidation.sBaseCellAddress.isEmpty() )
+ aScValidationData.SetSrcString( aValidation.sBaseCellAddress );
+
+ sal_uLong nIndex = pDoc->AddValidationEntry( aScValidationData );
+
+ ScPatternAttr aPattern( pDoc->GetPool() );
+ aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
+ if( rScRange.aStart == rScRange.aEnd ) //for a single cell
{
- if (!aValidation.sErrorMessage.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRMESS)), uno::makeAny(aValidation.sErrorMessage));
- if (!aValidation.sErrorTitle.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRTITLE)), uno::makeAny(aValidation.sErrorTitle));
- if (!aValidation.sImputMessage.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPMESS)), uno::makeAny(aValidation.sImputMessage));
- if (!aValidation.sImputTitle.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPTITLE)), uno::makeAny(aValidation.sImputTitle));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWERR)), uno::makeAny(aValidation.bShowErrorMessage));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWINP)), uno::makeAny(aValidation.bShowImputMessage));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_TYPE)), uno::makeAny(aValidation.aValidationType));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_IGNOREBL)), uno::makeAny(aValidation.bIgnoreBlanks));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWLIST)), uno::makeAny(aValidation.nShowList));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRALSTY)), uno::makeAny(aValidation.aAlertStyle));
- uno::Reference<sheet::XSheetCondition> xCondition(xPropertySet, uno::UNO_QUERY);
- if (xCondition.is())
- {
- xCondition->setFormula1(aValidation.sFormula1);
- xCondition->setFormula2(aValidation.sFormula2);
- xCondition->setOperator(aValidation.aOperator);
- // source position must be set as string, because it may
- // refer to a sheet that hasn't been loaded yet.
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SOURCESTR)), uno::makeAny(aValidation.sBaseCellAddress));
- // Transport grammar and formula namespace
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FORMULANMSP1)), uno::makeAny(aValidation.sFormulaNmsp1));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FORMULANMSP2)), uno::makeAny(aValidation.sFormulaNmsp2));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_GRAMMAR1)), uno::makeAny(static_cast<sal_Int32>(aValidation.eGrammar1)));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_GRAMMAR2)), uno::makeAny(static_cast<sal_Int32>(aValidation.eGrammar2)));
- }
+ pDoc->ApplyPattern( rScRange.aStart.Col(), rScRange.aStart.Row(),
+ rScRange.aStart.Tab(), aPattern );
+ }
+ else //for repeating cells
+ {
+ pDoc->ApplyPatternAreaTab( rScRange.aStart.Col(), rScRange.aStart.Row(),
+ rScRange.aEnd.Col(), rScRange.aEnd.Row(),
+ rScRange.aStart.Tab(), aPattern );
}
- xPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_VALIXML)), uno::makeAny(xPropertySet));
+ // is the below still needed?
// For now, any sheet with validity is blocked from stream-copying.
// Later, the validation names could be stored along with the style names.
ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
@@ -539,34 +608,9 @@ void ScXMLTableRowCellContext::SetContentValidation(com::sun::star::uno::Referen
}
}
-void ScXMLTableRowCellContext::SetCellProperties(const uno::Reference<table::XCellRange>& xCellRange,
- const ScAddress& aScCellAddress)
-{
- com::sun::star::table::CellAddress aCellAddress;
- ScUnoConversion::FillApiAddress( aCellAddress, aScCellAddress );
- 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>(nColsRepeated) - 1;
- if (nBottom > MAXROW)
- nBottom = MAXROW;
- if (nRight > MAXCOL)
- nRight = MAXCOL;
- uno::Reference <beans::XPropertySet> xProperties (xCellRange->getCellRangeByPosition(aCellAddress.Column, aCellAddress.Row,
- nRight, nBottom), uno::UNO_QUERY);
- if (xProperties.is())
- SetContentValidation(xProperties);
- }
-}
-
-void ScXMLTableRowCellContext::SetCellProperties(const uno::Reference<table::XCell>& xCell)
+void ScXMLTableRowCellContext::SetContentValidation( const ScAddress& rScCellPos )
{
- if (pContentValidationName && !pContentValidationName->isEmpty())
- {
- uno::Reference <beans::XPropertySet> xProperties (xCell, uno::UNO_QUERY);
- if (xProperties.is())
- SetContentValidation(xProperties);
- }
+ SetContentValidation( ScRange(rScCellPos, rScCellPos) );
}
void ScXMLTableRowCellContext::SetAnnotation(const ScAddress& rPos)
@@ -963,18 +1007,18 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos,
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);
+ SetContentValidation( aScRange );
+ rXMLImport.GetStylesImportHelper()->AddRange( aScRange );
}
else if( scCellExists(rScCellPos) )
{
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
- SetCellProperties(xCellRange, rScCellPos);
+ SetContentValidation( rScCellPos );
}
}
@@ -1056,7 +1100,7 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
}
if( xCell.is() )
{
- SetCellProperties(xCell); // set now only the validation
+ SetContentValidation( rScCellPos );
OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
if (!bIsMatrix)
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 6ba5ebd..11914b2 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -82,10 +82,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);
- void SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet);
- void SetCellProperties(const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange,
- const ScAddress& aCellAddress);
- void SetCellProperties(const com::sun::star::uno::Reference<com::sun::star::table::XCell>& xCell);
+ void SetContentValidation( const ScRange& rScRange );
+ void SetContentValidation( const ScAddress& rScCellPos );
void LockSolarMutex();
void UnlockSolarMutex();
commit cad1d9e06695be3e3d5ad3ebc09b08fc664d9be9
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 01:52:53 2012 -0500
Add unit test for ODS import of Data Validity
The unit test checks for the proper importation of the test document's
1) data validation entries
2) data validity of associate cells
3) content
Change-Id: I2858663c1d988557fc3783ecaf74892d370c1c93
diff --git a/sc/qa/unit/data/contentCSV/dataValidity1.csv b/sc/qa/unit/data/contentCSV/dataValidity1.csv
new file mode 100644
index 0000000..13fbdc9
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/dataValidity1.csv
@@ -0,0 +1,4 @@
+,,
+,,Enter a number greater than 3.14
+,,3.141
+,,999
diff --git a/sc/qa/unit/data/contentCSV/dataValidity2.csv b/sc/qa/unit/data/contentCSV/dataValidity2.csv
new file mode 100644
index 0000000..b54c933
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/dataValidity2.csv
@@ -0,0 +1,8 @@
+,,,,,,
+,,,,,,
+,,Enter a whole number between 1 and 10,,,,
+,,4,10,,,
+,,3,,,,
+,,,,,,
+,,,,,,
+,,5,5,5,5,5
diff --git a/sc/qa/unit/data/ods/dataValidity.ods b/sc/qa/unit/data/ods/dataValidity.ods
new file mode 100644
index 0000000..008cea5
Binary files /dev/null and b/sc/qa/unit/data/ods/dataValidity.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 7cc3f6d..e987d56 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -43,6 +43,7 @@
#include <editeng/justifyitem.hxx>
#include <editeng/borderline.hxx>
#include <dbdata.hxx>
+#include "validat.hxx"
#define CALC_DEBUG_OUTPUT 0
#define TEST_BUG_FILES 0
@@ -114,6 +115,7 @@ public:
void testBrokenQuotesCSV();
void testMergedCellsODS();
void testRepeatedColumnsODS();
+ void testDataValidityODS();
//change this test file only in excel and not in calc
void testSharedFormulaXLSX();
@@ -141,6 +143,7 @@ public:
CPPUNIT_TEST(testBugFixesXLSX);
CPPUNIT_TEST(testMergedCellsODS);
CPPUNIT_TEST(testRepeatedColumnsODS);
+ CPPUNIT_TEST(testDataValidityODS);
#if 0
CPPUNIT_TEST(testBrokenQuotesCSV);
#endif
@@ -705,6 +708,141 @@ void ScFiltersTest::testRepeatedColumnsODS()
xDocSh->DoClose();
}
+namespace {
+
+//for cleaner passing of parameters
+struct ValDataTestParams
+{
+ ScValidationMode eValMode;
+ ScConditionMode eCondOp;
+ String aStrVal1, aStrVal2;
+ ScDocument* pDocument;
+ ScAddress aPosition;
+ String aErrorTitle, aErrorMessage;
+ ScValidErrorStyle eErrorStyle;
+
+ ValDataTestParams( ScValidationMode eMode, ScConditionMode eOp,
+ String aExpr1, String aExpr2, ScDocument* pDoc,
+ ScAddress aPos, String aETitle, String aEMsg,
+ ScValidErrorStyle eEStyle ):
+ eValMode(eMode), eCondOp(eOp), aStrVal1(aExpr1),
+ aStrVal2(aExpr2), pDocument(pDoc), aPosition(aPos),
+ aErrorTitle(aETitle), aErrorMessage(aEMsg),
+ eErrorStyle(eEStyle) { };
+};
+
+void checkValiditationEntries( ValDataTestParams& rVDTParams )
+{
+ ScDocument* pDoc = rVDTParams.pDocument;
+
+ //create expected data validation entry
+ ScValidationData aValData(
+ rVDTParams.eValMode, rVDTParams.eCondOp, rVDTParams.aStrVal1,
+ rVDTParams.aStrVal2, pDoc, rVDTParams.aPosition, EMPTY_STRING,
+ EMPTY_STRING, pDoc->GetStorageGrammar(), pDoc->GetStorageGrammar()
+ );
+ aValData.SetIgnoreBlank( true );
+ aValData.SetListType( 1 );
+ aValData.ResetInput();
+ aValData.SetError( rVDTParams.aErrorTitle, rVDTParams.aErrorMessage, rVDTParams.eErrorStyle );
+ aValData.SetSrcString( EMPTY_STRING );
+
+ SCCOL nCol( rVDTParams.aPosition.Col() );
+ SCROW nRow( rVDTParams.aPosition.Row() );
+ SCTAB nTab( rVDTParams.aPosition.Tab() );
+ //get actual data validation entry from document
+ const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(nCol, nRow, nTab, ATTR_VALIDDATA) );
+ const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItem->GetValue() );
+
+ rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(nCol)) );
+ rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(nRow)) );
+ rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
+ rtl::OString msg( "Data Validation Entry with base-cell-address(Col,Row,Tab): (" +
+ sCol + "," + sRow + "," + sTab + ") was not imported correctly." );
+ //check if expected and actual data validation entries are equal
+ CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && aValData.EqualEntries(*pValDataTest) );
+}
+
+void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc )
+{
+ SCCOL nBCol( rValBaseAddr.Col() );
+ SCTAB nBRow( rValBaseAddr.Row() );
+ SCTAB nTab( rValBaseAddr.Tab() );
+ //get from the document the data validation entry we are checking against
+ const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pDoc->GetAttr(nBCol, nBRow, nTab, ATTR_VALIDDATA) );
+ const ScValidationData* pValData = pDoc->GetValidationEntry( pItem->GetValue() );
+
+ //check that each cell in the expected range is associated with the data validation entry
+ for(SCCOL i = rRange.aStart.Col(); i <= rRange.aEnd.Col(); ++i)
+ {
+ for(SCROW j = rRange.aStart.Row(); j <= rRange.aEnd.Row(); ++j)
+ {
+ const SfxUInt32Item* pItemTest = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(i, j, nTab, ATTR_VALIDDATA) );
+ const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItemTest->GetValue() );
+
+ rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(i)) );
+ rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(j)) );
+ rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
+ rtl::OString sBCol( rtl::OString::valueOf(static_cast<sal_Int32>(nBCol)) );
+ rtl::OString sBRow( rtl::OString::valueOf(static_cast<sal_Int32>(nBRow)) );
+ rtl::OString msg( "Cell at (" + sCol + "," + sRow + "," + sTab + ") does not reference " +
+ "Data Validation Entry with base-cell-address: (" +
+ sBCol + "," + sBRow + "," + sTab + ")." );
+ CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && pValData->GetKey() == pValDataTest->GetKey() );
+ }
+ }
+}
+
+}
+
+void ScFiltersTest::testDataValidityODS()
+{
+ const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("dataValidity."));
+ ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+
+ ScAddress aValBaseAddr1( 2,6,0 ); //sheet1
+ ScAddress aValBaseAddr2( 2,3,1 ); //sheet2
+
+ //sheet1's expected Data Validation Entry values
+ ValDataTestParams aVDTParams1(
+ SC_VALID_DECIMAL, SC_COND_GREATER, String("3.14"), EMPTY_STRING, pDoc,
+ aValBaseAddr1, String("Too small"),
+ String("The number you are trying to enter is not greater than 3.14! Are you sure you want to enter it anyway?"),
+ SC_VALERR_WARNING
+ );
+ //sheet2's expected Data Validation Entry values
+ ValDataTestParams aVDTParams2(
+ SC_VALID_WHOLE, SC_COND_BETWEEN, String("1"), String("10"), pDoc,
+ ScAddress(2,3,1), String("Error sheet 2"),
+ String("Must be a whole number between 1 and 10."),
+ SC_VALERR_STOP
+ );
+ //check each sheet's Data Validation Entries
+ checkValiditationEntries( aVDTParams1 );
+ checkValiditationEntries( aVDTParams2 );
+
+ //expected ranges to be associated with data validity
+ ScRange aRange1( 2,2,0, 2,6,0 ); //sheet1
+ ScRange aRange2( 2,3,1, 6,7,1 ); //sheet2
+
+ //check each sheet's cells for data validity
+ checkCellValidity( aValBaseAddr1, aRange1, pDoc );
+ checkCellValidity( aValBaseAddr2, aRange2, pDoc );
+
+ //check each sheet's content
+ rtl::OUString aCSVFileName1;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dataValidity1.")), aCSVFileName1);
+ testFile(aCSVFileName1, pDoc, 0);
+
+ rtl::OUString aCSVFileName2;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dataValidity2.")), aCSVFileName2);
+ testFile(aCSVFileName2, pDoc, 1);
+
+ xDocSh->DoClose();
+}
+
void ScFiltersTest::testBrokenQuotesCSV()
{
const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("fdo48621_broken_quotes."));
More information about the Libreoffice-commits
mailing list