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