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 #ifndef CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX 24 #define CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX 25 26 #include "WrappedProperty.hxx" 27 #include "Chart2ModelContact.hxx" 28 #include "macros.hxx" 29 #include "DiagramHelper.hxx" 30 #include <com/sun/star/chart2/XDataSeries.hpp> 31 32 #include <boost/shared_ptr.hpp> 33 #include <vector> 34 35 // this operator is not defined by default 36 inline bool operator!=( const ::com::sun::star::awt::Size& rSize1, const ::com::sun::star::awt::Size& rSize2 ) 37 { 38 return (rSize1.Width != rSize2.Width) || (rSize1.Height != rSize2.Height); 39 } 40 41 //............................................................................. 42 43 namespace chart 44 { 45 namespace wrapper 46 { 47 48 enum tSeriesOrDiagramPropertyType 49 { 50 DATA_SERIES, 51 DIAGRAM 52 }; 53 54 //PROPERTYTYPE is the type of the outer property 55 56 template< typename PROPERTYTYPE > 57 class WrappedSeriesOrDiagramProperty : public WrappedProperty 58 { 59 public: 60 virtual PROPERTYTYPE getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const =0; 61 virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, PROPERTYTYPE aNewValue ) const =0; 62 63 explicit WrappedSeriesOrDiagramProperty( const ::rtl::OUString& rName, const ::com::sun::star::uno::Any& rDefaulValue 64 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact 65 , tSeriesOrDiagramPropertyType ePropertyType ) 66 : WrappedProperty(rName,::rtl::OUString()) 67 , m_spChart2ModelContact(spChart2ModelContact) 68 , m_aOuterValue(rDefaulValue) 69 , m_aDefaultValue(rDefaulValue) 70 , m_ePropertyType( ePropertyType ) 71 { 72 } 73 virtual ~WrappedSeriesOrDiagramProperty() {}; 74 75 bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const 76 { 77 bool bHasDetectableInnerValue = false; 78 rHasAmbiguousValue = false; 79 if( m_ePropertyType == DIAGRAM && 80 m_spChart2ModelContact.get() ) 81 { 82 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector( 83 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) ); 84 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter = 85 aSeriesVector.begin(); 86 for( ; aIter != aSeriesVector.end(); aIter++ ) 87 { 88 PROPERTYTYPE aCurValue = getValueFromSeries( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >::query( *aIter ) ); 89 if( !bHasDetectableInnerValue ) 90 rValue = aCurValue; 91 else 92 { 93 if( rValue != aCurValue ) 94 { 95 rHasAmbiguousValue = true; 96 break; 97 } 98 else 99 rValue = aCurValue; 100 } 101 bHasDetectableInnerValue = true; 102 } 103 } 104 return bHasDetectableInnerValue; 105 } 106 void setInnerValue( PROPERTYTYPE aNewValue ) const 107 { 108 if( m_ePropertyType == DIAGRAM && 109 m_spChart2ModelContact.get() ) 110 { 111 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector( 112 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) ); 113 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter = 114 aSeriesVector.begin(); 115 for( ; aIter != aSeriesVector.end(); aIter++ ) 116 { 117 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSeriesPropertySet( *aIter, ::com::sun::star::uno::UNO_QUERY ); 118 if( xSeriesPropertySet.is() ) 119 { 120 setValueToSeries( xSeriesPropertySet, aNewValue ); 121 } 122 } 123 } 124 } 125 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 126 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) 127 { 128 PROPERTYTYPE aNewValue = PROPERTYTYPE(); 129 if( ! (rOuterValue >>= aNewValue) ) 130 throw ::com::sun::star::lang::IllegalArgumentException( C2U("statistic property requires different type"), 0, 0 ); 131 132 if( m_ePropertyType == DIAGRAM ) 133 { 134 m_aOuterValue = rOuterValue; 135 136 bool bHasAmbiguousValue = false; 137 PROPERTYTYPE aOldValue = PROPERTYTYPE(); 138 if( detectInnerValue( aOldValue, bHasAmbiguousValue ) ) 139 { 140 if( bHasAmbiguousValue || aNewValue != aOldValue ) 141 setInnerValue( aNewValue ); 142 } 143 } 144 else 145 { 146 setValueToSeries( xInnerPropertySet, aNewValue ); 147 } 148 } 149 150 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 151 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 152 { 153 if( m_ePropertyType == DIAGRAM ) 154 { 155 bool bHasAmbiguousValue = false; 156 PROPERTYTYPE aValue; 157 if( detectInnerValue( aValue, bHasAmbiguousValue ) ) 158 { 159 if(bHasAmbiguousValue) 160 m_aOuterValue <<= m_aDefaultValue; 161 else 162 m_aOuterValue <<= aValue; 163 } 164 return m_aOuterValue; 165 } 166 else 167 { 168 ::com::sun::star::uno::Any aRet( m_aDefaultValue ); 169 aRet <<= getValueFromSeries( xInnerPropertySet ); 170 return aRet; 171 } 172 } 173 174 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /* xInnerPropertyState */ ) const 175 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 176 { 177 return m_aDefaultValue; 178 } 179 180 protected: 181 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 182 mutable ::com::sun::star::uno::Any m_aOuterValue; 183 ::com::sun::star::uno::Any m_aDefaultValue; 184 tSeriesOrDiagramPropertyType m_ePropertyType; 185 }; 186 187 } //namespace wrapper 188 } //namespace chart 189 //............................................................................. 190 191 // CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX 192 #endif 193