LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - Chart2ModelContact.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 113 137 82.5 %
Date: 2014-11-03 Functions: 23 27 85.2 %
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 "Chart2ModelContact.hxx"
      21             : #include "ChartModelHelper.hxx"
      22             : #include "LegendHelper.hxx"
      23             : #include "CommonConverters.hxx"
      24             : #include "macros.hxx"
      25             : #include "servicenames.hxx"
      26             : #include "ObjectIdentifier.hxx"
      27             : #include "chartview/ExplicitValueProvider.hxx"
      28             : #include "chartview/DrawModelWrapper.hxx"
      29             : #include "AxisHelper.hxx"
      30             : #include "DiagramHelper.hxx"
      31             : 
      32             : #include "ChartModel.hxx"
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::chart2;
      36             : 
      37             : using ::com::sun::star::uno::Reference;
      38             : using ::com::sun::star::uno::Sequence;
      39             : 
      40             : namespace chart
      41             : {
      42             : namespace wrapper
      43             : {
      44             : 
      45         606 : Chart2ModelContact::Chart2ModelContact(
      46             :     const Reference< uno::XComponentContext > & xContext ) :
      47             :         m_xContext( xContext ),
      48             :         m_xChartModel( 0 ),
      49             :         mpModel( NULL ),
      50         606 :         m_xChartView(0)
      51             : {
      52         606 : }
      53             : 
      54        1722 : Chart2ModelContact::~Chart2ModelContact()
      55             : {
      56         574 :     this->clear();
      57        1148 : }
      58             : 
      59         606 : void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference<
      60             :                        ::com::sun::star::frame::XModel >& xChartModel )
      61             : {
      62         606 :     this->clear();
      63         606 :     m_xChartModel = xChartModel;
      64         606 :     mpModel = dynamic_cast<ChartModel*>(xChartModel.get());
      65         606 :     uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
      66         606 :     if( xTableFactory.is() )
      67             :     {
      68         606 :         uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
      69        1212 :         uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
      70        1212 :         uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
      71        1212 :         uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
      72        1212 :         uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
      73         606 :         m_aTableMap["LineDashName"] = xDashTable;
      74         606 :         m_aTableMap["FillGradientName"] = xGradientTable;
      75         606 :         m_aTableMap["FillHatchName"] = xHatchTable;
      76         606 :         m_aTableMap["FillBitmapName"] = xBitmapTable;
      77        1212 :         m_aTableMap["FillTransparenceGradientName"] = xTransparencyGradientTable;
      78         606 :     }
      79         606 : }
      80             : 
      81        1786 : void Chart2ModelContact::clear()
      82             : {
      83        1786 :     m_xChartModel = uno::WeakReference< frame::XModel >(0);
      84        1786 :     m_xChartView.clear();
      85        1786 :     mpModel = NULL;
      86        1786 : }
      87             : 
      88      779356 : Reference< frame::XModel > Chart2ModelContact::getChartModel() const
      89             : {
      90      779356 :     return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
      91             : }
      92             : 
      93       49670 : Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
      94             : {
      95       49670 :     return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
      96             : }
      97             : 
      98      719530 : Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
      99             : {
     100      719530 :     return ChartModelHelper::findDiagram( this->getChartModel() );
     101             : }
     102             : 
     103       31423 : uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const
     104             : {
     105       31423 :     if(!m_xChartView.is())
     106             :     {
     107             :         // get the chart view
     108         580 :         Reference<frame::XModel> xModel(m_xChartModel);
     109        1160 :         uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
     110         580 :         if( xFact.is() )
     111        1160 :             m_xChartView = Reference< lang::XUnoTunnel >( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
     112             :     }
     113       31423 :     return m_xChartView;
     114             : }
     115             : 
     116       31423 : ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
     117             : {
     118       31423 :     getChartView();
     119       31423 :     if(!m_xChartView.is())
     120           0 :         return 0;
     121             : 
     122             :     //obtain the ExplicitValueProvider from the chart view
     123       31423 :     ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
     124       31423 :         ExplicitValueProvider::getUnoTunnelId() ));
     125       31423 :     return pProvider;
     126             : }
     127             : 
     128        1839 : uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage()
     129             : {
     130        1839 :     uno::Reference< drawing::XDrawPage > xResult;
     131        1839 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     132        1839 :     if( pProvider )
     133             :     {
     134        1839 :         xResult.set( pProvider->getDrawModelWrapper()->getMainDrawPage() );
     135             :     }
     136        1839 :     return xResult;
     137             : }
     138             : 
     139       27156 : bool Chart2ModelContact::getExplicitValuesForAxis(
     140             :     const Reference< XAxis > & xAxis,
     141             :     ExplicitScaleData &  rOutExplicitScale,
     142             :     ExplicitIncrementData & rOutExplicitIncrement )
     143             : {
     144       27156 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     145       27156 :     if( pProvider )
     146             :     {
     147             :         return pProvider->getExplicitValuesForAxis(
     148       27156 :             xAxis, rOutExplicitScale, rOutExplicitIncrement );
     149             :     }
     150           0 :     return false;
     151             : }
     152             : 
     153        2636 : sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
     154             :             const Reference< chart2::XAxis >& xAxis )
     155             : {
     156             :     Reference< chart2::XCoordinateSystem > xCooSys(
     157             :         AxisHelper::getCoordinateSystemOfAxis(
     158        2636 :               xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
     159             : 
     160             :     return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
     161        2636 :               , getChart2Document());
     162             : }
     163             : 
     164         536 : sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
     165             :             const Reference< chart2::XDataSeries >& xSeries )
     166             : {
     167             :     return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
     168             :         uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ),
     169             :         xSeries,
     170             :         -1 /*-1 for whole series*/,
     171             :         ChartModelHelper::findDiagram( m_xChartModel )
     172         536 :         );
     173             : }
     174             : 
     175         358 : awt::Size Chart2ModelContact::GetPageSize() const
     176             : {
     177         358 :     return ChartModelHelper::getPageSize(m_xChartModel);
     178             : }
     179             : 
     180           0 : awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
     181             : {
     182             :     awt::Rectangle aRect = ExplicitValueProvider::substractAxisTitleSizes(
     183           0 :         *mpModel, getChartView(), rPositionRect );
     184           0 :     return aRect;
     185             : }
     186             : 
     187           0 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
     188             : {
     189           0 :     awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
     190             : 
     191             :     //add axis title sizes to the diagram size
     192             :     aRect = ExplicitValueProvider::addAxisTitleSizes(
     193           0 :         *mpModel, getChartView(), aRect );
     194             : 
     195           0 :     return aRect;
     196             : }
     197             : 
     198        1128 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
     199             : {
     200        1128 :     awt::Rectangle aRect(0,0,0,0);
     201        1128 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
     202             : 
     203        1128 :     if( DiagramPositioningMode_INCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
     204           2 :         aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
     205             :     else
     206             :     {
     207        1126 :         ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     208        1126 :         if( pProvider )
     209        1126 :             aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes");
     210             :     }
     211        1128 :     return aRect;
     212             : }
     213             : 
     214         576 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
     215             : {
     216         576 :     awt::Rectangle aRect(0,0,0,0);
     217         576 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
     218             : 
     219         576 :     if( DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
     220           0 :         aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
     221             :     else
     222             :     {
     223         576 :         ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     224         576 :         if( pProvider )
     225         576 :             aRect = pProvider->getDiagramRectangleExcludingAxes();
     226             :     }
     227         576 :     return aRect;
     228             : }
     229             : 
     230          12 : awt::Size Chart2ModelContact::GetLegendSize() const
     231             : {
     232          12 :     awt::Size aSize;
     233          12 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     234          12 :     if( pProvider )
     235             :     {
     236          12 :         uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
     237          24 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
     238          24 :         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
     239             :     }
     240          12 :     return aSize;
     241             : }
     242             : 
     243         442 : awt::Point Chart2ModelContact::GetLegendPosition() const
     244             : {
     245         442 :     awt::Point aPoint;
     246         442 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     247         442 :     if( pProvider )
     248             :     {
     249         442 :         uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
     250         884 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
     251         884 :         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
     252             :     }
     253         442 :     return aPoint;
     254             : }
     255             : 
     256          40 : awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference<
     257             :         ::com::sun::star::chart2::XTitle > & xTitle ) const
     258             : {
     259          40 :     awt::Size aSize;
     260          40 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     261          40 :     if( pProvider && xTitle.is() )
     262             :     {
     263          40 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
     264          40 :         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
     265             :     }
     266          40 :     return aSize;
     267             : }
     268             : 
     269         232 : awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference<
     270             :         ::com::sun::star::chart2::XTitle > & xTitle ) const
     271             : {
     272         232 :     awt::Point aPoint;
     273         232 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     274         232 :     if( pProvider && xTitle.is() )
     275             :     {
     276         232 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
     277         232 :         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
     278             :     }
     279         232 :     return aPoint;
     280             : }
     281             : 
     282           0 : awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference<
     283             :         ::com::sun::star::chart2::XAxis > & xAxis ) const
     284             : {
     285           0 :     awt::Size aSize;
     286           0 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     287           0 :     if( pProvider && xAxis.is() )
     288             :     {
     289           0 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
     290           0 :         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
     291             :     }
     292           0 :     return aSize;
     293             : }
     294             : 
     295           0 : awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference<
     296             :         ::com::sun::star::chart2::XAxis > & xAxis ) const
     297             : {
     298           0 :     awt::Point aPoint;
     299           0 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     300           0 :     if( pProvider && xAxis.is() )
     301             :     {
     302           0 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
     303           0 :         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
     304             :     }
     305           0 :     return aPoint;
     306             : }
     307             : 
     308             : } //  namespace wrapper
     309         102 : } //  namespace chart
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10