LibreOffice Module chart2 (master) 1
WrappedSeriesOrDiagramProperty.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#pragma once
20
21#include <WrappedProperty.hxx>
23#include <DiagramHelper.hxx>
24#include <DataSeries.hxx>
25
26#include <memory>
27#include <utility>
28#include <vector>
29
30namespace com::sun::star::chart2 { class XDataSeries; }
31
32namespace chart::wrapper
33{
34
36{
39};
40
41//PROPERTYTYPE is the type of the outer property
42
43template< typename PROPERTYTYPE >
45{
46public:
47 virtual PROPERTYTYPE getValueFromSeries( const css::uno::Reference< css::beans::XPropertySet >& xSeriesPropertySet ) const =0;
48 virtual void setValueToSeries( const css::uno::Reference< css::beans::XPropertySet >& xSeriesPropertySet, const PROPERTYTYPE & aNewValue ) const =0;
49
50 explicit WrappedSeriesOrDiagramProperty( const OUString& rName, const css::uno::Any& rDefaulValue
51 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact
52 , tSeriesOrDiagramPropertyType ePropertyType )
53 : WrappedProperty(rName,OUString())
54 , m_spChart2ModelContact(std::move(spChart2ModelContact))
55 , m_aOuterValue(rDefaulValue)
56 , m_aDefaultValue(rDefaulValue)
57 , m_ePropertyType( ePropertyType )
58 {
59 }
60
61 bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
62 {
63 rHasAmbiguousValue = false;
65 return false;
66 bool bHasDetectableInnerValue = false;
67 rtl::Reference<Diagram> xDiagram = m_spChart2ModelContact->getDiagram();
68 if (!xDiagram)
69 return false;
70 std::vector< rtl::Reference< DataSeries > > aSeriesVector =
71 xDiagram->getDataSeries();
72 for (auto const& series : aSeriesVector)
73 {
74 PROPERTYTYPE aCurValue = getValueFromSeries( series );
75 if( !bHasDetectableInnerValue )
76 rValue = aCurValue;
77 else
78 {
79 if( rValue != aCurValue )
80 {
81 rHasAmbiguousValue = true;
82 break;
83 }
84 else
85 rValue = aCurValue;
86 }
87 bHasDetectableInnerValue = true;
88 }
89 return bHasDetectableInnerValue;
90 }
91 void setInnerValue( PROPERTYTYPE aNewValue ) const
92 {
93 if( m_ePropertyType == DIAGRAM &&
95 {
96 std::vector< rtl::Reference< DataSeries > > aSeriesVector =
97 m_spChart2ModelContact->getDiagram()->getDataSeries();
98 for (auto const& series : aSeriesVector)
99 {
100 setValueToSeries( series, aNewValue );
101 }
102 }
103 }
104 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override
105 {
106 PROPERTYTYPE aNewValue = PROPERTYTYPE();
107 if( ! (rOuterValue >>= aNewValue) )
108 throw css::lang::IllegalArgumentException( "statistic property requires different type", nullptr, 0 );
109
110 if( m_ePropertyType == DIAGRAM )
111 {
112 m_aOuterValue = rOuterValue;
113
114 bool bHasAmbiguousValue = false;
115 PROPERTYTYPE aOldValue = PROPERTYTYPE();
116 if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
117 {
118 if( bHasAmbiguousValue || aNewValue != aOldValue )
119 setInnerValue( aNewValue );
120 }
121 }
122 else
123 {
124 setValueToSeries( xInnerPropertySet, aNewValue );
125 }
126 }
127
128 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override
129 {
130 if( m_ePropertyType == DIAGRAM )
131 {
132 bool bHasAmbiguousValue = false;
133 PROPERTYTYPE aValue = PROPERTYTYPE();
134 if( detectInnerValue( aValue, bHasAmbiguousValue ) )
135 {
136 if(bHasAmbiguousValue)
138 else
139 m_aOuterValue <<= aValue;
140 }
141 return m_aOuterValue;
142 }
143 else
144 {
145 css::uno::Any aRet( m_aDefaultValue );
146 aRet <<= getValueFromSeries( xInnerPropertySet );
147 return aRet;
148 }
149 }
150
151 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& /* xInnerPropertyState */ ) const override
152 {
153 return m_aDefaultValue;
154 }
155
156protected:
157 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
158 mutable css::uno::Any m_aOuterValue;
159 css::uno::Any m_aDefaultValue;
161};
162
163} //namespace chart::wrapper
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any getPropertyDefault(const css::uno::Reference< css::beans::XPropertyState > &) const override
virtual css::uno::Any getPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const override
virtual void setPropertyValue(const css::uno::Any &rOuterValue, const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const override
virtual PROPERTYTYPE getValueFromSeries(const css::uno::Reference< css::beans::XPropertySet > &xSeriesPropertySet) const =0
virtual void setValueToSeries(const css::uno::Reference< css::beans::XPropertySet > &xSeriesPropertySet, const PROPERTYTYPE &aNewValue) const =0
bool detectInnerValue(PROPERTYTYPE &rValue, bool &rHasAmbiguousValue) const
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
WrappedSeriesOrDiagramProperty(const OUString &rName, const css::uno::Any &rDefaulValue, std::shared_ptr< Chart2ModelContact > spChart2ModelContact, tSeriesOrDiagramPropertyType ePropertyType)