LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - RegressionCurveModel.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 170 7.1 %
Date: 2012-12-27 Functions: 7 79 8.9 %
Legend: Lines: hit not hit

          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 "RegressionCurveModel.hxx"
      21             : #include "macros.hxx"
      22             : #include "LineProperties.hxx"
      23             : #include "RegressionCurveHelper.hxx"
      24             : #include "RegressionCalculationHelper.hxx"
      25             : #include "RegressionEquation.hxx"
      26             : #include "ContainerHelper.hxx"
      27             : #include "CloneHelper.hxx"
      28             : #include "PropertyHelper.hxx"
      29             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      30             : #include <rtl/math.hxx>
      31             : #include <rtl/ustrbuf.hxx>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35             : using ::rtl::OUString;
      36             : using ::rtl::OUStringBuffer;
      37             : using ::com::sun::star::beans::Property;
      38             : using ::osl::MutexGuard;
      39             : 
      40             : namespace
      41             : {
      42           1 : static const OUString lcl_aImplementationName_MeanValue(
      43             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.MeanValueRegressionCurve" ));
      44           1 : static const OUString lcl_aImplementationName_Linear(
      45             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LinearRegressionCurve" ));
      46           1 : static const OUString lcl_aImplementationName_Logarithmic(
      47             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LogarithmicRegressionCurve" ));
      48           1 : static const OUString lcl_aImplementationName_Exponential(
      49             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ExponentialRegressionCurve" ));
      50           1 : static const OUString lcl_aImplementationName_Potential(
      51             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PotentialRegressionCurve" ));
      52             : 
      53           1 : static const OUString lcl_aServiceName(
      54             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionCurve" ));
      55             : 
      56             : struct StaticXXXDefaults_Initializer
      57             : {
      58           0 :     ::chart::tPropertyValueMap* operator()()
      59             :     {
      60           0 :         static ::chart::tPropertyValueMap aStaticDefaults;
      61           0 :         lcl_AddDefaultsToMap( aStaticDefaults );
      62           0 :         return &aStaticDefaults;
      63             :     }
      64             : private:
      65           0 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      66             :     {
      67           0 :         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
      68           0 :     }
      69             : };
      70             : 
      71             : struct StaticXXXDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticXXXDefaults_Initializer >
      72             : {
      73             : };
      74             : 
      75             : struct StaticRegressionCurveInfoHelper_Initializer
      76             : {
      77           0 :     ::cppu::OPropertyArrayHelper* operator()()
      78             :     {
      79           0 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      80           0 :         return &aPropHelper;
      81             :     }
      82             : 
      83             : private:
      84           0 :     uno::Sequence< Property > lcl_GetPropertySequence()
      85             :     {
      86           0 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      87           0 :         ::chart::LineProperties::AddPropertiesToVector( aProperties );
      88             : 
      89             :         ::std::sort( aProperties.begin(), aProperties.end(),
      90           0 :                      ::chart::PropertyNameLess() );
      91             : 
      92           0 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
      93             :     }
      94             : };
      95             : 
      96             : struct StaticRegressionCurveInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionCurveInfoHelper_Initializer >
      97             : {
      98             : };
      99             : 
     100             : struct StaticRegressionCurveInfo_Initializer
     101             : {
     102           0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     103             :     {
     104             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     105           0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionCurveInfoHelper::get() ) );
     106           0 :         return &xPropertySetInfo;
     107             :     }
     108             : };
     109             : 
     110             : struct StaticRegressionCurveInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionCurveInfo_Initializer >
     111             : {
     112             : };
     113             : 
     114             : } // anonymous namespace
     115             : 
     116             : namespace chart
     117             : {
     118             : 
     119           0 : RegressionCurveModel::RegressionCurveModel(
     120             :     uno::Reference< uno::XComponentContext > const & xContext,
     121             :     tCurveType eCurveType ) :
     122             :         ::property::OPropertySet( m_aMutex ),
     123             :     m_xContext( xContext ),
     124             :     m_eRegressionCurveType( eCurveType ),
     125             :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
     126           0 :         m_xEquationProperties( new RegressionEquation( xContext ))
     127             : {
     128             :     // set 0 line width (default) hard, so that it is always written to XML,
     129             :     // because the old implementation uses different defaults
     130             :     setFastPropertyValue_NoBroadcast(
     131           0 :         LineProperties::PROP_LINE_WIDTH, uno::makeAny( sal_Int32( 0 )));
     132           0 :     ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
     133           0 : }
     134             : 
     135           0 : RegressionCurveModel::RegressionCurveModel( const RegressionCurveModel & rOther ) :
     136             :         MutexContainer(),
     137             :         impl::RegressionCurveModel_Base(),
     138             :         ::property::OPropertySet( rOther, m_aMutex ),
     139             :     m_xContext( rOther.m_xContext ),
     140             :     m_eRegressionCurveType( rOther.m_eRegressionCurveType ),
     141           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     142             : {
     143           0 :     m_xEquationProperties.set( CloneHelper::CreateRefClone< uno::Reference< beans::XPropertySet > >()( rOther.m_xEquationProperties ));
     144           0 :     ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
     145           0 : }
     146             : 
     147           0 : RegressionCurveModel::~RegressionCurveModel()
     148           0 : {}
     149             : 
     150             : // ____ XRegressionCurve ____
     151             : uno::Reference< chart2::XRegressionCurveCalculator > SAL_CALL
     152           0 :     RegressionCurveModel::getCalculator()
     153             :     throw (uno::RuntimeException)
     154             : {
     155           0 :     return RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( getServiceName());
     156             : }
     157             : 
     158           0 : uno::Reference< beans::XPropertySet > SAL_CALL RegressionCurveModel::getEquationProperties()
     159             :     throw (uno::RuntimeException)
     160             : {
     161           0 :     return m_xEquationProperties;
     162             : }
     163             : 
     164           0 : void SAL_CALL RegressionCurveModel::setEquationProperties( const uno::Reference< beans::XPropertySet >& xEquationProperties )
     165             :     throw (uno::RuntimeException)
     166             : {
     167           0 :     if( xEquationProperties.is())
     168             :     {
     169           0 :         if( m_xEquationProperties.is())
     170           0 :             ModifyListenerHelper::removeListener( m_xEquationProperties, m_xModifyEventForwarder );
     171             : 
     172           0 :         m_xEquationProperties.set( xEquationProperties );
     173           0 :         ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
     174           0 :         fireModifyEvent();
     175             :     }
     176           0 : }
     177             : 
     178             : // ____ XServiceName ____
     179           0 : ::rtl::OUString SAL_CALL RegressionCurveModel::getServiceName()
     180             :     throw (uno::RuntimeException)
     181             : {
     182           0 :     switch( m_eRegressionCurveType )
     183             :     {
     184             :         case CURVE_TYPE_MEAN_VALUE:
     185           0 :             return C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
     186             :         case CURVE_TYPE_LINEAR:
     187           0 :             return C2U( "com.sun.star.chart2.LinearRegressionCurve" );
     188             :         case CURVE_TYPE_LOGARITHM:
     189           0 :             return C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
     190             :         case CURVE_TYPE_EXPONENTIAL:
     191           0 :             return C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
     192             :         case CURVE_TYPE_POWER:
     193           0 :             return C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
     194             :     }
     195             : 
     196           0 :     return ::rtl::OUString();
     197             : }
     198             : 
     199             : // ____ XModifyBroadcaster ____
     200           0 : void SAL_CALL RegressionCurveModel::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     201             :     throw (uno::RuntimeException)
     202             : {
     203             :     try
     204             :     {
     205           0 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     206           0 :         xBroadcaster->addModifyListener( aListener );
     207             :     }
     208           0 :     catch( const uno::Exception & ex )
     209             :     {
     210             :         ASSERT_EXCEPTION( ex );
     211             :     }
     212           0 : }
     213             : 
     214           0 : void SAL_CALL RegressionCurveModel::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     215             :     throw (uno::RuntimeException)
     216             : {
     217             :     try
     218             :     {
     219           0 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     220           0 :         xBroadcaster->removeModifyListener( aListener );
     221             :     }
     222           0 :     catch( const uno::Exception & ex )
     223             :     {
     224             :         ASSERT_EXCEPTION( ex );
     225             :     }
     226           0 : }
     227             : 
     228             : // ____ XModifyListener ____
     229           0 : void SAL_CALL RegressionCurveModel::modified( const lang::EventObject& aEvent )
     230             :     throw (uno::RuntimeException)
     231             : {
     232           0 :     m_xModifyEventForwarder->modified( aEvent );
     233           0 : }
     234             : 
     235             : // ____ XEventListener (base of XModifyListener) ____
     236           0 : void SAL_CALL RegressionCurveModel::disposing( const lang::EventObject& /* Source */ )
     237             :     throw (uno::RuntimeException)
     238             : {
     239             :     // nothing
     240           0 : }
     241             : 
     242             : // ____ OPropertySet ____
     243           0 : void RegressionCurveModel::firePropertyChangeEvent()
     244             : {
     245           0 :     fireModifyEvent();
     246           0 : }
     247             : 
     248           0 : void RegressionCurveModel::fireModifyEvent()
     249             : {
     250           0 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     251           0 : }
     252             : 
     253             : // ================================================================================
     254             : 
     255             : // ____ OPropertySet ____
     256           0 : uno::Any RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle ) const
     257             :     throw(beans::UnknownPropertyException)
     258             : {
     259           0 :     const tPropertyValueMap& rStaticDefaults = *StaticXXXDefaults::get();
     260           0 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     261           0 :     if( aFound == rStaticDefaults.end() )
     262           0 :         return uno::Any();
     263           0 :     return (*aFound).second;
     264             : }
     265             : 
     266           0 : ::cppu::IPropertyArrayHelper & SAL_CALL RegressionCurveModel::getInfoHelper()
     267             : {
     268           0 :     return *StaticRegressionCurveInfoHelper::get();
     269             : }
     270             : 
     271             : // ____ XPropertySet ____
     272           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL RegressionCurveModel::getPropertySetInfo()
     273             :     throw (uno::RuntimeException)
     274             : {
     275           0 :     return *StaticRegressionCurveInfo::get();
     276             : }
     277             : 
     278             : // ================================================================================
     279             : 
     280             : // needed by MSC compiler
     281             : using impl::RegressionCurveModel_Base;
     282             : 
     283           0 : IMPLEMENT_FORWARD_XINTERFACE2( RegressionCurveModel, RegressionCurveModel_Base, OPropertySet )
     284           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( RegressionCurveModel, RegressionCurveModel_Base, OPropertySet )
     285             : 
     286             : 
     287             : 
     288             : // implementations
     289             : 
     290             : // --------------------------------------------------------------------------------
     291             : 
     292           0 : MeanValueRegressionCurve::MeanValueRegressionCurve(
     293             :     const uno::Reference< uno::XComponentContext > & xContext )
     294           0 :         : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_MEAN_VALUE )
     295           0 : {}
     296           0 : MeanValueRegressionCurve::MeanValueRegressionCurve(
     297             :     const MeanValueRegressionCurve & rOther ) :
     298           0 :         RegressionCurveModel( rOther )
     299           0 : {}
     300           0 : MeanValueRegressionCurve::~MeanValueRegressionCurve()
     301           0 : {}
     302           0 : uno::Sequence< ::rtl::OUString > MeanValueRegressionCurve::getSupportedServiceNames_Static()
     303             : {
     304           0 :     uno::Sequence< ::rtl::OUString > aServices( 2 );
     305           0 :     aServices[ 0 ] = lcl_aServiceName;
     306           0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
     307           0 :     return aServices;
     308             : }
     309             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     310           3 : APPHELPER_XSERVICEINFO_IMPL( MeanValueRegressionCurve, lcl_aImplementationName_MeanValue );
     311             : 
     312           0 : uno::Reference< util::XCloneable > SAL_CALL MeanValueRegressionCurve::createClone()
     313             :     throw (uno::RuntimeException)
     314             : {
     315           0 :     return uno::Reference< util::XCloneable >( new MeanValueRegressionCurve( *this ));
     316             : }
     317             : 
     318             : // --------------------------------------------------------------------------------
     319             : 
     320           0 : LinearRegressionCurve::LinearRegressionCurve(
     321             :     const uno::Reference< uno::XComponentContext > & xContext )
     322           0 :         : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_LINEAR )
     323           0 : {}
     324           0 : LinearRegressionCurve::LinearRegressionCurve(
     325             :     const LinearRegressionCurve & rOther ) :
     326           0 :         RegressionCurveModel( rOther )
     327           0 : {}
     328           0 : LinearRegressionCurve::~LinearRegressionCurve()
     329           0 : {}
     330           0 : uno::Sequence< ::rtl::OUString > LinearRegressionCurve::getSupportedServiceNames_Static()
     331             : {
     332           0 :     uno::Sequence< ::rtl::OUString > aServices( 2 );
     333           0 :     aServices[ 0 ] = lcl_aServiceName;
     334           0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.LinearRegressionCurve" );
     335           0 :     return aServices;
     336             : }
     337             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     338           3 : APPHELPER_XSERVICEINFO_IMPL( LinearRegressionCurve, lcl_aImplementationName_Linear );
     339             : 
     340           0 : uno::Reference< util::XCloneable > SAL_CALL LinearRegressionCurve::createClone()
     341             :     throw (uno::RuntimeException)
     342             : {
     343           0 :     return uno::Reference< util::XCloneable >( new LinearRegressionCurve( *this ));
     344             : }
     345             : 
     346             : // --------------------------------------------------------------------------------
     347             : 
     348           0 : LogarithmicRegressionCurve::LogarithmicRegressionCurve(
     349             :     const uno::Reference< uno::XComponentContext > & xContext )
     350           0 :         : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_LOGARITHM )
     351           0 : {}
     352           0 : LogarithmicRegressionCurve::LogarithmicRegressionCurve(
     353             :     const LogarithmicRegressionCurve & rOther ) :
     354           0 :         RegressionCurveModel( rOther )
     355           0 : {}
     356           0 : LogarithmicRegressionCurve::~LogarithmicRegressionCurve()
     357           0 : {}
     358           0 : uno::Sequence< ::rtl::OUString > LogarithmicRegressionCurve::getSupportedServiceNames_Static()
     359             : {
     360           0 :     uno::Sequence< ::rtl::OUString > aServices( 2 );
     361           0 :     aServices[ 0 ] = lcl_aServiceName;
     362           0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
     363           0 :     return aServices;
     364             : }
     365             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     366           3 : APPHELPER_XSERVICEINFO_IMPL( LogarithmicRegressionCurve, lcl_aImplementationName_Logarithmic );
     367             : 
     368           0 : uno::Reference< util::XCloneable > SAL_CALL LogarithmicRegressionCurve::createClone()
     369             :     throw (uno::RuntimeException)
     370             : {
     371           0 :     return uno::Reference< util::XCloneable >( new LogarithmicRegressionCurve( *this ));
     372             : }
     373             : 
     374             : // --------------------------------------------------------------------------------
     375             : 
     376           0 : ExponentialRegressionCurve::ExponentialRegressionCurve(
     377             :     const uno::Reference< uno::XComponentContext > & xContext )
     378           0 :         : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_EXPONENTIAL )
     379           0 : {}
     380           0 : ExponentialRegressionCurve::ExponentialRegressionCurve(
     381             :     const ExponentialRegressionCurve & rOther ) :
     382           0 :         RegressionCurveModel( rOther )
     383           0 : {}
     384           0 : ExponentialRegressionCurve::~ExponentialRegressionCurve()
     385           0 : {}
     386           0 : uno::Sequence< ::rtl::OUString > ExponentialRegressionCurve::getSupportedServiceNames_Static()
     387             : {
     388           0 :     uno::Sequence< ::rtl::OUString > aServices( 2 );
     389           0 :     aServices[ 0 ] = lcl_aServiceName;
     390           0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
     391           0 :     return aServices;
     392             : }
     393             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     394           3 : APPHELPER_XSERVICEINFO_IMPL( ExponentialRegressionCurve, lcl_aImplementationName_Exponential );
     395             : 
     396           0 : uno::Reference< util::XCloneable > SAL_CALL ExponentialRegressionCurve::createClone()
     397             :     throw (uno::RuntimeException)
     398             : {
     399           0 :     return uno::Reference< util::XCloneable >( new ExponentialRegressionCurve( *this ));
     400             : }
     401             : 
     402             : // --------------------------------------------------------------------------------
     403             : 
     404           0 : PotentialRegressionCurve::PotentialRegressionCurve(
     405             :     const uno::Reference< uno::XComponentContext > & xContext )
     406           0 :         : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_POWER )
     407           0 : {}
     408           0 : PotentialRegressionCurve::PotentialRegressionCurve(
     409             :     const PotentialRegressionCurve & rOther ) :
     410           0 :         RegressionCurveModel( rOther )
     411           0 : {}
     412           0 : PotentialRegressionCurve::~PotentialRegressionCurve()
     413           0 : {}
     414           0 : uno::Sequence< ::rtl::OUString > PotentialRegressionCurve::getSupportedServiceNames_Static()
     415             : {
     416           0 :     uno::Sequence< ::rtl::OUString > aServices( 2 );
     417           0 :     aServices[ 0 ] = lcl_aServiceName;
     418           0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
     419           0 :     return aServices;
     420             : }
     421             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     422           3 : APPHELPER_XSERVICEINFO_IMPL( PotentialRegressionCurve, lcl_aImplementationName_Potential );
     423             : 
     424           0 : uno::Reference< util::XCloneable > SAL_CALL PotentialRegressionCurve::createClone()
     425             :     throw (uno::RuntimeException)
     426             : {
     427           0 :     return uno::Reference< util::XCloneable >( new PotentialRegressionCurve( *this ));
     428             : }
     429             : 
     430             : 
     431           3 : } //  namespace chart
     432             : 
     433             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10