tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedSeriesOrDiagramProperty.hxx
blob0eea39683474282ee2df2e8efc06a212e7afb846
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 #pragma once
21 #include <WrappedProperty.hxx>
22 #include "Chart2ModelContact.hxx"
23 #include <DataSeries.hxx>
25 #include <memory>
26 #include <utility>
27 #include <vector>
29 namespace com::sun::star::chart2 { class XDataSeries; }
31 namespace chart::wrapper
34 enum tSeriesOrDiagramPropertyType
36 DATA_SERIES,
37 DIAGRAM
40 //PROPERTYTYPE is the type of the outer property
42 template< typename PROPERTYTYPE >
43 class WrappedSeriesOrDiagramProperty : public WrappedProperty
45 public:
46 virtual PROPERTYTYPE getValueFromSeries( const css::uno::Reference< css::beans::XPropertySet >& xSeriesPropertySet ) const =0;
47 virtual void setValueToSeries( const css::uno::Reference< css::beans::XPropertySet >& xSeriesPropertySet, const PROPERTYTYPE & aNewValue ) const =0;
49 explicit WrappedSeriesOrDiagramProperty( const OUString& rName, const css::uno::Any& rDefaulValue
50 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact
51 , tSeriesOrDiagramPropertyType ePropertyType )
52 : WrappedProperty(rName,OUString())
53 , m_spChart2ModelContact(std::move(spChart2ModelContact))
54 , m_aOuterValue(rDefaulValue)
55 , m_aDefaultValue(rDefaulValue)
56 , m_ePropertyType( ePropertyType )
60 bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
62 rHasAmbiguousValue = false;
63 if( m_ePropertyType != DIAGRAM || !m_spChart2ModelContact )
64 return false;
65 bool bHasDetectableInnerValue = false;
66 rtl::Reference<Diagram> xDiagram = m_spChart2ModelContact->getDiagram();
67 if (!xDiagram)
68 return false;
69 std::vector< rtl::Reference< DataSeries > > aSeriesVector =
70 xDiagram->getDataSeries();
71 for (auto const& series : aSeriesVector)
73 PROPERTYTYPE aCurValue = getValueFromSeries( 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;
88 return bHasDetectableInnerValue;
90 void setInnerValue( PROPERTYTYPE aNewValue ) const
92 if( m_ePropertyType == DIAGRAM &&
93 m_spChart2ModelContact )
95 std::vector< rtl::Reference< DataSeries > > aSeriesVector =
96 m_spChart2ModelContact->getDiagram()->getDataSeries();
97 for (auto const& series : aSeriesVector)
99 setValueToSeries( series, aNewValue );
103 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override
105 PROPERTYTYPE aNewValue = PROPERTYTYPE();
106 if( ! (rOuterValue >>= aNewValue) )
107 throw css::lang::IllegalArgumentException( u"statistic property requires different type"_ustr, nullptr, 0 );
109 if( m_ePropertyType == DIAGRAM )
111 m_aOuterValue = rOuterValue;
113 bool bHasAmbiguousValue = false;
114 PROPERTYTYPE aOldValue = PROPERTYTYPE();
115 if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
117 if( bHasAmbiguousValue || aNewValue != aOldValue )
118 setInnerValue( aNewValue );
121 else
123 setValueToSeries( xInnerPropertySet, aNewValue );
127 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override
129 if( m_ePropertyType == DIAGRAM )
131 bool bHasAmbiguousValue = false;
132 PROPERTYTYPE aValue = PROPERTYTYPE();
133 if( detectInnerValue( aValue, bHasAmbiguousValue ) )
135 if(bHasAmbiguousValue)
136 m_aOuterValue = m_aDefaultValue;
137 else
138 m_aOuterValue <<= aValue;
140 return m_aOuterValue;
142 else
144 css::uno::Any aRet( m_aDefaultValue );
145 aRet <<= getValueFromSeries( xInnerPropertySet );
146 return aRet;
150 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& /* xInnerPropertyState */ ) const override
152 return m_aDefaultValue;
155 protected:
156 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
157 mutable css::uno::Any m_aOuterValue;
158 css::uno::Any m_aDefaultValue;
159 tSeriesOrDiagramPropertyType m_ePropertyType;
162 } //namespace chart::wrapper
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */