LCOV - code coverage report
Current view: top level - chart2/source/view/main - VLegendSymbolFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 85 78.8 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 81 204 39.7 %

           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                 :            : #include "VLegendSymbolFactory.hxx"
      21                 :            : #include "macros.hxx"
      22                 :            : #include "PropertyMapper.hxx"
      23                 :            : #include "ShapeFactory.hxx"
      24                 :            : #include "ObjectIdentifier.hxx"
      25                 :            : #include <com/sun/star/drawing/LineStyle.hpp>
      26                 :            : #include <com/sun/star/chart2/Symbol.hpp>
      27                 :            : 
      28                 :            : using namespace ::com::sun::star;
      29                 :            : using ::com::sun::star::uno::Reference;
      30                 :            : using ::com::sun::star::uno::Sequence;
      31                 :            : using ::rtl::OUString;
      32                 :            : 
      33                 :            : namespace
      34                 :            : {
      35                 :       3205 : void lcl_setPropetiesToShape(
      36                 :            :     const Reference< beans::XPropertySet > & xProp,
      37                 :            :     const Reference< drawing::XShape > & xShape,
      38                 :            :     ::chart::VLegendSymbolFactory::tPropertyType ePropertyType,
      39                 :            :     const awt::Size& aMaxSymbolExtent = awt::Size(0,0))
      40                 :            : {
      41         [ +  - ]:       3205 :     const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
      42         [ +  - ]:       3205 :     const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
      43         [ +  - ]:       3205 :     const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
      44         [ +  - ]:       3205 :     const ::chart::tPropertyNameMap & aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
      45         [ +  - ]:       3205 :     const ::chart::tPropertyNameMap & aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
      46                 :            : 
      47         [ +  - ]:       3205 :     Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
      48 [ +  - ][ +  - ]:       3205 :     if( xProp.is() && xShapeProp.is() )
                 [ +  - ]
      49                 :            :     {
      50         [ +  - ]:       3205 :         ::chart::tPropertyNameValueMap aValueMap;
      51   [ +  +  +  -  :       3205 :         switch( ePropertyType )
                   -  - ]
      52                 :            :         {
      53                 :            :             case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES:
      54         [ +  - ]:       2814 :                 ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
      55                 :       2814 :                 break;
      56                 :            :             case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES:
      57         [ +  - ]:        283 :                 ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
      58                 :        283 :                 break;
      59                 :            :             case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE:
      60         [ +  - ]:        108 :                 ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
      61                 :        108 :                 break;
      62                 :            :             case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL:
      63         [ #  # ]:          0 :                 ::chart::PropertyMapper::getValueMap( aValueMap, aFillNameMap, xProp );
      64                 :          0 :                 break;
      65                 :            :             case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE:
      66         [ #  # ]:          0 :                 ::chart::PropertyMapper::getValueMap( aValueMap, aFillLineNameMap, xProp );
      67                 :          0 :                 break;
      68                 :            :         }
      69                 :            : 
      70         [ +  - ]:       3205 :         ::chart::tNameSequence aPropNames;
      71         [ +  - ]:       3205 :         ::chart::tAnySequence aPropValues;
      72         [ +  - ]:       3205 :         ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames, aPropValues, aValueMap );
      73                 :            : 
      74 [ +  - ][ +  - ]:       3205 :         uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(aPropValues,aPropNames,C2U("LineWidth"));
      75                 :       3205 :         sal_Int32 nLineWidth = 0;
      76 [ +  - ][ +  - ]:       3205 :         if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
                 [ +  - ]
      77                 :            :         {
      78                 :            :             // use legend entry height as upper limit for line width
      79                 :       3205 :             sal_Int32 nMaxLineWidthForLegend = aMaxSymbolExtent.Height;
      80         [ +  + ]:       3205 :             if( nLineWidth>nMaxLineWidthForLegend )
      81         [ +  - ]:       3205 :                 *pLineWidthAny = uno::makeAny( nMaxLineWidthForLegend );
      82                 :            :         }
      83                 :            : 
      84 [ +  - ][ +  - ]:       3205 :         ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
                 [ +  - ]
      85                 :       3205 :     }
      86                 :       3205 : }
      87                 :            : 
      88                 :            : } // anonymous namespace
      89                 :            : 
      90                 :            : namespace chart
      91                 :            : {
      92                 :            : 
      93                 :       3205 : Reference< drawing::XShape > VLegendSymbolFactory::createSymbol(
      94                 :            :     const awt::Size& rEntryKeyAspectRatio,
      95                 :            :     const Reference< drawing::XShapes > xSymbolContainer,
      96                 :            :     LegendSymbolStyle eStyle,
      97                 :            :     const Reference< lang::XMultiServiceFactory > & xShapeFactory,
      98                 :            :     const Reference< beans::XPropertySet > & xLegendEntryProperties,
      99                 :            :     tPropertyType ePropertyType, const uno::Any& rExplicitSymbol )
     100                 :            : {
     101                 :       3205 :     Reference< drawing::XShape > xResult;
     102                 :            : 
     103 [ -  + ][ +  - ]:       3205 :     if( ! (xSymbolContainer.is() && xShapeFactory.is()))
                 [ +  - ]
     104                 :            :         return xResult;
     105                 :            : 
     106         [ +  - ]:       3205 :     xResult.set( xShapeFactory->createInstance(
     107 [ +  - ][ +  - ]:       3205 :                      C2U( "com.sun.star.drawing.GroupShape" )), uno::UNO_QUERY );
                 [ +  - ]
     108 [ +  - ][ +  - ]:       3205 :     xSymbolContainer->add( xResult );
     109         [ +  - ]:       3205 :     Reference< drawing::XShapes > xResultGroup( xResult, uno::UNO_QUERY );
     110         [ +  - ]:       3205 :     if( ! xResultGroup.is())
     111                 :            :         return xResult;
     112                 :            : 
     113                 :            :     // add an invisible square box to maintain aspect ratio
     114                 :            :     Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle(
     115 [ +  - ][ +  - ]:       3205 :                 xResultGroup, rEntryKeyAspectRatio  ));
                 [ +  - ]
     116                 :            : 
     117                 :            :     // create symbol
     118                 :            :     try
     119                 :            :     {
     120         [ +  + ]:       3205 :         if( eStyle == LegendSymbolStyle_LINE )
     121                 :            :         {
     122         [ +  - ]:        391 :             Reference< drawing::XShape > xLine( xShapeFactory->createInstance(
     123 [ +  - ][ +  - ]:        391 :                     C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY );
                 [ +  - ]
     124         [ +  - ]:        391 :             if( xLine.is())
     125                 :            :             {
     126 [ +  - ][ +  - ]:        391 :                 xResultGroup->add( xLine );
     127 [ +  - ][ +  - ]:        391 :                 xLine->setSize(  awt::Size( rEntryKeyAspectRatio.Width, 0 ));
     128 [ +  - ][ +  - ]:        391 :                 xLine->setPosition( awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
     129                 :            : 
     130         [ +  - ]:        391 :                 lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType, rEntryKeyAspectRatio );
     131                 :            :             }
     132                 :            : 
     133                 :        391 :             Reference< drawing::XShape > xSymbol;
     134         [ +  - ]:        391 :             const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
     135         [ +  - ]:        391 :             chart2::Symbol aSymbol;
     136 [ +  - ][ +  + ]:        391 :             if( rExplicitSymbol >>= aSymbol )
     137                 :            :             {
     138                 :        263 :                 drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
     139                 :        263 :                 drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2, rEntryKeyAspectRatio.Height/2, 0 );
     140         [ +  - ]:        263 :                 ShapeFactory aFactory( xShapeFactory );
     141         [ -  + ]:        263 :                 if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
     142                 :            :                 {
     143                 :            :                     // take series color as fill color
     144 [ #  # ][ #  # ]:          0 :                     xLegendEntryProperties->getPropertyValue( C2U("Color")) >>= aSymbol.FillColor;
                 [ #  # ]
     145                 :            :                     // border of symbols always same as fill color
     146                 :          0 :                     aSymbol.BorderColor = aSymbol.FillColor;
     147                 :            : 
     148                 :            :                     xSymbol.set( aFactory.createSymbol2D(
     149                 :            :                                      xResultGroup,
     150                 :            :                                      aPos,
     151                 :            :                                      aSymbolSize,
     152                 :            :                                      aSymbol.StandardSymbol,
     153                 :            :                                      aSymbol.BorderColor,
     154 [ #  # ][ #  # ]:          0 :                                      aSymbol.FillColor ));
     155                 :            :                 }
     156         [ -  + ]:        263 :                 else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
     157                 :            :                 {
     158                 :            :                     xSymbol.set( aFactory.createGraphic2D(
     159                 :            :                                      xResultGroup,
     160                 :            :                                      aPos,
     161                 :            :                                      aSymbolSize,
     162 [ #  # ][ #  # ]:          0 :                                      aSymbol.Graphic ));
     163                 :            :                 }
     164                 :        263 :                 else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
     165                 :            :                 {
     166                 :            :                     OSL_TRACE("the given parameter is not allowed to contain an automatic symbol style");
     167         [ +  - ]:        263 :                 }
     168         [ +  - ]:        391 :             }
     169                 :            :         }
     170         [ -  + ]:       2814 :         else if( eStyle == LegendSymbolStyle_CIRCLE )
     171                 :            :         {
     172         [ #  # ]:          0 :             Reference< drawing::XShape > xShape( xShapeFactory->createInstance(
     173 [ #  # ][ #  # ]:          0 :                 C2U( "com.sun.star.drawing.EllipseShape" )), uno::UNO_QUERY );
                 [ #  # ]
     174         [ #  # ]:          0 :             if( xShape.is() )
     175                 :            :             {
     176 [ #  # ][ #  # ]:          0 :                 xResultGroup->add( xShape );
     177         [ #  # ]:          0 :                 sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
     178 [ #  # ][ #  # ]:          0 :                 xShape->setSize( awt::Size( nSize, nSize ) );
     179 [ #  # ][ #  # ]:          0 :                 xShape->setPosition( awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ) );
     180         [ #  # ]:          0 :                 lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
     181                 :          0 :             }
     182                 :            :         }
     183                 :            :         else // eStyle == LegendSymbolStyle_BOX
     184                 :            :         {
     185         [ +  - ]:       2814 :             Reference< drawing::XShape > xShape( xShapeFactory->createInstance(
     186 [ +  - ][ +  - ]:       2814 :                 C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY );
                 [ +  - ]
     187         [ +  - ]:       2814 :             if( xShape.is() )
     188                 :            :             {
     189 [ +  - ][ +  - ]:       2814 :                 xResultGroup->add( xShape );
     190 [ +  - ][ +  - ]:       2814 :                 xShape->setSize( rEntryKeyAspectRatio );
     191 [ +  - ][ +  - ]:       2814 :                 xShape->setPosition( awt::Point( 0, 0 ) );
     192         [ +  - ]:       2814 :                 lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
     193         [ #  # ]:       2814 :             }
     194                 :            :         }
     195                 :            :     }
     196         [ #  # ]:          0 :     catch( const uno::Exception & ex )
     197                 :            :     {
     198                 :            :         ASSERT_EXCEPTION( ex );
     199                 :            :     }
     200                 :            : 
     201                 :       3205 :     return xResult;
     202                 :            : }
     203                 :            : 
     204                 :            : } //  namespace chart
     205                 :            : 
     206                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10