Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : : #ifndef CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX
20 : : #define CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX
21 : :
22 : : #include "WrappedProperty.hxx"
23 : : #include "Chart2ModelContact.hxx"
24 : : #include "macros.hxx"
25 : : #include "DiagramHelper.hxx"
26 : : #include <com/sun/star/chart2/XDataSeries.hpp>
27 : :
28 : : #include <boost/shared_ptr.hpp>
29 : : #include <vector>
30 : :
31 : : //.............................................................................
32 : : namespace chart
33 : : {
34 : : namespace wrapper
35 : : {
36 : :
37 : : enum tSeriesOrDiagramPropertyType
38 : : {
39 : : DATA_SERIES,
40 : : DIAGRAM
41 : : };
42 : :
43 : : //PROPERTYTYPE is the type of the outer property
44 : :
45 : : template< typename PROPERTYTYPE >
46 : : class WrappedSeriesOrDiagramProperty : public WrappedProperty
47 : : {
48 : : public:
49 : : virtual PROPERTYTYPE getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const =0;
50 : : virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, PROPERTYTYPE aNewValue ) const =0;
51 : :
52 : 2423 : explicit WrappedSeriesOrDiagramProperty( const ::rtl::OUString& rName, const ::com::sun::star::uno::Any& rDefaulValue
53 : : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
54 : : , tSeriesOrDiagramPropertyType ePropertyType )
55 : : : WrappedProperty(rName,::rtl::OUString())
56 : : , m_spChart2ModelContact(spChart2ModelContact)
57 : : , m_aOuterValue(rDefaulValue)
58 : : , m_aDefaultValue(rDefaulValue)
59 [ + - ][ + - ]: 2423 : , m_ePropertyType( ePropertyType )
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
60 : : {
61 : 2423 : }
62 [ + - ][ - + ]: 2423 : virtual ~WrappedSeriesOrDiagramProperty() {};
[ + - ][ - + ]
[ + - ][ - + ]
[ # # ][ # # ]
[ + - ][ - + ]
[ + - ][ - + ]
[ + - ][ - + ]
[ + - ][ - + ]
63 : :
64 : 372 : bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
65 : : {
66 : 372 : bool bHasDetectableInnerValue = false;
67 : 372 : rHasAmbiguousValue = false;
68 [ + - ][ + - ]: 372 : if( m_ePropertyType == DIAGRAM &&
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ # # ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ # # ][ # # ]
69 : : m_spChart2ModelContact.get() )
70 : : {
71 : : ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
72 [ + - ][ + - ]: 372 : ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
73 : : ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
74 [ + - + - : 372 : aSeriesVector.begin();
+ - + - #
# + - + -
# # ]
75 [ + - ][ + - ]: 1496 : for( ; aIter != aSeriesVector.end(); aIter++ )
[ # # + + ]
[ # # ][ + - ]
[ # # ][ + - ]
[ # # + + ]
[ # # ][ + - ]
[ # # ][ + - ]
[ # # + + ]
[ # # ][ + - ]
[ # # ][ + - ]
[ # # + + ]
[ # # ][ # # ]
[ # # ][ # # ]
[ + - ][ + - ]
[ + + ][ + - ]
[ + - ][ + + ]
[ # # ][ # # ]
[ # # ]
76 : : {
77 [ + - ][ + - ]: 1124 : PROPERTYTYPE aCurValue = getValueFromSeries( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >::query( *aIter ) );
[ + - ]
[ # # + - ]
[ # # ][ + - ]
[ + - ][ # # ]
[ # # ][ + - ]
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ # # ]
78 [ + + + + : 1124 : if( !bHasDetectableInnerValue )
+ + + + #
# + + + +
# # ]
79 [ # # ]: 288 : rValue = aCurValue;
80 : : else
81 : : {
82 [ - + # ]: 836 : if( rValue != aCurValue )
[ - + # # ]
[ - + # # ]
[ - + # # ]
[ # # ][ - + ]
[ - + ][ # # ]
[ # # ]
83 : : {
84 : 0 : rHasAmbiguousValue = true;
85 : 0 : break;
86 : : }
87 : : else
88 [ # # ]: 836 : rValue = aCurValue;
89 : : }
90 [ # # ][ + - ]: 594 : bHasDetectableInnerValue = true;
[ # # ]
91 : : }
92 : : }
93 : 372 : return bHasDetectableInnerValue;
94 : : }
95 : 18 : void setInnerValue( PROPERTYTYPE aNewValue ) const
96 : : {
97 [ + - ][ + - ]: 18 : if( m_ePropertyType == DIAGRAM &&
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ + - ][ + - ]
[ + - ][ # # ]
[ # # ][ # # ]
98 : : m_spChart2ModelContact.get() )
99 : : {
100 : : ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
101 [ + - ][ + - ]: 18 : ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ # # ][ # # ]
[ + - ][ + - ]
[ # # ][ # # ]
102 : : ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
103 [ + - + - : 18 : aSeriesVector.begin();
+ - + - #
# # # + -
# # ]
104 [ + - ][ + - ]: 72 : for( ; aIter != aSeriesVector.end(); aIter++ )
[ + + ][ + - ]
[ + - ][ + + ]
[ + - ][ + - ]
[ + + ][ + - ]
[ + - ][ + + ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ + - ][ + - ]
[ + + ][ # # ]
[ # # ][ # # ]
105 : : {
106 [ + - ][ + - ]: 54 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSeriesPropertySet( *aIter, ::com::sun::star::uno::UNO_QUERY );
[ + - ][ + - ]
[ # # ][ # # ]
[ + - ][ # # ]
107 [ + - ][ + - ]: 54 : if( xSeriesPropertySet.is() )
[ + - ][ + - ]
[ # # ][ # # ]
[ + - ][ # # ]
108 : : {
109 [ + - ]: 72 : setValueToSeries( xSeriesPropertySet, aNewValue );
[ + - # ]
[ + - ][ # # ]
[ + - ][ # # ]
[ # # ][ # # ]
[ + - ][ # # ]
110 : : }
111 : : }
112 : : }
113 : 18 : }
114 : 346 : virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
115 : : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
116 : : {
117 : 142 : PROPERTYTYPE aNewValue = PROPERTYTYPE();
118 [ - + # # : 346 : if( ! (rOuterValue >>= aNewValue) )
+ - ]
[ + - - + ]
[ - + # # ]
[ - + ][ + - ]
[ - + ]
[ # # - + ]
[ + - ]
[ - + # # ]
[ # # ]
119 [ # # ][ # # ]: 0 : throw ::com::sun::star::lang::IllegalArgumentException( "statistic property requires different type", 0, 0 );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
120 : :
121 [ + + ][ + - ]: 346 : if( m_ePropertyType == DIAGRAM )
[ + + ][ + - ]
[ # # ][ - + ]
[ + + ][ # # ]
122 : : {
123 : 78 : m_aOuterValue = rOuterValue;
124 : :
125 : 78 : bool bHasAmbiguousValue = false;
126 : 20 : PROPERTYTYPE aOldValue = PROPERTYTYPE();
127 [ + + + - ]: 78 : if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
[ + - + - ]
[ + + + - ]
[ + - # # ]
[ # # # # ]
[ # # + - ]
[ + + # # ]
[ # # ][ + - ]
128 : : {
129 [ + - ][ + - ]: 18 : if( bHasAmbiguousValue || aNewValue != aOldValue )
[ + - ]
[ + - # ]
[ + - ][ + - ]
[ # # + - ]
[ # # + - ]
[ # # # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # ][ + - ]
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ]
130 [ + - ]: 78 : setInnerValue( aNewValue );
[ + - # ]
[ + - ][ + - ]
[ # # # ]
[ # # # # ]
[ + - ][ # # ]
131 : : }
132 : : }
133 : : else
134 : : {
135 [ + - ]: 268 : setValueToSeries( xInnerPropertySet, aNewValue );
[ # # # ]
[ + - ][ # # ]
[ # # ][ + - ]
[ + - ][ # # ]
[ + - ][ # # ]
136 : : }
137 : 346 : }
138 : :
139 : 1344 : virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
140 : : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
141 : : {
142 [ + + ][ + - ]: 1344 : if( m_ePropertyType == DIAGRAM )
[ + + ][ + + ]
[ # # ][ + + ]
[ + + ][ - + ]
143 : : {
144 : 270 : bool bHasAmbiguousValue = false;
145 : 54 : PROPERTYTYPE aValue;
146 [ + - ]: 270 : if( detectInnerValue( aValue, bHasAmbiguousValue ) )
[ + + # # ]
[ + - # #
# # ]
[ + - # # ]
[ + - # # ]
[ + - # # ]
[ + - ][ + - ]
[ # # ]
[ # # + - ]
[ + - ][ + - ]
[ + + # # ]
[ # # ]
147 : : {
148 [ - + ][ - + ]: 252 : if(bHasAmbiguousValue)
[ - + ][ - + ]
[ # # ][ - + ]
[ - + ][ # # ]
149 [ # # ][ # # ]: 0 : m_aOuterValue <<= m_aDefaultValue;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
150 : : else
151 [ + - ][ # # ]: 252 : m_aOuterValue <<= aValue;
[ + - ][ + - ]
[ # # ]
152 : : }
153 : 270 : return m_aOuterValue;
154 : : }
155 : : else
156 : : {
157 : 1074 : ::com::sun::star::uno::Any aRet( m_aDefaultValue );
158 [ + - # # ]: 1074 : aRet <<= getValueFromSeries( xInnerPropertySet );
[ + + - ]
[ + - # ]
[ # # ][ + - ]
[ + - ][ + - ]
[ + - + - ]
[ + - ][ + - ]
159 : 1344 : return aRet;
160 : : }
161 : : }
162 : :
163 : 1196 : virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /* xInnerPropertyState */ ) const
164 : : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
165 : : {
166 : 1196 : return m_aDefaultValue;
167 : : }
168 : :
169 : : protected:
170 : : ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
171 : : mutable ::com::sun::star::uno::Any m_aOuterValue;
172 : : ::com::sun::star::uno::Any m_aDefaultValue;
173 : : tSeriesOrDiagramPropertyType m_ePropertyType;
174 : : };
175 : :
176 : : } //namespace wrapper
177 : : } //namespace chart
178 : : //.............................................................................
179 : :
180 : : // CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX
181 : : #endif
182 : :
183 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|