LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/dialogs - res_Trendline.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 125 0.0 %
Date: 2012-12-27 Functions: 0 16 0.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             : 
      21             : #include "dlg_InsertTrendline.hrc"
      22             : #include "res_Trendline.hxx"
      23             : #include "res_Trendline_IDs.hrc"
      24             : #include "ResId.hxx"
      25             : #include "Strings.hrc"
      26             : #include "Bitmaps.hrc"
      27             : #include "chartview/ChartSfxItemIds.hxx"
      28             : 
      29             : #include <vector>
      30             : #include <algorithm>
      31             : 
      32             : namespace
      33             : {
      34             : template< class T >
      35           0 :     long lcl_getRightEdge( T & rControl )
      36             : {
      37           0 :     return rControl.CalcMinimumSize().Width() + rControl.GetPosPixel().X() - rControl.GetParent()->GetPosPixel().X();
      38             : }
      39             : 
      40             : template< class T >
      41           0 :     void lcl_AdjustControlSize( T & rControl )
      42             : {
      43           0 :     Size aSize( rControl.GetSizePixel());
      44           0 :     aSize.setWidth( rControl.CalcMinimumSize().Width());
      45           0 :     rControl.SetSizePixel( aSize );
      46           0 : }
      47             : 
      48           0 : void lcl_AdjustControlSize( Control & rControl, long nRightEdge )
      49             : {
      50           0 :     Size aSize( rControl.GetSizePixel());
      51           0 :     Point aPosition( rControl.GetPosPixel());
      52           0 :     aSize.setWidth( nRightEdge - aPosition.getX());
      53           0 :     rControl.SetSizePixel( aSize );
      54           0 : }
      55             : 
      56             : } // anonymous namespace
      57             : 
      58             : namespace chart
      59             : {
      60             : 
      61             : enum StatTrendLine
      62             : {
      63             :     TRENDLINE_NONE,
      64             :     TRENDLINE_LINE,
      65             :     TRENDLINE_LOG,
      66             :     TRENDLINE_EXP,
      67             :     TRENDLINE_POW
      68             : };
      69             : 
      70           0 : TrendlineResources::TrendlineResources( Window * pParent, const SfxItemSet& rInAttrs, bool bNoneAvailable ) :
      71             :         m_aFLType( pParent, SchResId( FL_TYPE )),
      72             : 
      73             :         m_aRBNone(        pParent, SchResId( RB_NONE        )),
      74             :         m_aRBLinear(      pParent, SchResId( RB_LINEAR      )),
      75             :         m_aRBLogarithmic( pParent, SchResId( RB_LOGARITHMIC )),
      76             :         m_aRBExponential( pParent, SchResId( RB_EXPONENTIAL )),
      77             :         m_aRBPower(       pParent, SchResId( RB_POWER       )),
      78             : 
      79             :         m_aFINone(        pParent, SchResId( FI_NONE        )),
      80             :         m_aFILinear(      pParent, SchResId( FI_LINEAR      )),
      81             :         m_aFILogarithmic( pParent, SchResId( FI_LOGARITHMIC )),
      82             :         m_aFIExponential( pParent, SchResId( FI_EXPONENTIAL )),
      83             :         m_aFIPower(       pParent, SchResId( FI_POWER       )),
      84             : 
      85             :         m_aFLEquation(             pParent, SchResId( FL_EQUATION               )),
      86             :         m_aCBShowEquation(         pParent, SchResId( CB_SHOW_EQUATION          )),
      87             :         m_aCBShowCorrelationCoeff( pParent, SchResId( CB_SHOW_CORRELATION_COEFF )),
      88             : 
      89             :         m_eTrendLineType( CHREGRESS_NONE ),
      90             :         m_bNoneAvailable( bNoneAvailable ),
      91           0 :         m_bTrendLineUnique( true )
      92             : {
      93           0 :     FillValueSets();
      94             : 
      95           0 :     if( m_bNoneAvailable )
      96           0 :         m_aRBNone.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine ));
      97             :     else
      98           0 :         m_aRBNone.Hide();
      99             : 
     100           0 :     m_aRBLinear.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine ));
     101           0 :     m_aRBLogarithmic.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine ));
     102           0 :     m_aRBExponential.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine ));
     103           0 :     m_aRBPower.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine ));
     104             : 
     105           0 :     Reset( rInAttrs );
     106           0 :     UpdateControlStates();
     107           0 : }
     108             : 
     109           0 : TrendlineResources::~TrendlineResources()
     110           0 : {}
     111             : 
     112           0 : long TrendlineResources::adjustControlSizes()
     113             : {
     114             :     // calculate right edge
     115           0 :     ::std::vector< long > aControlRightEdges;
     116           0 :     aControlRightEdges.push_back( lcl_getRightEdge( m_aRBNone ));
     117           0 :     aControlRightEdges.push_back( lcl_getRightEdge( m_aRBLinear ));
     118           0 :     aControlRightEdges.push_back( lcl_getRightEdge( m_aRBLogarithmic ));
     119           0 :     aControlRightEdges.push_back( lcl_getRightEdge( m_aRBExponential ));
     120           0 :     aControlRightEdges.push_back( lcl_getRightEdge( m_aRBPower ));
     121           0 :     aControlRightEdges.push_back( lcl_getRightEdge( m_aCBShowEquation ));
     122           0 :     aControlRightEdges.push_back( lcl_getRightEdge( m_aCBShowCorrelationCoeff ));
     123             : 
     124           0 :     lcl_AdjustControlSize( m_aRBNone );
     125           0 :     lcl_AdjustControlSize( m_aRBLinear );
     126           0 :     lcl_AdjustControlSize( m_aRBLogarithmic );
     127           0 :     lcl_AdjustControlSize( m_aRBExponential );
     128           0 :     lcl_AdjustControlSize( m_aRBPower );
     129           0 :     lcl_AdjustControlSize( m_aCBShowEquation );
     130           0 :     lcl_AdjustControlSize( m_aCBShowCorrelationCoeff );
     131             : 
     132             :     // Note: FixedLine has no CalcMinimumSize, workaround: use a FixedText
     133           0 :     FixedText aDummyTextCtrl( m_aFLType.GetParent());
     134           0 :     aDummyTextCtrl.SetText( m_aFLType.GetText());
     135           0 :     aControlRightEdges.push_back( lcl_getRightEdge( aDummyTextCtrl ));
     136           0 :     aDummyTextCtrl.SetText( m_aFLEquation.GetText());
     137           0 :     aControlRightEdges.push_back( lcl_getRightEdge( aDummyTextCtrl ));
     138             : 
     139           0 :     long nRightEdgeOfControls = *(::std::max_element( aControlRightEdges.begin(), aControlRightEdges.end()));
     140             :     // leave some more space after the longest text
     141           0 :     nRightEdgeOfControls += m_aFLType.LogicToPixel( Size( 6, 0 ), MapMode( MAP_APPFONT )).getWidth();
     142             : 
     143           0 :     lcl_AdjustControlSize( m_aFLType, nRightEdgeOfControls );
     144           0 :     lcl_AdjustControlSize( m_aFLEquation, nRightEdgeOfControls );
     145             : 
     146           0 :     return nRightEdgeOfControls;
     147             : }
     148             : 
     149           0 : IMPL_LINK( TrendlineResources, SelectTrendLine, RadioButton *, pRadioButton )
     150             : {
     151           0 :     if( pRadioButton == &m_aRBLinear )
     152           0 :         m_eTrendLineType = CHREGRESS_LINEAR;
     153           0 :     else if( pRadioButton == &m_aRBLogarithmic )
     154           0 :         m_eTrendLineType = CHREGRESS_LOG;
     155           0 :     else if( pRadioButton == &m_aRBExponential )
     156           0 :         m_eTrendLineType = CHREGRESS_EXP;
     157           0 :     else if( pRadioButton == &m_aRBPower )
     158           0 :         m_eTrendLineType = CHREGRESS_POWER;
     159           0 :     else if( pRadioButton == &m_aRBNone )
     160             :     {
     161             :         OSL_ASSERT( m_bNoneAvailable );
     162           0 :         m_eTrendLineType = CHREGRESS_NONE;
     163             :     }
     164           0 :     m_bTrendLineUnique = true;
     165             : 
     166           0 :     UpdateControlStates();
     167             : 
     168           0 :     return 0;
     169             : }
     170             : 
     171           0 : void TrendlineResources::Reset( const SfxItemSet& rInAttrs )
     172             : {
     173           0 :     const SfxPoolItem *pPoolItem = NULL;
     174             : 
     175           0 :     SfxItemState aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_TYPE, sal_True, &pPoolItem );
     176           0 :     m_bTrendLineUnique = ( aState != SFX_ITEM_DONTCARE );
     177           0 :     if( aState == SFX_ITEM_SET )
     178             :     {
     179           0 :         const SvxChartRegressItem * pItem = dynamic_cast< const SvxChartRegressItem * >( pPoolItem );
     180           0 :         if( pItem )
     181           0 :             m_eTrendLineType = pItem->GetValue();
     182             :     }
     183             : 
     184           0 :     aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_SHOW_EQUATION, sal_True, &pPoolItem );
     185           0 :     if( aState == SFX_ITEM_DONTCARE )
     186             :     {
     187           0 :         m_aCBShowEquation.EnableTriState( sal_True );
     188           0 :         m_aCBShowEquation.SetState( STATE_DONTKNOW );
     189             :     }
     190             :     else
     191             :     {
     192           0 :         m_aCBShowEquation.EnableTriState( sal_False );
     193           0 :         if( aState == SFX_ITEM_SET )
     194           0 :             m_aCBShowEquation.Check( static_cast< const SfxBoolItem * >( pPoolItem )->GetValue());
     195             :     }
     196             : 
     197           0 :     aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_SHOW_COEFF, sal_True, &pPoolItem );
     198           0 :     if( aState == SFX_ITEM_DONTCARE )
     199             :     {
     200           0 :         m_aCBShowCorrelationCoeff.EnableTriState( sal_True );
     201           0 :         m_aCBShowCorrelationCoeff.SetState( STATE_DONTKNOW );
     202             :     }
     203             :     else
     204             :     {
     205           0 :         m_aCBShowCorrelationCoeff.EnableTriState( sal_False );
     206           0 :         if( aState == SFX_ITEM_SET )
     207           0 :             m_aCBShowCorrelationCoeff.Check( static_cast< const SfxBoolItem * >( pPoolItem )->GetValue());
     208             :     }
     209             : 
     210           0 :     if( m_bTrendLineUnique )
     211             :     {
     212           0 :         switch( m_eTrendLineType )
     213             :         {
     214             :             case CHREGRESS_LINEAR :
     215           0 :                 m_aRBLinear.Check();
     216           0 :                 break;
     217             :             case CHREGRESS_LOG :
     218           0 :                 m_aRBLogarithmic.Check();
     219           0 :                 break;
     220             :             case CHREGRESS_EXP :
     221           0 :                 m_aRBExponential.Check();
     222           0 :                 break;
     223             :             case CHREGRESS_POWER :
     224           0 :                 m_aRBPower.Check();
     225           0 :                 break;
     226             :             case CHREGRESS_NONE:
     227             :                 OSL_ASSERT( m_bNoneAvailable );
     228           0 :                 m_aRBNone.Check();
     229           0 :                 break;
     230             :         }
     231             :     }
     232           0 : }
     233             : 
     234           0 : sal_Bool TrendlineResources::FillItemSet(SfxItemSet& rOutAttrs) const
     235             : {
     236           0 :     if( m_bTrendLineUnique )
     237           0 :         rOutAttrs.Put( SvxChartRegressItem( m_eTrendLineType, SCHATTR_REGRESSION_TYPE ));
     238           0 :     if( m_aCBShowEquation.GetState() != STATE_DONTKNOW )
     239           0 :         rOutAttrs.Put( SfxBoolItem( SCHATTR_REGRESSION_SHOW_EQUATION, m_aCBShowEquation.IsChecked() ));
     240           0 :     if( m_aCBShowCorrelationCoeff.GetState() != STATE_DONTKNOW )
     241           0 :         rOutAttrs.Put( SfxBoolItem( SCHATTR_REGRESSION_SHOW_COEFF, m_aCBShowCorrelationCoeff.IsChecked() ));
     242           0 :     return sal_True;
     243             : }
     244             : 
     245           0 : void TrendlineResources::FillValueSets()
     246             : {
     247           0 :     if( m_bNoneAvailable )
     248           0 :         m_aFINone.SetImage(    Image( SchResId( BMP_REGRESSION_NONE   ) ) );
     249           0 :     m_aFILinear.SetImage(      Image( SchResId( BMP_REGRESSION_LINEAR ) ) );
     250           0 :     m_aFILogarithmic.SetImage( Image( SchResId( BMP_REGRESSION_LOG    ) ) );
     251           0 :     m_aFIExponential.SetImage( Image( SchResId( BMP_REGRESSION_EXP    ) ) );
     252           0 :     m_aFIPower.SetImage(       Image( SchResId( BMP_REGRESSION_POWER  ) ) );
     253           0 : }
     254             : 
     255           0 : void TrendlineResources::UpdateControlStates()
     256             : {
     257           0 :     if( m_bNoneAvailable )
     258             :     {
     259           0 :         bool bEnableEquationControls = !m_bTrendLineUnique || (m_eTrendLineType != CHREGRESS_NONE);
     260           0 :         m_aCBShowEquation.Enable( bEnableEquationControls );
     261           0 :         m_aCBShowCorrelationCoeff.Enable( bEnableEquationControls );
     262             :     }
     263           0 : }
     264             : 
     265             : } //  namespace chart
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10