LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - Chart2ModelContact.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 114 137 83.2 %
Date: 2015-06-13 12:38:46 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         322 : Chart2ModelContact::Chart2ModelContact(
      46             :     const Reference< uno::XComponentContext > & xContext ) :
      47             :         m_xContext( xContext ),
      48             :         m_xChartModel( 0 ),
      49             :         mpModel( NULL ),
      50         322 :         m_xChartView(0)
      51             : {
      52         322 : }
      53             : 
      54         918 : Chart2ModelContact::~Chart2ModelContact()
      55             : {
      56         306 :     this->clear();
      57         612 : }
      58             : 
      59         321 : void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference<
      60             :                        ::com::sun::star::frame::XModel >& xChartModel )
      61             : {
      62         321 :     this->clear();
      63         321 :     m_xChartModel = xChartModel;
      64         321 :     mpModel = dynamic_cast<ChartModel*>(xChartModel.get());
      65         321 :     uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
      66         321 :     if( xTableFactory.is() )
      67             :     {
      68         321 :         uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
      69         642 :         uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
      70         642 :         uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
      71         642 :         uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
      72         642 :         uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
      73         321 :         m_aTableMap["LineDashName"] = xDashTable;
      74         321 :         m_aTableMap["FillGradientName"] = xGradientTable;
      75         321 :         m_aTableMap["FillHatchName"] = xHatchTable;
      76         321 :         m_aTableMap["FillBitmapName"] = xBitmapTable;
      77         642 :         m_aTableMap["FillTransparenceGradientName"] = xTransparencyGradientTable;
      78         321 :     }
      79         321 : }
      80             : 
      81         949 : void Chart2ModelContact::clear()
      82             : {
      83         949 :     m_xChartModel = uno::WeakReference< frame::XModel >(0);
      84         949 :     m_xChartView.clear();
      85         949 :     mpModel = NULL;
      86         949 : }
      87             : 
      88      398364 : Reference< frame::XModel > Chart2ModelContact::getChartModel() const
      89             : {
      90      398364 :     return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
      91             : }
      92             : 
      93       24196 : Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
      94             : {
      95       24196 :     return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
      96             : }
      97             : 
      98      355660 : Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
      99             : {
     100      355660 :     return ChartModelHelper::findDiagram( this->getChartModel() );
     101             : }
     102             : 
     103       15676 : uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const
     104             : {
     105       15676 :     if(!m_xChartView.is())
     106             :     {
     107             :         // get the chart view
     108         306 :         Reference<frame::XModel> xModel(m_xChartModel);
     109         612 :         uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
     110         306 :         if( xFact.is() )
     111         612 :             m_xChartView = Reference< lang::XUnoTunnel >( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
     112             :     }
     113       15676 :     return m_xChartView;
     114             : }
     115             : 
     116       15676 : ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
     117             : {
     118       15676 :     getChartView();
     119       15676 :     if(!m_xChartView.is())
     120           0 :         return 0;
     121             : 
     122             :     //obtain the ExplicitValueProvider from the chart view
     123       15676 :     ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
     124       15676 :         ExplicitValueProvider::getUnoTunnelId() ));
     125       15676 :     return pProvider;
     126             : }
     127             : 
     128         797 : uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage()
     129             : {
     130         797 :     uno::Reference< drawing::XDrawPage > xResult;
     131         797 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     132         797 :     if( pProvider )
     133             :     {
     134         797 :         xResult.set( pProvider->getDrawModelWrapper()->getMainDrawPage() );
     135             :     }
     136         797 :     return xResult;
     137             : }
     138             : 
     139       13543 : bool Chart2ModelContact::getExplicitValuesForAxis(
     140             :     const Reference< XAxis > & xAxis,
     141             :     ExplicitScaleData &  rOutExplicitScale,
     142             :     ExplicitIncrementData & rOutExplicitIncrement )
     143             : {
     144       13543 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     145       13543 :     if( pProvider )
     146             :     {
     147             :         return pProvider->getExplicitValuesForAxis(
     148       13543 :             xAxis, rOutExplicitScale, rOutExplicitIncrement );
     149             :     }
     150           0 :     return false;
     151             : }
     152             : 
     153         964 : sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
     154             :             const Reference< chart2::XAxis >& xAxis )
     155             : {
     156             :     Reference< chart2::XCoordinateSystem > xCooSys(
     157             :         AxisHelper::getCoordinateSystemOfAxis(
     158         964 :               xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
     159             : 
     160             :     return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
     161         964 :               , getChart2Document());
     162             : }
     163             : 
     164         220 : 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         220 :         );
     173             : }
     174             : 
     175         139 : awt::Size Chart2ModelContact::GetPageSize() const
     176             : {
     177         139 :     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         594 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
     199             : {
     200         594 :     awt::Rectangle aRect(0,0,0,0);
     201         594 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
     202             : 
     203         594 :     if( DiagramPositioningMode_INCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
     204           1 :         aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
     205             :     else
     206             :     {
     207         593 :         ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     208         593 :         if( pProvider )
     209         593 :             aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes");
     210             :     }
     211         594 :     return aRect;
     212             : }
     213             : 
     214         321 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
     215             : {
     216         321 :     awt::Rectangle aRect(0,0,0,0);
     217         321 :     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
     218             : 
     219         321 :     if( DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
     220           2 :         aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
     221             :     else
     222             :     {
     223         319 :         ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     224         319 :         if( pProvider )
     225         319 :             aRect = pProvider->getDiagramRectangleExcludingAxes();
     226             :     }
     227         321 :     return aRect;
     228             : }
     229             : 
     230           7 : awt::Size Chart2ModelContact::GetLegendSize() const
     231             : {
     232           7 :     awt::Size aSize;
     233           7 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     234           7 :     if( pProvider )
     235             :     {
     236           7 :         uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
     237          14 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
     238          14 :         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
     239             :     }
     240           7 :     return aSize;
     241             : }
     242             : 
     243         217 : awt::Point Chart2ModelContact::GetLegendPosition() const
     244             : {
     245         217 :     awt::Point aPoint;
     246         217 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     247         217 :     if( pProvider )
     248             :     {
     249         217 :         uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
     250         434 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
     251         434 :         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
     252             :     }
     253         217 :     return aPoint;
     254             : }
     255             : 
     256          25 : awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference<
     257             :         ::com::sun::star::chart2::XTitle > & xTitle ) const
     258             : {
     259          25 :     awt::Size aSize;
     260          25 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     261          25 :     if( pProvider && xTitle.is() )
     262             :     {
     263          25 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
     264          25 :         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
     265             :     }
     266          25 :     return aSize;
     267             : }
     268             : 
     269         175 : awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference<
     270             :         ::com::sun::star::chart2::XTitle > & xTitle ) const
     271             : {
     272         175 :     awt::Point aPoint;
     273         175 :     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
     274         175 :     if( pProvider && xTitle.is() )
     275             :     {
     276         175 :         OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
     277         175 :         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
     278             :     }
     279         175 :     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          57 : } //  namespace chart
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11