| 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 <RegressionCurveModel.hxx> |
| 22 |
#include <RegressionCurveItemConverter.hxx> |
| 23 |
#include "SchWhichPairs.hxx" |
| 24 |
#include <GraphicPropertyItemConverter.hxx> |
| 25 |
#include <DataSeries.hxx> |
| 26 |
#include <ChartModel.hxx> |
| 27 |
|
| 28 |
#include <com/sun/star/chart2/XRegressionCurve.hpp> |
| 29 |
#include <osl/diagnose.h> |
| 30 |
|
| 31 |
#include <svl/eitem.hxx> |
| 32 |
#include <svl/intitem.hxx> |
| 33 |
#include <svl/stritem.hxx> |
| 34 |
#include <utility> |
| 35 |
|
| 36 |
using namespace ::com::sun::star; |
| 37 |
|
| 38 |
namespace |
| 39 |
{ |
| 40 |
template <class T, class D> |
| 41 |
bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID) |
| 42 |
{ |
| 43 |
OSL_ASSERT(xProperties.is()); |
| 44 |
if( xProperties.is() ) |
| 45 |
{ |
| 46 |
T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue()); |
| 47 |
T aOldValue = aValue; |
| 48 |
bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue; |
| 49 |
if (!aSuccess || aOldValue != aValue) |
| 50 |
{ |
| 51 |
xProperties->setPropertyValue( aPropertyID , uno::Any( aValue )); |
| 52 |
return true; |
| 53 |
} |
| 54 |
} |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
template <class T, class D> |
| 59 |
void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID) |
| 60 |
{ |
| 61 |
OSL_ASSERT(xProperties.is()); |
| 62 |
if( xProperties.is() ) |
| 63 |
{ |
| 64 |
T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue()); |
| 65 |
if(xProperties->getPropertyValue( aPropertyID ) >>= aValue) |
| 66 |
{ |
| 67 |
rItemSet.Put(D( nWhichId, aValue )); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
void lclConvertToItemSetDouble(SfxItemSet& rItemSet, TypedWhichId<SvxDoubleItem> nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID) |
| 73 |
{ |
| 74 |
OSL_ASSERT(xProperties.is()); |
| 75 |
if( xProperties.is() ) |
| 76 |
{ |
| 77 |
double aValue = rItemSet.Get( nWhichId ).GetValue(); |
| 78 |
if(xProperties->getPropertyValue( aPropertyID ) >>= aValue) |
| 79 |
{ |
| 80 |
rItemSet.Put(SvxDoubleItem( aValue, nWhichId )); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
} // anonymous namespace |
| 86 |
|
| 87 |
namespace chart::wrapper |
| 88 |
{ |
| 89 |
|
| 90 |
RegressionCurveItemConverter::RegressionCurveItemConverter( |
| 91 |
const uno::Reference< beans::XPropertySet >& rPropertySet, |
| 92 |
rtl::Reference< DataSeries > xContainer, |
| 93 |
SfxItemPool& rItemPool, |
| 94 |
SdrModel& rDrawModel, |
| 95 |
const rtl::Reference< ChartModel > & xChartModel ) : |
| 96 |
ItemConverter( rPropertySet, rItemPool ), |
| 97 |
m_spGraphicConverter( std::make_shared<GraphicPropertyItemConverter>( |
| 98 |
rPropertySet, rItemPool, rDrawModel, |
| 99 |
xChartModel, |
| 100 |
GraphicObjectType::LineProperties )), |
| 101 |
m_xCurveContainer(std::move( xContainer )) |
| 102 |
{} |
| 103 |
|
| 104 |
RegressionCurveItemConverter::~RegressionCurveItemConverter() |
| 105 |
{} |
| 106 |
|
| 107 |
void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const |
| 108 |
{ |
| 109 |
m_spGraphicConverter->FillItemSet( rOutItemSet ); |
| 110 |
|
| 111 |
// own items |
| 112 |
ItemConverter::FillItemSet( rOutItemSet ); |
| 113 |
} |
| 114 |
|
| 115 |
bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet ) |
| 116 |
{ |
| 117 |
bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet ); |
| 118 |
|
| 119 |
// own items |
| 120 |
return ItemConverter::ApplyItemSet( rItemSet ) || bResult; |
| 121 |
} |
| 122 |
|
| 123 |
const WhichRangesContainer& RegressionCurveItemConverter::GetWhichPairs() const |
| 124 |
{ |
| 125 |
// must span all used items! |
| 126 |
return nRegressionCurveWhichPairs; |
| 127 |
} |
| 128 |
|
| 129 |
bool RegressionCurveItemConverter::GetItemProperty( |
| 130 |
tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const |
| 131 |
{ |
| 132 |
// No own (non-special) properties |
| 133 |
return false; |
| 134 |
} |
| 135 |
|
| 136 |
bool RegressionCurveItemConverter::ApplySpecialItem( |
| 137 |
sal_uInt16 nWhichId, const SfxItemSet & rItemSet ) |
| 138 |
{ |
| 139 |
uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY ); |
| 140 |
bool bChanged = false; |
| 141 |
|
| 142 |
OSL_ASSERT(xCurve.is()); |
| 143 |
if(!xCurve.is()) |
| 144 |
return false; |
| 145 |
|
| 146 |
switch( nWhichId ) |
| 147 |
{ |
| 148 |
case SCHATTR_REGRESSION_TYPE: |
| 149 |
{ |
| 150 |
SvxChartRegress eRegress = RegressionCurveHelper::getRegressionType(xCurve); |
| 151 |
SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >( |
| 152 |
rItemSet.Get( nWhichId )).GetValue(); |
| 153 |
if( eRegress != eNewRegress ) |
| 154 |
{ |
| 155 |
// note that changing the regression type changes the object |
| 156 |
// for which this converter was created. Not optimal, but |
| 157 |
// currently the only way to handle the type in the |
| 158 |
// regression curve properties dialog |
| 159 |
xCurve = RegressionCurveHelper::changeRegressionCurveType( |
| 160 |
eNewRegress, |
| 161 |
m_xCurveContainer, |
| 162 |
xCurve); |
| 163 |
uno::Reference<beans::XPropertySet> xProperties( xCurve, uno::UNO_QUERY ); |
| 164 |
resetPropertySet( xProperties ); |
| 165 |
bChanged = true; |
| 166 |
} |
| 167 |
} |
| 168 |
break; |
| 169 |
|
| 170 |
case SCHATTR_REGRESSION_DEGREE: |
| 171 |
{ |
| 172 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 173 |
bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr); |
| 174 |
} |
| 175 |
break; |
| 176 |
|
| 177 |
case SCHATTR_REGRESSION_PERIOD: |
| 178 |
{ |
| 179 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 180 |
bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr); |
| 181 |
} |
| 182 |
break; |
| 183 |
|
| 184 |
case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD: |
| 185 |
{ |
| 186 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 187 |
bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateForward"_ustr); |
| 188 |
} |
| 189 |
break; |
| 190 |
|
| 191 |
case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD: |
| 192 |
{ |
| 193 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 194 |
bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateBackward"_ustr); |
| 195 |
} |
| 196 |
break; |
| 197 |
|
| 198 |
case SCHATTR_REGRESSION_SET_INTERCEPT: |
| 199 |
{ |
| 200 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 201 |
bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr); |
| 202 |
} |
| 203 |
break; |
| 204 |
|
| 205 |
case SCHATTR_REGRESSION_INTERCEPT_VALUE: |
| 206 |
{ |
| 207 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 208 |
bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"InterceptValue"_ustr); |
| 209 |
} |
| 210 |
break; |
| 211 |
|
| 212 |
case SCHATTR_REGRESSION_CURVE_NAME: |
| 213 |
{ |
| 214 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 215 |
bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, u"CurveName"_ustr); |
| 216 |
} |
| 217 |
break; |
| 218 |
|
| 219 |
case SCHATTR_REGRESSION_MOVING_TYPE: |
| 220 |
{ |
| 221 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 222 |
bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr); |
| 223 |
} |
| 224 |
break; |
| 225 |
|
| 226 |
case SCHATTR_REGRESSION_SHOW_EQUATION: |
| 227 |
{ |
| 228 |
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); |
| 229 |
bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowEquation"_ustr); |
| 230 |
} |
| 231 |
break; |
| 232 |
|
| 233 |
case SCHATTR_REGRESSION_XNAME: |
| 234 |
{ |
| 235 |
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); |
| 236 |
bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"XName"_ustr); |
| 237 |
} |
| 238 |
break; |
| 239 |
|
| 240 |
case SCHATTR_REGRESSION_YNAME: |
| 241 |
{ |
| 242 |
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); |
| 243 |
bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"YName"_ustr); |
| 244 |
} |
| 245 |
break; |
| 246 |
|
| 247 |
case SCHATTR_REGRESSION_SHOW_COEFF: |
| 248 |
{ |
| 249 |
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); |
| 250 |
bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowCorrelationCoefficient"_ustr); |
| 251 |
} |
| 252 |
break; |
| 253 |
|
| 254 |
} |
| 255 |
return bChanged; |
| 256 |
} |
| 257 |
|
| 258 |
void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet& rOutItemSet ) const |
| 259 |
{ |
| 260 |
uno::Reference<chart2::XRegressionCurve> xCurve(GetPropertySet(), uno::UNO_QUERY); |
| 261 |
OSL_ASSERT(xCurve.is()); |
| 262 |
if(!xCurve.is()) |
| 263 |
return; |
| 264 |
|
| 265 |
uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); |
| 266 |
|
| 267 |
switch( nWhichId ) |
| 268 |
{ |
| 269 |
case SCHATTR_REGRESSION_TYPE: |
| 270 |
{ |
| 271 |
SvxChartRegress eRegress = RegressionCurveHelper::getRegressionType(xCurve); |
| 272 |
rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE )); |
| 273 |
} |
| 274 |
break; |
| 275 |
|
| 276 |
case SCHATTR_REGRESSION_DEGREE: |
| 277 |
{ |
| 278 |
lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr); |
| 279 |
} |
| 280 |
break; |
| 281 |
|
| 282 |
case SCHATTR_REGRESSION_PERIOD: |
| 283 |
{ |
| 284 |
lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr); |
| 285 |
} |
| 286 |
break; |
| 287 |
|
| 288 |
case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD: |
| 289 |
{ |
| 290 |
lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD, xProperties, u"ExtrapolateForward"_ustr); |
| 291 |
} |
| 292 |
break; |
| 293 |
|
| 294 |
case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD: |
| 295 |
{ |
| 296 |
lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD, xProperties, u"ExtrapolateBackward"_ustr); |
| 297 |
} |
| 298 |
break; |
| 299 |
|
| 300 |
case SCHATTR_REGRESSION_SET_INTERCEPT: |
| 301 |
{ |
| 302 |
lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr); |
| 303 |
} |
| 304 |
break; |
| 305 |
|
| 306 |
case SCHATTR_REGRESSION_INTERCEPT_VALUE: |
| 307 |
{ |
| 308 |
lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_INTERCEPT_VALUE, xProperties, u"InterceptValue"_ustr); |
| 309 |
} |
| 310 |
break; |
| 311 |
|
| 312 |
case SCHATTR_REGRESSION_CURVE_NAME: |
| 313 |
{ |
| 314 |
lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, u"CurveName"_ustr); |
| 315 |
} |
| 316 |
break; |
| 317 |
|
| 318 |
case SCHATTR_REGRESSION_MOVING_TYPE: |
| 319 |
{ |
| 320 |
lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr); |
| 321 |
} |
| 322 |
break; |
| 323 |
|
| 324 |
case SCHATTR_REGRESSION_SHOW_EQUATION: |
| 325 |
{ |
| 326 |
lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"ShowEquation"_ustr); |
| 327 |
} |
| 328 |
break; |
| 329 |
|
| 330 |
case SCHATTR_REGRESSION_XNAME: |
| 331 |
{ |
| 332 |
lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"XName"_ustr); |
| 333 |
} |
| 334 |
break; |
| 335 |
|
| 336 |
case SCHATTR_REGRESSION_YNAME: |
| 337 |
{ |
| 338 |
lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"YName"_ustr); |
| 339 |
} |
| 340 |
break; |
| 341 |
|
| 342 |
case SCHATTR_REGRESSION_SHOW_COEFF: |
| 343 |
{ |
| 344 |
lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"ShowCorrelationCoefficient"_ustr); |
| 345 |
} |
| 346 |
break; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
} // namespace chart::wrapper |
| 351 |
|
| 352 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |