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

Generated by: LCOV version 1.10