1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "InternalData.hxx" 32*cdf0e10cSrcweir #include "ResId.hxx" 33*cdf0e10cSrcweir #include "Strings.hrc" 34*cdf0e10cSrcweir #include "macros.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <rtl/math.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 39*cdf0e10cSrcweir using ::rtl::OUString; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace ::com::sun::star; 42*cdf0e10cSrcweir using namespace ::std; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace chart 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // ---------------------------------------- 48*cdf0e10cSrcweir namespace 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir struct lcl_NumberedStringGenerator 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir lcl_NumberedStringGenerator( const OUString & rStub, const OUString & rWildcard ) : 53*cdf0e10cSrcweir m_aStub( rStub ), 54*cdf0e10cSrcweir m_nCounter( 0 ), 55*cdf0e10cSrcweir m_nStubStartIndex( rStub.indexOf( rWildcard )), 56*cdf0e10cSrcweir m_nWildcardLength( rWildcard.getLength()) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir vector< uno::Any > operator()() 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir vector< uno::Any > aRet(1); 62*cdf0e10cSrcweir aRet[0] = uno::makeAny( m_aStub.replaceAt( m_nStubStartIndex, m_nWildcardLength, OUString::valueOf( ++m_nCounter )) ); 63*cdf0e10cSrcweir return aRet; 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir private: 66*cdf0e10cSrcweir OUString m_aStub; 67*cdf0e10cSrcweir sal_Int32 m_nCounter; 68*cdf0e10cSrcweir const sal_Int32 m_nStubStartIndex; 69*cdf0e10cSrcweir const sal_Int32 m_nWildcardLength; 70*cdf0e10cSrcweir }; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir template< typename T > 73*cdf0e10cSrcweir Sequence< T > lcl_ValarrayToSequence( const ::std::valarray< T > & rValarray ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir // is there a more elegant way of conversion? 76*cdf0e10cSrcweir Sequence< T > aResult( rValarray.size()); 77*cdf0e10cSrcweir for( size_t i = 0; i < rValarray.size(); ++i ) 78*cdf0e10cSrcweir aResult[i] = rValarray[i]; 79*cdf0e10cSrcweir return aResult; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir } // anonymous namespace 83*cdf0e10cSrcweir // ---------------------------------------- 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir InternalData::InternalData() 86*cdf0e10cSrcweir : m_nColumnCount( 0 ) 87*cdf0e10cSrcweir , m_nRowCount( 0 ) 88*cdf0e10cSrcweir , m_aRowLabels( 0 ) 89*cdf0e10cSrcweir , m_aColumnLabels( 0 ) 90*cdf0e10cSrcweir {} 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir void InternalData::createDefaultData() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir const sal_Int32 nRowCount = 4; 95*cdf0e10cSrcweir const sal_Int32 nColumnCount = 3; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir m_nRowCount = nRowCount; 98*cdf0e10cSrcweir m_nColumnCount = nColumnCount; 99*cdf0e10cSrcweir const sal_Int32 nSize = nColumnCount * nRowCount; 100*cdf0e10cSrcweir // @todo: localize this! 101*cdf0e10cSrcweir const OUString aRowName( ::chart::SchResId::getResString( STR_ROW_LABEL )); 102*cdf0e10cSrcweir const OUString aColName( ::chart::SchResId::getResString( STR_COLUMN_LABEL )); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir const double fDefaultData[ nSize ] = 105*cdf0e10cSrcweir { 9.10, 3.20, 4.54, 106*cdf0e10cSrcweir 2.40, 8.80, 9.65, 107*cdf0e10cSrcweir 3.10, 1.50, 3.70, 108*cdf0e10cSrcweir 4.30, 9.02, 6.20 }; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir m_aData.resize( nSize ); 111*cdf0e10cSrcweir for( sal_Int32 i=0; i<nSize; ++i ) 112*cdf0e10cSrcweir m_aData[i] = fDefaultData[i]; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir m_aRowLabels.clear(); 115*cdf0e10cSrcweir m_aRowLabels.reserve( m_nRowCount ); 116*cdf0e10cSrcweir generate_n( back_inserter( m_aRowLabels ), m_nRowCount, 117*cdf0e10cSrcweir lcl_NumberedStringGenerator( aRowName, C2U("%ROWNUMBER") )); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir m_aColumnLabels.clear(); 120*cdf0e10cSrcweir m_aColumnLabels.reserve( m_nColumnCount ); 121*cdf0e10cSrcweir generate_n( back_inserter( m_aColumnLabels ), m_nColumnCount, 122*cdf0e10cSrcweir lcl_NumberedStringGenerator( aColName, C2U("%COLUMNNUMBER") )); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir void InternalData::setData( const Sequence< Sequence< double > >& rDataInRows ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir m_nRowCount = rDataInRows.getLength(); 128*cdf0e10cSrcweir m_nColumnCount = (m_nRowCount ? rDataInRows[0].getLength() : 0); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir if( m_aRowLabels.size() != static_cast< sal_uInt32 >( m_nRowCount )) 131*cdf0e10cSrcweir m_aRowLabels.resize( m_nRowCount ); 132*cdf0e10cSrcweir if( m_aColumnLabels.size() != static_cast< sal_uInt32 >( m_nColumnCount )) 133*cdf0e10cSrcweir m_aColumnLabels.resize( m_nColumnCount ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir m_aData.resize( m_nRowCount * m_nColumnCount ); 136*cdf0e10cSrcweir double fNan; 137*cdf0e10cSrcweir ::rtl::math::setNan( & fNan ); 138*cdf0e10cSrcweir // set all values to Nan 139*cdf0e10cSrcweir m_aData = fNan; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir for( sal_Int32 nRow=0; nRow<m_nRowCount; ++nRow ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir int nDataIdx = nRow*m_nColumnCount; 144*cdf0e10cSrcweir const sal_Int32 nMax = ::std::min( rDataInRows[nRow].getLength(), m_nColumnCount ); 145*cdf0e10cSrcweir for( sal_Int32 nCol=0; nCol < nMax; ++nCol ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir m_aData[nDataIdx] = rDataInRows[nRow][nCol]; 148*cdf0e10cSrcweir nDataIdx += 1; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir Sequence< Sequence< double > > InternalData::getData() const 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir Sequence< Sequence< double > > aResult( m_nRowCount ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir for( sal_Int32 i=0; i<m_nRowCount; ++i ) 158*cdf0e10cSrcweir aResult[i] = lcl_ValarrayToSequence< tDataType::value_type >( 159*cdf0e10cSrcweir m_aData[ ::std::slice( i*m_nColumnCount, m_nColumnCount, 1 ) ] ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir return aResult; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir Sequence< double > InternalData::getColumnValues( sal_Int32 nColumnIndex ) const 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir if( nColumnIndex >= 0 && nColumnIndex < m_nColumnCount ) 167*cdf0e10cSrcweir return lcl_ValarrayToSequence< tDataType::value_type >( 168*cdf0e10cSrcweir m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ] ); 169*cdf0e10cSrcweir return Sequence< double >(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir Sequence< double > InternalData::getRowValues( sal_Int32 nRowIndex ) const 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir if( nRowIndex >= 0 && nRowIndex < m_nRowCount ) 174*cdf0e10cSrcweir return lcl_ValarrayToSequence< tDataType::value_type >( 175*cdf0e10cSrcweir m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ] ); 176*cdf0e10cSrcweir return Sequence< double >(); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir void InternalData::setColumnValues( sal_Int32 nColumnIndex, const vector< double > & rNewData ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir if( nColumnIndex < 0 ) 182*cdf0e10cSrcweir return; 183*cdf0e10cSrcweir enlargeData( nColumnIndex + 1, rNewData.size() ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir tDataType aSlice = m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ]; 186*cdf0e10cSrcweir for( vector< double >::size_type i = 0; i < rNewData.size(); ++i ) 187*cdf0e10cSrcweir aSlice[i] = rNewData[i]; 188*cdf0e10cSrcweir m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ] = aSlice; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir void InternalData::setRowValues( sal_Int32 nRowIndex, const vector< double > & rNewData ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir if( nRowIndex < 0 ) 194*cdf0e10cSrcweir return; 195*cdf0e10cSrcweir enlargeData( rNewData.size(), nRowIndex+1 ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir tDataType aSlice = m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ]; 198*cdf0e10cSrcweir for( vector< double >::size_type i = 0; i < rNewData.size(); ++i ) 199*cdf0e10cSrcweir aSlice[i] = rNewData[i]; 200*cdf0e10cSrcweir m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ]= aSlice; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, const vector< uno::Any >& rComplexLabel ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir if( nColumnIndex < 0 ) 206*cdf0e10cSrcweir return; 207*cdf0e10cSrcweir if( nColumnIndex >= static_cast< sal_Int32 >( m_aColumnLabels.size() ) ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir m_aColumnLabels.resize(nColumnIndex+1); 210*cdf0e10cSrcweir enlargeData( nColumnIndex+1, 0 ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir m_aColumnLabels[nColumnIndex]=rComplexLabel; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, const vector< uno::Any >& rComplexLabel ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir if( nRowIndex < 0 ) 218*cdf0e10cSrcweir return; 219*cdf0e10cSrcweir if( nRowIndex >= static_cast< sal_Int32 >( m_aRowLabels.size() ) ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir m_aRowLabels.resize(nRowIndex+1); 222*cdf0e10cSrcweir enlargeData( 0, nRowIndex+1 ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir m_aRowLabels[nRowIndex] = rComplexLabel; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir vector< uno::Any > InternalData::getComplexColumnLabel( sal_Int32 nColumnIndex ) const 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir if( nColumnIndex < static_cast< sal_Int32 >( m_aColumnLabels.size() ) ) 230*cdf0e10cSrcweir return m_aColumnLabels[nColumnIndex]; 231*cdf0e10cSrcweir else 232*cdf0e10cSrcweir return vector< uno::Any >(); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir vector< uno::Any > InternalData::getComplexRowLabel( sal_Int32 nRowIndex ) const 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir if( nRowIndex < static_cast< sal_Int32 >( m_aRowLabels.size() ) ) 237*cdf0e10cSrcweir return m_aRowLabels[nRowIndex]; 238*cdf0e10cSrcweir else 239*cdf0e10cSrcweir return vector< uno::Any >(); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir void InternalData::swapRowWithNext( sal_Int32 nRowIndex ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir if( nRowIndex < m_nRowCount - 1 ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir const sal_Int32 nMax = m_nColumnCount; 247*cdf0e10cSrcweir for( sal_Int32 nColIdx=0; nColIdx<nMax; ++nColIdx ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir size_t nIndex1 = nColIdx + nRowIndex*m_nColumnCount; 250*cdf0e10cSrcweir size_t nIndex2 = nIndex1 + m_nColumnCount; 251*cdf0e10cSrcweir double fTemp = m_aData[nIndex1]; 252*cdf0e10cSrcweir m_aData[nIndex1] = m_aData[nIndex2]; 253*cdf0e10cSrcweir m_aData[nIndex2] = fTemp; 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir vector< uno::Any > aTemp( m_aRowLabels[nRowIndex] ); 257*cdf0e10cSrcweir m_aRowLabels[nRowIndex] = m_aRowLabels[nRowIndex + 1]; 258*cdf0e10cSrcweir m_aRowLabels[nRowIndex + 1] = aTemp; 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir void InternalData::swapColumnWithNext( sal_Int32 nColumnIndex ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir if( nColumnIndex < m_nColumnCount - 1 ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir const sal_Int32 nMax = m_nRowCount; 267*cdf0e10cSrcweir for( sal_Int32 nRowIdx=0; nRowIdx<nMax; ++nRowIdx ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir size_t nIndex1 = nColumnIndex + nRowIdx*m_nColumnCount; 270*cdf0e10cSrcweir size_t nIndex2 = nIndex1 + 1; 271*cdf0e10cSrcweir double fTemp = m_aData[nIndex1]; 272*cdf0e10cSrcweir m_aData[nIndex1] = m_aData[nIndex2]; 273*cdf0e10cSrcweir m_aData[nIndex2] = fTemp; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir vector< uno::Any > aTemp( m_aColumnLabels[nColumnIndex] ); 277*cdf0e10cSrcweir m_aColumnLabels[nColumnIndex] = m_aColumnLabels[nColumnIndex + 1]; 278*cdf0e10cSrcweir m_aColumnLabels[nColumnIndex + 1] = aTemp; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir bool InternalData::enlargeData( sal_Int32 nColumnCount, sal_Int32 nRowCount ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir sal_Int32 nNewColumnCount( ::std::max<sal_Int32>( m_nColumnCount, nColumnCount ) ); 285*cdf0e10cSrcweir sal_Int32 nNewRowCount( ::std::max<sal_Int32>( m_nRowCount, nRowCount ) ); 286*cdf0e10cSrcweir sal_Int32 nNewSize( nNewColumnCount*nNewRowCount ); 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir bool bGrow = (nNewSize > m_nColumnCount*m_nRowCount); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir if( bGrow ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir double fNan; 293*cdf0e10cSrcweir ::rtl::math::setNan( &fNan ); 294*cdf0e10cSrcweir tDataType aNewData( fNan, nNewSize ); 295*cdf0e10cSrcweir // copy old data 296*cdf0e10cSrcweir for( int nCol=0; nCol<m_nColumnCount; ++nCol ) 297*cdf0e10cSrcweir static_cast< tDataType >( 298*cdf0e10cSrcweir aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] ) = 299*cdf0e10cSrcweir m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ]; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir m_aData.resize( nNewSize ); 302*cdf0e10cSrcweir m_aData = aNewData; 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir m_nColumnCount = nNewColumnCount; 305*cdf0e10cSrcweir m_nRowCount = nNewRowCount; 306*cdf0e10cSrcweir return bGrow; 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir void InternalData::insertColumn( sal_Int32 nAfterIndex ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir // note: -1 is allowed, as we insert after the given index 312*cdf0e10cSrcweir OSL_ASSERT( nAfterIndex < m_nColumnCount && nAfterIndex >= -1 ); 313*cdf0e10cSrcweir if( nAfterIndex >= m_nColumnCount || nAfterIndex < -1 ) 314*cdf0e10cSrcweir return; 315*cdf0e10cSrcweir sal_Int32 nNewColumnCount = m_nColumnCount + 1; 316*cdf0e10cSrcweir sal_Int32 nNewSize( nNewColumnCount * m_nRowCount ); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir double fNan; 319*cdf0e10cSrcweir ::rtl::math::setNan( &fNan ); 320*cdf0e10cSrcweir tDataType aNewData( fNan, nNewSize ); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // copy old data 323*cdf0e10cSrcweir int nCol=0; 324*cdf0e10cSrcweir for( ; nCol<=nAfterIndex; ++nCol ) 325*cdf0e10cSrcweir aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] = 326*cdf0e10cSrcweir static_cast< tDataType >( 327*cdf0e10cSrcweir m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ] ); 328*cdf0e10cSrcweir for( ++nCol; nCol<nNewColumnCount; ++nCol ) 329*cdf0e10cSrcweir aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] = 330*cdf0e10cSrcweir static_cast< tDataType >( 331*cdf0e10cSrcweir m_aData[ ::std::slice( nCol - 1, m_nRowCount, m_nColumnCount ) ] ); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir m_nColumnCount = nNewColumnCount; 334*cdf0e10cSrcweir m_aData.resize( nNewSize ); 335*cdf0e10cSrcweir m_aData = aNewData; 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // labels 338*cdf0e10cSrcweir if( nAfterIndex < static_cast< sal_Int32 >( m_aColumnLabels.size())) 339*cdf0e10cSrcweir m_aColumnLabels.insert( m_aColumnLabels.begin() + (nAfterIndex + 1), vector< uno::Any >(1) ); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2 342*cdf0e10cSrcweir traceData(); 343*cdf0e10cSrcweir #endif 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir sal_Int32 InternalData::appendColumn() 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir insertColumn( getColumnCount() - 1 ); 349*cdf0e10cSrcweir return getColumnCount() - 1; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir sal_Int32 InternalData::appendRow() 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir insertRow( getRowCount() - 1 ); 355*cdf0e10cSrcweir return getRowCount() - 1; 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir void InternalData::insertRow( sal_Int32 nAfterIndex ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir // note: -1 is allowed, as we insert after the given index 361*cdf0e10cSrcweir OSL_ASSERT( nAfterIndex < m_nRowCount && nAfterIndex >= -1 ); 362*cdf0e10cSrcweir if( nAfterIndex >= m_nRowCount || nAfterIndex < -1 ) 363*cdf0e10cSrcweir return; 364*cdf0e10cSrcweir sal_Int32 nNewRowCount = m_nRowCount + 1; 365*cdf0e10cSrcweir sal_Int32 nNewSize( m_nColumnCount * nNewRowCount ); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir double fNan; 368*cdf0e10cSrcweir ::rtl::math::setNan( &fNan ); 369*cdf0e10cSrcweir tDataType aNewData( fNan, nNewSize ); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir // copy old data 372*cdf0e10cSrcweir sal_Int32 nIndex = nAfterIndex + 1; 373*cdf0e10cSrcweir aNewData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] = 374*cdf0e10cSrcweir static_cast< tDataType >( 375*cdf0e10cSrcweir m_aData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] ); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir if( nIndex < m_nRowCount ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir sal_Int32 nRemainingCount = m_nColumnCount * (m_nRowCount - nIndex); 380*cdf0e10cSrcweir aNewData[ ::std::slice( (nIndex + 1) * m_nColumnCount, nRemainingCount, 1 ) ] = 381*cdf0e10cSrcweir static_cast< tDataType >( 382*cdf0e10cSrcweir m_aData[ ::std::slice( nIndex * m_nColumnCount, nRemainingCount, 1 ) ] ); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir m_nRowCount = nNewRowCount; 386*cdf0e10cSrcweir m_aData.resize( nNewSize ); 387*cdf0e10cSrcweir m_aData = aNewData; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir // labels 390*cdf0e10cSrcweir if( nAfterIndex < static_cast< sal_Int32 >( m_aRowLabels.size())) 391*cdf0e10cSrcweir m_aRowLabels.insert( m_aRowLabels.begin() + nIndex, vector< uno::Any > (1)); 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2 394*cdf0e10cSrcweir traceData(); 395*cdf0e10cSrcweir #endif 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir void InternalData::deleteColumn( sal_Int32 nAtIndex ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir OSL_ASSERT( nAtIndex < m_nColumnCount && nAtIndex >= 0 ); 401*cdf0e10cSrcweir if( nAtIndex >= m_nColumnCount || m_nColumnCount < 1 || nAtIndex < 0 ) 402*cdf0e10cSrcweir return; 403*cdf0e10cSrcweir sal_Int32 nNewColumnCount = m_nColumnCount - 1; 404*cdf0e10cSrcweir sal_Int32 nNewSize( nNewColumnCount * m_nRowCount ); 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir double fNan; 407*cdf0e10cSrcweir ::rtl::math::setNan( &fNan ); 408*cdf0e10cSrcweir tDataType aNewData( fNan, nNewSize ); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir // copy old data 411*cdf0e10cSrcweir int nCol=0; 412*cdf0e10cSrcweir for( ; nCol<nAtIndex; ++nCol ) 413*cdf0e10cSrcweir aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] = 414*cdf0e10cSrcweir static_cast< tDataType >( 415*cdf0e10cSrcweir m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ] ); 416*cdf0e10cSrcweir for( ; nCol<nNewColumnCount; ++nCol ) 417*cdf0e10cSrcweir aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] = 418*cdf0e10cSrcweir static_cast< tDataType >( 419*cdf0e10cSrcweir m_aData[ ::std::slice( nCol + 1, m_nRowCount, m_nColumnCount ) ] ); 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir m_nColumnCount = nNewColumnCount; 422*cdf0e10cSrcweir m_aData.resize( nNewSize ); 423*cdf0e10cSrcweir m_aData = aNewData; 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir // labels 426*cdf0e10cSrcweir if( nAtIndex < static_cast< sal_Int32 >( m_aColumnLabels.size())) 427*cdf0e10cSrcweir m_aColumnLabels.erase( m_aColumnLabels.begin() + nAtIndex ); 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2 430*cdf0e10cSrcweir traceData(); 431*cdf0e10cSrcweir #endif 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir void InternalData::deleteRow( sal_Int32 nAtIndex ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir OSL_ASSERT( nAtIndex < m_nRowCount && nAtIndex >= 0 ); 437*cdf0e10cSrcweir if( nAtIndex >= m_nRowCount || m_nRowCount < 1 || nAtIndex < 0 ) 438*cdf0e10cSrcweir return; 439*cdf0e10cSrcweir sal_Int32 nNewRowCount = m_nRowCount - 1; 440*cdf0e10cSrcweir sal_Int32 nNewSize( m_nColumnCount * nNewRowCount ); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir double fNan; 443*cdf0e10cSrcweir ::rtl::math::setNan( &fNan ); 444*cdf0e10cSrcweir tDataType aNewData( fNan, nNewSize ); 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir // copy old data 447*cdf0e10cSrcweir sal_Int32 nIndex = nAtIndex; 448*cdf0e10cSrcweir if( nIndex ) 449*cdf0e10cSrcweir aNewData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] = 450*cdf0e10cSrcweir static_cast< tDataType >( 451*cdf0e10cSrcweir m_aData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] ); 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir if( nIndex < nNewRowCount ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir sal_Int32 nRemainingCount = m_nColumnCount * (nNewRowCount - nIndex); 456*cdf0e10cSrcweir aNewData[ ::std::slice( nIndex * m_nColumnCount, nRemainingCount, 1 ) ] = 457*cdf0e10cSrcweir static_cast< tDataType >( 458*cdf0e10cSrcweir m_aData[ ::std::slice( (nIndex + 1) * m_nColumnCount, nRemainingCount, 1 ) ] ); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir m_nRowCount = nNewRowCount; 462*cdf0e10cSrcweir m_aData.resize( nNewSize ); 463*cdf0e10cSrcweir m_aData = aNewData; 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir // labels 466*cdf0e10cSrcweir if( nAtIndex < static_cast< sal_Int32 >( m_aRowLabels.size())) 467*cdf0e10cSrcweir m_aRowLabels.erase( m_aRowLabels.begin() + nAtIndex ); 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2 470*cdf0e10cSrcweir traceData(); 471*cdf0e10cSrcweir #endif 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir sal_Int32 InternalData::getRowCount() const 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir return m_nRowCount; 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir sal_Int32 InternalData::getColumnCount() const 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir return m_nColumnCount; 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir void InternalData::setComplexRowLabels( const vector< vector< uno::Any > >& rNewRowLabels ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir m_aRowLabels = rNewRowLabels; 487*cdf0e10cSrcweir sal_Int32 nNewRowCount = static_cast< sal_Int32 >( m_aRowLabels.size() ); 488*cdf0e10cSrcweir if( nNewRowCount < m_nRowCount ) 489*cdf0e10cSrcweir m_aRowLabels.resize( m_nRowCount ); 490*cdf0e10cSrcweir else 491*cdf0e10cSrcweir enlargeData( 0, nNewRowCount ); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir vector< vector< uno::Any > > InternalData::getComplexRowLabels() const 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir return m_aRowLabels; 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir void InternalData::setComplexColumnLabels( const vector< vector< uno::Any > >& rNewColumnLabels ) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir m_aColumnLabels = rNewColumnLabels; 502*cdf0e10cSrcweir sal_Int32 nNewColumnCount = static_cast< sal_Int32 >( m_aColumnLabels.size() ); 503*cdf0e10cSrcweir if( nNewColumnCount < m_nColumnCount ) 504*cdf0e10cSrcweir m_aColumnLabels.resize( m_nColumnCount ); 505*cdf0e10cSrcweir else 506*cdf0e10cSrcweir enlargeData( nNewColumnCount, 0 ); 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir vector< vector< uno::Any > > InternalData::getComplexColumnLabels() const 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir return m_aColumnLabels; 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2 515*cdf0e10cSrcweir void InternalData::traceData() const 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir OSL_TRACE( "InternalData: Data in rows\n" ); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir for( sal_Int32 i=0; i<m_nRowCount; ++i ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir tDataType aSlice( m_aData[ ::std::slice( i*m_nColumnCount, m_nColumnCount, 1 ) ] ); 522*cdf0e10cSrcweir for( sal_Int32 j=0; j<m_nColumnCount; ++j ) 523*cdf0e10cSrcweir OSL_TRACE( "%lf ", aSlice[j] ); 524*cdf0e10cSrcweir OSL_TRACE( "\n" ); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir OSL_TRACE( "\n" ); 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir #endif 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir } // namespace chart 531