introduce getValue(sKey) for SequenceAsHashMap

returns the plain value (Any) if it exists, else return an empty Any
replaces some getUnpackedValueOrDefault calls in sw
where is was not clear if the unpacked value exsisted or was default

needed for removal of Any-to-Any template specialisations

Change-Id: I618da7a7174143f5edef48e47e7aa1b6a52845e1
Reviewed-on: https://gerrit.libreoffice.org/30114
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Jochen Nitschke
2016-10-21 17:23:10 +02:00
committed by Stephan Bergmann
parent 1617eef124
commit 783b93978d
3 changed files with 43 additions and 41 deletions

View File

@@ -237,6 +237,30 @@ class COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAsHashMapBase
return aValue;
}
/** @short check if the specified item exists
and return its value or it returns
an empty css::uno::Any.
@descr If a value should be extracted only in case
the requested property exists really (without creating
of new items as the index operator of a
hash map does!) this method can be used.
@param sKey
key name of the item.
@return The value of the specified property or
an empty css::uno::Any.
*/
inline css::uno::Any getValue(const OUString& sKey) const
{
const_iterator pIt = find(sKey);
if (pIt == end())
return css::uno::Any();
return pIt->second;
}
/** @short creates a new item with the specified
name and value only in case such item name

View File

@@ -1172,25 +1172,18 @@ void makeRedline( SwPaM& rPaM,
//todo: what about REDLINE_FMTCOLL?
comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
uno::Any aAuthorValue;
aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue);
sal_uInt16 nAuthor = 0;
OUString sAuthor;
if( aAuthorValue >>= sAuthor )
if( aPropMap.getValue("RedlineAuthor") >>= sAuthor )
nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
OUString sComment;
uno::Any aCommentValue;
aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue);
SwRedlineData aRedlineData( eType, nAuthor );
if( aCommentValue >>= sComment )
if( aPropMap.getValue("RedlineComment") >>= sComment )
aRedlineData.SetComment( sComment );
::util::DateTime aStamp;
uno::Any aDateTimeValue;
aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue);
if( aDateTimeValue >>= aStamp )
if( aPropMap.getValue("RedlineDateTime") >>= aStamp )
{
aRedlineData.SetTimeStamp( DateTime( aStamp));
}
@@ -1199,11 +1192,8 @@ void makeRedline( SwPaM& rPaM,
// Read the 'Redline Revert Properties' from the parameters
uno::Sequence< beans::PropertyValue > aRevertProperties;
uno::Any aRevertPropertiesValue;
aRevertPropertiesValue = aPropMap.getUnpackedValueOrDefault("RedlineRevertProperties", aRevertPropertiesValue);
// Check if the value exists
if ( aRevertPropertiesValue >>= aRevertProperties )
if ( aPropMap.getValue("RedlineRevertProperties") >>= aRevertProperties )
{
int nMap = 0;
// Make sure that paragraph format gets its own map, otherwise e.g. fill attributes are not preserved.
@@ -1297,25 +1287,18 @@ void makeTableRowRedline( SwTableLine& rTableLine,
}
comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
uno::Any aAuthorValue;
aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue);
sal_uInt16 nAuthor = 0;
OUString sAuthor;
if( aAuthorValue >>= sAuthor )
if( aPropMap.getValue("RedlineAuthor") >>= sAuthor )
nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
OUString sComment;
uno::Any aCommentValue;
aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue);
SwRedlineData aRedlineData( eType, nAuthor );
if( aCommentValue >>= sComment )
if( aPropMap.getValue("RedlineComment") >>= sComment )
aRedlineData.SetComment( sComment );
::util::DateTime aStamp;
uno::Any aDateTimeValue;
aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue);
if( aDateTimeValue >>= aStamp )
if( aPropMap.getValue("RedlineDateTime") >>= aStamp )
{
aRedlineData.SetTimeStamp(
DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), tools::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) );
@@ -1354,25 +1337,18 @@ void makeTableCellRedline( SwTableBox& rTableBox,
}
comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
uno::Any aAuthorValue;
aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue);
sal_uInt16 nAuthor = 0;
OUString sAuthor;
if( aAuthorValue >>= sAuthor )
if( aPropMap.getValue("RedlineAuthor") >>= sAuthor )
nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
OUString sComment;
uno::Any aCommentValue;
aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue);
SwRedlineData aRedlineData( eType, nAuthor );
if( aCommentValue >>= sComment )
if( aPropMap.getValue("RedlineComment") >>= sComment )
aRedlineData.SetComment( sComment );
::util::DateTime aStamp;
uno::Any aDateTimeValue;
aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue);
if( aDateTimeValue >>= aStamp )
if( aPropMap.getValue("RedlineDateTime") >>= aStamp )
{
aRedlineData.SetTimeStamp(
DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), tools::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) );

View File

@@ -1037,11 +1037,15 @@ void SwXCell::setPropertyValue(const OUString& rPropertyName, const uno::Any& aV
uno::Sequence<beans::PropertyValue> tableCellProperties;
tableCellProperties = aValue.get< uno::Sequence< beans::PropertyValue > >();
comphelper::SequenceAsHashMap aPropMap(tableCellProperties);
uno::Any sRedlineTypeValue = aPropMap.getUnpackedValueOrDefault("RedlineType", uno::Any());
if(!sRedlineTypeValue.has<OUString>())
OUString sRedlineType;
if(aPropMap.getValue("RedlineType") >>= sRedlineType)
{
// Create a 'Table Cell Redline' object
SwUnoCursorHelper::makeTableCellRedline(*pBox, sRedlineType, tableCellProperties);
}
else
throw beans::UnknownPropertyException("No redline type property: ", static_cast<cppu::OWeakObject*>(this));
// Create a 'Table Cell Redline' object
SwUnoCursorHelper::makeTableCellRedline(*pBox, sRedlineTypeValue.get<OUString>(), tableCellProperties);
}
else
{
@@ -1312,9 +1316,7 @@ void SwXTextTableRow::setPropertyValue(const OUString& rPropertyName, const uno:
tableRowProperties = aValue.get< uno::Sequence< beans::PropertyValue > >();
comphelper::SequenceAsHashMap aPropMap( tableRowProperties );
OUString sRedlineType;
uno::Any sRedlineTypeValue;
sRedlineTypeValue = aPropMap.getUnpackedValueOrDefault("RedlineType", sRedlineTypeValue);
if( sRedlineTypeValue >>= sRedlineType )
if( aPropMap.getValue("RedlineType") >>= sRedlineType )
{
// Create a 'Table Row Redline' object
SwUnoCursorHelper::makeTableRowRedline( *pLn, sRedlineType, tableRowProperties);