1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "ColorPerPointHelper.hxx"
28 #include "macros.hxx"
29 #include <com/sun/star/chart2/XDataSeries.hpp>
30 #include <com/sun/star/beans/XPropertyState.hpp>
31
32 #include <algorithm>
33
34 //.............................................................................
35 namespace chart
36 {
37 //.............................................................................
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::chart2;
40
hasPointOwnColor(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & xDataSeriesProperties,sal_Int32 nPointIndex,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & xDataPointProperties)41 bool ColorPerPointHelper::hasPointOwnColor(
42 const ::com::sun::star::uno::Reference<
43 ::com::sun::star::beans::XPropertySet >& xDataSeriesProperties
44 , sal_Int32 nPointIndex
45 , const ::com::sun::star::uno::Reference<
46 ::com::sun::star::beans::XPropertySet >& xDataPointProperties //may be NULL this is just for performance
47 )
48 {
49 if( !xDataSeriesProperties.is() )
50 return false;
51
52 if( hasPointOwnProperties( xDataSeriesProperties, nPointIndex ))
53 {
54 uno::Reference< beans::XPropertyState > xPointState( xDataPointProperties, uno::UNO_QUERY );
55 if( !xPointState.is() )
56 {
57 uno::Reference< XDataSeries > xSeries( xDataSeriesProperties, uno::UNO_QUERY );
58 if(xSeries.is())
59 xPointState.set( xSeries->getDataPointByIndex( nPointIndex ), uno::UNO_QUERY );
60 }
61 if( !xPointState.is() )
62 return false;
63
64 return (xPointState->getPropertyState( C2U("Color")) != beans::PropertyState_DEFAULT_VALUE );
65 }
66
67 return false;
68 }
69
hasPointOwnProperties(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & xSeriesProperties,sal_Int32 nPointIndex)70 bool ColorPerPointHelper::hasPointOwnProperties(
71 const ::com::sun::star::uno::Reference<
72 ::com::sun::star::beans::XPropertySet >& xSeriesProperties
73 , sal_Int32 nPointIndex )
74 {
75 if( xSeriesProperties.is() )
76 {
77 uno::Sequence< sal_Int32 > aIndexList;
78 if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aIndexList )
79 {
80 const sal_Int32 * pBegIt = aIndexList.getConstArray();
81 const sal_Int32 * pEndIt = pBegIt + aIndexList.getLength();
82 return ( ::std::find( pBegIt, pEndIt, nPointIndex ) != pEndIt );
83 }
84 }
85
86 return false;
87 }
88
89 //.............................................................................
90 } //namespace chart
91 //.............................................................................
92