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

Generated by: LCOV version 1.11