1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedSeriesOrDiagramProperty.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX
31 #define CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX
33 #include "WrappedProperty.hxx"
34 #include "Chart2ModelContact.hxx"
36 #include "DiagramHelper.hxx"
37 #include <com/sun/star/chart2/XDataSeries.hpp>
39 #include <boost/shared_ptr.hpp>
42 //.............................................................................
48 enum tSeriesOrDiagramPropertyType
54 //PROPERTYTYPE is the type of the outer property
56 template< typename PROPERTYTYPE
>
57 class WrappedSeriesOrDiagramProperty
: public WrappedProperty
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;
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
)
73 virtual ~WrappedSeriesOrDiagramProperty() {};
75 bool detectInnerValue( PROPERTYTYPE
& rValue
, bool& rHasAmbiguousValue
) const
77 bool bHasDetectableInnerValue
= false;
78 rHasAmbiguousValue
= false;
79 if( m_ePropertyType
== DIAGRAM
&&
80 m_spChart2ModelContact
.get() )
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
++ )
88 PROPERTYTYPE aCurValue
= getValueFromSeries( ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>::query( *aIter
) );
89 if( !bHasDetectableInnerValue
)
93 if( rValue
!= aCurValue
)
95 rHasAmbiguousValue
= true;
101 bHasDetectableInnerValue
= true;
104 return bHasDetectableInnerValue
;
106 void setInnerValue( PROPERTYTYPE aNewValue
) const
108 if( m_ePropertyType
== DIAGRAM
&&
109 m_spChart2ModelContact
.get() )
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
++ )
117 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xSeriesPropertySet( *aIter
, ::com::sun::star::uno::UNO_QUERY
);
118 if( xSeriesPropertySet
.is() )
120 setValueToSeries( xSeriesPropertySet
, aNewValue
);
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
)
128 PROPERTYTYPE aNewValue
= PROPERTYTYPE();
129 if( ! (rOuterValue
>>= aNewValue
) )
130 throw ::com::sun::star::lang::IllegalArgumentException( C2U("statistic property requires different type"), 0, 0 );
132 if( m_ePropertyType
== DIAGRAM
)
134 m_aOuterValue
= rOuterValue
;
136 bool bHasAmbiguousValue
= false;
137 PROPERTYTYPE aOldValue
= PROPERTYTYPE();
138 if( detectInnerValue( aOldValue
, bHasAmbiguousValue
) )
140 if( bHasAmbiguousValue
|| aNewValue
!= aOldValue
)
141 setInnerValue( aNewValue
);
146 setValueToSeries( xInnerPropertySet
, aNewValue
);
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
)
153 if( m_ePropertyType
== DIAGRAM
)
155 bool bHasAmbiguousValue
= false;
157 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
159 if(bHasAmbiguousValue
)
160 m_aOuterValue
<<= m_aDefaultValue
;
162 m_aOuterValue
<<= aValue
;
164 return m_aOuterValue
;
168 ::com::sun::star::uno::Any
aRet( m_aDefaultValue
);
169 aRet
<<= getValueFromSeries( xInnerPropertySet
);
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
)
177 return m_aDefaultValue
;
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
;
187 } //namespace wrapper
189 //.............................................................................
191 // CHART_WRAPPED_SERIES_OR_DIAGRAM_PROPERTY_HXX