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 "DialogModel.hxx" 32*cdf0e10cSrcweir #include "RangeSelectionHelper.hxx" 33*cdf0e10cSrcweir #include "PropertyHelper.hxx" 34*cdf0e10cSrcweir #include "DataSeriesHelper.hxx" 35*cdf0e10cSrcweir #include "DataSourceHelper.hxx" 36*cdf0e10cSrcweir #include "DiagramHelper.hxx" 37*cdf0e10cSrcweir #include "macros.hxx" 38*cdf0e10cSrcweir #include "Strings.hrc" 39*cdf0e10cSrcweir #include "ResId.hxx" 40*cdf0e10cSrcweir #include "ContainerHelper.hxx" 41*cdf0e10cSrcweir #include "CommonFunctors.hxx" 42*cdf0e10cSrcweir #include "ControllerLockGuard.hxx" 43*cdf0e10cSrcweir #include "ChartTypeHelper.hxx" 44*cdf0e10cSrcweir #include "ThreeDHelper.hxx" 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/chart2/AxisType.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSink.hpp> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include <tools/string.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <utility> 57*cdf0e10cSrcweir #include <algorithm> 58*cdf0e10cSrcweir #include <iterator> 59*cdf0e10cSrcweir #include <functional> 60*cdf0e10cSrcweir #include <numeric> 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir using namespace ::com::sun::star; 63*cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 64*cdf0e10cSrcweir using namespace ::chart::ContainerHelper; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 67*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 68*cdf0e10cSrcweir using ::rtl::OUString; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // ---------------------------------------- 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir namespace 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir const OUString lcl_aLabelRole( RTL_CONSTASCII_USTRINGPARAM( "label" )); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir struct lcl_ChartTypeToSeriesCnt : ::std::unary_function< 77*cdf0e10cSrcweir Reference< XChartType >, Reference< XDataSeriesContainer > > 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir Reference< XDataSeriesContainer > operator() ( 80*cdf0e10cSrcweir const Reference< XChartType > & xChartType ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir return Reference< XDataSeriesContainer >::query( xChartType ); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir OUString lcl_ConvertRole( const OUString & rRoleString, bool bFromInternalToUI ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir OUString aResult( rRoleString ); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir typedef ::std::map< OUString, OUString > tTranslationMap; 91*cdf0e10cSrcweir static tTranslationMap aTranslationMap; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if( aTranslationMap.size() == 0 ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir aTranslationMap[ C2U( "categories" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_CATEGORIES ))); 96*cdf0e10cSrcweir aTranslationMap[ C2U( "error-bars-x" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_X_ERROR ))); 97*cdf0e10cSrcweir aTranslationMap[ C2U( "error-bars-x-positive" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_X_ERROR_POSITIVE ))); 98*cdf0e10cSrcweir aTranslationMap[ C2U( "error-bars-x-negative" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_X_ERROR_NEGATIVE ))); 99*cdf0e10cSrcweir aTranslationMap[ C2U( "error-bars-y" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_Y_ERROR ))); 100*cdf0e10cSrcweir aTranslationMap[ C2U( "error-bars-y-positive" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_Y_ERROR_POSITIVE ))); 101*cdf0e10cSrcweir aTranslationMap[ C2U( "error-bars-y-negative" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_Y_ERROR_NEGATIVE ))); 102*cdf0e10cSrcweir aTranslationMap[ C2U( "label" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_LABEL ))); 103*cdf0e10cSrcweir aTranslationMap[ C2U( "values-first" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_FIRST ))); 104*cdf0e10cSrcweir aTranslationMap[ C2U( "values-last" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_LAST ))); 105*cdf0e10cSrcweir aTranslationMap[ C2U( "values-max" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_MAX ))); 106*cdf0e10cSrcweir aTranslationMap[ C2U( "values-min" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_MIN ))); 107*cdf0e10cSrcweir aTranslationMap[ C2U( "values-x" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_X ))); 108*cdf0e10cSrcweir aTranslationMap[ C2U( "values-y" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_Y ))); 109*cdf0e10cSrcweir aTranslationMap[ C2U( "values-size" ) ] = OUString( String( ::chart::SchResId( STR_DATA_ROLE_SIZE ))); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if( bFromInternalToUI ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir tTranslationMap::const_iterator aIt( aTranslationMap.find( rRoleString )); 115*cdf0e10cSrcweir if( aIt != aTranslationMap.end()) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir aResult = (*aIt).second; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir else 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir tTranslationMap::const_iterator aIt( 123*cdf0e10cSrcweir ::std::find_if( aTranslationMap.begin(), aTranslationMap.end(), 124*cdf0e10cSrcweir ::std::compose1( ::std::bind2nd( 125*cdf0e10cSrcweir ::std::equal_to< tTranslationMap::mapped_type >(), 126*cdf0e10cSrcweir rRoleString ), 127*cdf0e10cSrcweir ::std::select2nd< tTranslationMap::value_type >()))); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir if( aIt != aTranslationMap.end()) 130*cdf0e10cSrcweir aResult = (*aIt).first; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir return aResult; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir typedef ::std::map< ::rtl::OUString, sal_Int32 > lcl_tRoleIndexMap; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void lcl_createRoleIndexMap( lcl_tRoleIndexMap & rOutMap ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir rOutMap.clear(); 141*cdf0e10cSrcweir sal_Int32 nIndex = 0; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir rOutMap[ C2U( "label" ) ] = ++nIndex; 144*cdf0e10cSrcweir rOutMap[ C2U( "categories" ) ] = ++nIndex; 145*cdf0e10cSrcweir rOutMap[ C2U( "values-x" ) ] = ++nIndex; 146*cdf0e10cSrcweir rOutMap[ C2U( "values-y" ) ] = ++nIndex; 147*cdf0e10cSrcweir rOutMap[ C2U( "error-bars-x" ) ] = ++nIndex; 148*cdf0e10cSrcweir rOutMap[ C2U( "error-bars-x-positive" ) ] = ++nIndex; 149*cdf0e10cSrcweir rOutMap[ C2U( "error-bars-x-negative" ) ] = ++nIndex; 150*cdf0e10cSrcweir rOutMap[ C2U( "error-bars-y" ) ] = ++nIndex; 151*cdf0e10cSrcweir rOutMap[ C2U( "error-bars-y-positive" ) ] = ++nIndex; 152*cdf0e10cSrcweir rOutMap[ C2U( "error-bars-y-negative" ) ] = ++nIndex; 153*cdf0e10cSrcweir rOutMap[ C2U( "values-first" ) ] = ++nIndex; 154*cdf0e10cSrcweir rOutMap[ C2U( "values-min" ) ] = ++nIndex; 155*cdf0e10cSrcweir rOutMap[ C2U( "values-max" ) ] = ++nIndex; 156*cdf0e10cSrcweir rOutMap[ C2U( "values-last" ) ] = ++nIndex; 157*cdf0e10cSrcweir rOutMap[ C2U( "values-size" ) ] = ++nIndex; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir struct lcl_DataSeriesContainerAppend : public 161*cdf0e10cSrcweir ::std::iterator< ::std::output_iterator_tag, Reference< XDataSeriesContainer > > 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir typedef ::std::vector< ::chart::DialogModel::tSeriesWithChartTypeByName > tContainerType; 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir explicit lcl_DataSeriesContainerAppend( tContainerType & rCnt ) 166*cdf0e10cSrcweir : m_rDestCnt( rCnt ) 167*cdf0e10cSrcweir {} 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir lcl_DataSeriesContainerAppend & operator= ( const value_type & xVal ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir try 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir if( xVal.is()) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aSeq( xVal->getDataSeries()); 176*cdf0e10cSrcweir OUString aRole( RTL_CONSTASCII_USTRINGPARAM("values-y")); 177*cdf0e10cSrcweir Reference< XChartType > xCT( xVal, uno::UNO_QUERY ); 178*cdf0e10cSrcweir if( xCT.is()) 179*cdf0e10cSrcweir aRole = xCT->getRoleOfSequenceForSeriesLabel(); 180*cdf0e10cSrcweir for( sal_Int32 nI = 0; nI < aSeq.getLength(); ++ nI ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir m_rDestCnt.push_back( 183*cdf0e10cSrcweir ::chart::DialogModel::tSeriesWithChartTypeByName( 184*cdf0e10cSrcweir ::chart::DataSeriesHelper::getDataSeriesLabel( aSeq[nI], aRole ), 185*cdf0e10cSrcweir ::std::make_pair( aSeq[nI], xCT ))); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir catch( uno::Exception & ex ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir return *this; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir lcl_DataSeriesContainerAppend & operator* () { return *this; } 197*cdf0e10cSrcweir lcl_DataSeriesContainerAppend & operator++ () { return *this; } 198*cdf0e10cSrcweir lcl_DataSeriesContainerAppend & operator++ (int) { return *this; } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir private: 201*cdf0e10cSrcweir tContainerType & m_rDestCnt; 202*cdf0e10cSrcweir }; 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir struct lcl_RolesWithRangeAppend : public 205*cdf0e10cSrcweir ::std::iterator< ::std::output_iterator_tag, Reference< data::XLabeledDataSequence > > 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir typedef ::chart::DialogModel::tRolesWithRanges tContainerType; 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir explicit lcl_RolesWithRangeAppend( tContainerType & rCnt, 210*cdf0e10cSrcweir const ::rtl::OUString & aLabelRole ) 211*cdf0e10cSrcweir : m_rDestCnt( rCnt ), 212*cdf0e10cSrcweir m_aRoleForLabelSeq( aLabelRole ) 213*cdf0e10cSrcweir {} 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir lcl_RolesWithRangeAppend & operator= ( const value_type & xVal ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir try 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir if( xVal.is()) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir // data sequence 222*cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( xVal->getValues()); 223*cdf0e10cSrcweir if( xSeq.is()) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir OUString aRole; 226*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW ); 227*cdf0e10cSrcweir if( xProp->getPropertyValue( C2U("Role")) >>= aRole ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir m_rDestCnt.insert( 230*cdf0e10cSrcweir tContainerType::value_type( 231*cdf0e10cSrcweir aRole, xSeq->getSourceRangeRepresentation())); 232*cdf0e10cSrcweir // label 233*cdf0e10cSrcweir if( aRole.equals( m_aRoleForLabelSeq )) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir Reference< data::XDataSequence > xLabelSeq( xVal->getLabel()); 236*cdf0e10cSrcweir if( xLabelSeq.is()) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir m_rDestCnt.insert( 239*cdf0e10cSrcweir tContainerType::value_type( 240*cdf0e10cSrcweir lcl_aLabelRole, xLabelSeq->getSourceRangeRepresentation())); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir catch( uno::Exception & ex ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir return *this; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir lcl_RolesWithRangeAppend & operator* () { return *this; } 255*cdf0e10cSrcweir lcl_RolesWithRangeAppend & operator++ () { return *this; } 256*cdf0e10cSrcweir lcl_RolesWithRangeAppend & operator++ (int) { return *this; } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir private: 259*cdf0e10cSrcweir tContainerType & m_rDestCnt; 260*cdf0e10cSrcweir OUString m_aRoleForLabelSeq; 261*cdf0e10cSrcweir }; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir void lcl_SetSequenceRole( 264*cdf0e10cSrcweir const Reference< data::XDataSequence > & xSeq, 265*cdf0e10cSrcweir const OUString & rRole ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY ); 268*cdf0e10cSrcweir if( xProp.is()) 269*cdf0e10cSrcweir xProp->setPropertyValue( C2U("Role"), uno::makeAny( rRole )); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir Reference< XDataSeries > lcl_CreateNewSeries( 273*cdf0e10cSrcweir const Reference< uno::XComponentContext > & xContext, 274*cdf0e10cSrcweir const Reference< XChartType > & xChartType, 275*cdf0e10cSrcweir sal_Int32 nNewSeriesIndex, 276*cdf0e10cSrcweir sal_Int32 nTotalNumberOfSeriesInCTGroup, 277*cdf0e10cSrcweir const Reference< XDiagram > & xDiagram, 278*cdf0e10cSrcweir const Reference< XChartTypeTemplate > & xTemplate, 279*cdf0e10cSrcweir bool bCreateDataCachedSequences ) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir // create plain series 282*cdf0e10cSrcweir Reference< XDataSeries > xResult( 283*cdf0e10cSrcweir xContext->getServiceManager()->createInstanceWithContext( 284*cdf0e10cSrcweir C2U( "com.sun.star.chart2.DataSeries" ), 285*cdf0e10cSrcweir xContext ), uno::UNO_QUERY ); 286*cdf0e10cSrcweir if( xTemplate.is()) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir Reference< beans::XPropertySet > xResultProp( xResult, uno::UNO_QUERY ); 289*cdf0e10cSrcweir if( xResultProp.is()) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir // @deprecated: correct default color should be found by view 292*cdf0e10cSrcweir // without setting it as hard attribute 293*cdf0e10cSrcweir Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme()); 294*cdf0e10cSrcweir if( xColorScheme.is()) 295*cdf0e10cSrcweir xResultProp->setPropertyValue( 296*cdf0e10cSrcweir C2U("Color"), uno::makeAny( xColorScheme->getColorByIndex( nNewSeriesIndex ))); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir sal_Int32 nGroupIndex=0; 299*cdf0e10cSrcweir if( xChartType.is()) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir Sequence< Reference< XChartType > > aCTs( 302*cdf0e10cSrcweir ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram )); 303*cdf0e10cSrcweir for( ; nGroupIndex<aCTs.getLength(); ++nGroupIndex) 304*cdf0e10cSrcweir if( aCTs[nGroupIndex] == xChartType ) 305*cdf0e10cSrcweir break; 306*cdf0e10cSrcweir if( nGroupIndex == aCTs.getLength()) 307*cdf0e10cSrcweir nGroupIndex = 0; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir xTemplate->applyStyle( xResult, nGroupIndex, nNewSeriesIndex, nTotalNumberOfSeriesInCTGroup ); 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir if( bCreateDataCachedSequences ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir // set chart type specific roles 315*cdf0e10cSrcweir Reference< data::XDataSink > xSink( xResult, uno::UNO_QUERY ); 316*cdf0e10cSrcweir if( xChartType.is() && xSink.is()) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir ::std::vector< Reference< data::XLabeledDataSequence > > aNewSequences; 319*cdf0e10cSrcweir const OUString aRoleOfSeqForSeriesLabel = xChartType->getRoleOfSequenceForSeriesLabel(); 320*cdf0e10cSrcweir const OUString aLabel( String( ::chart::SchResId( STR_DATA_UNNAMED_SERIES ))); 321*cdf0e10cSrcweir const Sequence< OUString > aRoles( xChartType->getSupportedMandatoryRoles()); 322*cdf0e10cSrcweir const Sequence< OUString > aOptRoles( xChartType->getSupportedOptionalRoles()); 323*cdf0e10cSrcweir sal_Int32 nI = 0; 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir for(nI=0; nI<aRoles.getLength(); ++nI) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir if( aRoles[nI].equals( lcl_aLabelRole )) 328*cdf0e10cSrcweir continue; 329*cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( ::chart::DataSourceHelper::createCachedDataSequence() ); 330*cdf0e10cSrcweir lcl_SetSequenceRole( xSeq, aRoles[nI] ); 331*cdf0e10cSrcweir // assert that aRoleOfSeqForSeriesLabel is part of the mandatory roles 332*cdf0e10cSrcweir if( aRoles[nI].equals( aRoleOfSeqForSeriesLabel )) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir Reference< data::XDataSequence > xLabel( ::chart::DataSourceHelper::createCachedDataSequence( aLabel )); 335*cdf0e10cSrcweir lcl_SetSequenceRole( xLabel, lcl_aLabelRole ); 336*cdf0e10cSrcweir aNewSequences.push_back( ::chart::DataSourceHelper::createLabeledDataSequence( xSeq, xLabel )); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir else 339*cdf0e10cSrcweir aNewSequences.push_back( ::chart::DataSourceHelper::createLabeledDataSequence( xSeq )); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir for(nI=0; nI<aOptRoles.getLength(); ++nI) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir if( aOptRoles[nI].equals( lcl_aLabelRole )) 345*cdf0e10cSrcweir continue; 346*cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( ::chart::DataSourceHelper::createCachedDataSequence()); 347*cdf0e10cSrcweir lcl_SetSequenceRole( xSeq, aOptRoles[nI] ); 348*cdf0e10cSrcweir aNewSequences.push_back( ::chart::DataSourceHelper::createLabeledDataSequence( xSeq )); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir xSink->setData( ContainerToSequence( aNewSequences )); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir return xResult; 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir struct lcl_addSeriesNumber : public ::std::binary_function< 359*cdf0e10cSrcweir sal_Int32, Reference< XDataSeriesContainer >, sal_Int32 > 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir sal_Int32 operator() ( sal_Int32 nCurrentNumber, const Reference< XDataSeriesContainer > & xCnt ) const 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir if( xCnt.is()) 364*cdf0e10cSrcweir return nCurrentNumber + (xCnt->getDataSeries().getLength()); 365*cdf0e10cSrcweir return nCurrentNumber; 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir }; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir } // anonymous namespace 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir // ---------------------------------------- 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir namespace chart 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir DialogModel::DialogModel( 378*cdf0e10cSrcweir const Reference< XChartDocument > & xChartDocument, 379*cdf0e10cSrcweir const Reference< uno::XComponentContext > & xContext ) : 380*cdf0e10cSrcweir m_xChartDocument( xChartDocument ), 381*cdf0e10cSrcweir m_xContext( xContext ), 382*cdf0e10cSrcweir m_aTimerTriggeredControllerLock( uno::Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir DialogModel::~DialogModel() 387*cdf0e10cSrcweir {} 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir void DialogModel::setTemplate( 390*cdf0e10cSrcweir const Reference< XChartTypeTemplate > & xTemplate ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir m_xTemplate = xTemplate; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir ::boost::shared_ptr< RangeSelectionHelper > 396*cdf0e10cSrcweir DialogModel::getRangeSelectionHelper() const 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir if( ! m_spRangeSelectionHelper.get()) 399*cdf0e10cSrcweir m_spRangeSelectionHelper.reset( 400*cdf0e10cSrcweir new RangeSelectionHelper( m_xChartDocument )); 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir return m_spRangeSelectionHelper; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir Reference< frame::XModel > DialogModel::getChartModel() const 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir Reference< frame::XModel > xResult( m_xChartDocument, uno::UNO_QUERY ); 408*cdf0e10cSrcweir return xResult; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir Reference< data::XDataProvider > DialogModel::getDataProvider() const 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir Reference< data::XDataProvider > xResult; 414*cdf0e10cSrcweir if( m_xChartDocument.is()) 415*cdf0e10cSrcweir xResult.set( m_xChartDocument->getDataProvider()); 416*cdf0e10cSrcweir return xResult; 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir ::std::vector< Reference< XDataSeriesContainer > > 420*cdf0e10cSrcweir DialogModel::getAllDataSeriesContainers() const 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir ::std::vector< Reference< XDataSeriesContainer > > aResult; 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir try 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir Reference< XDiagram > xDiagram; 427*cdf0e10cSrcweir if( m_xChartDocument.is()) 428*cdf0e10cSrcweir xDiagram.set( m_xChartDocument->getFirstDiagram()); 429*cdf0e10cSrcweir if( xDiagram.is()) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysCnt( 432*cdf0e10cSrcweir xDiagram, uno::UNO_QUERY_THROW ); 433*cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysSeq( 434*cdf0e10cSrcweir xCooSysCnt->getCoordinateSystems()); 435*cdf0e10cSrcweir for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW ); 438*cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes()); 439*cdf0e10cSrcweir ::std::transform( 440*cdf0e10cSrcweir aChartTypeSeq.getConstArray(), aChartTypeSeq.getConstArray() + aChartTypeSeq.getLength(), 441*cdf0e10cSrcweir ::std::back_inserter( aResult ), 442*cdf0e10cSrcweir lcl_ChartTypeToSeriesCnt() ); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir catch( uno::Exception & ex ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir return aResult; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir ::std::vector< DialogModel::tSeriesWithChartTypeByName > 455*cdf0e10cSrcweir DialogModel::getAllDataSeriesWithLabel() const 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir ::std::vector< tSeriesWithChartTypeByName > aResult; 458*cdf0e10cSrcweir ::std::vector< Reference< XDataSeriesContainer > > aContainers( 459*cdf0e10cSrcweir getAllDataSeriesContainers()); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir ::std::copy( aContainers.begin(), aContainers.end(), 462*cdf0e10cSrcweir lcl_DataSeriesContainerAppend( aResult )); 463*cdf0e10cSrcweir return aResult; 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir DialogModel::tRolesWithRanges DialogModel::getRolesWithRanges( 467*cdf0e10cSrcweir const Reference< XDataSeries > & xSeries, 468*cdf0e10cSrcweir const ::rtl::OUString & aRoleOfSequenceForLabel, 469*cdf0e10cSrcweir const Reference< chart2::XChartType > & xChartType ) const 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir DialogModel::tRolesWithRanges aResult; 472*cdf0e10cSrcweir try 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir Reference< data::XDataSource > xSource( xSeries, uno::UNO_QUERY_THROW ); 475*cdf0e10cSrcweir const Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSource->getDataSequences()); 476*cdf0e10cSrcweir ::std::copy( aSeq.getConstArray(), aSeq.getConstArray() + aSeq.getLength(), 477*cdf0e10cSrcweir lcl_RolesWithRangeAppend( aResult, aRoleOfSequenceForLabel )); 478*cdf0e10cSrcweir if( xChartType.is()) 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir // add missing mandatory roles 481*cdf0e10cSrcweir Sequence< OUString > aRoles( xChartType->getSupportedMandatoryRoles()); 482*cdf0e10cSrcweir OUString aEmptyString; 483*cdf0e10cSrcweir sal_Int32 nI = 0; 484*cdf0e10cSrcweir for( nI=0; nI < aRoles.getLength(); ++nI ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir if( aResult.find( aRoles[nI] ) == aResult.end() ) 487*cdf0e10cSrcweir aResult.insert( DialogModel::tRolesWithRanges::value_type( aRoles[nI], aEmptyString )); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir // add missing optional roles 491*cdf0e10cSrcweir aRoles = xChartType->getSupportedOptionalRoles(); 492*cdf0e10cSrcweir for( nI=0; nI < aRoles.getLength(); ++nI ) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir if( aResult.find( aRoles[nI] ) == aResult.end() ) 495*cdf0e10cSrcweir aResult.insert( DialogModel::tRolesWithRanges::value_type( aRoles[nI], aEmptyString )); 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir catch( uno::Exception & ex ) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir return aResult; 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir void DialogModel::moveSeries( 507*cdf0e10cSrcweir const Reference< XDataSeries > & xSeries, 508*cdf0e10cSrcweir eMoveDirection eDirection ) 509*cdf0e10cSrcweir { 510*cdf0e10cSrcweir m_aTimerTriggeredControllerLock.startTimer(); 511*cdf0e10cSrcweir ControllerLockGuard aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ); 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir Reference< XDiagram > xDiagram( m_xChartDocument->getFirstDiagram()); 514*cdf0e10cSrcweir DiagramHelper::moveSeries( xDiagram, xSeries, eDirection==MOVE_UP ); 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir Reference< chart2::XDataSeries > DialogModel::insertSeriesAfter( 518*cdf0e10cSrcweir const Reference< XDataSeries > & xSeries, 519*cdf0e10cSrcweir const Reference< XChartType > & xChartType, 520*cdf0e10cSrcweir bool bCreateDataCachedSequences /* = false */ ) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir m_aTimerTriggeredControllerLock.startTimer(); 523*cdf0e10cSrcweir ControllerLockGuard aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ); 524*cdf0e10cSrcweir Reference< XDataSeries > xNewSeries; 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir try 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( m_xChartDocument->getFirstDiagram() ); 529*cdf0e10cSrcweir ThreeDLookScheme e3DScheme = ThreeDHelper::detectScheme( xDiagram ); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir sal_Int32 nSeriesInChartType = 0; 532*cdf0e10cSrcweir const sal_Int32 nTotalSeries = countSeries(); 533*cdf0e10cSrcweir if( xChartType.is()) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir Reference< XDataSeriesContainer > xCnt( xChartType, uno::UNO_QUERY_THROW ); 536*cdf0e10cSrcweir nSeriesInChartType = xCnt->getDataSeries().getLength(); 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir // create new series 540*cdf0e10cSrcweir xNewSeries.set( 541*cdf0e10cSrcweir lcl_CreateNewSeries( 542*cdf0e10cSrcweir m_xContext, 543*cdf0e10cSrcweir xChartType, 544*cdf0e10cSrcweir nTotalSeries, // new series' index 545*cdf0e10cSrcweir nSeriesInChartType, 546*cdf0e10cSrcweir xDiagram, 547*cdf0e10cSrcweir m_xTemplate, 548*cdf0e10cSrcweir bCreateDataCachedSequences )); 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir // add new series to container 551*cdf0e10cSrcweir if( xNewSeries.is()) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir Reference< XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY_THROW ); 554*cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > > aSeries( 555*cdf0e10cSrcweir SequenceToVector( xSeriesCnt->getDataSeries())); 556*cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > >::iterator aIt = 557*cdf0e10cSrcweir ::std::find( aSeries.begin(), aSeries.end(), xSeries ); 558*cdf0e10cSrcweir if( aIt == aSeries.end()) 559*cdf0e10cSrcweir // if we have no series we insert at the first position. 560*cdf0e10cSrcweir aIt = aSeries.begin(); 561*cdf0e10cSrcweir else 562*cdf0e10cSrcweir // vector::insert inserts before, so we have to advance 563*cdf0e10cSrcweir ++aIt; 564*cdf0e10cSrcweir aSeries.insert( aIt, xNewSeries ); 565*cdf0e10cSrcweir xSeriesCnt->setDataSeries( ContainerToSequence( aSeries )); 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir ThreeDHelper::setScheme( xDiagram, e3DScheme ); 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir catch( uno::Exception & ex ) 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir return xNewSeries; 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir void DialogModel::deleteSeries( 578*cdf0e10cSrcweir const Reference< XDataSeries > & xSeries, 579*cdf0e10cSrcweir const Reference< XChartType > & xChartType ) 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir m_aTimerTriggeredControllerLock.startTimer(); 582*cdf0e10cSrcweir ControllerLockGuard aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ); 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir DataSeriesHelper::deleteSeries( xSeries, xChartType ); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir Reference< data::XLabeledDataSequence > DialogModel::getCategories() const 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir Reference< data::XLabeledDataSequence > xResult; 590*cdf0e10cSrcweir try 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir if( m_xChartDocument.is()) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( m_xChartDocument->getFirstDiagram()); 595*cdf0e10cSrcweir xResult.set( DiagramHelper::getCategoriesFromDiagram( xDiagram )); 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir catch( uno::Exception & ex ) 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir return xResult; 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir void DialogModel::setCategories( const Reference< chart2::data::XLabeledDataSequence > & xCategories ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir if( m_xChartDocument.is()) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( m_xChartDocument->getFirstDiagram()); 610*cdf0e10cSrcweir if( xDiagram.is()) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir // categories 613*cdf0e10cSrcweir bool bSupportsCategories = true; 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir Reference< XChartType > xFirstChartType( DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ); 616*cdf0e10cSrcweir if( xFirstChartType.is() ) 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir sal_Int32 nAxisType = ChartTypeHelper::getAxisType( xFirstChartType, 0 ); // x-axis 619*cdf0e10cSrcweir bSupportsCategories = (nAxisType == AxisType::CATEGORY); 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir DiagramHelper::setCategoriesToDiagram( xCategories, xDiagram, true, bSupportsCategories ); 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir OUString DialogModel::getCategoriesRange() const 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir Reference< data::XLabeledDataSequence > xLSeq( getCategories()); 629*cdf0e10cSrcweir OUString aRange; 630*cdf0e10cSrcweir if( xLSeq.is()) 631*cdf0e10cSrcweir { 632*cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( xLSeq->getValues()); 633*cdf0e10cSrcweir if( xSeq.is()) 634*cdf0e10cSrcweir aRange = xSeq->getSourceRangeRepresentation(); 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir return aRange; 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir bool DialogModel::isCategoryDiagram() const 640*cdf0e10cSrcweir { 641*cdf0e10cSrcweir bool bRet = false; 642*cdf0e10cSrcweir if( m_xChartDocument.is()) 643*cdf0e10cSrcweir bRet = DiagramHelper::isCategoryDiagram( m_xChartDocument->getFirstDiagram() ); 644*cdf0e10cSrcweir return bRet; 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir 647*cdf0e10cSrcweir void DialogModel::detectArguments( 648*cdf0e10cSrcweir OUString & rOutRangeString, 649*cdf0e10cSrcweir bool & rOutUseColumns, 650*cdf0e10cSrcweir bool & rOutFirstCellAsLabel, 651*cdf0e10cSrcweir bool & rOutHasCategories ) const 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir try 654*cdf0e10cSrcweir { 655*cdf0e10cSrcweir uno::Sequence< sal_Int32 > aSequenceMapping;//todo YYYX 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir // Note: unused data is currently not supported in being passed to detectRangeSegmentation 658*cdf0e10cSrcweir if( m_xChartDocument.is()) 659*cdf0e10cSrcweir DataSourceHelper::detectRangeSegmentation( 660*cdf0e10cSrcweir Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY_THROW ), 661*cdf0e10cSrcweir rOutRangeString, aSequenceMapping, rOutUseColumns, rOutFirstCellAsLabel, rOutHasCategories ); 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir catch( uno::Exception & ex ) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir bool DialogModel::allArgumentsForRectRangeDetected() const 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir return DataSourceHelper::allArgumentsForRectRangeDetected( m_xChartDocument ); 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir void DialogModel::startControllerLockTimer() 675*cdf0e10cSrcweir { 676*cdf0e10cSrcweir m_aTimerTriggeredControllerLock.startTimer(); 677*cdf0e10cSrcweir } 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir bool DialogModel::setData( 680*cdf0e10cSrcweir const Sequence< beans::PropertyValue > & rArguments ) 681*cdf0e10cSrcweir { 682*cdf0e10cSrcweir m_aTimerTriggeredControllerLock.startTimer(); 683*cdf0e10cSrcweir ControllerLockGuard aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) ); 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir Reference< data::XDataProvider > xDataProvider( getDataProvider()); 686*cdf0e10cSrcweir if( ! xDataProvider.is() || 687*cdf0e10cSrcweir ! m_xTemplate.is() ) 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir OSL_ENSURE( false, "Model objects missing" ); 690*cdf0e10cSrcweir return false; 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir try 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir Reference< chart2::data::XDataSource > xDataSource( 696*cdf0e10cSrcweir xDataProvider->createDataSource( rArguments ) ); 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir Reference< chart2::XDataInterpreter > xInterpreter( 699*cdf0e10cSrcweir m_xTemplate->getDataInterpreter()); 700*cdf0e10cSrcweir if( xInterpreter.is()) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( m_xChartDocument->getFirstDiagram() ); 703*cdf0e10cSrcweir ThreeDLookScheme e3DScheme = ThreeDHelper::detectScheme( xDiagram ); 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > > aSeriesToReUse( 706*cdf0e10cSrcweir DiagramHelper::getDataSeriesFromDiagram( xDiagram )); 707*cdf0e10cSrcweir applyInterpretedData( 708*cdf0e10cSrcweir xInterpreter->interpretDataSource( 709*cdf0e10cSrcweir xDataSource, rArguments, 710*cdf0e10cSrcweir ContainerToSequence( aSeriesToReUse )), 711*cdf0e10cSrcweir aSeriesToReUse, 712*cdf0e10cSrcweir true /* bSetStyles */); 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir ThreeDHelper::setScheme( xDiagram, e3DScheme ); 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir catch( uno::Exception & ex ) 718*cdf0e10cSrcweir { 719*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 720*cdf0e10cSrcweir return false; 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir return true; 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir OUString DialogModel::ConvertRoleFromInternalToUI( const OUString & rRoleString ) 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir return lcl_ConvertRole( rRoleString, true ); 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir OUString DialogModel::GetRoleDataLabel() 732*cdf0e10cSrcweir { 733*cdf0e10cSrcweir return OUString( String( ::chart::SchResId( STR_OBJECT_DATALABELS ))); 734*cdf0e10cSrcweir } 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir sal_Int32 DialogModel::GetRoleIndexForSorting( const ::rtl::OUString & rInternalRoleString ) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir static lcl_tRoleIndexMap aRoleIndexMap; 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir if( aRoleIndexMap.empty()) 741*cdf0e10cSrcweir lcl_createRoleIndexMap( aRoleIndexMap ); 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir lcl_tRoleIndexMap::const_iterator aIt( aRoleIndexMap.find( rInternalRoleString )); 744*cdf0e10cSrcweir if( aIt != aRoleIndexMap.end()) 745*cdf0e10cSrcweir return aIt->second; 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir return 0; 748*cdf0e10cSrcweir } 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir // private methods 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir void DialogModel::applyInterpretedData( 753*cdf0e10cSrcweir const InterpretedData & rNewData, 754*cdf0e10cSrcweir const ::std::vector< Reference< XDataSeries > > & rSeriesToReUse, 755*cdf0e10cSrcweir bool bSetStyles ) 756*cdf0e10cSrcweir { 757*cdf0e10cSrcweir if( ! m_xChartDocument.is()) 758*cdf0e10cSrcweir return; 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir m_aTimerTriggeredControllerLock.startTimer(); 761*cdf0e10cSrcweir Reference< XDiagram > xDiagram( m_xChartDocument->getFirstDiagram()); 762*cdf0e10cSrcweir if( xDiagram.is()) 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir // styles 765*cdf0e10cSrcweir if( bSetStyles && m_xTemplate.is() ) 766*cdf0e10cSrcweir { 767*cdf0e10cSrcweir sal_Int32 nGroup = 0; 768*cdf0e10cSrcweir sal_Int32 nSeriesCounter = 0; 769*cdf0e10cSrcweir sal_Int32 nNewSeriesIndex = static_cast< sal_Int32 >( rSeriesToReUse.size()); 770*cdf0e10cSrcweir const sal_Int32 nOuterSize=rNewData.Series.getLength(); 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir for(; nGroup < nOuterSize; ++nGroup) 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aSeries( rNewData.Series[ nGroup ] ); 775*cdf0e10cSrcweir const sal_Int32 nSeriesInGroup = aSeries.getLength(); 776*cdf0e10cSrcweir for( sal_Int32 nSeries=0; nSeries<nSeriesInGroup; ++nSeries, ++nSeriesCounter ) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir if( ::std::find( rSeriesToReUse.begin(), rSeriesToReUse.end(), aSeries[nSeries] ) 779*cdf0e10cSrcweir == rSeriesToReUse.end()) 780*cdf0e10cSrcweir { 781*cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProp( aSeries[nSeries], uno::UNO_QUERY ); 782*cdf0e10cSrcweir if( xSeriesProp.is()) 783*cdf0e10cSrcweir { 784*cdf0e10cSrcweir // @deprecated: correct default color should be found by view 785*cdf0e10cSrcweir // without setting it as hard attribute 786*cdf0e10cSrcweir Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme()); 787*cdf0e10cSrcweir if( xColorScheme.is()) 788*cdf0e10cSrcweir xSeriesProp->setPropertyValue( 789*cdf0e10cSrcweir C2U("Color"), uno::makeAny( xColorScheme->getColorByIndex( nSeriesCounter ))); 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir m_xTemplate->applyStyle( aSeries[nSeries], nGroup, nNewSeriesIndex++, nSeriesInGroup ); 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir } 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir 797*cdf0e10cSrcweir // data series 798*cdf0e10cSrcweir ::std::vector< Reference< XDataSeriesContainer > > aSeriesCnt( getAllDataSeriesContainers()); 799*cdf0e10cSrcweir ::std::vector< Sequence< Reference< XDataSeries > > > aNewSeries( 800*cdf0e10cSrcweir SequenceToVector( rNewData.Series )); 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir OSL_ASSERT( aSeriesCnt.size() == aNewSeries.size()); 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir ::std::vector< Sequence< Reference< XDataSeries > > >::const_iterator aSrcIt( aNewSeries.begin()); 805*cdf0e10cSrcweir ::std::vector< Reference< XDataSeriesContainer > >::iterator aDestIt( aSeriesCnt.begin()); 806*cdf0e10cSrcweir for(; aSrcIt != aNewSeries.end() && aDestIt != aSeriesCnt.end(); 807*cdf0e10cSrcweir ++aSrcIt, ++aDestIt ) 808*cdf0e10cSrcweir { 809*cdf0e10cSrcweir try 810*cdf0e10cSrcweir { 811*cdf0e10cSrcweir OSL_ASSERT( (*aDestIt).is()); 812*cdf0e10cSrcweir (*aDestIt)->setDataSeries( *aSrcIt ); 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir catch( uno::Exception & ex ) 815*cdf0e10cSrcweir { 816*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir 820*cdf0e10cSrcweir DialogModel::setCategories(rNewData.Categories); 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir sal_Int32 DialogModel::countSeries() const 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir ::std::vector< Reference< XDataSeriesContainer > > aCnt( getAllDataSeriesContainers()); 827*cdf0e10cSrcweir return ::std::accumulate( aCnt.begin(), aCnt.end(), 0, lcl_addSeriesNumber()); 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir } // namespace chart 831