Branch data Line data Source code
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 : :
20 : : #include "RegressionCurveHelper.hxx"
21 : : #include "RegressionCurveItemConverter.hxx"
22 : : #include "SchWhichPairs.hxx"
23 : : #include "macros.hxx"
24 : : #include "ItemPropertyMap.hxx"
25 : : #include "GraphicPropertyItemConverter.hxx"
26 : :
27 : : #include <com/sun/star/chart2/XRegressionCurve.hpp>
28 : :
29 : : // for SfxBoolItem
30 : : #include <svl/eitem.hxx>
31 : : #include <svx/chrtitem.hxx>
32 : :
33 : : #include <functional>
34 : : #include <algorithm>
35 : :
36 : : using namespace ::com::sun::star;
37 : :
38 : : namespace
39 : : {
40 : :
41 : 0 : ::chart::RegressionCurveHelper::tRegressionType lcl_convertRegressionType( SvxChartRegress eRegress )
42 : : {
43 : 0 : ::chart::RegressionCurveHelper::tRegressionType eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_NONE;
44 [ # # # # : 0 : switch( eRegress )
# # ]
45 : : {
46 : : case CHREGRESS_LINEAR:
47 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR;
48 : 0 : break;
49 : : case CHREGRESS_LOG:
50 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG;
51 : 0 : break;
52 : : case CHREGRESS_EXP:
53 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP;
54 : 0 : break;
55 : : case CHREGRESS_POWER:
56 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER;
57 : 0 : break;
58 : : case CHREGRESS_NONE:
59 : 0 : break;
60 : : }
61 : 0 : return eType;
62 : : }
63 : :
64 : : } // anonymous namespace
65 : :
66 : : namespace chart
67 : : {
68 : : namespace wrapper
69 : : {
70 : :
71 : 0 : RegressionCurveItemConverter::RegressionCurveItemConverter(
72 : : const uno::Reference< beans::XPropertySet > & rPropertySet,
73 : : const uno::Reference< chart2::XRegressionCurveContainer > & xRegCurveCnt,
74 : : SfxItemPool& rItemPool,
75 : : SdrModel& rDrawModel,
76 : : const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) :
77 : : ItemConverter( rPropertySet, rItemPool ),
78 : : m_spGraphicConverter( new GraphicPropertyItemConverter(
79 : : rPropertySet, rItemPool, rDrawModel,
80 : : xNamedPropertyContainerFactory,
81 [ # # ]: 0 : GraphicPropertyItemConverter::LINE_PROPERTIES )),
82 [ # # ][ # # ]: 0 : m_xCurveContainer( xRegCurveCnt )
83 : 0 : {}
84 : :
85 [ # # ]: 0 : RegressionCurveItemConverter::~RegressionCurveItemConverter()
86 [ # # ]: 0 : {}
87 : :
88 : 0 : void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
89 : : {
90 : 0 : m_spGraphicConverter->FillItemSet( rOutItemSet );
91 : :
92 : : // own items
93 : 0 : ItemConverter::FillItemSet( rOutItemSet );
94 : 0 : }
95 : :
96 : 0 : bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
97 : : {
98 : 0 : bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet );
99 : :
100 : : // own items
101 [ # # ][ # # ]: 0 : return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
102 : : }
103 : :
104 : 0 : const sal_uInt16 * RegressionCurveItemConverter::GetWhichPairs() const
105 : : {
106 : : // must span all used items!
107 : 0 : return nRegressionCurveWhichPairs;
108 : : }
109 : :
110 : 0 : bool RegressionCurveItemConverter::GetItemProperty(
111 : : tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const
112 : : {
113 : : // No own (non-special) properties
114 : 0 : return false;
115 : : }
116 : :
117 : :
118 : 0 : bool RegressionCurveItemConverter::ApplySpecialItem(
119 : : sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
120 : : throw( uno::Exception )
121 : : {
122 [ # # ][ # # ]: 0 : uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
123 : 0 : bool bChanged = false;
124 : :
125 [ # # # # ]: 0 : switch( nWhichId )
126 : : {
127 : : case SCHATTR_REGRESSION_TYPE:
128 : : {
129 : : OSL_ASSERT( xCurve.is());
130 [ # # ]: 0 : if( xCurve.is())
131 : : {
132 : : SvxChartRegress eRegress = static_cast< SvxChartRegress >(
133 [ # # ]: 0 : static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve )));
134 : : SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >(
135 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue();
136 [ # # ]: 0 : if( eRegress != eNewRegress )
137 : : {
138 : : // note that changing the regression type changes the object
139 : : // for which this converter was created. Not optimal, but
140 : : // currently the only way to handle the type in the
141 : : // regression curve properties dialog
142 : : RegressionCurveHelper::replaceOrAddCurveAndReduceToOne(
143 : : lcl_convertRegressionType( eNewRegress ), m_xCurveContainer,
144 [ # # ]: 0 : uno::Reference< uno::XComponentContext >());
145 : : uno::Reference< beans::XPropertySet > xNewPropSet(
146 : : RegressionCurveHelper::getFirstCurveNotMeanValueLine( m_xCurveContainer ),
147 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
148 : : OSL_ASSERT( xNewPropSet.is());
149 [ # # ]: 0 : if( xNewPropSet.is())
150 : : {
151 [ # # ]: 0 : resetPropertySet( xNewPropSet );
152 : 0 : bChanged = true;
153 : 0 : }
154 : : }
155 : : }
156 : : }
157 : 0 : break;
158 : :
159 : : case SCHATTR_REGRESSION_SHOW_EQUATION:
160 : : {
161 : : OSL_ASSERT( xCurve.is());
162 [ # # ]: 0 : if( xCurve.is())
163 : : {
164 : : bool bNewShow = static_cast< sal_Bool >(
165 : : static_cast< const SfxBoolItem & >(
166 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue());
167 : :
168 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
169 : : OSL_ASSERT( xEqProp.is());
170 : 0 : bool bOldShow = false;
171 [ # # # # ]: 0 : if( xEqProp.is() &&
[ # # ][ # # ]
172 [ # # ][ # # ]: 0 : (xEqProp->getPropertyValue( C2U( "ShowEquation" )) >>= bOldShow) &&
[ # # ][ # # ]
[ # # ]
[ # # # # ]
173 : : bOldShow != bNewShow )
174 : : {
175 [ # # ][ # # ]: 0 : xEqProp->setPropertyValue( C2U( "ShowEquation" ), uno::makeAny( bNewShow ));
[ # # ][ # # ]
176 : 0 : bChanged = true;
177 : 0 : }
178 : : }
179 : : }
180 : 0 : break;
181 : :
182 : : case SCHATTR_REGRESSION_SHOW_COEFF:
183 : : {
184 : : OSL_ASSERT( xCurve.is());
185 [ # # ]: 0 : if( xCurve.is())
186 : : {
187 : : bool bNewShow = static_cast< sal_Bool >(
188 : : static_cast< const SfxBoolItem & >(
189 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue());
190 : :
191 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
192 : : OSL_ASSERT( xEqProp.is());
193 : 0 : bool bOldShow = false;
194 [ # # # # ]: 0 : if( xEqProp.is() &&
[ # # ][ # # ]
195 [ # # ][ # # ]: 0 : (xEqProp->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bOldShow) &&
[ # # ][ # # ]
[ # # ]
[ # # # # ]
196 : : bOldShow != bNewShow )
197 : : {
198 [ # # ][ # # ]: 0 : xEqProp->setPropertyValue( C2U( "ShowCorrelationCoefficient" ), uno::makeAny( bNewShow ));
[ # # ][ # # ]
199 : 0 : bChanged = true;
200 : 0 : }
201 : : }
202 : : }
203 : 0 : break;
204 : : }
205 : :
206 : 0 : return bChanged;
207 : : }
208 : :
209 : 0 : void RegressionCurveItemConverter::FillSpecialItem(
210 : : sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
211 : : throw( uno::Exception )
212 : : {
213 [ # # ][ # # ]: 0 : uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
214 : :
215 [ # # # # ]: 0 : switch( nWhichId )
216 : : {
217 : : case SCHATTR_REGRESSION_TYPE:
218 : : {
219 : : OSL_ASSERT( xCurve.is());
220 [ # # ]: 0 : if( xCurve.is())
221 : : {
222 : : SvxChartRegress eRegress = static_cast< SvxChartRegress >(
223 [ # # ]: 0 : static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve )));
224 [ # # ][ # # ]: 0 : rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
[ # # ]
225 : : }
226 : : }
227 : 0 : break;
228 : :
229 : : case SCHATTR_REGRESSION_SHOW_EQUATION:
230 : : {
231 : : OSL_ASSERT( xCurve.is());
232 [ # # ]: 0 : if( xCurve.is())
233 : : {
234 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
235 : : OSL_ASSERT( xEqProp.is());
236 : 0 : bool bShow = false;
237 [ # # # # ]: 0 : if( xEqProp.is() &&
[ # # ]
238 [ # # ][ # # ]: 0 : (xEqProp->getPropertyValue( C2U( "ShowEquation" )) >>= bShow))
[ # # ][ # # ]
[ # # ]
[ # # # # ]
239 : : {
240 [ # # ][ # # ]: 0 : rOutItemSet.Put( SfxBoolItem( nWhichId, bShow ));
[ # # ]
241 : 0 : }
242 : : }
243 : : }
244 : 0 : break;
245 : :
246 : : case SCHATTR_REGRESSION_SHOW_COEFF:
247 : : {
248 : : OSL_ASSERT( xCurve.is());
249 [ # # ]: 0 : if( xCurve.is())
250 : : {
251 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
252 : : OSL_ASSERT( xEqProp.is());
253 : 0 : bool bShow = false;
254 [ # # # # ]: 0 : if( xEqProp.is() &&
[ # # ]
255 [ # # ][ # # ]: 0 : (xEqProp->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bShow))
[ # # ][ # # ]
[ # # ]
[ # # # # ]
256 : : {
257 [ # # ][ # # ]: 0 : rOutItemSet.Put( SfxBoolItem( nWhichId, bShow ));
[ # # ]
258 : 0 : }
259 : : }
260 : : }
261 : 0 : break;
262 : 0 : }
263 : 0 : }
264 : :
265 : : } // namespace wrapper
266 : : } // namespace chart
267 : :
268 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|