LCOV - code coverage report
Current view: top level - chart2/source/model/template - GL3DBarChartTypeTemplate.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 42 68 61.8 %
Date: 2014-11-03 Functions: 16 20 80.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             : 
      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          14 :     tPropertyValueMap* operator()()
      36             :     {
      37          14 :         static tPropertyValueMap aStaticDefaults;
      38             : 
      39          14 :         if (aStaticDefaults.empty())
      40          14 :             addDefaults(aStaticDefaults);
      41             : 
      42          14 :         return &aStaticDefaults;
      43             :     }
      44             : private:
      45             : 
      46          14 :     void addDefaults( tPropertyValueMap & rOutMap )
      47             :     {
      48          14 :         PropertyHelper::setPropertyValueDefault(rOutMap, PROP_GL3DCHARTTYPE_ROUNDED_EDGE, false);
      49          14 :     }
      50             : };
      51             : 
      52             : struct Defaults : public rtl::StaticAggregate<tPropertyValueMap, DefaultsInitializer> {};
      53             : 
      54             : struct InfoHelperInitializer
      55             : {
      56          14 :     cppu::OPropertyArrayHelper* operator()()
      57             :     {
      58          14 :         static cppu::OPropertyArrayHelper aHelper(getProperties());
      59          14 :         return &aHelper;
      60             :     }
      61             : 
      62          14 :     uno::Sequence<beans::Property> getProperties()
      63             :     {
      64          14 :         uno::Sequence<beans::Property> aRet(1);
      65             : 
      66          42 :         aRet[0] = beans::Property(
      67             :             CHART_UNONAME_ROUNDED_EDGE,
      68             :             PROP_GL3DCHARTTYPE_ROUNDED_EDGE,
      69          14 :             ::getCppuBooleanType(),
      70          14 :             beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT);
      71             : 
      72          14 :         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        7648 : GL3DBarChartTypeTemplate::GL3DBarChartTypeTemplate(
      96             :     const uno::Reference<uno::XComponentContext>& xContext, const OUString& rServiceName ) :
      97             :     property::OPropertySet(m_aMutex),
      98        7648 :     ChartTypeTemplate(xContext, rServiceName) {}
      99             : 
     100       15296 : 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        7648 : 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        7648 :     bool bResult = ChartTypeTemplate::matchesTemplate(xDiagram, bAdaptProperties);
     134             : 
     135        7648 :     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        7648 :     return bResult;
     147             : }
     148             : 
     149             : uno::Reference<chart2::XChartType>
     150        7648 : GL3DBarChartTypeTemplate::getChartTypeForNewSeries( const uno::Sequence<uno::Reference<chart2::XChartType> >& /*xOldChartTypes*/ )
     151             :     throw (css::uno::RuntimeException, ::std::exception)
     152             : {
     153        7648 :     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        7648 :         xResult.set(new GL3DBarChartType(GetComponentContext()));
     160        7648 :         uno::Reference<beans::XPropertySet> xCTProp(xResult, uno::UNO_QUERY);
     161        7648 :         if (xCTProp.is())
     162             :         {
     163        7648 :             bool bVal = false;
     164        7648 :             getFastPropertyValue(PROP_GL3DCHARTTYPE_ROUNDED_EDGE) >>= bVal;
     165        7648 :             xCTProp->setPropertyValue(CHART_UNONAME_ROUNDED_EDGE, uno::makeAny(bVal));
     166        7648 :         }
     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        7648 :     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        7648 : css::uno::Any GL3DBarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
     189             :     throw (css::beans::UnknownPropertyException)
     190             : {
     191        7648 :     const tPropertyValueMap& rDefaults = *Defaults::get();
     192        7648 :     tPropertyValueMap::const_iterator it = rDefaults.find(nHandle);
     193        7648 :     return it == rDefaults.end() ? uno::Any() : it->second;
     194             : }
     195             : 
     196        7648 : cppu::IPropertyArrayHelper& GL3DBarChartTypeTemplate::getInfoHelper()
     197             : {
     198        7648 :     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       61184 : IMPLEMENT_FORWARD_XINTERFACE2(GL3DBarChartTypeTemplate, ChartTypeTemplate, OPropertySet)
     208             : 
     209         108 : }
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10