Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedSeriesOrDiagramProperty.hxx
bloba57525acca71e80ff4ee2249292ac2e9b77733a5
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 <DiagramHelper.hxx>
26 #include <memory>
27 #include <vector>
29 namespace com { namespace sun { namespace star { namespace chart2 { class XDataSeries; } } } }
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 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 )
75 rValue = aCurValue;
76 else
78 if( rValue != aCurValue )
80 rHasAmbiguousValue = true;
81 break;
83 else
84 rValue = aCurValue;
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 );
126 else
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;
142 else
143 m_aOuterValue <<= aValue;
145 return m_aOuterValue;
147 else
149 css::uno::Any aRet( m_aDefaultValue );
150 aRet <<= getValueFromSeries( xInnerPropertySet );
151 return aRet;
155 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& /* xInnerPropertyState */ ) const override
157 return m_aDefaultValue;
160 protected:
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
168 } //namespace chart
170 // INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_WRAPPEDSERIESORDIAGRAMPROPERTY_HXX
171 #endif
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */