LCOV - code coverage report
Current view: top level - chart2/source/view/main - VLegendSymbolFactory.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 62 75 82.7 %
Date: 2014-04-11 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        1975 : 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        1975 :     const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
      42        1975 :     const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
      43        1975 :     const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
      44        1975 :     const ::chart::tPropertyNameMap & aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
      45        1975 :     const ::chart::tPropertyNameMap & aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
      46             : 
      47        1975 :     ::chart::tPropertyNameValueMap aValueMap;
      48        1975 :     switch( ePropertyType )
      49             :     {
      50             :         case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES:
      51        1770 :             ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
      52        1770 :             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          53 :             ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
      58          53 :             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        1975 :     ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( rNames, rValues, aValueMap );
      68             : 
      69        1975 :     uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(rValues,rNames,"LineWidth");
      70        1975 :     sal_Int32 nLineWidth = 0;
      71        1975 :     if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
      72             :     {
      73             :         // use legend entry height as upper limit for line width
      74        1975 :         sal_Int32 nMaxLineWidthForLegend = aMaxSymbolExtent.Height;
      75        1975 :         if( nLineWidth>nMaxLineWidthForLegend )
      76          10 :             *pLineWidthAny = uno::makeAny( nMaxLineWidthForLegend );
      77        1975 :     }
      78        1975 : }
      79             : 
      80         205 : 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         205 :     ::chart::tNameSequence aPropNames;
      87         410 :     ::chart::tAnySequence aPropValues;
      88             :     getPropNamesAndValues( xProp, aPropNames, aPropValues,
      89         205 :             ePropertyType, aMaxSymbolExtent );
      90             : 
      91         410 :     Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
      92         410 :     ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
      93         205 : }
      94             : 
      95             : } // anonymous namespace
      96             : 
      97             : namespace chart
      98             : {
      99             : 
     100        1975 : Reference< drawing::XShape > VLegendSymbolFactory::createSymbol(
     101             :     const awt::Size& rEntryKeyAspectRatio,
     102             :     const Reference< drawing::XShapes > xSymbolContainer,
     103             :     LegendSymbolStyle eStyle,
     104             :     const Reference< lang::XMultiServiceFactory > & xShapeFactory,
     105             :     const Reference< beans::XPropertySet > & xLegendEntryProperties,
     106             :     tPropertyType ePropertyType, const uno::Any& rExplicitSymbol )
     107             : {
     108        1975 :     Reference< drawing::XShape > xResult;
     109             : 
     110        1975 :     if( ! (xSymbolContainer.is() && xShapeFactory.is()))
     111           0 :         return xResult;
     112             : 
     113        1975 :     AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(xShapeFactory);
     114        1975 :     xResult.set( pShapeFactory->createGroup2D( xSymbolContainer ), uno::UNO_QUERY );
     115             : 
     116        3950 :     Reference< drawing::XShapes > xResultGroup( xResult, uno::UNO_QUERY );
     117        1975 :     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        3950 :                 xResultGroup, rEntryKeyAspectRatio  ));
     123             : 
     124             :     // create symbol
     125             :     try
     126             :     {
     127        1975 :         if( eStyle == LegendSymbolStyle_LINE )
     128             :         {
     129             :             Reference< drawing::XShape > xLine =
     130             :                 pShapeFactory->createLine( xResultGroup, awt::Size( rEntryKeyAspectRatio.Width, 0 ),
     131         205 :                         awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
     132         205 :             if( xLine.is())
     133             :             {
     134         205 :                 lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType, rEntryKeyAspectRatio );
     135             :             }
     136             : 
     137         410 :             Reference< drawing::XShape > xSymbol;
     138         205 :             const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
     139         410 :             chart2::Symbol aSymbol;
     140         205 :             if( rExplicitSymbol >>= aSymbol )
     141             :             {
     142         141 :                 drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
     143         141 :                 drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2, rEntryKeyAspectRatio.Height/2, 0 );
     144         141 :                 AbstractShapeFactory* pFactory = AbstractShapeFactory::getOrCreateShapeFactory( xShapeFactory );
     145         141 :                 if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
     146             :                 {
     147             :                     // take series color as fill color
     148          25 :                     xLegendEntryProperties->getPropertyValue( "Color") >>= aSymbol.FillColor;
     149             :                     // border of symbols always same as fill color
     150          25 :                     aSymbol.BorderColor = aSymbol.FillColor;
     151             : 
     152             :                     xSymbol.set( pFactory->createSymbol2D(
     153             :                                      xResultGroup,
     154             :                                      aPos,
     155             :                                      aSymbolSize,
     156             :                                      aSymbol.StandardSymbol,
     157             :                                      aSymbol.BorderColor,
     158          25 :                                      aSymbol.FillColor ));
     159             :                 }
     160         116 :                 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         116 :                 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         205 :             }
     173             :         }
     174        1770 :         else if( eStyle == LegendSymbolStyle_CIRCLE )
     175             :         {
     176           0 :             sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
     177             :             Reference< drawing::XShape > xShape =
     178             :                 pShapeFactory->createCircle( xResultGroup, awt::Size( nSize, nSize ),
     179           0 :                         awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ));
     180           0 :             if( xShape.is() )
     181             :             {
     182           0 :                 lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
     183           0 :             }
     184             :         }
     185             :         else // eStyle == LegendSymbolStyle_BOX
     186             :         {
     187        1770 :             tNameSequence aPropNames;
     188        3540 :             tAnySequence aPropValues;
     189             : 
     190             :             getPropNamesAndValues( xLegendEntryProperties, aPropNames, aPropValues,
     191        1770 :                     ePropertyType );// PROP_TYPE_FILLED_SERIES
     192             : 
     193             :             Reference< drawing::XShape > xShape =
     194             :                 pShapeFactory->createRectangle( xResultGroup,
     195             :                         rEntryKeyAspectRatio, awt::Point( 0, 0 ),
     196        3540 :                         aPropNames, aPropValues );
     197             :         }
     198             :     }
     199           0 :     catch( const uno::Exception & ex )
     200             :     {
     201             :         ASSERT_EXCEPTION( ex );
     202             :     }
     203             : 
     204        1975 :     return xResult;
     205             : }
     206             : 
     207             : } //  namespace chart
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10