1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10*cde9e8dcSAndrew Rist * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*cde9e8dcSAndrew Rist * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19*cde9e8dcSAndrew Rist * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "DataBrowserModel.hxx" 28cdf0e10cSrcweir #include "DialogModel.hxx" 29cdf0e10cSrcweir #include "ChartModelHelper.hxx" 30cdf0e10cSrcweir #include "DiagramHelper.hxx" 31cdf0e10cSrcweir #include "DataSeriesHelper.hxx" 32cdf0e10cSrcweir #include "PropertyHelper.hxx" 33cdf0e10cSrcweir #include "ControllerLockGuard.hxx" 34cdf0e10cSrcweir #include "macros.hxx" 35cdf0e10cSrcweir #include "StatisticsHelper.hxx" 36cdf0e10cSrcweir #include "ContainerHelper.hxx" 37cdf0e10cSrcweir #include "ChartTypeHelper.hxx" 38cdf0e10cSrcweir #include "chartview/ExplicitValueProvider.hxx" 39cdf0e10cSrcweir #include "ExplicitCategoriesProvider.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp> 42cdf0e10cSrcweir #include <com/sun/star/chart2/XAxis.hpp> 43cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp> 44cdf0e10cSrcweir #include <com/sun/star/chart2/XInternalDataProvider.hpp> 45cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> 46cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp> 47cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSource.hpp> 48cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSink.hpp> 49cdf0e10cSrcweir #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> 50cdf0e10cSrcweir #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp> 51cdf0e10cSrcweir #include <com/sun/star/chart2/data/XTextualDataSequence.hpp> 52cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include <rtl/math.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir #include <algorithm> 57cdf0e10cSrcweir 58cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 59cdf0e10cSrcweir #include <cstdio> 60cdf0e10cSrcweir #endif 61cdf0e10cSrcweir 62cdf0e10cSrcweir using namespace ::com::sun::star; 63cdf0e10cSrcweir 64cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 65cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 66cdf0e10cSrcweir using ::rtl::OUString; 67cdf0e10cSrcweir 68cdf0e10cSrcweir namespace 69cdf0e10cSrcweir { 70cdf0e10cSrcweir OUString lcl_getRole( 71cdf0e10cSrcweir const Reference< chart2::data::XDataSequence > & xSeq ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir OUString aResult; 74cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY ); 75cdf0e10cSrcweir if( xProp.is()) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir try 78cdf0e10cSrcweir { 79cdf0e10cSrcweir xProp->getPropertyValue( C2U("Role")) >>= aResult; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir catch( const uno::Exception & ex ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir return aResult; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir 90cdf0e10cSrcweir OUString lcl_getRole( 91cdf0e10cSrcweir const Reference< chart2::data::XLabeledDataSequence > & xLSeq ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir OUString aResult; 94cdf0e10cSrcweir if( xLSeq.is()) 95cdf0e10cSrcweir aResult = lcl_getRole( xLSeq->getValues()); 96cdf0e10cSrcweir return aResult; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir OUString lcl_getUIRoleName( 100cdf0e10cSrcweir const Reference< chart2::data::XLabeledDataSequence > & xLSeq ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir OUString aResult( lcl_getRole( xLSeq )); 103cdf0e10cSrcweir if( aResult.getLength()) 104cdf0e10cSrcweir aResult = ::chart::DialogModel::ConvertRoleFromInternalToUI( aResult ); 105cdf0e10cSrcweir return aResult; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir void lcl_copyDataSequenceProperties( 109cdf0e10cSrcweir const Reference< chart2::data::XDataSequence > & xOldSequence, 110cdf0e10cSrcweir const Reference< chart2::data::XDataSequence > & xNewSequence ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir Reference< beans::XPropertySet > xOldSeqProp( xOldSequence, uno::UNO_QUERY ); 113cdf0e10cSrcweir Reference< beans::XPropertySet > xNewSeqProp( xNewSequence, uno::UNO_QUERY ); 114cdf0e10cSrcweir comphelper::copyProperties( xOldSeqProp, xNewSeqProp ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir bool lcl_SequenceOfSeriesIsShared( 118cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries, 119cdf0e10cSrcweir const Reference< chart2::data::XDataSequence > & xValues ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir bool bResult = false; 122cdf0e10cSrcweir if( !xValues.is()) 123cdf0e10cSrcweir return bResult; 124cdf0e10cSrcweir try 125cdf0e10cSrcweir { 126cdf0e10cSrcweir OUString aValuesRole( lcl_getRole( xValues )); 127cdf0e10cSrcweir OUString aValuesRep( xValues->getSourceRangeRepresentation()); 128cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY_THROW ); 129cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSeq( xSource->getDataSequences()); 130cdf0e10cSrcweir for( sal_Int32 i=0; i<aLSeq.getLength(); ++i ) 131cdf0e10cSrcweir if( aLSeq[i].is() && 132cdf0e10cSrcweir lcl_getRole( aLSeq[i] ).equals( aValuesRole )) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir // getValues().is(), because lcl_getRole checked that already 135cdf0e10cSrcweir bResult = (aValuesRep == aLSeq[i]->getValues()->getSourceRangeRepresentation()); 136cdf0e10cSrcweir // assumption: a role appears only once in a series 137cdf0e10cSrcweir break; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir catch( const uno::Exception & ex ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir return bResult; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir typedef ::std::vector< Reference< chart2::data::XLabeledDataSequence > > lcl_tSharedSeqVec; 148cdf0e10cSrcweir 149cdf0e10cSrcweir lcl_tSharedSeqVec lcl_getSharedSequences( const Sequence< Reference< chart2::XDataSeries > > & rSeries ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir // @todo: if only some series share a sequence, those have to be duplicated 152cdf0e10cSrcweir // and made unshared for all series 153cdf0e10cSrcweir lcl_tSharedSeqVec aResult; 154cdf0e10cSrcweir // if we have only one series, we don't want any shared sequences 155cdf0e10cSrcweir if( rSeries.getLength() <= 1 ) 156cdf0e10cSrcweir return aResult; 157cdf0e10cSrcweir 158cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( rSeries[0], uno::UNO_QUERY ); 159cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSeq( xSource->getDataSequences()); 160cdf0e10cSrcweir for( sal_Int32 nIdx=0; nIdx<aLSeq.getLength(); ++nIdx ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xValues( aLSeq[nIdx]->getValues()); 163cdf0e10cSrcweir bool bShared = true; 164cdf0e10cSrcweir for( sal_Int32 nSeriesIdx=1; nSeriesIdx<rSeries.getLength(); ++nSeriesIdx ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir bShared = lcl_SequenceOfSeriesIsShared( rSeries[nSeriesIdx], xValues ); 167cdf0e10cSrcweir if( !bShared ) 168cdf0e10cSrcweir break; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir if( bShared ) 171cdf0e10cSrcweir aResult.push_back( aLSeq[nIdx] ); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir return aResult; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir sal_Int32 lcl_getValuesRepresentationIndex( 178cdf0e10cSrcweir const Reference< chart2::data::XLabeledDataSequence > & xLSeq ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir sal_Int32 nResult = -1; 181cdf0e10cSrcweir if( xLSeq.is()) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xSeq( xLSeq->getValues()); 184cdf0e10cSrcweir if( xSeq.is()) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir OUString aRep( xSeq->getSourceRangeRepresentation()); 187cdf0e10cSrcweir nResult = aRep.toInt32(); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } 190cdf0e10cSrcweir return nResult; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir struct lcl_RepresentationsOfLSeqMatch : public ::std::unary_function< Reference< chart2::data::XLabeledDataSequence >, bool > 194cdf0e10cSrcweir { 195cdf0e10cSrcweir lcl_RepresentationsOfLSeqMatch( const Reference< chart2::data::XLabeledDataSequence > & xLSeq ) : 196cdf0e10cSrcweir m_aValuesRep( xLSeq.is() ? 197cdf0e10cSrcweir (xLSeq->getValues().is() ? xLSeq->getValues()->getSourceRangeRepresentation() : OUString()) 198cdf0e10cSrcweir : OUString() ) 199cdf0e10cSrcweir {} 200cdf0e10cSrcweir bool operator() ( const Reference< chart2::data::XLabeledDataSequence > & xLSeq ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir return (xLSeq.is() && 203cdf0e10cSrcweir xLSeq->getValues().is() && 204cdf0e10cSrcweir (xLSeq->getValues()->getSourceRangeRepresentation() == m_aValuesRep )); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir private: 207cdf0e10cSrcweir OUString m_aValuesRep; 208cdf0e10cSrcweir }; 209cdf0e10cSrcweir 210cdf0e10cSrcweir struct lcl_RolesOfLSeqMatch : public ::std::unary_function< Reference< chart2::data::XLabeledDataSequence >, bool > 211cdf0e10cSrcweir { 212cdf0e10cSrcweir lcl_RolesOfLSeqMatch( const Reference< chart2::data::XLabeledDataSequence > & xLSeq ) : 213cdf0e10cSrcweir m_aRole( lcl_getRole( xLSeq )) 214cdf0e10cSrcweir {} 215cdf0e10cSrcweir bool operator() ( const Reference< chart2::data::XLabeledDataSequence > & xLSeq ) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir return lcl_getRole( xLSeq ).equals( m_aRole ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir private: 220cdf0e10cSrcweir OUString m_aRole; 221cdf0e10cSrcweir }; 222cdf0e10cSrcweir 223cdf0e10cSrcweir bool lcl_ShowCategories( const Reference< chart2::XDiagram > & /* xDiagram */ ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir // show categories for all charts 226cdf0e10cSrcweir return true; 227cdf0e10cSrcweir // return DiagramHelper::isCategoryDiagram( xDiagram ); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir bool lcl_ShowCategoriesAsDataLabel( const Reference< chart2::XDiagram > & xDiagram ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir return ! ::chart::DiagramHelper::isCategoryDiagram( xDiagram ); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir } // anonymous namespace 236cdf0e10cSrcweir 237cdf0e10cSrcweir namespace chart 238cdf0e10cSrcweir { 239cdf0e10cSrcweir 240cdf0e10cSrcweir 241cdf0e10cSrcweir struct DataBrowserModel::tDataColumn 242cdf0e10cSrcweir { 243cdf0e10cSrcweir ::com::sun::star::uno::Reference< 244cdf0e10cSrcweir ::com::sun::star::chart2::XDataSeries > m_xDataSeries; 245cdf0e10cSrcweir sal_Int32 m_nIndexInDataSeries; 246cdf0e10cSrcweir ::rtl::OUString m_aUIRoleName; 247cdf0e10cSrcweir ::com::sun::star::uno::Reference< 248cdf0e10cSrcweir ::com::sun::star::chart2::data::XLabeledDataSequence > m_xLabeledDataSequence; 249cdf0e10cSrcweir eCellType m_eCellType; 250cdf0e10cSrcweir sal_Int32 m_nNumberFormatKey; 251cdf0e10cSrcweir 252cdf0e10cSrcweir // default CTOR 253cdf0e10cSrcweir tDataColumn() : m_nIndexInDataSeries( -1 ), m_eCellType( TEXT ), m_nNumberFormatKey( 0 ) {} 254cdf0e10cSrcweir // "full" CTOR 255cdf0e10cSrcweir tDataColumn( 256cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 257cdf0e10cSrcweir ::com::sun::star::chart2::XDataSeries > & xDataSeries, 258cdf0e10cSrcweir sal_Int32 nIndexInDataSeries, 259cdf0e10cSrcweir ::rtl::OUString aUIRoleName, 260cdf0e10cSrcweir ::com::sun::star::uno::Reference< 261cdf0e10cSrcweir ::com::sun::star::chart2::data::XLabeledDataSequence > xLabeledDataSequence, 262cdf0e10cSrcweir eCellType aCellType, 263cdf0e10cSrcweir sal_Int32 nNumberFormatKey ) : 264cdf0e10cSrcweir m_xDataSeries( xDataSeries ), 265cdf0e10cSrcweir m_nIndexInDataSeries( nIndexInDataSeries ), 266cdf0e10cSrcweir m_aUIRoleName( aUIRoleName ), 267cdf0e10cSrcweir m_xLabeledDataSequence( xLabeledDataSequence ), 268cdf0e10cSrcweir m_eCellType( aCellType ), 269cdf0e10cSrcweir m_nNumberFormatKey( nNumberFormatKey ) 270cdf0e10cSrcweir {} 271cdf0e10cSrcweir }; 272cdf0e10cSrcweir 273cdf0e10cSrcweir struct DataBrowserModel::implColumnLess : public ::std::binary_function< 274cdf0e10cSrcweir DataBrowserModel::tDataColumn, DataBrowserModel::tDataColumn, bool > 275cdf0e10cSrcweir { 276cdf0e10cSrcweir bool operator() ( const first_argument_type & rLeft, const second_argument_type & rRight ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir if( rLeft.m_xLabeledDataSequence.is() && rRight.m_xLabeledDataSequence.is()) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir return DialogModel::GetRoleIndexForSorting( lcl_getRole( rLeft.m_xLabeledDataSequence )) < 281cdf0e10cSrcweir DialogModel::GetRoleIndexForSorting( lcl_getRole( rRight.m_xLabeledDataSequence )); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir return true; 284cdf0e10cSrcweir } 285cdf0e10cSrcweir }; 286cdf0e10cSrcweir 287cdf0e10cSrcweir DataBrowserModel::DataBrowserModel( 288cdf0e10cSrcweir const Reference< chart2::XChartDocument > & xChartDoc, 289cdf0e10cSrcweir const Reference< uno::XComponentContext > & xContext ) : 290cdf0e10cSrcweir m_xChartDocument( xChartDoc ), 291cdf0e10cSrcweir m_xContext( xContext ), 292cdf0e10cSrcweir m_apDialogModel( new DialogModel( xChartDoc, xContext )) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir updateFromModel(); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir DataBrowserModel::~DataBrowserModel() 298cdf0e10cSrcweir {} 299cdf0e10cSrcweir 300cdf0e10cSrcweir namespace 301cdf0e10cSrcweir { 302cdf0e10cSrcweir struct lcl_DataSeriesOfHeaderMatches : public ::std::unary_function< ::chart::DataBrowserModel::tDataHeader, bool > 303cdf0e10cSrcweir { 304cdf0e10cSrcweir lcl_DataSeriesOfHeaderMatches( 305cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeriesToCompareWith ) : 306cdf0e10cSrcweir m_xSeries( xSeriesToCompareWith ) 307cdf0e10cSrcweir {} 308cdf0e10cSrcweir bool operator() ( const ::chart::DataBrowserModel::tDataHeader & rHeader ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir return (m_xSeries == rHeader.m_xDataSeries); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir private: 313cdf0e10cSrcweir Reference< chart2::XDataSeries > m_xSeries; 314cdf0e10cSrcweir }; 315cdf0e10cSrcweir } 316cdf0e10cSrcweir 317cdf0e10cSrcweir void DataBrowserModel::insertDataSeries( sal_Int32 nAfterColumnIndex ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir OSL_ASSERT( m_apDialogModel.get()); 320cdf0e10cSrcweir Reference< chart2::XInternalDataProvider > xDataProvider( 321cdf0e10cSrcweir m_apDialogModel->getDataProvider(), uno::UNO_QUERY ); 322cdf0e10cSrcweir if( xDataProvider.is()) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir if( isCategoriesColumn(nAfterColumnIndex) ) 325cdf0e10cSrcweir nAfterColumnIndex = getCategoryColumnCount()-1; 326cdf0e10cSrcweir 327cdf0e10cSrcweir sal_Int32 nStartCol = 0; 328cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartDocument )); 329cdf0e10cSrcweir Reference< chart2::XChartType > xChartType; 330cdf0e10cSrcweir Reference< chart2::XDataSeries > xSeries; 331cdf0e10cSrcweir if( static_cast< tDataColumnVector::size_type >( nAfterColumnIndex ) <= m_aColumns.size()) 332cdf0e10cSrcweir xSeries.set( m_aColumns[nAfterColumnIndex].m_xDataSeries ); 333cdf0e10cSrcweir 334cdf0e10cSrcweir sal_Int32 nSeriesNumberFormat = 0; 335cdf0e10cSrcweir if( xSeries.is()) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir xChartType.set( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries )); 338cdf0e10cSrcweir tDataHeaderVector::const_iterator aIt( 339cdf0e10cSrcweir ::std::find_if( m_aHeaders.begin(), m_aHeaders.end(), 340cdf0e10cSrcweir lcl_DataSeriesOfHeaderMatches( xSeries ))); 341cdf0e10cSrcweir if( aIt != m_aHeaders.end()) 342cdf0e10cSrcweir nStartCol = aIt->m_nEndColumn; 343cdf0e10cSrcweir 344cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProps( xSeries, uno::UNO_QUERY ); 345cdf0e10cSrcweir if( xSeriesProps.is() ) 346cdf0e10cSrcweir xSeriesProps->getPropertyValue( C2U( "NumberFormat" )) >>= nSeriesNumberFormat; 347cdf0e10cSrcweir } 348cdf0e10cSrcweir else 349cdf0e10cSrcweir { 350cdf0e10cSrcweir xChartType.set( DiagramHelper::getChartTypeByIndex( xDiagram, 0 )); 351cdf0e10cSrcweir nStartCol = nAfterColumnIndex; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir if( xChartType.is()) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir sal_Int32 nOffset = 0; 357cdf0e10cSrcweir if( xDiagram.is() && lcl_ShowCategories( xDiagram )) 358cdf0e10cSrcweir nOffset=getCategoryColumnCount(); 359cdf0e10cSrcweir // get shared sequences of current series 360cdf0e10cSrcweir Reference< chart2::XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY ); 361cdf0e10cSrcweir lcl_tSharedSeqVec aSharedSequences; 362cdf0e10cSrcweir if( xSeriesCnt.is()) 363cdf0e10cSrcweir aSharedSequences = lcl_getSharedSequences( xSeriesCnt->getDataSeries()); 364cdf0e10cSrcweir Reference< chart2::XDataSeries > xNewSeries( 365cdf0e10cSrcweir m_apDialogModel->insertSeriesAfter( xSeries, xChartType, true /* bCreateDataCachedSequences */ )); 366cdf0e10cSrcweir if( xNewSeries.is()) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir { 369cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xNewSeries, uno::UNO_QUERY ); 370cdf0e10cSrcweir if( xSource.is()) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSequences( 373cdf0e10cSrcweir xSource->getDataSequences()); 374cdf0e10cSrcweir sal_Int32 nSeqIdx = 0; 375cdf0e10cSrcweir sal_Int32 nSeqSize = aLSequences.getLength(); 376cdf0e10cSrcweir nStartCol -= (nOffset - 1); 377cdf0e10cSrcweir for( sal_Int32 nIndex = nStartCol; 378cdf0e10cSrcweir (nSeqIdx < nSeqSize); 379cdf0e10cSrcweir ++nSeqIdx ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir lcl_tSharedSeqVec::const_iterator aSharedIt( 382cdf0e10cSrcweir ::std::find_if( aSharedSequences.begin(), aSharedSequences.end(), 383cdf0e10cSrcweir lcl_RolesOfLSeqMatch( aLSequences[nSeqIdx] ))); 384cdf0e10cSrcweir if( aSharedIt != aSharedSequences.end()) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir aLSequences[nSeqIdx]->setValues( (*aSharedIt)->getValues()); 387cdf0e10cSrcweir aLSequences[nSeqIdx]->setLabel( (*aSharedIt)->getLabel()); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir else 390cdf0e10cSrcweir { 391cdf0e10cSrcweir xDataProvider->insertSequence( nIndex - 1 ); 392cdf0e10cSrcweir 393cdf0e10cSrcweir // values 394cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xNewSeq( 395cdf0e10cSrcweir xDataProvider->createDataSequenceByRangeRepresentation( 396cdf0e10cSrcweir OUString::valueOf( nIndex ))); 397cdf0e10cSrcweir lcl_copyDataSequenceProperties( 398cdf0e10cSrcweir aLSequences[nSeqIdx]->getValues(), xNewSeq ); 399cdf0e10cSrcweir aLSequences[nSeqIdx]->setValues( xNewSeq ); 400cdf0e10cSrcweir 401cdf0e10cSrcweir // labels 402cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xNewLabelSeq( 403cdf0e10cSrcweir xDataProvider->createDataSequenceByRangeRepresentation( 404cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "label " )) + 405cdf0e10cSrcweir OUString::valueOf( nIndex ))); 406cdf0e10cSrcweir lcl_copyDataSequenceProperties( 407cdf0e10cSrcweir aLSequences[nSeqIdx]->getLabel(), xNewLabelSeq ); 408cdf0e10cSrcweir aLSequences[nSeqIdx]->setLabel( xNewLabelSeq ); 409cdf0e10cSrcweir ++nIndex; 410cdf0e10cSrcweir } 411cdf0e10cSrcweir } 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir if( nSeriesNumberFormat != 0 ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir //give the new series the same number format as the former series especially for bubble charts thus the bubble size values can be edited with same format immidiately 417cdf0e10cSrcweir Reference< beans::XPropertySet > xNewSeriesProps( xNewSeries, uno::UNO_QUERY ); 418cdf0e10cSrcweir if( xNewSeriesProps.is() ) 419cdf0e10cSrcweir xNewSeriesProps->setPropertyValue( C2U( "NumberFormat" ), uno::makeAny( nSeriesNumberFormat ) ); 420cdf0e10cSrcweir } 421cdf0e10cSrcweir 422cdf0e10cSrcweir updateFromModel(); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir } 425cdf0e10cSrcweir } 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir void DataBrowserModel::insertComplexCategoryLevel( sal_Int32 nAfterColumnIndex ) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir //create a new text column for complex categories 431cdf0e10cSrcweir 432cdf0e10cSrcweir OSL_ASSERT( m_apDialogModel.get()); 433cdf0e10cSrcweir Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY ); 434cdf0e10cSrcweir if( xDataProvider.is() ) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir if( !isCategoriesColumn(nAfterColumnIndex) ) 437cdf0e10cSrcweir nAfterColumnIndex = getCategoryColumnCount()-1; 438cdf0e10cSrcweir 439cdf0e10cSrcweir if(nAfterColumnIndex<0) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir OSL_ENSURE( false, "wrong index for category level insertion" ); 442cdf0e10cSrcweir return; 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir m_apDialogModel->startControllerLockTimer(); 446cdf0e10cSrcweir ControllerLockGuard aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ); 447cdf0e10cSrcweir xDataProvider->insertComplexCategoryLevel( nAfterColumnIndex+1 ); 448cdf0e10cSrcweir updateFromModel(); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir void DataBrowserModel::removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColumnIndex ) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir OSL_ASSERT( m_apDialogModel.get()); 455cdf0e10cSrcweir if( static_cast< tDataColumnVector::size_type >( nAtColumnIndex ) < m_aColumns.size()) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir Reference< chart2::XDataSeries > xSeries( m_aColumns[nAtColumnIndex].m_xDataSeries ); 458cdf0e10cSrcweir if( xSeries.is()) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir m_apDialogModel->deleteSeries( 461cdf0e10cSrcweir xSeries, getHeaderForSeries( xSeries ).m_xChartType ); 462cdf0e10cSrcweir 463cdf0e10cSrcweir //delete sequences from internal data provider that are not used anymore 464cdf0e10cSrcweir //but do not delete sequences that are still in use by the remaining series 465cdf0e10cSrcweir Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY ); 466cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSourceOfDeletedSeries( xSeries, uno::UNO_QUERY ); 467cdf0e10cSrcweir if( xDataProvider.is() && xSourceOfDeletedSeries.is()) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir ::std::vector< sal_Int32 > aSequenceIndexesToDelete; 470cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequencesOfDeletedSeries( xSourceOfDeletedSeries->getDataSequences() ); 471cdf0e10cSrcweir Reference< chart2::XDataSeriesContainer > xSeriesCnt( getHeaderForSeries( xSeries ).m_xChartType, uno::UNO_QUERY ); 472cdf0e10cSrcweir if( xSeriesCnt.is()) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir Reference< chart2::data::XDataSource > xRemainingDataSource( DataSeriesHelper::getDataSource( xSeriesCnt->getDataSeries() ) ); 475cdf0e10cSrcweir if( xRemainingDataSource.is() ) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aRemainingSeq( ContainerHelper::SequenceToVector( xRemainingDataSource->getDataSequences() ) ); 478cdf0e10cSrcweir for( sal_Int32 i=0; i<aSequencesOfDeletedSeries.getLength(); ++i ) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::const_iterator aHitIt( 481cdf0e10cSrcweir ::std::find_if( aRemainingSeq.begin(), aRemainingSeq.end(), 482cdf0e10cSrcweir lcl_RepresentationsOfLSeqMatch( aSequencesOfDeletedSeries[i] ))); 483cdf0e10cSrcweir // if not used by the remaining series this sequence can be deleted 484cdf0e10cSrcweir if( aHitIt == aRemainingSeq.end() ) 485cdf0e10cSrcweir aSequenceIndexesToDelete.push_back( lcl_getValuesRepresentationIndex( aSequencesOfDeletedSeries[i] ) ); 486cdf0e10cSrcweir } 487cdf0e10cSrcweir } 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir // delete unnecessary sequences of the internal data 491cdf0e10cSrcweir // iterate using greatest index first, so that deletion does not 492cdf0e10cSrcweir // shift other sequences that will be deleted later 493cdf0e10cSrcweir ::std::sort( aSequenceIndexesToDelete.begin(), aSequenceIndexesToDelete.end()); 494cdf0e10cSrcweir for( ::std::vector< sal_Int32 >::reverse_iterator aIt( 495cdf0e10cSrcweir aSequenceIndexesToDelete.rbegin()); aIt != aSequenceIndexesToDelete.rend(); ++aIt ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir if( *aIt != -1 ) 498cdf0e10cSrcweir xDataProvider->deleteSequence( *aIt ); 499cdf0e10cSrcweir } 500cdf0e10cSrcweir } 501cdf0e10cSrcweir updateFromModel(); 502cdf0e10cSrcweir } 503cdf0e10cSrcweir else 504cdf0e10cSrcweir { 505cdf0e10cSrcweir //delete a category column if there is more than one level (in case of a single column we do not get here) 506cdf0e10cSrcweir OSL_ENSURE(nAtColumnIndex>0, "wrong index for categories deletion" ); 507cdf0e10cSrcweir 508cdf0e10cSrcweir Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY ); 509cdf0e10cSrcweir if( xDataProvider.is() ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir m_apDialogModel->startControllerLockTimer(); 512cdf0e10cSrcweir ControllerLockGuard aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ); 513cdf0e10cSrcweir xDataProvider->deleteComplexCategoryLevel( nAtColumnIndex ); 514cdf0e10cSrcweir updateFromModel(); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir } 517cdf0e10cSrcweir } 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520cdf0e10cSrcweir void DataBrowserModel::swapDataSeries( sal_Int32 nFirstColumnIndex ) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir OSL_ASSERT( m_apDialogModel.get()); 523cdf0e10cSrcweir if( static_cast< tDataColumnVector::size_type >( nFirstColumnIndex ) < m_aColumns.size() - 1 ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir Reference< chart2::XDataSeries > xSeries( m_aColumns[nFirstColumnIndex].m_xDataSeries ); 526cdf0e10cSrcweir if( xSeries.is()) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir m_apDialogModel->moveSeries( xSeries, DialogModel::MOVE_DOWN ); 529cdf0e10cSrcweir updateFromModel(); 530cdf0e10cSrcweir } 531cdf0e10cSrcweir } 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir void DataBrowserModel::swapDataPointForAllSeries( sal_Int32 nFirstIndex ) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir OSL_ASSERT( m_apDialogModel.get()); 537cdf0e10cSrcweir Reference< chart2::XInternalDataProvider > xDataProvider( 538cdf0e10cSrcweir m_apDialogModel->getDataProvider(), uno::UNO_QUERY ); 539cdf0e10cSrcweir // lockControllers 540cdf0e10cSrcweir ControllerLockGuard aGuard( m_apDialogModel->getChartModel()); 541cdf0e10cSrcweir if( xDataProvider.is()) 542cdf0e10cSrcweir xDataProvider->swapDataPointWithNextOneForAllSequences( nFirstIndex ); 543cdf0e10cSrcweir // unlockControllers 544cdf0e10cSrcweir } 545cdf0e10cSrcweir 546cdf0e10cSrcweir void DataBrowserModel::insertDataPointForAllSeries( sal_Int32 nAfterIndex ) 547cdf0e10cSrcweir { 548cdf0e10cSrcweir Reference< chart2::XInternalDataProvider > xDataProvider( 549cdf0e10cSrcweir m_apDialogModel->getDataProvider(), uno::UNO_QUERY ); 550cdf0e10cSrcweir // lockControllers 551cdf0e10cSrcweir ControllerLockGuard aGuard( m_apDialogModel->getChartModel()); 552cdf0e10cSrcweir if( xDataProvider.is()) 553cdf0e10cSrcweir xDataProvider->insertDataPointForAllSequences( nAfterIndex ); 554cdf0e10cSrcweir // unlockControllers 555cdf0e10cSrcweir } 556cdf0e10cSrcweir 557cdf0e10cSrcweir void DataBrowserModel::removeDataPointForAllSeries( sal_Int32 nAtIndex ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir Reference< chart2::XInternalDataProvider > xDataProvider( 560cdf0e10cSrcweir m_apDialogModel->getDataProvider(), uno::UNO_QUERY ); 561cdf0e10cSrcweir // lockControllers 562cdf0e10cSrcweir ControllerLockGuard aGuard( m_apDialogModel->getChartModel()); 563cdf0e10cSrcweir if( xDataProvider.is()) 564cdf0e10cSrcweir xDataProvider->deleteDataPointForAllSequences( nAtIndex ); 565cdf0e10cSrcweir // unlockControllers 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir DataBrowserModel::tDataHeader DataBrowserModel::getHeaderForSeries( 569cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries ) const 570cdf0e10cSrcweir { 571cdf0e10cSrcweir for( tDataHeaderVector::const_iterator aIt( m_aHeaders.begin()); 572cdf0e10cSrcweir aIt != m_aHeaders.end(); ++aIt ) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir if( aIt->m_xDataSeries == xSeries ) 575cdf0e10cSrcweir return (*aIt); 576cdf0e10cSrcweir } 577cdf0e10cSrcweir return tDataHeader(); 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir Reference< chart2::XDataSeries > 581cdf0e10cSrcweir DataBrowserModel::getDataSeriesByColumn( sal_Int32 nColumn ) const 582cdf0e10cSrcweir { 583cdf0e10cSrcweir tDataColumnVector::size_type nIndex( nColumn ); 584cdf0e10cSrcweir if( nIndex < m_aColumns.size()) 585cdf0e10cSrcweir return m_aColumns[nIndex].m_xDataSeries; 586cdf0e10cSrcweir return 0; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir 589cdf0e10cSrcweir DataBrowserModel::eCellType DataBrowserModel::getCellType( sal_Int32 nAtColumn, sal_Int32 /* nAtRow */ ) const 590cdf0e10cSrcweir { 591cdf0e10cSrcweir eCellType eResult = TEXT; 592cdf0e10cSrcweir tDataColumnVector::size_type nIndex( nAtColumn ); 593cdf0e10cSrcweir if( nIndex < m_aColumns.size()) 594cdf0e10cSrcweir eResult = m_aColumns[nIndex].m_eCellType; 595cdf0e10cSrcweir return eResult; 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir double DataBrowserModel::getCellNumber( sal_Int32 nAtColumn, sal_Int32 nAtRow ) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir double fResult; 601cdf0e10cSrcweir ::rtl::math::setNan( & fResult ); 602cdf0e10cSrcweir 603cdf0e10cSrcweir tDataColumnVector::size_type nIndex( nAtColumn ); 604cdf0e10cSrcweir if( nIndex < m_aColumns.size() && 605cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence.is()) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir Reference< chart2::data::XNumericalDataSequence > xData( 608cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence->getValues(), uno::UNO_QUERY ); 609cdf0e10cSrcweir if( xData.is()) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir Sequence< double > aValues( xData->getNumericalData()); 612cdf0e10cSrcweir if( nAtRow < aValues.getLength()) 613cdf0e10cSrcweir fResult = aValues[nAtRow]; 614cdf0e10cSrcweir } 615cdf0e10cSrcweir } 616cdf0e10cSrcweir return fResult; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir uno::Any DataBrowserModel::getCellAny( sal_Int32 nAtColumn, sal_Int32 nAtRow ) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir uno::Any aResult; 622cdf0e10cSrcweir 623cdf0e10cSrcweir tDataColumnVector::size_type nIndex( nAtColumn ); 624cdf0e10cSrcweir if( nIndex < m_aColumns.size() && 625cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence.is()) 626cdf0e10cSrcweir { 627cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xData( 628cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence->getValues() ); 629cdf0e10cSrcweir if( xData.is() ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir Sequence< uno::Any > aValues( xData->getData()); 632cdf0e10cSrcweir if( nAtRow < aValues.getLength()) 633cdf0e10cSrcweir aResult = aValues[nAtRow]; 634cdf0e10cSrcweir } 635cdf0e10cSrcweir } 636cdf0e10cSrcweir return aResult; 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir OUString DataBrowserModel::getCellText( sal_Int32 nAtColumn, sal_Int32 nAtRow ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir OUString aResult; 642cdf0e10cSrcweir 643cdf0e10cSrcweir tDataColumnVector::size_type nIndex( nAtColumn ); 644cdf0e10cSrcweir if( nIndex < m_aColumns.size() && 645cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence.is()) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir Reference< chart2::data::XTextualDataSequence > xData( 648cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence->getValues(), uno::UNO_QUERY ); 649cdf0e10cSrcweir if( xData.is()) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir Sequence< OUString > aValues( xData->getTextualData()); 652cdf0e10cSrcweir if( nAtRow < aValues.getLength()) 653cdf0e10cSrcweir aResult = aValues[nAtRow]; 654cdf0e10cSrcweir } 655cdf0e10cSrcweir } 656cdf0e10cSrcweir return aResult; 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir sal_uInt32 DataBrowserModel::getNumberFormatKey( sal_Int32 nAtColumn, sal_Int32 /* nAtRow */ ) 660cdf0e10cSrcweir { 661cdf0e10cSrcweir tDataColumnVector::size_type nIndex( nAtColumn ); 662cdf0e10cSrcweir if( nIndex < m_aColumns.size()) 663cdf0e10cSrcweir return m_aColumns[ nIndex ].m_nNumberFormatKey; 664cdf0e10cSrcweir return 0; 665cdf0e10cSrcweir } 666cdf0e10cSrcweir 667cdf0e10cSrcweir bool DataBrowserModel::setCellAny( sal_Int32 nAtColumn, sal_Int32 nAtRow, const uno::Any & rValue ) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir bool bResult = false; 670cdf0e10cSrcweir tDataColumnVector::size_type nIndex( nAtColumn ); 671cdf0e10cSrcweir if( nIndex < m_aColumns.size() && 672cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence.is()) 673cdf0e10cSrcweir { 674cdf0e10cSrcweir bResult = true; 675cdf0e10cSrcweir try 676cdf0e10cSrcweir { 677cdf0e10cSrcweir ControllerLockGuard aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir // label 680cdf0e10cSrcweir if( nAtRow == -1 ) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir Reference< container::XIndexReplace > xIndexReplace( 683cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence->getLabel(), uno::UNO_QUERY_THROW ); 684cdf0e10cSrcweir xIndexReplace->replaceByIndex( 0, rValue ); 685cdf0e10cSrcweir } 686cdf0e10cSrcweir else 687cdf0e10cSrcweir { 688cdf0e10cSrcweir Reference< container::XIndexReplace > xIndexReplace( 689cdf0e10cSrcweir m_aColumns[ nIndex ].m_xLabeledDataSequence->getValues(), uno::UNO_QUERY_THROW ); 690cdf0e10cSrcweir xIndexReplace->replaceByIndex( nAtRow, rValue ); 691cdf0e10cSrcweir } 692cdf0e10cSrcweir 693cdf0e10cSrcweir m_apDialogModel->startControllerLockTimer(); 694cdf0e10cSrcweir //notify change directly to the model (this is necessary here as sequences for complex categories not known directly to the chart model so they do not notify their changes) (for complex categories see issue #i82971#) 695cdf0e10cSrcweir Reference< util::XModifiable > xModifiable( m_xChartDocument, uno::UNO_QUERY ); 696cdf0e10cSrcweir if( xModifiable.is() ) 697cdf0e10cSrcweir xModifiable->setModified(true); 698cdf0e10cSrcweir } 699cdf0e10cSrcweir catch( const uno::Exception & ex ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir (void)(ex); 702cdf0e10cSrcweir bResult = false; 703cdf0e10cSrcweir } 704cdf0e10cSrcweir } 705cdf0e10cSrcweir return bResult; 706cdf0e10cSrcweir } 707cdf0e10cSrcweir 708cdf0e10cSrcweir bool DataBrowserModel::setCellNumber( sal_Int32 nAtColumn, sal_Int32 nAtRow, double fValue ) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir return (getCellType( nAtColumn, nAtRow ) == NUMBER) && 711cdf0e10cSrcweir setCellAny( nAtColumn, nAtRow, uno::makeAny( fValue )); 712cdf0e10cSrcweir } 713cdf0e10cSrcweir 714cdf0e10cSrcweir bool DataBrowserModel::setCellText( sal_Int32 nAtColumn, sal_Int32 nAtRow, const ::rtl::OUString & rText ) 715cdf0e10cSrcweir { 716cdf0e10cSrcweir return (getCellType( nAtColumn, nAtRow ) == TEXT) && 717cdf0e10cSrcweir setCellAny( nAtColumn, nAtRow, uno::makeAny( rText )); 718cdf0e10cSrcweir } 719cdf0e10cSrcweir 720cdf0e10cSrcweir sal_Int32 DataBrowserModel::getColumnCount() const 721cdf0e10cSrcweir { 722cdf0e10cSrcweir return static_cast< sal_Int32 >( m_aColumns.size()); 723cdf0e10cSrcweir } 724cdf0e10cSrcweir 725cdf0e10cSrcweir sal_Int32 DataBrowserModel::getMaxRowCount() const 726cdf0e10cSrcweir { 727cdf0e10cSrcweir sal_Int32 nResult = 0; 728cdf0e10cSrcweir tDataColumnVector::const_iterator aIt( m_aColumns.begin()); 729cdf0e10cSrcweir for( ; aIt != m_aColumns.end(); ++aIt ) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir if( aIt->m_xLabeledDataSequence.is()) 732cdf0e10cSrcweir { 733cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xSeq( 734cdf0e10cSrcweir aIt->m_xLabeledDataSequence->getValues()); 735cdf0e10cSrcweir if( !xSeq.is()) 736cdf0e10cSrcweir continue; 737cdf0e10cSrcweir sal_Int32 nLength( xSeq->getData().getLength()); 738cdf0e10cSrcweir if( nLength > nResult ) 739cdf0e10cSrcweir nResult = nLength; 740cdf0e10cSrcweir } 741cdf0e10cSrcweir } 742cdf0e10cSrcweir 743cdf0e10cSrcweir return nResult; 744cdf0e10cSrcweir } 745cdf0e10cSrcweir 746cdf0e10cSrcweir OUString DataBrowserModel::getRoleOfColumn( sal_Int32 nColumnIndex ) const 747cdf0e10cSrcweir { 748cdf0e10cSrcweir if( nColumnIndex != -1 && 749cdf0e10cSrcweir static_cast< sal_uInt32 >( nColumnIndex ) < m_aColumns.size()) 750cdf0e10cSrcweir return m_aColumns[ nColumnIndex ].m_aUIRoleName; 751cdf0e10cSrcweir return OUString(); 752cdf0e10cSrcweir } 753cdf0e10cSrcweir 754cdf0e10cSrcweir bool DataBrowserModel::isCategoriesColumn( sal_Int32 nColumnIndex ) const 755cdf0e10cSrcweir { 756cdf0e10cSrcweir bool bIsCategories = false; 757cdf0e10cSrcweir if( nColumnIndex>=0 && nColumnIndex<static_cast< sal_Int32 >(m_aColumns.size()) ) 758cdf0e10cSrcweir bIsCategories = !m_aColumns[ nColumnIndex ].m_xDataSeries.is(); 759cdf0e10cSrcweir return bIsCategories; 760cdf0e10cSrcweir } 761cdf0e10cSrcweir 762cdf0e10cSrcweir sal_Int32 DataBrowserModel::getCategoryColumnCount() 763cdf0e10cSrcweir { 764cdf0e10cSrcweir sal_Int32 nLastTextColumnIndex = -1; 765cdf0e10cSrcweir tDataColumnVector::const_iterator aIt = m_aColumns.begin(); 766cdf0e10cSrcweir for( ; aIt != m_aColumns.end(); ++aIt ) 767cdf0e10cSrcweir { 768cdf0e10cSrcweir if( !aIt->m_xDataSeries.is() ) 769cdf0e10cSrcweir nLastTextColumnIndex++; 770cdf0e10cSrcweir else 771cdf0e10cSrcweir break; 772cdf0e10cSrcweir } 773cdf0e10cSrcweir return nLastTextColumnIndex+1; 774cdf0e10cSrcweir } 775cdf0e10cSrcweir 776cdf0e10cSrcweir const DataBrowserModel::tDataHeaderVector& DataBrowserModel::getDataHeaders() const 777cdf0e10cSrcweir { 778cdf0e10cSrcweir return m_aHeaders; 779cdf0e10cSrcweir } 780cdf0e10cSrcweir 781cdf0e10cSrcweir void DataBrowserModel::updateFromModel() 782cdf0e10cSrcweir { 783cdf0e10cSrcweir if( !m_xChartDocument.is()) 784cdf0e10cSrcweir return; 785cdf0e10cSrcweir m_aColumns.clear(); 786cdf0e10cSrcweir m_aHeaders.clear(); 787cdf0e10cSrcweir 788cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartDocument )); 789cdf0e10cSrcweir if( !xDiagram.is()) 790cdf0e10cSrcweir return; 791cdf0e10cSrcweir 792cdf0e10cSrcweir // set template at DialogModel 793cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFact( m_xChartDocument->getChartTypeManager(), uno::UNO_QUERY ); 794cdf0e10cSrcweir DiagramHelper::tTemplateWithServiceName aTemplateAndService = 795cdf0e10cSrcweir DiagramHelper::getTemplateForDiagram( xDiagram, xFact ); 796cdf0e10cSrcweir if( aTemplateAndService.first.is()) 797cdf0e10cSrcweir m_apDialogModel->setTemplate( aTemplateAndService.first ); 798cdf0e10cSrcweir 799cdf0e10cSrcweir sal_Int32 nHeaderStart = 0; 800cdf0e10cSrcweir sal_Int32 nHeaderEnd = 0; 801cdf0e10cSrcweir if( lcl_ShowCategories( xDiagram )) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir Reference< frame::XModel > xChartModel( m_xChartDocument, uno::UNO_QUERY ); 804cdf0e10cSrcweir ExplicitCategoriesProvider aExplicitCategoriesProvider( ChartModelHelper::getFirstCoordinateSystem(xChartModel), xChartModel ); 805cdf0e10cSrcweir 806cdf0e10cSrcweir const Sequence< Reference< chart2::data::XLabeledDataSequence> >& rSplitCategoriesList( aExplicitCategoriesProvider.getSplitCategoriesList() ); 807cdf0e10cSrcweir sal_Int32 nLevelCount = rSplitCategoriesList.getLength(); 808cdf0e10cSrcweir for( sal_Int32 nL = 0; nL<nLevelCount; nL++ ) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xCategories( rSplitCategoriesList[nL] ); 811cdf0e10cSrcweir if( !xCategories.is() ) 812cdf0e10cSrcweir continue; 813cdf0e10cSrcweir 814cdf0e10cSrcweir tDataColumn aCategories; 815cdf0e10cSrcweir aCategories.m_xLabeledDataSequence.set( xCategories ); 816cdf0e10cSrcweir if( lcl_ShowCategoriesAsDataLabel( xDiagram )) 817cdf0e10cSrcweir aCategories.m_aUIRoleName = DialogModel::GetRoleDataLabel(); 818cdf0e10cSrcweir else 819cdf0e10cSrcweir aCategories.m_aUIRoleName = lcl_getUIRoleName( xCategories ); 820cdf0e10cSrcweir aCategories.m_eCellType = TEXTORDATE; 821cdf0e10cSrcweir m_aColumns.push_back( aCategories ); 822cdf0e10cSrcweir ++nHeaderStart; 823cdf0e10cSrcweir } 824cdf0e10cSrcweir } 825cdf0e10cSrcweir 826cdf0e10cSrcweir Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY ); 827cdf0e10cSrcweir if( !xCooSysCnt.is()) 828cdf0e10cSrcweir return; 829cdf0e10cSrcweir Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems()); 830cdf0e10cSrcweir for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx ) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW ); 833cdf0e10cSrcweir Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes()); 834cdf0e10cSrcweir sal_Int32 nXAxisNumberFormat = DataSeriesHelper::getNumberFormatKeyFromAxis( 0, aCooSysSeq[nCooSysIdx], 0, 0 ); 835cdf0e10cSrcweir 836cdf0e10cSrcweir for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx ) 837cdf0e10cSrcweir { 838cdf0e10cSrcweir Reference< chart2::XDataSeriesContainer > xSeriesCnt( aChartTypes[nCTIdx], uno::UNO_QUERY ); 839cdf0e10cSrcweir if( xSeriesCnt.is()) 840cdf0e10cSrcweir { 841cdf0e10cSrcweir rtl::OUString aRoleForDataLabelNumberFormat = ChartTypeHelper::getRoleOfSequenceForDataLabelNumberFormatDetection( aChartTypes[nCTIdx] ); 842cdf0e10cSrcweir 843cdf0e10cSrcweir Sequence< Reference< chart2::XDataSeries > > aSeries( xSeriesCnt->getDataSeries()); 844cdf0e10cSrcweir lcl_tSharedSeqVec aSharedSequences( lcl_getSharedSequences( aSeries )); 845cdf0e10cSrcweir for( lcl_tSharedSeqVec::const_iterator aIt( aSharedSequences.begin()); 846cdf0e10cSrcweir aIt != aSharedSequences.end(); ++aIt ) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir tDataColumn aSharedSequence; 849cdf0e10cSrcweir aSharedSequence.m_xLabeledDataSequence = *aIt; 850cdf0e10cSrcweir aSharedSequence.m_aUIRoleName = lcl_getUIRoleName( *aIt ); 851cdf0e10cSrcweir aSharedSequence.m_eCellType = NUMBER; 852cdf0e10cSrcweir // as the sequences are shared it should be ok to take the first series 853cdf0e10cSrcweir // @todo: dimension index 0 for x-values used here. This is just a guess. 854cdf0e10cSrcweir // Also, the axis index is 0, as there is usually only one x-axis 855cdf0e10cSrcweir aSharedSequence.m_nNumberFormatKey = nXAxisNumberFormat; 856cdf0e10cSrcweir m_aColumns.push_back( aSharedSequence ); 857cdf0e10cSrcweir ++nHeaderStart; 858cdf0e10cSrcweir } 859cdf0e10cSrcweir for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeries.getLength(); ++nSeriesIdx ) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir tDataColumnVector::size_type nStartColIndex = m_aColumns.size(); 862cdf0e10cSrcweir Reference< chart2::XDataSeries > xSeries( aSeries[nSeriesIdx] ); 863cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); 864cdf0e10cSrcweir if( xSource.is()) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSeqs( xSource->getDataSequences()); 867cdf0e10cSrcweir if( aLSeqs.getLength() == 0 ) 868cdf0e10cSrcweir continue; 869cdf0e10cSrcweir nHeaderEnd = nHeaderStart; 870cdf0e10cSrcweir 871cdf0e10cSrcweir // @todo: dimension index 1 for y-values used here. This is just a guess 872cdf0e10cSrcweir sal_Int32 nYAxisNumberFormatKey = 873cdf0e10cSrcweir DataSeriesHelper::getNumberFormatKeyFromAxis( 874cdf0e10cSrcweir aSeries[nSeriesIdx], aCooSysSeq[nCooSysIdx], 1 ); 875cdf0e10cSrcweir 876cdf0e10cSrcweir sal_Int32 nSeqIdx=0; 877cdf0e10cSrcweir for( ; nSeqIdx<aLSeqs.getLength(); ++nSeqIdx ) 878cdf0e10cSrcweir { 879cdf0e10cSrcweir sal_Int32 nSequenceNumberFormatKey = nYAxisNumberFormatKey; 880cdf0e10cSrcweir OUString aRole = lcl_getRole( aLSeqs[nSeqIdx] ); 881cdf0e10cSrcweir 882cdf0e10cSrcweir if( aRole.equals( aRoleForDataLabelNumberFormat ) ) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir nSequenceNumberFormatKey = ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( 885cdf0e10cSrcweir Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ), xSeries, -1, xDiagram ); 886cdf0e10cSrcweir } 887cdf0e10cSrcweir else if( aRole.equals( C2U( "values-x" ) ) ) 888cdf0e10cSrcweir nSequenceNumberFormatKey = nXAxisNumberFormat; 889cdf0e10cSrcweir 890cdf0e10cSrcweir if( ::std::find_if( aSharedSequences.begin(), aSharedSequences.end(), 891cdf0e10cSrcweir lcl_RepresentationsOfLSeqMatch( aLSeqs[nSeqIdx] )) == aSharedSequences.end()) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir // no shared sequence 894cdf0e10cSrcweir m_aColumns.push_back( 895cdf0e10cSrcweir tDataColumn( 896cdf0e10cSrcweir aSeries[nSeriesIdx], 897cdf0e10cSrcweir nSeqIdx, 898cdf0e10cSrcweir lcl_getUIRoleName( aLSeqs[nSeqIdx] ), 899cdf0e10cSrcweir aLSeqs[nSeqIdx], 900cdf0e10cSrcweir NUMBER, 901cdf0e10cSrcweir nSequenceNumberFormatKey )); 902cdf0e10cSrcweir ++nHeaderEnd; 903cdf0e10cSrcweir } 904cdf0e10cSrcweir // else skip 905cdf0e10cSrcweir } 906cdf0e10cSrcweir bool bSwapXAndYAxis = false; 907cdf0e10cSrcweir try 908cdf0e10cSrcweir { 909cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY ); 910cdf0e10cSrcweir xProp->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("SwapXAndYAxis"))) >>= bSwapXAndYAxis; 911cdf0e10cSrcweir } 912cdf0e10cSrcweir catch( const beans::UnknownPropertyException & ex ) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir (void)ex; 915cdf0e10cSrcweir } 916cdf0e10cSrcweir 917cdf0e10cSrcweir // add ranges for error bars if present for a series 918cdf0e10cSrcweir if( StatisticsHelper::usesErrorBarRanges( aSeries[nSeriesIdx], /* bYError = */ true )) 919cdf0e10cSrcweir addErrorBarRanges( aSeries[nSeriesIdx], nYAxisNumberFormatKey, nSeqIdx, nHeaderEnd ); 920cdf0e10cSrcweir 921cdf0e10cSrcweir m_aHeaders.push_back( 922cdf0e10cSrcweir tDataHeader( 923cdf0e10cSrcweir aSeries[nSeriesIdx], 924cdf0e10cSrcweir aChartTypes[nCTIdx], 925cdf0e10cSrcweir bSwapXAndYAxis, 926cdf0e10cSrcweir nHeaderStart, 927cdf0e10cSrcweir nHeaderEnd - 1 )); 928cdf0e10cSrcweir 929cdf0e10cSrcweir nHeaderStart = nHeaderEnd; 930cdf0e10cSrcweir 931cdf0e10cSrcweir ::std::sort( m_aColumns.begin() + nStartColIndex, m_aColumns.end(), implColumnLess() ); 932cdf0e10cSrcweir } 933cdf0e10cSrcweir } 934cdf0e10cSrcweir } 935cdf0e10cSrcweir } 936cdf0e10cSrcweir } 937cdf0e10cSrcweir } 938cdf0e10cSrcweir 939cdf0e10cSrcweir void DataBrowserModel::addErrorBarRanges( 940cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xDataSeries, 941cdf0e10cSrcweir sal_Int32 nNumberFormatKey, 942cdf0e10cSrcweir sal_Int32 & rInOutSequenceIndex, 943cdf0e10cSrcweir sal_Int32 & rInOutHeaderEnd ) 944cdf0e10cSrcweir { 945cdf0e10cSrcweir try 946cdf0e10cSrcweir { 947cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aSequences; 948cdf0e10cSrcweir 949cdf0e10cSrcweir // x error bars 950cdf0e10cSrcweir // ------------ 951cdf0e10cSrcweir Reference< chart2::data::XDataSource > xErrorSource( 952cdf0e10cSrcweir StatisticsHelper::getErrorBars( xDataSeries, /* bYError = */ false ), uno::UNO_QUERY ); 953cdf0e10cSrcweir 954cdf0e10cSrcweir // positive x error bars 955cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xErrorLSequence( 956cdf0e10cSrcweir StatisticsHelper::getErrorLabeledDataSequenceFromDataSource( 957cdf0e10cSrcweir xErrorSource, 958cdf0e10cSrcweir /* bPositiveValue = */ true, 959cdf0e10cSrcweir /* bYError = */ false )); 960cdf0e10cSrcweir if( xErrorLSequence.is()) 961cdf0e10cSrcweir aSequences.push_back( xErrorLSequence ); 962cdf0e10cSrcweir 963cdf0e10cSrcweir // negative x error bars 964cdf0e10cSrcweir xErrorLSequence.set( 965cdf0e10cSrcweir StatisticsHelper::getErrorLabeledDataSequenceFromDataSource( 966cdf0e10cSrcweir xErrorSource, 967cdf0e10cSrcweir /* bPositiveValue = */ false, 968cdf0e10cSrcweir /* bYError = */ false )); 969cdf0e10cSrcweir if( xErrorLSequence.is()) 970cdf0e10cSrcweir aSequences.push_back( xErrorLSequence ); 971cdf0e10cSrcweir 972cdf0e10cSrcweir // y error bars 973cdf0e10cSrcweir // ------------ 974cdf0e10cSrcweir xErrorSource.set( 975cdf0e10cSrcweir StatisticsHelper::getErrorBars( xDataSeries, /* bYError = */ true ), uno::UNO_QUERY ); 976cdf0e10cSrcweir 977cdf0e10cSrcweir // positive y error bars 978cdf0e10cSrcweir xErrorLSequence.set( 979cdf0e10cSrcweir StatisticsHelper::getErrorLabeledDataSequenceFromDataSource( 980cdf0e10cSrcweir xErrorSource, 981cdf0e10cSrcweir /* bPositiveValue = */ true, 982cdf0e10cSrcweir /* bYError = */ true )); 983cdf0e10cSrcweir if( xErrorLSequence.is()) 984cdf0e10cSrcweir aSequences.push_back( xErrorLSequence ); 985cdf0e10cSrcweir 986cdf0e10cSrcweir // negative y error bars 987cdf0e10cSrcweir xErrorLSequence.set( 988cdf0e10cSrcweir StatisticsHelper::getErrorLabeledDataSequenceFromDataSource( 989cdf0e10cSrcweir xErrorSource, 990cdf0e10cSrcweir /* bPositiveValue = */ false, 991cdf0e10cSrcweir /* bYError = */ true )); 992cdf0e10cSrcweir if( xErrorLSequence.is()) 993cdf0e10cSrcweir aSequences.push_back( xErrorLSequence ); 994cdf0e10cSrcweir 995cdf0e10cSrcweir 996cdf0e10cSrcweir for( ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::const_iterator aIt( aSequences.begin()); 997cdf0e10cSrcweir aIt != aSequences.end(); ++aIt ) 998cdf0e10cSrcweir { 999cdf0e10cSrcweir m_aColumns.push_back( 1000cdf0e10cSrcweir tDataColumn( 1001cdf0e10cSrcweir xDataSeries, 1002cdf0e10cSrcweir rInOutSequenceIndex, 1003cdf0e10cSrcweir lcl_getUIRoleName( *aIt ), 1004cdf0e10cSrcweir *aIt, 1005cdf0e10cSrcweir NUMBER, 1006cdf0e10cSrcweir nNumberFormatKey )); 1007cdf0e10cSrcweir ++rInOutSequenceIndex; 1008cdf0e10cSrcweir ++rInOutHeaderEnd; 1009cdf0e10cSrcweir } 1010cdf0e10cSrcweir } 1011cdf0e10cSrcweir catch( const uno::Exception & ex ) 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 1014cdf0e10cSrcweir } 1015cdf0e10cSrcweir } 1016cdf0e10cSrcweir 1017cdf0e10cSrcweir } // namespace chart 1018