1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_chartcontroller.hxx" 26 #include "RegressionCurveHelper.hxx" 27 #include "RegressionCurveItemConverter.hxx" 28 #include "SchWhichPairs.hxx" 29 #include "macros.hxx" 30 #include "ItemPropertyMap.hxx" 31 #include "GraphicPropertyItemConverter.hxx" 32 33 #include <com/sun/star/chart2/XRegressionCurve.hpp> 34 35 // for SfxBoolItem 36 #include <svl/eitem.hxx> 37 #include <svx/chrtitem.hxx> 38 39 #include <functional> 40 #include <algorithm> 41 42 using namespace ::com::sun::star; 43 44 namespace 45 { 46 47 ::chart::RegressionCurveHelper::tRegressionType lcl_convertRegressionType( SvxChartRegress eRegress ) 48 { 49 ::chart::RegressionCurveHelper::tRegressionType eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_NONE; 50 switch( eRegress ) 51 { 52 case CHREGRESS_LINEAR: 53 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR; 54 break; 55 case CHREGRESS_LOG: 56 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG; 57 break; 58 case CHREGRESS_EXP: 59 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP; 60 break; 61 case CHREGRESS_POWER: 62 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER; 63 break; 64 case CHREGRESS_NONE: 65 break; 66 } 67 return eType; 68 } 69 70 } // anonymous namespace 71 72 namespace chart 73 { 74 namespace wrapper 75 { 76 77 RegressionCurveItemConverter::RegressionCurveItemConverter( 78 const uno::Reference< beans::XPropertySet > & rPropertySet, 79 const uno::Reference< chart2::XRegressionCurveContainer > & xRegCurveCnt, 80 SfxItemPool& rItemPool, 81 SdrModel& rDrawModel, 82 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) : 83 ItemConverter( rPropertySet, rItemPool ), 84 m_spGraphicConverter( new GraphicPropertyItemConverter( 85 rPropertySet, rItemPool, rDrawModel, 86 xNamedPropertyContainerFactory, 87 GraphicPropertyItemConverter::LINE_PROPERTIES )), 88 m_xCurveContainer( xRegCurveCnt ) 89 {} 90 91 RegressionCurveItemConverter::~RegressionCurveItemConverter() 92 {} 93 94 void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const 95 { 96 m_spGraphicConverter->FillItemSet( rOutItemSet ); 97 98 // own items 99 ItemConverter::FillItemSet( rOutItemSet ); 100 } 101 102 bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet ) 103 { 104 bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet ); 105 106 // own items 107 return ItemConverter::ApplyItemSet( rItemSet ) || bResult; 108 } 109 110 const sal_uInt16 * RegressionCurveItemConverter::GetWhichPairs() const 111 { 112 // must span all used items! 113 return nRegressionCurveWhichPairs; 114 } 115 116 bool RegressionCurveItemConverter::GetItemProperty( 117 tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const 118 { 119 // No own (non-special) properties 120 return false; 121 } 122 123 124 bool RegressionCurveItemConverter::ApplySpecialItem( 125 sal_uInt16 nWhichId, const SfxItemSet & rItemSet ) 126 { 127 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY ); 128 bool bChanged = false; 129 130 switch( nWhichId ) 131 { 132 case SCHATTR_REGRESSION_TYPE: 133 { 134 OSL_ASSERT( xCurve.is()); 135 if( xCurve.is()) 136 { 137 SvxChartRegress eRegress = static_cast< SvxChartRegress >( 138 static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve ))); 139 SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >( 140 rItemSet.Get( nWhichId )).GetValue(); 141 if( eRegress != eNewRegress ) 142 { 143 // note that changing the regression type changes the object 144 // for which this converter was created. Not optimal, but 145 // currently the only way to handle the type in the 146 // regression curve properties dialog 147 RegressionCurveHelper::replaceOrAddCurveAndReduceToOne( 148 lcl_convertRegressionType( eNewRegress ), m_xCurveContainer, 149 uno::Reference< uno::XComponentContext >()); 150 uno::Reference< beans::XPropertySet > xNewPropSet( 151 RegressionCurveHelper::getFirstCurveNotMeanValueLine( m_xCurveContainer ), 152 uno::UNO_QUERY ); 153 OSL_ASSERT( xNewPropSet.is()); 154 if( xNewPropSet.is()) 155 { 156 resetPropertySet( xNewPropSet ); 157 bChanged = true; 158 } 159 } 160 } 161 } 162 break; 163 164 case SCHATTR_REGRESSION_SHOW_EQUATION: 165 { 166 OSL_ASSERT( xCurve.is()); 167 if( xCurve.is()) 168 { 169 bool bNewShow = static_cast< sal_Bool >( 170 static_cast< const SfxBoolItem & >( 171 rItemSet.Get( nWhichId )).GetValue()); 172 173 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); 174 OSL_ASSERT( xEqProp.is()); 175 bool bOldShow = false; 176 if( xEqProp.is() && 177 (xEqProp->getPropertyValue( C2U( "ShowEquation" )) >>= bOldShow) && 178 bOldShow != bNewShow ) 179 { 180 xEqProp->setPropertyValue( C2U( "ShowEquation" ), uno::makeAny( bNewShow )); 181 bChanged = true; 182 } 183 } 184 } 185 break; 186 187 case SCHATTR_REGRESSION_SHOW_COEFF: 188 { 189 OSL_ASSERT( xCurve.is()); 190 if( xCurve.is()) 191 { 192 bool bNewShow = static_cast< sal_Bool >( 193 static_cast< const SfxBoolItem & >( 194 rItemSet.Get( nWhichId )).GetValue()); 195 196 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); 197 OSL_ASSERT( xEqProp.is()); 198 bool bOldShow = false; 199 if( xEqProp.is() && 200 (xEqProp->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bOldShow) && 201 bOldShow != bNewShow ) 202 { 203 xEqProp->setPropertyValue( C2U( "ShowCorrelationCoefficient" ), uno::makeAny( bNewShow )); 204 bChanged = true; 205 } 206 } 207 } 208 break; 209 } 210 211 return bChanged; 212 } 213 214 void RegressionCurveItemConverter::FillSpecialItem( 215 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const 216 { 217 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY ); 218 219 switch( nWhichId ) 220 { 221 case SCHATTR_REGRESSION_TYPE: 222 { 223 OSL_ASSERT( xCurve.is()); 224 if( xCurve.is()) 225 { 226 SvxChartRegress eRegress = static_cast< SvxChartRegress >( 227 static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve ))); 228 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE )); 229 } 230 } 231 break; 232 233 case SCHATTR_REGRESSION_SHOW_EQUATION: 234 { 235 OSL_ASSERT( xCurve.is()); 236 if( xCurve.is()) 237 { 238 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); 239 OSL_ASSERT( xEqProp.is()); 240 bool bShow = false; 241 if( xEqProp.is() && 242 (xEqProp->getPropertyValue( C2U( "ShowEquation" )) >>= bShow)) 243 { 244 rOutItemSet.Put( SfxBoolItem( nWhichId, bShow )); 245 } 246 } 247 } 248 break; 249 250 case SCHATTR_REGRESSION_SHOW_COEFF: 251 { 252 OSL_ASSERT( xCurve.is()); 253 if( xCurve.is()) 254 { 255 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); 256 OSL_ASSERT( xEqProp.is()); 257 bool bShow = false; 258 if( xEqProp.is() && 259 (xEqProp->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bShow)) 260 { 261 rOutItemSet.Put( SfxBoolItem( nWhichId, bShow )); 262 } 263 } 264 } 265 break; 266 } 267 } 268 269 } // namespace wrapper 270 } // namespace chart 271