fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedSeriesOrDiagramProperty.hxx
blob717fa93e2cf23d1f3577fba1424b04dc9c206599
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
20 #define INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
22 #include "WrappedProperty.hxx"
23 #include "Chart2ModelContact.hxx"
24 #include "macros.hxx"
25 #include "DiagramHelper.hxx"
26 #include <com/sun/star/chart2/XDataSeries.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <vector>
31 namespace chart
33 namespace wrapper
36 enum tSeriesOrDiagramPropertyType
38 DATA_SERIES,
39 DIAGRAM
42 //PROPERTYTYPE is the type of the outer property
44 template< typename PROPERTYTYPE >
45 class WrappedSeriesOrDiagramProperty : public WrappedProperty
47 public:
48 virtual PROPERTYTYPE getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const =0;
49 virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, const PROPERTYTYPE & aNewValue ) const =0;
51 explicit WrappedSeriesOrDiagramProperty( const OUString& rName, const ::com::sun::star::uno::Any& rDefaulValue
52 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
53 , tSeriesOrDiagramPropertyType ePropertyType )
54 : WrappedProperty(rName,OUString())
55 , m_spChart2ModelContact(spChart2ModelContact)
56 , m_aOuterValue(rDefaulValue)
57 , m_aDefaultValue(rDefaulValue)
58 , m_ePropertyType( ePropertyType )
61 virtual ~WrappedSeriesOrDiagramProperty() {};
63 bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
65 bool bHasDetectableInnerValue = false;
66 rHasAmbiguousValue = false;
67 if( m_ePropertyType == DIAGRAM &&
68 m_spChart2ModelContact.get() )
70 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
71 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
72 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
73 aSeriesVector.begin();
74 for( ; aIter != aSeriesVector.end(); ++aIter )
76 PROPERTYTYPE aCurValue = getValueFromSeries( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >::query( *aIter ) );
77 if( !bHasDetectableInnerValue )
78 rValue = aCurValue;
79 else
81 if( rValue != aCurValue )
83 rHasAmbiguousValue = true;
84 break;
86 else
87 rValue = aCurValue;
89 bHasDetectableInnerValue = true;
92 return bHasDetectableInnerValue;
94 void setInnerValue( PROPERTYTYPE aNewValue ) const
96 if( m_ePropertyType == DIAGRAM &&
97 m_spChart2ModelContact.get() )
99 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > aSeriesVector(
100 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
101 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >::const_iterator aIter =
102 aSeriesVector.begin();
103 for( ; aIter != aSeriesVector.end(); ++aIter )
105 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSeriesPropertySet( *aIter, ::com::sun::star::uno::UNO_QUERY );
106 if( xSeriesPropertySet.is() )
108 setValueToSeries( xSeriesPropertySet, aNewValue );
113 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
114 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) SAL_OVERRIDE
116 PROPERTYTYPE aNewValue = PROPERTYTYPE();
117 if( ! (rOuterValue >>= aNewValue) )
118 throw ::com::sun::star::lang::IllegalArgumentException( "statistic property requires different type", 0, 0 );
120 if( m_ePropertyType == DIAGRAM )
122 m_aOuterValue = rOuterValue;
124 bool bHasAmbiguousValue = false;
125 PROPERTYTYPE aOldValue = PROPERTYTYPE();
126 if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
128 if( bHasAmbiguousValue || aNewValue != aOldValue )
129 setInnerValue( aNewValue );
132 else
134 setValueToSeries( xInnerPropertySet, aNewValue );
138 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
139 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
141 if( m_ePropertyType == DIAGRAM )
143 bool bHasAmbiguousValue = false;
144 PROPERTYTYPE aValue;
145 if( detectInnerValue( aValue, bHasAmbiguousValue ) )
147 if(bHasAmbiguousValue)
148 m_aOuterValue <<= m_aDefaultValue;
149 else
150 m_aOuterValue <<= aValue;
152 return m_aOuterValue;
154 else
156 ::com::sun::star::uno::Any aRet( m_aDefaultValue );
157 aRet <<= getValueFromSeries( xInnerPropertySet );
158 return aRet;
162 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /* xInnerPropertyState */ ) const
163 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
165 return m_aDefaultValue;
168 protected:
169 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
170 mutable ::com::sun::star::uno::Any m_aOuterValue;
171 ::com::sun::star::uno::Any m_aDefaultValue;
172 tSeriesOrDiagramPropertyType m_ePropertyType;
175 } //namespace wrapper
176 } //namespace chart
178 // INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
179 #endif
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */