LCOV - code coverage report
Current view: top level - chart2/source/tools - RegressionEquation.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 112 55.4 %
Date: 2012-08-25 Functions: 17 32 53.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 60 224 26.8 %

           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                 :            : 
      21                 :            : #include "RegressionEquation.hxx"
      22                 :            : #include "LineProperties.hxx"
      23                 :            : #include "FillProperties.hxx"
      24                 :            : #include "UserDefinedProperties.hxx"
      25                 :            : #include "CharacterProperties.hxx"
      26                 :            : #include "PropertyHelper.hxx"
      27                 :            : #include "macros.hxx"
      28                 :            : #include "ContainerHelper.hxx"
      29                 :            : 
      30                 :            : #include <com/sun/star/uno/Sequence.hxx>
      31                 :            : #include <com/sun/star/drawing/FillStyle.hpp>
      32                 :            : #include <com/sun/star/drawing/LineStyle.hpp>
      33                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      34                 :            : #include <com/sun/star/chart2/RelativePosition.hpp>
      35                 :            : #include <com/sun/star/awt/Size.hpp>
      36                 :            : 
      37                 :            : #include <algorithm>
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : 
      41                 :            : using ::com::sun::star::uno::Reference;
      42                 :            : using ::com::sun::star::beans::Property;
      43                 :            : using ::osl::MutexGuard;
      44                 :            : 
      45                 :            : // ____________________________________________________________
      46                 :            : 
      47                 :            : namespace
      48                 :            : {
      49                 :            : 
      50                 :         16 : static const ::rtl::OUString lcl_aImplementationName(
      51                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.RegressionEquation" ));
      52                 :         16 : static const ::rtl::OUString lcl_aServiceName(
      53                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" ));
      54                 :            : 
      55                 :            : enum
      56                 :            : {
      57                 :            :     PROP_EQUATION_SHOW,
      58                 :            :     PROP_EQUATION_SHOW_CORRELATION_COEFF,
      59                 :            :     PROP_EQUATION_REF_PAGE_SIZE,
      60                 :            :     PROP_EQUATION_REL_POS,
      61                 :            :     PROP_EQUATION_NUMBER_FORMAT
      62                 :            : };
      63                 :            : 
      64                 :          2 : void lcl_AddPropertiesToVector(
      65                 :            :     ::std::vector< Property > & rOutProperties )
      66                 :            : {
      67                 :            :     rOutProperties.push_back(
      68                 :            :         Property( C2U( "ShowEquation" ),
      69                 :            :                   PROP_EQUATION_SHOW,
      70         [ +  - ]:          2 :                   ::getBooleanCppuType(),
      71                 :            :                   beans::PropertyAttribute::BOUND
      72 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      73                 :            : 
      74                 :            :     rOutProperties.push_back(
      75                 :            :         Property( C2U( "ShowCorrelationCoefficient" ),
      76                 :            :                   PROP_EQUATION_SHOW_CORRELATION_COEFF,
      77         [ +  - ]:          2 :                   ::getBooleanCppuType(),
      78                 :            :                   beans::PropertyAttribute::BOUND
      79 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      80                 :            : 
      81                 :            :     rOutProperties.push_back(
      82                 :            :         Property( C2U( "ReferencePageSize" ),
      83                 :            :                   PROP_EQUATION_REF_PAGE_SIZE,
      84         [ +  - ]:          2 :                   ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
      85                 :            :                   beans::PropertyAttribute::BOUND
      86 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEVOID ));
      87                 :            : 
      88                 :            :     rOutProperties.push_back(
      89                 :            :         Property( C2U( "RelativePosition" ),
      90                 :            :                   PROP_EQUATION_REL_POS,
      91         [ +  - ]:          2 :                   ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
      92                 :            :                   beans::PropertyAttribute::BOUND
      93 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEVOID ));
      94                 :            : 
      95                 :            :     rOutProperties.push_back(
      96                 :            :         Property( C2U( "NumberFormat" ),
      97                 :            :                   PROP_EQUATION_NUMBER_FORMAT,
      98         [ +  - ]:          2 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
      99                 :            :                   beans::PropertyAttribute::BOUND
     100 [ +  - ][ +  - ]:          2 :                   | beans::PropertyAttribute::MAYBEVOID ));
     101                 :          2 : }
     102                 :            : 
     103                 :            : struct StaticRegressionEquationDefaults_Initializer
     104                 :            : {
     105                 :          2 :     ::chart::tPropertyValueMap* operator()()
     106                 :            :     {
     107 [ +  - ][ +  - ]:          2 :         static ::chart::tPropertyValueMap aStaticDefaults;
         [ +  - ][ #  # ]
     108                 :          2 :         lcl_AddDefaultsToMap( aStaticDefaults );
     109                 :          2 :         return &aStaticDefaults;
     110                 :            :     }
     111                 :            : private:
     112                 :          2 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
     113                 :            :     {
     114         [ +  - ]:          2 :         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
     115         [ +  - ]:          2 :         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
     116         [ +  - ]:          2 :         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
     117                 :            : 
     118         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
     119         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
     120                 :            :         //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, ::rtl::OUString( sal_Unicode( '\n' )));
     121                 :            : 
     122                 :            :         // override other defaults
     123         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
     124         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
     125                 :            : 
     126                 :          2 :         float fDefaultCharHeight = 10.0;
     127         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
     128         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
     129         [ +  - ]:          2 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
     130                 :          2 :     }
     131                 :            : };
     132                 :            : 
     133                 :            : struct StaticRegressionEquationDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticRegressionEquationDefaults_Initializer >
     134                 :            : {
     135                 :            : };
     136                 :            : 
     137                 :            : struct StaticRegressionEquationInfoHelper_Initializer
     138                 :            : {
     139                 :          2 :     ::cppu::OPropertyArrayHelper* operator()()
     140                 :            :     {
     141 [ +  - ][ +  - ]:          2 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     142                 :          2 :         return &aPropHelper;
     143                 :            :     }
     144                 :            : 
     145                 :            : private:
     146                 :          2 :     uno::Sequence< Property > lcl_GetPropertySequence()
     147                 :            :     {
     148         [ +  - ]:          2 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     149         [ +  - ]:          2 :         lcl_AddPropertiesToVector( aProperties );
     150         [ +  - ]:          2 :         ::chart::LineProperties::AddPropertiesToVector( aProperties );
     151         [ +  - ]:          2 :         ::chart::FillProperties::AddPropertiesToVector( aProperties );
     152         [ +  - ]:          2 :         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
     153         [ +  - ]:          2 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
     154                 :            : 
     155                 :            :         ::std::sort( aProperties.begin(), aProperties.end(),
     156         [ +  - ]:          2 :                      ::chart::PropertyNameLess() );
     157                 :            : 
     158         [ +  - ]:          2 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     159                 :            :     }
     160                 :            : 
     161                 :            : };
     162                 :            : 
     163                 :            : struct StaticRegressionEquationInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionEquationInfoHelper_Initializer >
     164                 :            : {
     165                 :            : };
     166                 :            : 
     167                 :            : struct StaticRegressionEquationInfo_Initializer
     168                 :            : {
     169                 :          0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     170                 :            :     {
     171                 :            :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     172 [ #  # ][ #  # ]:          0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     173                 :          0 :         return &xPropertySetInfo;
     174                 :            :     }
     175                 :            : };
     176                 :            : 
     177                 :            : struct StaticRegressionEquationInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionEquationInfo_Initializer >
     178                 :            : {
     179                 :            : };
     180                 :            : 
     181                 :            : } // anonymous namespace
     182                 :            : 
     183                 :            : // ____________________________________________________________
     184                 :            : 
     185                 :            : namespace chart
     186                 :            : {
     187                 :            : 
     188                 :         14 : RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) :
     189                 :            :         ::property::OPropertySet( m_aMutex ),
     190                 :          0 :         m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
     191 [ +  - ][ +  - ]:         14 :         m_xContext( xContext )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     192                 :         14 : {}
     193                 :            : 
     194                 :          0 : RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) :
     195                 :            :         MutexContainer(),
     196                 :            :         impl::RegressionEquation_Base(),
     197                 :            :         ::property::OPropertySet( rOther, m_aMutex ),
     198                 :          0 :     m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
     199 [ #  # ][ #  # ]:          0 :     m_xContext( NULL )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     200                 :          0 : {}
     201                 :            : 
     202 [ +  - ][ +  - ]:         14 : RegressionEquation::~RegressionEquation()
                 [ +  - ]
     203         [ -  + ]:         28 : {}
     204                 :            : 
     205                 :            : 
     206                 :            : // ____ XCloneable ____
     207                 :          0 : uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone()
     208                 :            :     throw (uno::RuntimeException)
     209                 :            : {
     210 [ #  # ][ #  # ]:          0 :     return uno::Reference< util::XCloneable >( new RegressionEquation( *this ));
     211                 :            : }
     212                 :            : 
     213                 :            : // ____ OPropertySet ____
     214                 :        248 : uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const
     215                 :            :     throw(beans::UnknownPropertyException)
     216                 :            : {
     217         [ +  - ]:        248 :     const tPropertyValueMap& rStaticDefaults = *StaticRegressionEquationDefaults::get();
     218         [ +  - ]:        248 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     219         [ -  + ]:        248 :     if( aFound == rStaticDefaults.end() )
     220                 :          0 :         return uno::Any();
     221                 :        248 :     return (*aFound).second;
     222                 :            : }
     223                 :            : 
     224                 :        496 : ::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper()
     225                 :            : {
     226                 :        496 :     return *StaticRegressionEquationInfoHelper::get();
     227                 :            : }
     228                 :            : 
     229                 :            : // ____ XPropertySet ____
     230                 :          0 : Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo()
     231                 :            :     throw (uno::RuntimeException)
     232                 :            : {
     233                 :          0 :     return *StaticRegressionEquationInfo::get();
     234                 :            : }
     235                 :            : 
     236                 :            : // ____ XModifyBroadcaster ____
     237                 :         14 : void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     238                 :            :     throw (uno::RuntimeException)
     239                 :            : {
     240                 :            :     try
     241                 :            :     {
     242         [ +  - ]:         14 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     243 [ +  - ][ +  - ]:         14 :         xBroadcaster->addModifyListener( aListener );
                 [ #  # ]
     244                 :            :     }
     245                 :          0 :     catch( const uno::Exception & ex )
     246                 :            :     {
     247                 :            :         ASSERT_EXCEPTION( ex );
     248                 :            :     }
     249                 :         14 : }
     250                 :            : 
     251                 :          0 : void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     252                 :            :     throw (uno::RuntimeException)
     253                 :            : {
     254                 :            :     try
     255                 :            :     {
     256         [ #  # ]:          0 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     257 [ #  # ][ #  # ]:          0 :         xBroadcaster->removeModifyListener( aListener );
                 [ #  # ]
     258                 :            :     }
     259                 :          0 :     catch( const uno::Exception & ex )
     260                 :            :     {
     261                 :            :         ASSERT_EXCEPTION( ex );
     262                 :            :     }
     263                 :          0 : }
     264                 :            : 
     265                 :            : // ____ XModifyListener ____
     266                 :          0 : void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
     267                 :            :     throw (uno::RuntimeException)
     268                 :            : {
     269                 :          0 :     m_xModifyEventForwarder->modified( aEvent );
     270                 :          0 : }
     271                 :            : 
     272                 :            : // ____ XEventListener (base of XModifyListener) ____
     273                 :          0 : void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
     274                 :            :     throw (uno::RuntimeException)
     275                 :            : {
     276                 :            :     // nothing
     277                 :          0 : }
     278                 :            : 
     279                 :            : // ____ OPropertySet ____
     280                 :          0 : void RegressionEquation::firePropertyChangeEvent()
     281                 :            : {
     282                 :          0 :     fireModifyEvent();
     283                 :          0 : }
     284                 :            : 
     285                 :          0 : void RegressionEquation::fireModifyEvent()
     286                 :            : {
     287 [ #  # ][ #  # ]:          0 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
                 [ #  # ]
     288                 :          0 : }
     289                 :            : 
     290                 :            : // --------------------------------------------------------------------------------
     291                 :            : 
     292                 :            : // ____ XTitle ____
     293                 :          0 : uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText()
     294                 :            :     throw (uno::RuntimeException)
     295                 :            : {
     296 [ #  # ][ #  # ]:          0 :     MutexGuard aGuard( GetMutex() );
     297 [ #  # ][ #  # ]:          0 :     return m_aStrings;
     298                 :            : }
     299                 :            : 
     300                 :          0 : void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings )
     301                 :            :     throw (uno::RuntimeException)
     302                 :            : {
     303 [ #  # ][ #  # ]:          0 :     MutexGuard aGuard( GetMutex() );
     304                 :            :     ModifyListenerHelper::removeListenerFromAllElements(
     305 [ #  # ][ #  # ]:          0 :         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
     306         [ #  # ]:          0 :     m_aStrings = Strings;
     307                 :            :     ModifyListenerHelper::addListenerToAllElements(
     308 [ #  # ][ #  # ]:          0 :         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
     309 [ #  # ][ #  # ]:          0 :     fireModifyEvent();
     310                 :          0 : }
     311                 :            : 
     312                 :            : // ================================================================================
     313                 :            : 
     314                 :          0 : uno::Sequence< ::rtl::OUString > RegressionEquation::getSupportedServiceNames_Static()
     315                 :            : {
     316                 :          0 :     const sal_Int32 nNumServices( 5 );
     317                 :          0 :     sal_Int32 nI = 0;
     318                 :          0 :     uno::Sequence< ::rtl::OUString > aServices( nNumServices );
     319         [ #  # ]:          0 :     aServices[ nI++ ] = lcl_aServiceName;
     320 [ #  # ][ #  # ]:          0 :     aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" );
     321 [ #  # ][ #  # ]:          0 :     aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" );
     322 [ #  # ][ #  # ]:          0 :     aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" );
     323 [ #  # ][ #  # ]:          0 :     aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" );
     324                 :            :     OSL_ASSERT( nNumServices == nI );
     325                 :          0 :     return aServices;
     326                 :            : }
     327                 :            : 
     328                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     329 [ #  # ][ #  # ]:         30 : APPHELPER_XSERVICEINFO_IMPL( RegressionEquation, lcl_aImplementationName );
         [ #  # ][ #  # ]
                 [ #  # ]
     330                 :            : 
     331                 :            : using impl::RegressionEquation_Base;
     332                 :            : 
     333 [ -  + ][ #  # ]:        318 : IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet )
     334                 :            : 
     335 [ +  - ][ +  - ]:         48 : } //  namespace chart
     336                 :            : 
     337                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10