summaryrefslogtreecommitdiff
path: root/chart2/source/tools
diff options
context:
space:
mode:
authorMuthu Subramanian K <sumuthu@novell.com>2010-10-15 15:40:19 +0530
committerMuthu Subramanian K <sumuthu@novell.com>2010-10-16 21:45:43 +0530
commit381b99b434a5bd2402f7813eacda15094aba3bab (patch)
tree4374d1e4843c268f2554c57df1d9807feb3e12e9 /chart2/source/tools
parent537da0d932acabd5342f571d0217c4e5061eb663 (diff)
Adding support for importing charts using InternalData.
This is similar to sc's chart importer.
Diffstat (limited to 'chart2/source/tools')
-rw-r--r--chart2/source/tools/InternalData.cxx38
-rw-r--r--chart2/source/tools/InternalDataProvider.cxx78
2 files changed, 106 insertions, 10 deletions
diff --git a/chart2/source/tools/InternalData.cxx b/chart2/source/tools/InternalData.cxx
index e57e5fa8c..cede61bd9 100644
--- a/chart2/source/tools/InternalData.cxx
+++ b/chart2/source/tools/InternalData.cxx
@@ -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();
diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx
index 8a37210cf..50b694567 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -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 >();