LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - UncachedDataSequence.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 123 52.8 %
Date: 2012-12-27 Functions: 20 40 50.0 %
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             : 
      21             : #include "UncachedDataSequence.hxx"
      22             : #include "macros.hxx"
      23             : #include "PropertyHelper.hxx"
      24             : #include "CommonFunctors.hxx"
      25             : #include "ModifyListenerHelper.hxx"
      26             : 
      27             : #include <algorithm>
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : #include <rtl/math.hxx>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33             : using ::com::sun::star::uno::Sequence;
      34             : using ::com::sun::star::uno::Reference;
      35             : using ::com::sun::star::uno::Any;
      36             : using ::rtl::OUString;
      37             : using ::osl::MutexGuard;
      38             : 
      39             : // necessary for MS compiler
      40             : using ::comphelper::OPropertyContainer;
      41             : using ::chart::impl::UncachedDataSequence_Base;
      42             : 
      43             : namespace
      44             : {
      45           1 : static const OUString lcl_aServiceName(
      46             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.UncachedDataSequence" ));
      47             : 
      48             : enum
      49             : {
      50             :     PROP_NUMBERFORMAT_KEY,
      51             :     PROP_PROPOSED_ROLE,
      52             :     PROP_XML_RANGE
      53             : };
      54             : }  // anonymous namespace
      55             : 
      56             : 
      57             : // ____________________
      58             : namespace chart
      59             : {
      60             : 
      61         246 : UncachedDataSequence::UncachedDataSequence(
      62             :     const Reference< chart2::XInternalDataProvider > & xIntDataProv,
      63             :     const OUString & rRangeRepresentation )
      64         246 :         : OPropertyContainer( GetBroadcastHelper()),
      65         246 :           UncachedDataSequence_Base( GetMutex()),
      66             :           m_nNumberFormatKey(0),
      67             :           m_xDataProvider( xIntDataProv ),
      68             :           m_aSourceRepresentation( rRangeRepresentation ),
      69         738 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      70             : {
      71         246 :     registerProperties();
      72         246 : }
      73             : 
      74         656 : UncachedDataSequence::UncachedDataSequence(
      75             :     const Reference< chart2::XInternalDataProvider > & xIntDataProv,
      76             :     const OUString & rRangeRepresentation,
      77             :     const OUString & rRole )
      78         656 :         : OPropertyContainer( GetBroadcastHelper()),
      79         656 :           UncachedDataSequence_Base( GetMutex()),
      80             :           m_nNumberFormatKey(0),
      81             :           m_xDataProvider( xIntDataProv ),
      82             :           m_aSourceRepresentation( rRangeRepresentation ),
      83        1968 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      84             : {
      85         656 :     registerProperties();
      86         656 :     setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE, uno::makeAny( rRole ));
      87         656 : }
      88             : 
      89           0 : UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence & rSource )
      90             :         : ::comphelper::OMutexAndBroadcastHelper(),
      91           0 :           OPropertyContainer( GetBroadcastHelper()),
      92             :           ::comphelper::OPropertyArrayUsageHelper< UncachedDataSequence >(),
      93           0 :           UncachedDataSequence_Base( GetMutex()),
      94             :           m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
      95             :           m_sRole( rSource.m_sRole ),
      96             :           m_xDataProvider( rSource.m_xDataProvider ),
      97             :           m_aSourceRepresentation( rSource.m_aSourceRepresentation ),
      98           0 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      99             : {
     100           0 :     registerProperties();
     101           0 : }
     102             : 
     103        1804 : UncachedDataSequence::~UncachedDataSequence()
     104        1804 : {}
     105             : 
     106         902 : void UncachedDataSequence::registerProperties()
     107             : {
     108             :     registerProperty( C2U( "NumberFormatKey" ),
     109             :                       PROP_NUMBERFORMAT_KEY,
     110             :                       0,   // PropertyAttributes
     111             :                       & m_nNumberFormatKey,
     112         902 :                       ::getCppuType( & m_nNumberFormatKey ) );
     113             : 
     114             :     registerProperty( C2U( "Role" ),
     115             :                       PROP_PROPOSED_ROLE,
     116             :                       0,   // PropertyAttributes
     117             :                       & m_sRole,
     118         902 :                       ::getCppuType( & m_sRole ) );
     119             : 
     120             :     registerProperty( C2U( "CachedXMLRange" ),
     121             :                       PROP_XML_RANGE,
     122             :                       0,   // PropertyAttributes
     123             :                       & m_aXMLRange,
     124         902 :                       ::getCppuType( & m_aXMLRange ) );
     125         902 : }
     126             : 
     127             : // ================================================================================
     128             : 
     129           0 : Sequence< OUString > UncachedDataSequence::getSupportedServiceNames_Static()
     130             : {
     131           0 :     Sequence< OUString > aServices( 4 );
     132           0 :     aServices[ 0 ] = lcl_aServiceName;
     133           0 :     aServices[ 1 ] = C2U( "com.sun.star.chart2.data.DataSequence" );
     134           0 :     aServices[ 2 ] = C2U( "com.sun.star.chart2.data.NumericalDataSequence" );
     135           0 :     aServices[ 3 ] = C2U( "com.sun.star.chart2.data.TextualDataSequence" );
     136           0 :     return aServices;
     137             : }
     138             : 
     139       25174 : IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
     140           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
     141             : 
     142             : // ____ XPropertySet ____
     143           0 : Reference< beans::XPropertySetInfo > SAL_CALL UncachedDataSequence::getPropertySetInfo()
     144             :     throw(uno::RuntimeException)
     145             : {
     146           0 :     return Reference< beans::XPropertySetInfo >( createPropertySetInfo( getInfoHelper() ) );
     147             : }
     148             : 
     149             : // ____ ::comphelper::OPropertySetHelper ____
     150             : // __________________________________________
     151        1599 : ::cppu::IPropertyArrayHelper& UncachedDataSequence::getInfoHelper()
     152             : {
     153        1599 :     return *getArrayHelper();
     154             : }
     155             : 
     156             : // ____ ::comphelper::OPropertyArrayHelper ____
     157             : // ____________________________________________
     158           3 : ::cppu::IPropertyArrayHelper* UncachedDataSequence::createArrayHelper() const
     159             : {
     160           3 :     Sequence< beans::Property > aProps;
     161             :     // describes all properties which have been registered in the ctor
     162           3 :     describeProperties( aProps );
     163             : 
     164           3 :     return new ::cppu::OPropertyArrayHelper( aProps );
     165             : }
     166             : 
     167             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     168           0 : APPHELPER_XSERVICEINFO_IMPL( UncachedDataSequence, lcl_aServiceName )
     169             : 
     170             : // ================================================================================
     171             : 
     172             : // ________ XNumericalDataSequence ________
     173         123 : Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData()
     174             :     throw (uno::RuntimeException)
     175             : {
     176         123 :     Sequence< double > aResult;
     177         123 :     MutexGuard aGuard( GetMutex() );
     178         123 :     if( m_xDataProvider.is())
     179             :     {
     180         123 :         Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
     181         123 :         aResult.realloc( aValues.getLength());
     182         123 :         ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
     183         246 :                           aResult.getArray(), CommonFunctors::AnyToDouble());
     184             :     }
     185         123 :     return aResult;
     186             : }
     187             : 
     188             : // ________ XTextualDataSequence ________
     189         123 : Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData()
     190             :     throw (uno::RuntimeException)
     191             : {
     192         123 :     Sequence< OUString > aResult;
     193         123 :     MutexGuard aGuard( GetMutex() );
     194         123 :     if( m_xDataProvider.is())
     195             :     {
     196         123 :         Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
     197         123 :         aResult.realloc( aValues.getLength());
     198         123 :         ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
     199         246 :                           aResult.getArray(), CommonFunctors::AnyToString());
     200             :     }
     201         123 :     return aResult;
     202             : }
     203             : 
     204             : // ________ XDataSequence  ________
     205         164 : Sequence< Any > SAL_CALL UncachedDataSequence::getData()
     206             :     throw (uno::RuntimeException)
     207             : {
     208         164 :     MutexGuard aGuard( GetMutex() );
     209         164 :     if( m_xDataProvider.is())
     210         164 :         return m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation );
     211           0 :     return Sequence< Any >();
     212             : }
     213             : 
     214         123 : OUString SAL_CALL UncachedDataSequence::getSourceRangeRepresentation()
     215             :     throw (uno::RuntimeException)
     216             : {
     217         123 :     return getName();
     218             : }
     219             : 
     220             : 
     221           0 : Sequence< OUString > SAL_CALL UncachedDataSequence::generateLabel( chart2::data::LabelOrigin )
     222             :     throw (uno::RuntimeException)
     223             : {
     224             :     // auto-generated label is an empty string
     225           0 :     return Sequence< OUString >(1);
     226             : }
     227             : 
     228         123 : ::sal_Int32 SAL_CALL UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 )
     229             :     throw (lang::IndexOutOfBoundsException,
     230             :            uno::RuntimeException)
     231             : {
     232         123 :     return m_nNumberFormatKey;
     233             : }
     234             : 
     235             : // ____ XIndexReplace ____
     236           0 : void SAL_CALL UncachedDataSequence::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
     237             :     throw (lang::IllegalArgumentException,
     238             :            lang::IndexOutOfBoundsException,
     239             :            lang::WrappedTargetException,
     240             :            uno::RuntimeException)
     241             : {
     242           0 :     MutexGuard aGuard( GetMutex() );
     243           0 :     Sequence< Any > aData( getData());
     244           0 :     if( Index < aData.getLength() &&
     245           0 :         m_xDataProvider.is() )
     246             :     {
     247           0 :         aData[Index] = Element;
     248           0 :         m_xDataProvider->setDataByRangeRepresentation( m_aSourceRepresentation, aData );
     249           0 :         fireModifyEvent();
     250           0 :     }
     251           0 : }
     252             : 
     253             : // ____ XIndexAccess (base of XIndexReplace) ____
     254           0 : ::sal_Int32 SAL_CALL UncachedDataSequence::getCount()
     255             :     throw (uno::RuntimeException)
     256             : {
     257             :     OSL_FAIL( "Implement!" );
     258           0 :     return 0;
     259             : }
     260             : 
     261           0 : uno::Any SAL_CALL UncachedDataSequence::getByIndex( ::sal_Int32 )
     262             :     throw (lang::IndexOutOfBoundsException,
     263             :            lang::WrappedTargetException,
     264             :            uno::RuntimeException)
     265             : {
     266             :     OSL_FAIL( "Implement!" );
     267           0 :     return uno::Any();
     268             : }
     269             : 
     270             : // ____ XElementAccess (base of XIndexAccess) ____
     271           0 : uno::Type SAL_CALL UncachedDataSequence::getElementType()
     272             :     throw (uno::RuntimeException)
     273             : {
     274           0 :     return ::getCppuType( reinterpret_cast< uno::Any * >(0));
     275             : }
     276             : 
     277           0 : ::sal_Bool SAL_CALL UncachedDataSequence::hasElements()
     278             :     throw (uno::RuntimeException)
     279             : {
     280           0 :     if( ! m_xDataProvider.is())
     281           0 :         return sal_False;
     282           0 :     return m_xDataProvider->hasDataByRangeRepresentation( m_aSourceRepresentation );
     283             : }
     284             : 
     285             : // ____ XNamed ____
     286         123 : ::rtl::OUString SAL_CALL UncachedDataSequence::getName()
     287             :     throw (uno::RuntimeException)
     288             : {
     289         123 :     return m_aSourceRepresentation;
     290             : }
     291             : 
     292           0 : void SAL_CALL UncachedDataSequence::setName( const OUString& aName )
     293             :     throw (uno::RuntimeException)
     294             : {
     295           0 :     m_aSourceRepresentation = aName;
     296           0 :     fireModifyEvent();
     297           0 : }
     298             : 
     299             : 
     300             : 
     301           0 : Reference< util::XCloneable > SAL_CALL UncachedDataSequence::createClone()
     302             :     throw (uno::RuntimeException)
     303             : {
     304           0 :     UncachedDataSequence * pNewSeq = new UncachedDataSequence( *this );
     305           0 :     return Reference< util::XCloneable >( pNewSeq );
     306             : }
     307             : 
     308             : 
     309             : // ____ XModifiable ____
     310           0 : ::sal_Bool SAL_CALL UncachedDataSequence::isModified()
     311             :     throw (uno::RuntimeException)
     312             : {
     313           0 :     return sal_False;
     314             : }
     315             : 
     316           0 : void SAL_CALL UncachedDataSequence::setModified( ::sal_Bool bModified )
     317             :     throw (beans::PropertyVetoException,
     318             :            uno::RuntimeException)
     319             : {
     320           0 :     if( bModified )
     321           0 :         fireModifyEvent();
     322           0 : }
     323             : 
     324             : // ____ XModifyBroadcaster (base of XModifiable) ____
     325         902 : void SAL_CALL UncachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
     326             :     throw (uno::RuntimeException)
     327             : {
     328             :     try
     329             :     {
     330         902 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     331         902 :         xBroadcaster->addModifyListener( aListener );
     332             :     }
     333           0 :     catch( const uno::Exception & ex )
     334             :     {
     335             :         ASSERT_EXCEPTION( ex );
     336             :     }
     337         902 : }
     338             : 
     339         902 : void SAL_CALL UncachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     340             :     throw (uno::RuntimeException)
     341             : {
     342             :     try
     343             :     {
     344         902 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     345         902 :         xBroadcaster->removeModifyListener( aListener );
     346             :     }
     347           0 :     catch( const uno::Exception & ex )
     348             :     {
     349             :         ASSERT_EXCEPTION( ex );
     350             :     }
     351         902 : }
     352             : 
     353           0 : void UncachedDataSequence::fireModifyEvent()
     354             : {
     355             :     // @todo: currently never called, as data changes are not yet reported by
     356             :     // the data provider
     357           0 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     358           0 : }
     359             : 
     360           3 : }  // namespace chart
     361             : 
     362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10