1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <DiagramHelper.hxx>
29 namespace com
{ namespace sun
{ namespace star
{ namespace chart2
{ class XDataSeries
; } } } }
36 enum tSeriesOrDiagramPropertyType
42 //PROPERTYTYPE is the type of the outer property
44 template< typename PROPERTYTYPE
>
45 class WrappedSeriesOrDiagramProperty
: public WrappedProperty
48 virtual PROPERTYTYPE
getValueFromSeries( const css::uno::Reference
< css::beans::XPropertySet
>& xSeriesPropertySet
) const =0;
49 virtual void setValueToSeries( const css::uno::Reference
< css::beans::XPropertySet
>& xSeriesPropertySet
, const PROPERTYTYPE
& aNewValue
) const =0;
51 explicit WrappedSeriesOrDiagramProperty( const OUString
& rName
, const css::uno::Any
& rDefaulValue
52 , const std::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
)
62 bool detectInnerValue( PROPERTYTYPE
& rValue
, bool& rHasAmbiguousValue
) const
64 bool bHasDetectableInnerValue
= false;
65 rHasAmbiguousValue
= false;
66 if( m_ePropertyType
== DIAGRAM
&&
67 m_spChart2ModelContact
.get() )
69 std::vector
< css::uno::Reference
< css::chart2::XDataSeries
> > aSeriesVector(
70 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
71 for (auto const& series
: aSeriesVector
)
73 PROPERTYTYPE aCurValue
= getValueFromSeries( css::uno::Reference
< css::beans::XPropertySet
>::query(series
) );
74 if( !bHasDetectableInnerValue
)
78 if( rValue
!= aCurValue
)
80 rHasAmbiguousValue
= true;
86 bHasDetectableInnerValue
= true;
89 return bHasDetectableInnerValue
;
91 void setInnerValue( PROPERTYTYPE aNewValue
) const
93 if( m_ePropertyType
== DIAGRAM
&&
94 m_spChart2ModelContact
.get() )
96 std::vector
< css::uno::Reference
< css::chart2::XDataSeries
> > aSeriesVector(
97 ::chart::DiagramHelper::getDataSeriesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
98 for (auto const& series
: aSeriesVector
)
100 css::uno::Reference
< css::beans::XPropertySet
> xSeriesPropertySet(series
, css::uno::UNO_QUERY
);
101 if( xSeriesPropertySet
.is() )
103 setValueToSeries( xSeriesPropertySet
, aNewValue
);
108 virtual void setPropertyValue( const css::uno::Any
& rOuterValue
, const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
110 PROPERTYTYPE aNewValue
= PROPERTYTYPE();
111 if( ! (rOuterValue
>>= aNewValue
) )
112 throw css::lang::IllegalArgumentException( "statistic property requires different type", nullptr, 0 );
114 if( m_ePropertyType
== DIAGRAM
)
116 m_aOuterValue
= rOuterValue
;
118 bool bHasAmbiguousValue
= false;
119 PROPERTYTYPE aOldValue
= PROPERTYTYPE();
120 if( detectInnerValue( aOldValue
, bHasAmbiguousValue
) )
122 if( bHasAmbiguousValue
|| aNewValue
!= aOldValue
)
123 setInnerValue( aNewValue
);
128 setValueToSeries( xInnerPropertySet
, aNewValue
);
132 virtual css::uno::Any
getPropertyValue( const css::uno::Reference
< css::beans::XPropertySet
>& xInnerPropertySet
) const override
134 if( m_ePropertyType
== DIAGRAM
)
136 bool bHasAmbiguousValue
= false;
137 PROPERTYTYPE aValue
= PROPERTYTYPE();
138 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
140 if(bHasAmbiguousValue
)
141 m_aOuterValue
= m_aDefaultValue
;
143 m_aOuterValue
<<= aValue
;
145 return m_aOuterValue
;
149 css::uno::Any
aRet( m_aDefaultValue
);
150 aRet
<<= getValueFromSeries( xInnerPropertySet
);
155 virtual css::uno::Any
getPropertyDefault( const css::uno::Reference
< css::beans::XPropertyState
>& /* xInnerPropertyState */ ) const override
157 return m_aDefaultValue
;
161 std::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
162 mutable css::uno::Any m_aOuterValue
;
163 css::uno::Any m_aDefaultValue
;
164 tSeriesOrDiagramPropertyType m_ePropertyType
;
167 } //namespace wrapper
170 // INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */