1*de7b3f82SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*de7b3f82SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*de7b3f82SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*de7b3f82SAndrew Rist * distributed with this work for additional information 6*de7b3f82SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*de7b3f82SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*de7b3f82SAndrew Rist * "License"); you may not use this file except in compliance 9*de7b3f82SAndrew Rist * with the License. You may obtain a copy of the License at 10*de7b3f82SAndrew Rist * 11*de7b3f82SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*de7b3f82SAndrew Rist * 13*de7b3f82SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*de7b3f82SAndrew Rist * software distributed under the License is distributed on an 15*de7b3f82SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*de7b3f82SAndrew Rist * KIND, either express or implied. See the License for the 17*de7b3f82SAndrew Rist * specific language governing permissions and limitations 18*de7b3f82SAndrew Rist * under the License. 19*de7b3f82SAndrew Rist * 20*de7b3f82SAndrew Rist *************************************************************/ 21*de7b3f82SAndrew Rist 22*de7b3f82SAndrew Rist 23cdf0e10cSrcweir #ifndef CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX 24cdf0e10cSrcweir #define CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "WrappedProperty.hxx" 27cdf0e10cSrcweir #include "Chart2ModelContact.hxx" 28cdf0e10cSrcweir #include "macros.hxx" 29cdf0e10cSrcweir #include "DiagramHelper.hxx" 30cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeries.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 33cdf0e10cSrcweir #include <vector> 34cdf0e10cSrcweir 35cdf0e10cSrcweir //............................................................................. 36cdf0e10cSrcweir namespace chart 37cdf0e10cSrcweir { 38cdf0e10cSrcweir namespace wrapper 39cdf0e10cSrcweir { 40cdf0e10cSrcweir 41cdf0e10cSrcweir enum tSeriesOrDiagramPropertyType 42cdf0e10cSrcweir { 43cdf0e10cSrcweir DATA_SERIES, 44cdf0e10cSrcweir DIAGRAM 45cdf0e10cSrcweir }; 46cdf0e10cSrcweir 47cdf0e10cSrcweir //PROPERTYTYPE is the type of the outer property 48cdf0e10cSrcweir 49cdf0e10cSrcweir template< typename PROPERTYTYPE > 50cdf0e10cSrcweir class WrappedSeriesOrDiagramProperty : public WrappedProperty 51cdf0e10cSrcweir { 52cdf0e10cSrcweir public: 53cdf0e10cSrcweir virtual PROPERTYTYPE getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const =0; 54cdf0e10cSrcweir virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, PROPERTYTYPE aNewValue ) const =0; 55cdf0e10cSrcweir 56cdf0e10cSrcweir explicit WrappedSeriesOrDiagramProperty( const ::rtl::OUString& rName, const ::com::sun::star::uno::Any& rDefaulValue 57cdf0e10cSrcweir , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact 58cdf0e10cSrcweir , tSeriesOrDiagramPropertyType ePropertyType ) 59cdf0e10cSrcweir : WrappedProperty(rName,::rtl::OUString()) 60cdf0e10cSrcweir , m_spChart2ModelContact(spChart2ModelContact) 61cdf0e10cSrcweir , m_aOuterValue(rDefaulValue) 62cdf0e10cSrcweir , m_aDefaultValue(rDefaulValue) 63cdf0e10cSrcweir , m_ePropertyType( ePropertyType ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir } 66cdf0e10cSrcweir virtual ~WrappedSeriesOrDiagramProperty() {}; 67cdf0e10cSrcweir 68cdf0e10cSrcweir bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const 69cdf0e10cSrcweir { 70cdf0e10cSrcweir bool bHasDetectableInnerValue = false; 71cdf0e10cSrcweir rHasAmbiguousValue = false; 72cdf0e10cSrcweir if( m_ePropertyType == DIAGRAM && 73cdf0e10cSrcweir m_spChart2ModelContact.get() ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector( 76cdf0e10cSrcweir ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) ); 77cdf0e10cSrcweir ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter = 78cdf0e10cSrcweir aSeriesVector.begin(); 79cdf0e10cSrcweir for( ; aIter != aSeriesVector.end(); aIter++ ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir PROPERTYTYPE aCurValue = getValueFromSeries( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >::query( *aIter ) ); 82cdf0e10cSrcweir if( !bHasDetectableInnerValue ) 83cdf0e10cSrcweir rValue = aCurValue; 84cdf0e10cSrcweir else 85cdf0e10cSrcweir { 86cdf0e10cSrcweir if( rValue != aCurValue ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir rHasAmbiguousValue = true; 89cdf0e10cSrcweir break; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir else 92cdf0e10cSrcweir rValue = aCurValue; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir bHasDetectableInnerValue = true; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir return bHasDetectableInnerValue; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir void setInnerValue( PROPERTYTYPE aNewValue ) const 100cdf0e10cSrcweir { 101cdf0e10cSrcweir if( m_ePropertyType == DIAGRAM && 102cdf0e10cSrcweir m_spChart2ModelContact.get() ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector( 105cdf0e10cSrcweir ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) ); 106cdf0e10cSrcweir ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter = 107cdf0e10cSrcweir aSeriesVector.begin(); 108cdf0e10cSrcweir for( ; aIter != aSeriesVector.end(); aIter++ ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSeriesPropertySet( *aIter, ::com::sun::star::uno::UNO_QUERY ); 111cdf0e10cSrcweir if( xSeriesPropertySet.is() ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir setValueToSeries( xSeriesPropertySet, aNewValue ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir } 118cdf0e10cSrcweir virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 119cdf0e10cSrcweir 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) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir PROPERTYTYPE aNewValue = PROPERTYTYPE(); 122cdf0e10cSrcweir if( ! (rOuterValue >>= aNewValue) ) 123cdf0e10cSrcweir throw ::com::sun::star::lang::IllegalArgumentException( C2U("statistic property requires different type"), 0, 0 ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir if( m_ePropertyType == DIAGRAM ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir m_aOuterValue = rOuterValue; 128cdf0e10cSrcweir 129cdf0e10cSrcweir bool bHasAmbiguousValue = false; 130cdf0e10cSrcweir PROPERTYTYPE aOldValue = PROPERTYTYPE(); 131cdf0e10cSrcweir if( detectInnerValue( aOldValue, bHasAmbiguousValue ) ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir if( bHasAmbiguousValue || aNewValue != aOldValue ) 134cdf0e10cSrcweir setInnerValue( aNewValue ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir else 138cdf0e10cSrcweir { 139cdf0e10cSrcweir setValueToSeries( xInnerPropertySet, aNewValue ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 144cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir if( m_ePropertyType == DIAGRAM ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir bool bHasAmbiguousValue = false; 149cdf0e10cSrcweir PROPERTYTYPE aValue; 150cdf0e10cSrcweir if( detectInnerValue( aValue, bHasAmbiguousValue ) ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir if(bHasAmbiguousValue) 153cdf0e10cSrcweir m_aOuterValue <<= m_aDefaultValue; 154cdf0e10cSrcweir else 155cdf0e10cSrcweir m_aOuterValue <<= aValue; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir return m_aOuterValue; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir else 160cdf0e10cSrcweir { 161cdf0e10cSrcweir ::com::sun::star::uno::Any aRet( m_aDefaultValue ); 162cdf0e10cSrcweir aRet <<= getValueFromSeries( xInnerPropertySet ); 163cdf0e10cSrcweir return aRet; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /* xInnerPropertyState */ ) const 168cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir return m_aDefaultValue; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir protected: 174cdf0e10cSrcweir ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 175cdf0e10cSrcweir mutable ::com::sun::star::uno::Any m_aOuterValue; 176cdf0e10cSrcweir ::com::sun::star::uno::Any m_aDefaultValue; 177cdf0e10cSrcweir tSeriesOrDiagramPropertyType m_ePropertyType; 178cdf0e10cSrcweir }; 179cdf0e10cSrcweir 180cdf0e10cSrcweir } //namespace wrapper 181cdf0e10cSrcweir } //namespace chart 182cdf0e10cSrcweir //............................................................................. 183cdf0e10cSrcweir 184cdf0e10cSrcweir // CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX 185cdf0e10cSrcweir #endif 186