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

Generated by: LCOV version 1.10