Kaydet (Commit) f350a71d authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Reduce scope levels.

Change-Id: I64684a80c79c3c7f5a8f23b07703fbcee3fe5887
üst 52a36fb3
...@@ -3287,225 +3287,225 @@ void SchXMLExportHelper_Impl::exportDataPoints( ...@@ -3287,225 +3287,225 @@ void SchXMLExportHelper_Impl::exportDataPoints(
// do have own attributes. This increases the performance substantially. // do have own attributes. This increases the performance substantially.
// more performant version for #93600# // more performant version for #93600#
if( mxExpPropMapper.is()) if (!mxExpPropMapper.is())
{ return;
uno::Reference< chart2::XDataSeries > xSeries( xSeriesProperties, uno::UNO_QUERY );
std::vector< XMLPropertyState > aPropertyStates; uno::Reference< chart2::XDataSeries > xSeries( xSeriesProperties, uno::UNO_QUERY );
const OUString sNumFormat("NumberFormat"); std::vector< XMLPropertyState > aPropertyStates;
const OUString sPercentageNumFormat( "PercentageNumberFormat");
bool bVaryColorsByPoint = false; const OUString sNumFormat("NumberFormat");
Sequence< sal_Int32 > aDataPointSeq; const OUString sPercentageNumFormat( "PercentageNumberFormat");
if( xSeriesProperties.is())
{
Any aAny = xSeriesProperties->getPropertyValue(
OUString( "AttributedDataPoints" ));
aAny >>= aDataPointSeq;
xSeriesProperties->getPropertyValue(
OUString( "VaryColorsByPoint" )) >>= bVaryColorsByPoint;
}
sal_Int32 nSize = aDataPointSeq.getLength(); bool bVaryColorsByPoint = false;
SAL_WARN_IF( nSize > nSeriesLength, "xmloff.chart", "Too many point attributes" ); Sequence< sal_Int32 > aDataPointSeq;
if( xSeriesProperties.is())
{
Any aAny = xSeriesProperties->getPropertyValue(
OUString( "AttributedDataPoints" ));
aAny >>= aDataPointSeq;
xSeriesProperties->getPropertyValue(
OUString( "VaryColorsByPoint" )) >>= bVaryColorsByPoint;
}
const sal_Int32 * pPoints = aDataPointSeq.getConstArray(); sal_Int32 nSize = aDataPointSeq.getLength();
sal_Int32 nElement; SAL_WARN_IF( nSize > nSeriesLength, "xmloff.chart", "Too many point attributes" );
sal_Int32 nRepeat;
Reference< chart2::XColorScheme > xColorScheme; const sal_Int32 * pPoints = aDataPointSeq.getConstArray();
if( xDiagram.is()) sal_Int32 nElement;
xColorScheme.set( xDiagram->getDefaultColorScheme()); sal_Int32 nRepeat;
Reference< chart2::XColorScheme > xColorScheme;
if( xDiagram.is())
xColorScheme.set( xDiagram->getDefaultColorScheme());
::std::list< SchXMLDataPointStruct > aDataPointList; ::std::list< SchXMLDataPointStruct > aDataPointList;
sal_Int32 nLastIndex = -1; sal_Int32 nLastIndex = -1;
sal_Int32 nCurrIndex = 0; sal_Int32 nCurrIndex = 0;
// collect elements // collect elements
if( bVaryColorsByPoint && xColorScheme.is() ) if( bVaryColorsByPoint && xColorScheme.is() )
{
::std::set< sal_Int32 > aAttrPointSet;
::std::copy( pPoints, pPoints + aDataPointSeq.getLength(),
::std::inserter( aAttrPointSet, aAttrPointSet.begin()));
const ::std::set< sal_Int32 >::const_iterator aEndIt( aAttrPointSet.end());
for( nElement = 0; nElement < nSeriesLength; ++nElement )
{ {
::std::set< sal_Int32 > aAttrPointSet; aPropertyStates.clear();
::std::copy( pPoints, pPoints + aDataPointSeq.getLength(), uno::Reference< beans::XPropertySet > xPropSet;
::std::inserter( aAttrPointSet, aAttrPointSet.begin())); bool bExportNumFmt = false;
const ::std::set< sal_Int32 >::const_iterator aEndIt( aAttrPointSet.end()); if( aAttrPointSet.find( nElement ) != aEndIt )
for( nElement = 0; nElement < nSeriesLength; ++nElement )
{ {
aPropertyStates.clear(); try
uno::Reference< beans::XPropertySet > xPropSet;
bool bExportNumFmt = false;
if( aAttrPointSet.find( nElement ) != aEndIt )
{ {
try xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
{ xSeries, nElement, mrExport.GetModel() );
xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet( bExportNumFmt = true;
xSeries, nElement, mrExport.GetModel() );
bExportNumFmt = true;
}
catch( const uno::Exception & rEx )
{
SAL_INFO("xmloff.chart", "Exception caught during Export of data point: " << rEx.Message );
}
} }
else catch( const uno::Exception & rEx )
{ {
// property set only containing the color SAL_INFO("xmloff.chart", "Exception caught during Export of data point: " << rEx.Message );
xPropSet.set( new ::xmloff::chart::ColorPropertySet(
xColorScheme->getColorByIndex( nElement )));
} }
SAL_WARN_IF( !xPropSet.is(), "xmloff.chart", "Pie Segments should have properties" ); }
if( xPropSet.is()) else
{
// property set only containing the color
xPropSet.set( new ::xmloff::chart::ColorPropertySet(
xColorScheme->getColorByIndex( nElement )));
}
SAL_WARN_IF( !xPropSet.is(), "xmloff.chart", "Pie Segments should have properties" );
if( xPropSet.is())
{
const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 && bExportNumFmt )
{ {
const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport );
if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 && bExportNumFmt ) lcl_exportNumberFormat( sPercentageNumFormat, xPropSet, mrExport );
{ }
lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport );
lcl_exportNumberFormat( sPercentageNumFormat, xPropSet, mrExport );
}
aPropertyStates = mxExpPropMapper->Filter( xPropSet ); aPropertyStates = mxExpPropMapper->Filter( xPropSet );
if( !aPropertyStates.empty() ) if( !aPropertyStates.empty() )
{
if( bExportContent )
{ {
if( bExportContent ) // write data-point with style
{ SAL_WARN_IF( maAutoStyleNameQueue.empty(), "xmloff.chart", "Autostyle queue empty!" );
// write data-point with style
SAL_WARN_IF( maAutoStyleNameQueue.empty(), "xmloff.chart", "Autostyle queue empty!" );
SchXMLDataPointStruct aPoint; SchXMLDataPointStruct aPoint;
aPoint.maStyleName = maAutoStyleNameQueue.front(); aPoint.maStyleName = maAutoStyleNameQueue.front();
maAutoStyleNameQueue.pop(); maAutoStyleNameQueue.pop();
aDataPointList.push_back( aPoint ); aDataPointList.push_back( aPoint );
} }
else else
{ {
CollectAutoStyle( aPropertyStates ); CollectAutoStyle( aPropertyStates );
}
} }
} }
} }
SAL_WARN_IF( bExportContent && (static_cast<sal_Int32>(aDataPointList.size()) != nSeriesLength), "xmloff.chart", "not enough data points on content export" );
} }
else SAL_WARN_IF( bExportContent && (static_cast<sal_Int32>(aDataPointList.size()) != nSeriesLength), "xmloff.chart", "not enough data points on content export" );
}
else
{
for( nElement = 0; nElement < nSize; ++nElement )
{ {
for( nElement = 0; nElement < nSize; ++nElement ) aPropertyStates.clear();
{ nCurrIndex = pPoints[ nElement ];
aPropertyStates.clear(); //assuming sorted indices in pPoints
nCurrIndex = pPoints[ nElement ];
//assuming sorted indices in pPoints
if( nCurrIndex<0 || nCurrIndex>=nSeriesLength ) if( nCurrIndex<0 || nCurrIndex>=nSeriesLength )
break; break;
// write leading empty data points // write leading empty data points
if( nCurrIndex - nLastIndex > 1 ) if( nCurrIndex - nLastIndex > 1 )
{ {
SchXMLDataPointStruct aPoint; SchXMLDataPointStruct aPoint;
aPoint.mnRepeat = nCurrIndex - nLastIndex - 1; aPoint.mnRepeat = nCurrIndex - nLastIndex - 1;
aDataPointList.push_back( aPoint ); aDataPointList.push_back( aPoint );
} }
uno::Reference< beans::XPropertySet > xPropSet; uno::Reference< beans::XPropertySet > xPropSet;
// get property states // get property states
try try
{ {
xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet( xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
xSeries, nCurrIndex, mrExport.GetModel() ); xSeries, nCurrIndex, mrExport.GetModel() );
} }
catch( const uno::Exception & rEx ) catch( const uno::Exception & rEx )
{
SAL_INFO("xmloff.chart", "Exception caught during Export of data point: " << rEx.Message );
}
if( xPropSet.is())
{
const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 )
{ {
SAL_INFO("xmloff.chart", "Exception caught during Export of data point: " << rEx.Message ); lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport );
lcl_exportNumberFormat( sPercentageNumFormat, xPropSet, mrExport );
} }
if( xPropSet.is())
aPropertyStates = mxExpPropMapper->Filter( xPropSet );
if( !aPropertyStates.empty() )
{ {
const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); if( bExportContent )
if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 )
{ {
lcl_exportNumberFormat( sNumFormat, xPropSet, mrExport ); // write data-point with style
lcl_exportNumberFormat( sPercentageNumFormat, xPropSet, mrExport ); SAL_WARN_IF( maAutoStyleNameQueue.empty(), "xmloff.chart", "Autostyle queue empty!" );
SchXMLDataPointStruct aPoint;
aPoint.maStyleName = maAutoStyleNameQueue.front();
maAutoStyleNameQueue.pop();
aDataPointList.push_back( aPoint );
nLastIndex = nCurrIndex;
} }
else
aPropertyStates = mxExpPropMapper->Filter( xPropSet );
if( !aPropertyStates.empty() )
{ {
if( bExportContent ) CollectAutoStyle( aPropertyStates );
{
// write data-point with style
SAL_WARN_IF( maAutoStyleNameQueue.empty(), "xmloff.chart", "Autostyle queue empty!" );
SchXMLDataPointStruct aPoint;
aPoint.maStyleName = maAutoStyleNameQueue.front();
maAutoStyleNameQueue.pop();
aDataPointList.push_back( aPoint );
nLastIndex = nCurrIndex;
}
else
{
CollectAutoStyle( aPropertyStates );
}
continue;
} }
continue;
} }
}
// if we get here the property states are empty // if we get here the property states are empty
SchXMLDataPointStruct aPoint; SchXMLDataPointStruct aPoint;
aDataPointList.push_back( aPoint ); aDataPointList.push_back( aPoint );
nLastIndex = nCurrIndex; nLastIndex = nCurrIndex;
}
// final empty elements
nRepeat = nSeriesLength - nLastIndex - 1;
if( nRepeat > 0 )
{
SchXMLDataPointStruct aPoint;
aPoint.mnRepeat = nRepeat;
aDataPointList.push_back( aPoint );
}
} }
// final empty elements
if( bExportContent ) nRepeat = nSeriesLength - nLastIndex - 1;
if( nRepeat > 0 )
{ {
// write elements (merge equal ones)
::std::list< SchXMLDataPointStruct >::iterator aIter = aDataPointList.begin();
SchXMLDataPointStruct aPoint; SchXMLDataPointStruct aPoint;
SchXMLDataPointStruct aLastPoint; aPoint.mnRepeat = nRepeat;
aDataPointList.push_back( aPoint );
}
}
// initialize so that it doesn't matter if if (!bExportContent)
// the element is counted in the first iteration return;
aLastPoint.mnRepeat = 0;
for( ; aIter != aDataPointList.end(); ++aIter ) // write elements (merge equal ones)
{ ::std::list< SchXMLDataPointStruct >::iterator aIter = aDataPointList.begin();
aPoint = (*aIter); SchXMLDataPointStruct aPoint;
SchXMLDataPointStruct aLastPoint;
if( aPoint.maStyleName == aLastPoint.maStyleName ) // initialize so that it doesn't matter if
aPoint.mnRepeat += aLastPoint.mnRepeat; // the element is counted in the first iteration
else if( aLastPoint.mnRepeat > 0 ) aLastPoint.mnRepeat = 0;
{
// write last element
if( !aLastPoint.maStyleName.isEmpty() )
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName );
if( aLastPoint.mnRepeat > 1 ) for( ; aIter != aDataPointList.end(); ++aIter )
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED, {
OUString::number( ( aLastPoint.mnRepeat ) )); aPoint = (*aIter);
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true ); if( aPoint.maStyleName == aLastPoint.maStyleName )
} aPoint.mnRepeat += aLastPoint.mnRepeat;
aLastPoint = aPoint; else if( aLastPoint.mnRepeat > 0 )
} {
// write last element if it hasn't been written in last iteration // write last element
if( aPoint.maStyleName == aLastPoint.maStyleName ) if( !aLastPoint.maStyleName.isEmpty() )
{ mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName );
if( !aLastPoint.maStyleName.isEmpty() )
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName );
if( aLastPoint.mnRepeat > 1 ) if( aLastPoint.mnRepeat > 1 )
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED, mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
OUString::number( ( aLastPoint.mnRepeat ) )); OUString::number( ( aLastPoint.mnRepeat ) ));
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true ); SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
}
} }
aLastPoint = aPoint;
}
// write last element if it hasn't been written in last iteration
if( aPoint.maStyleName == aLastPoint.maStyleName )
{
if( !aLastPoint.maStyleName.isEmpty() )
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName );
if( aLastPoint.mnRepeat > 1 )
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
OUString::number( ( aLastPoint.mnRepeat ) ));
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment