Adding support for importing charts using InternalData.
This is similar to sc's chart importer.
This commit is contained in:
parent
fb67b98f1a
commit
c161564bd0
3 changed files with 108 additions and 10 deletions
|
@ -41,6 +41,8 @@ public:
|
|||
InternalData();
|
||||
|
||||
void createDefaultData();
|
||||
bool isDefaultData();
|
||||
void clearDefaultData();
|
||||
|
||||
void setData( const ::com::sun::star::uno::Sequence<
|
||||
::com::sun::star::uno::Sequence< double > > & rDataInRows );
|
||||
|
|
|
@ -89,6 +89,13 @@ InternalData::InternalData()
|
|||
, m_aColumnLabels( 0 )
|
||||
{}
|
||||
|
||||
static const double fDefaultData[] = {
|
||||
9.10, 3.20, 4.54,
|
||||
2.40, 8.80, 9.65,
|
||||
3.10, 1.50, 3.70,
|
||||
4.30, 9.02, 6.20
|
||||
};
|
||||
|
||||
void InternalData::createDefaultData()
|
||||
{
|
||||
const sal_Int32 nRowCount = 4;
|
||||
|
@ -101,12 +108,6 @@ void InternalData::createDefaultData()
|
|||
const OUString aRowName( ::chart::SchResId::getResString( STR_ROW_LABEL ));
|
||||
const OUString aColName( ::chart::SchResId::getResString( STR_COLUMN_LABEL ));
|
||||
|
||||
const double fDefaultData[ nSize ] =
|
||||
{ 9.10, 3.20, 4.54,
|
||||
2.40, 8.80, 9.65,
|
||||
3.10, 1.50, 3.70,
|
||||
4.30, 9.02, 6.20 };
|
||||
|
||||
m_aData.resize( nSize );
|
||||
for( sal_Int32 i=0; i<nSize; ++i )
|
||||
m_aData[i] = fDefaultData[i];
|
||||
|
@ -122,6 +123,31 @@ void InternalData::createDefaultData()
|
|||
lcl_NumberedStringGenerator( aColName, C2U("%COLUMNNUMBER") ));
|
||||
}
|
||||
|
||||
bool InternalData::isDefaultData()
|
||||
{
|
||||
|
||||
if( m_nRowCount == 4 && m_nColumnCount == 3 )
|
||||
{
|
||||
for( sal_Int32 i=0; i<(4*3); ++i )
|
||||
if( m_aData[i] != fDefaultData[i] )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void InternalData::clearDefaultData()
|
||||
{
|
||||
if( isDefaultData() )
|
||||
{
|
||||
m_nRowCount = m_nColumnCount = 1;
|
||||
m_aData.resize( 1 );
|
||||
m_aRowLabels.clear();
|
||||
m_aColumnLabels.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void InternalData::setData( const Sequence< Sequence< double > >& rDataInRows )
|
||||
{
|
||||
m_nRowCount = rDataInRows.getLength();
|
||||
|
|
|
@ -488,9 +488,80 @@ void InternalDataProvider::lcl_decreaseMapReferences(
|
|||
Reference< chart2::data::XDataSequence > InternalDataProvider::lcl_createDataSequenceAndAddToMap(
|
||||
const OUString & rRangeRepresentation )
|
||||
{
|
||||
OUString aRangeRepresentation = rRangeRepresentation;
|
||||
if( aRangeRepresentation.indexOf('{') >= 0 )
|
||||
{
|
||||
sal_Int32 i, m, n;
|
||||
::std::vector< double > aNewData;
|
||||
::std::vector< OUString > aNewLabels;
|
||||
OUString aToken;
|
||||
sal_Int32 nCategories = 0;
|
||||
sal_Int32 nIndex = 0;
|
||||
bool bValues = true;
|
||||
bool bLabelSet = false;
|
||||
OUString str = aRangeRepresentation.replace('{',' ').replace('}',' ');
|
||||
|
||||
m_aInternalData.clearDefaultData();
|
||||
n = m_aInternalData.getColumnCount();
|
||||
if( n )
|
||||
n = n - 1;
|
||||
|
||||
do
|
||||
{
|
||||
// TODO: This will be problematic if ';' is used in label names
|
||||
// '"' character also needs to be considered in such cases
|
||||
aToken = str.getToken(0,';',nIndex);
|
||||
if( !aToken.getLength() )
|
||||
break;
|
||||
if( aToken.indexOf('"') < 0 )
|
||||
{
|
||||
aNewData.push_back( aToken.toDouble() );
|
||||
}
|
||||
else
|
||||
{
|
||||
aNewLabels.push_back( aToken.replace('"', ' ').trim() );
|
||||
if( !nCategories &&
|
||||
( !m_aInternalData.getComplexColumnLabel(n).size() ||
|
||||
!m_aInternalData.getComplexColumnLabel(n).front().getLength() ) )
|
||||
{
|
||||
m_aInternalData.setComplexColumnLabel( n, aNewLabels );
|
||||
bLabelSet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_aInternalData.setComplexRowLabel(nCategories, aNewLabels);
|
||||
if(nCategories==1 && bLabelSet)
|
||||
{
|
||||
::std::vector< OUString > aLabels;
|
||||
m_aInternalData.setComplexRowLabel( 0, m_aInternalData.getComplexColumnLabel( n ) );
|
||||
m_aInternalData.setComplexColumnLabel( n, aLabels );
|
||||
}
|
||||
}
|
||||
aNewLabels.pop_back();
|
||||
nCategories++;
|
||||
bValues = false;
|
||||
}
|
||||
} while( nIndex >= 0 );
|
||||
|
||||
if( bValues )
|
||||
{
|
||||
m_aInternalData.insertColumn( n );
|
||||
m_aInternalData.setColumnValues( n, aNewData );
|
||||
aRangeRepresentation = OUString::valueOf( n );
|
||||
}
|
||||
else if( nCategories > 1 )
|
||||
{
|
||||
aRangeRepresentation = lcl_aCategoriesRangeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
aRangeRepresentation = lcl_aLabelRangePrefix+OUString::valueOf( n );
|
||||
}
|
||||
}
|
||||
|
||||
Reference< chart2::data::XDataSequence > xSeq(
|
||||
new UncachedDataSequence( this, rRangeRepresentation ));
|
||||
lcl_addDataSequenceToMap( rRangeRepresentation, xSeq );
|
||||
new UncachedDataSequence( this, aRangeRepresentation ));
|
||||
lcl_addDataSequenceToMap( aRangeRepresentation, xSeq );
|
||||
return xSeq;
|
||||
}
|
||||
|
||||
|
@ -685,8 +756,7 @@ Reference< chart2::data::XDataSequence > SAL_CALL InternalDataProvider::createDa
|
|||
else if( aRangeRepresentation.getLength())
|
||||
{
|
||||
// data
|
||||
sal_Int32 nIndex = aRangeRepresentation.toInt32();
|
||||
return lcl_createDataSequenceAndAddToMap( OUString::valueOf( nIndex ));
|
||||
return lcl_createDataSequenceAndAddToMap( aRangeRepresentation );
|
||||
}
|
||||
|
||||
return Reference< chart2::data::XDataSequence >();
|
||||
|
|
Loading…
Reference in a new issue