LCOV - code coverage report
Current view: top level - chart2/source/model/template - GL3DBarChartTypeTemplate.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 41 67 61.2 %
Date: 2014-04-11 Functions: 14 18 77.8 %
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             : 
      10             : #include "GL3DBarChartTypeTemplate.hxx"
      11             : #include "GL3DBarChartType.hxx"
      12             : 
      13             : #include <servicenames_charttypes.hxx>
      14             : #include <PropertyHelper.hxx>
      15             : #include <DiagramHelper.hxx>
      16             : #include <unonames.hxx>
      17             : #include <macros.hxx>
      18             : 
      19             : #include <com/sun/star/beans/Property.hpp>
      20             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      21             : 
      22             : using namespace com::sun::star;
      23             : 
      24             : namespace chart {
      25             : 
      26             : namespace {
      27             : 
      28             : enum
      29             : {
      30             :     PROP_GL3DCHARTTYPE_ROUNDED_EDGE
      31             : };
      32             : 
      33             : struct DefaultsInitializer
      34             : {
      35           5 :     tPropertyValueMap* operator()()
      36             :     {
      37           5 :         static tPropertyValueMap aStaticDefaults;
      38             : 
      39           5 :         if (aStaticDefaults.empty())
      40           5 :             addDefaults(aStaticDefaults);
      41             : 
      42           5 :         return &aStaticDefaults;
      43             :     }
      44             : private:
      45             : 
      46           5 :     void addDefaults( tPropertyValueMap & rOutMap )
      47             :     {
      48           5 :         PropertyHelper::setPropertyValueDefault(rOutMap, PROP_GL3DCHARTTYPE_ROUNDED_EDGE, false);
      49           5 :     }
      50             : };
      51             : 
      52             : struct Defaults : public rtl::StaticAggregate<tPropertyValueMap, DefaultsInitializer> {};
      53             : 
      54             : struct InfoHelperInitializer
      55             : {
      56           5 :     cppu::OPropertyArrayHelper* operator()()
      57             :     {
      58           5 :         static cppu::OPropertyArrayHelper aHelper(getProperties());
      59           5 :         return &aHelper;
      60             :     }
      61             : 
      62           5 :     uno::Sequence<beans::Property> getProperties()
      63             :     {
      64           5 :         uno::Sequence<beans::Property> aRet(1);
      65             : 
      66          15 :         aRet[0] = beans::Property(
      67             :             CHART_UNONAME_ROUNDED_EDGE,
      68             :             PROP_GL3DCHARTTYPE_ROUNDED_EDGE,
      69           5 :             ::getCppuBooleanType(),
      70           5 :             beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT);
      71             : 
      72           5 :         return aRet;
      73             :     }
      74             : };
      75             : 
      76             : struct InfoHelper : public rtl::StaticAggregate<cppu::OPropertyArrayHelper, InfoHelperInitializer> {};
      77             : 
      78             : struct ChartTypeInfoInitializer
      79             : {
      80           0 :     uno::Reference<beans::XPropertySetInfo>* operator()()
      81             :     {
      82           0 :         static uno::Reference<beans::XPropertySetInfo> xPropertySetInfo;
      83             : 
      84           0 :         if (!xPropertySetInfo.is())
      85           0 :             xPropertySetInfo = cppu::OPropertySetHelper::createPropertySetInfo(*InfoHelper::get());
      86             : 
      87           0 :         return &xPropertySetInfo;
      88             :     }
      89             : };
      90             : 
      91             : struct ChartTypeInfo : public rtl::StaticAggregate<uno::Reference<beans::XPropertySetInfo>, ChartTypeInfoInitializer> {};
      92             : 
      93             : }
      94             : 
      95        2534 : GL3DBarChartTypeTemplate::GL3DBarChartTypeTemplate(
      96             :     const uno::Reference<uno::XComponentContext>& xContext, const OUString& rServiceName ) :
      97             :     property::OPropertySet(m_aMutex),
      98        2534 :     ChartTypeTemplate(xContext, rServiceName) {}
      99             : 
     100        5068 : GL3DBarChartTypeTemplate::~GL3DBarChartTypeTemplate() {}
     101             : 
     102           0 : uno::Reference<chart2::XChartType> GL3DBarChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
     103             : {
     104           0 :     uno::Reference<chart2::XChartType> xResult;
     105             : 
     106             :     try
     107             :     {
     108             :         uno::Reference<lang::XMultiServiceFactory> xFact(
     109           0 :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW);
     110             : 
     111           0 :         xResult.set(xFact->createInstance(CHART2_SERVICE_NAME_CHARTTYPE_GL3DBAR), uno::UNO_QUERY_THROW);
     112             : 
     113           0 :         uno::Reference<beans::XPropertySet> xCTProp(xResult, uno::UNO_QUERY);
     114           0 :         if (xCTProp.is())
     115             :         {
     116           0 :             xCTProp->setPropertyValue(
     117           0 :                 CHART_UNONAME_ROUNDED_EDGE, getFastPropertyValue(PROP_GL3DCHARTTYPE_ROUNDED_EDGE));
     118           0 :         }
     119             :     }
     120           0 :     catch (const uno::Exception & ex)
     121             :     {
     122             :         ASSERT_EXCEPTION( ex );
     123             :     }
     124             : 
     125           0 :     return xResult;
     126             : }
     127             : 
     128        2534 : sal_Bool SAL_CALL GL3DBarChartTypeTemplate::matchesTemplate(
     129             :     const css::uno::Reference<css::chart2::XDiagram>& xDiagram,
     130             :     sal_Bool bAdaptProperties )
     131             :     throw (css::uno::RuntimeException, std::exception)
     132             : {
     133        2534 :     bool bResult = ChartTypeTemplate::matchesTemplate(xDiagram, bAdaptProperties);
     134             : 
     135        2534 :     if (bResult && bAdaptProperties)
     136             :     {
     137           0 :         uno::Reference<chart2::XChartType> xChartType = DiagramHelper::getChartTypeByIndex(xDiagram, 0);
     138           0 :         uno::Reference<beans::XPropertySet> xPS(xChartType, uno::UNO_QUERY);
     139           0 :         if (xPS.is())
     140             :         {
     141             :             setFastPropertyValue_NoBroadcast(
     142           0 :                 PROP_GL3DCHARTTYPE_ROUNDED_EDGE, xPS->getPropertyValue(CHART_UNONAME_ROUNDED_EDGE));
     143           0 :         }
     144             :     }
     145             : 
     146        2534 :     return bResult;
     147             : }
     148             : 
     149             : uno::Reference<chart2::XChartType>
     150        2534 : GL3DBarChartTypeTemplate::getChartTypeForNewSeries( const uno::Sequence<uno::Reference<chart2::XChartType> >& /*xOldChartTypes*/ )
     151             :     throw (::css::uno::RuntimeException, ::std::exception)
     152             : {
     153        2534 :     uno::Reference<chart2::XChartType> xResult;
     154             : 
     155             :     try
     156             :     {
     157             : #if 1
     158             :         // I gave up trying to use UNO just to instantiate this little thing...
     159        2534 :         xResult.set(new GL3DBarChartType(GetComponentContext()));
     160        2534 :         uno::Reference<beans::XPropertySet> xCTProp(xResult, uno::UNO_QUERY);
     161        2534 :         if (xCTProp.is())
     162             :         {
     163        2534 :             bool bVal = false;
     164        2534 :             getFastPropertyValue(PROP_GL3DCHARTTYPE_ROUNDED_EDGE) >>= bVal;
     165        2534 :             xCTProp->setPropertyValue(CHART_UNONAME_ROUNDED_EDGE, uno::makeAny(bVal));
     166        2534 :         }
     167             : #else
     168             :         // This never works for me.
     169             :         uno::Reference<lang::XMultiServiceFactory> xFact(
     170             :             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW);
     171             :         xResult.set(xFact->createInstance(CHART2_SERVICE_NAME_CHARTTYPE_GL3DBAR), uno::UNO_QUERY_THROW);
     172             : #endif
     173             :     }
     174           0 :     catch (const uno::Exception & ex)
     175             :     {
     176             :         ASSERT_EXCEPTION( ex );
     177             :     }
     178             : 
     179        2534 :     return xResult;
     180             : }
     181             : 
     182           0 : sal_Bool GL3DBarChartTypeTemplate::supportsCategories()
     183             :     throw (::css::uno::RuntimeException, ::std::exception)
     184             : {
     185           0 :     return false;
     186             : }
     187             : 
     188        2534 : css::uno::Any GL3DBarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
     189             :     throw (css::beans::UnknownPropertyException)
     190             : {
     191        2534 :     const tPropertyValueMap& rDefaults = *Defaults::get();
     192        2534 :     tPropertyValueMap::const_iterator it = rDefaults.find(nHandle);
     193        2534 :     return it == rDefaults.end() ? uno::Any() : it->second;
     194             : }
     195             : 
     196        2534 : cppu::IPropertyArrayHelper& GL3DBarChartTypeTemplate::getInfoHelper()
     197             : {
     198        2534 :     return *InfoHelper::get();
     199             : }
     200             : 
     201           0 : css::uno::Reference<css::beans::XPropertySetInfo> GL3DBarChartTypeTemplate::getPropertySetInfo()
     202             :     throw (css::uno::RuntimeException, std::exception)
     203             : {
     204           0 :     return *ChartTypeInfo::get();
     205             : }
     206             : 
     207       20272 : IMPLEMENT_FORWARD_XINTERFACE2(GL3DBarChartTypeTemplate, ChartTypeTemplate, OPropertySet)
     208             : 
     209             : }
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10