LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - dpgroupdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 172 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 29 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             : #ifdef SC_DLLIMPLEMENTATION
      21             : #undef SC_DLLIMPLEMENTATION
      22             : #endif
      23             : 
      24             : #include "dpgroupdlg.hxx"
      25             : #include "scresid.hxx"
      26             : #include "sc.hrc"
      27             : #include "globstr.hrc"
      28             : 
      29             : #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
      30             : 
      31             : namespace {
      32             : 
      33             : /** Date part flags in order of the list box entries. */
      34             : static const sal_Int32 spnDateParts[] =
      35             : {
      36             :     com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS,
      37             :     com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES,
      38             :     com::sun::star::sheet::DataPilotFieldGroupBy::HOURS,
      39             :     com::sun::star::sheet::DataPilotFieldGroupBy::DAYS,
      40             :     com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS,
      41             :     com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS,
      42             :     com::sun::star::sheet::DataPilotFieldGroupBy::YEARS
      43             : };
      44             : 
      45             : static const sal_uInt16 nDatePartResIds[] =
      46             : {
      47             :     STR_DPFIELD_GROUP_BY_SECONDS,
      48             :     STR_DPFIELD_GROUP_BY_MINUTES,
      49             :     STR_DPFIELD_GROUP_BY_HOURS,
      50             :     STR_DPFIELD_GROUP_BY_DAYS,
      51             :     STR_DPFIELD_GROUP_BY_MONTHS,
      52             :     STR_DPFIELD_GROUP_BY_QUARTERS,
      53             :     STR_DPFIELD_GROUP_BY_YEARS
      54             : };
      55             : 
      56             : } // namespace
      57             : 
      58           0 : ScDPGroupEditHelper::ScDPGroupEditHelper( RadioButton* pRbAuto, RadioButton* pRbMan, Edit* pEdValue ) :
      59             :     mpRbAuto( pRbAuto ),
      60             :     mpRbMan( pRbMan ),
      61           0 :     mpEdValue( pEdValue )
      62             : {
      63           0 :     mpRbAuto->SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
      64           0 :     mpRbMan->SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
      65           0 : }
      66             : 
      67           0 : bool ScDPGroupEditHelper::IsAuto() const
      68             : {
      69           0 :     return mpRbAuto->IsChecked();
      70             : }
      71             : 
      72           0 : double ScDPGroupEditHelper::GetValue() const
      73             : {
      74             :     double fValue;
      75           0 :     if( !ImplGetValue( fValue ) )
      76           0 :         fValue = 0.0;
      77           0 :     return fValue;
      78             : }
      79             : 
      80           0 : void ScDPGroupEditHelper::SetValue( bool bAuto, double fValue )
      81             : {
      82           0 :     if( bAuto )
      83             :     {
      84           0 :         mpRbAuto->Check();
      85           0 :         ClickHdl( mpRbAuto );
      86             :     }
      87             :     else
      88             :     {
      89           0 :         mpRbMan->Check();
      90           0 :         ClickHdl( mpRbMan );
      91             :     }
      92           0 :     ImplSetValue( fValue );
      93           0 : }
      94             : 
      95           0 : IMPL_LINK( ScDPGroupEditHelper, ClickHdl, RadioButton*, pButton )
      96             : {
      97           0 :     if( pButton == mpRbAuto )
      98             :     {
      99             :         // disable edit field on clicking "automatic" radio button
     100           0 :         mpEdValue->Disable();
     101             :     }
     102           0 :     else if( pButton == mpRbMan )
     103             :     {
     104             :         // enable and set focus to edit field on clicking "manual" radio button
     105           0 :         mpEdValue->Enable();
     106           0 :         mpEdValue->GrabFocus();
     107             :     }
     108           0 :     return 0;
     109             : }
     110             : 
     111           0 : ScDPNumGroupEditHelper::ScDPNumGroupEditHelper(
     112             :         RadioButton* pRbAuto, RadioButton* pRbMan, ScDoubleField* pEdValue ) :
     113             :     ScDPGroupEditHelper( pRbAuto, pRbMan, pEdValue ),
     114           0 :     mpEdValue( pEdValue )
     115             : {
     116           0 : }
     117             : 
     118           0 : bool ScDPNumGroupEditHelper::ImplGetValue( double& rfValue ) const
     119             : {
     120           0 :     return mpEdValue->GetValue( rfValue );
     121             : }
     122             : 
     123           0 : void ScDPNumGroupEditHelper::ImplSetValue( double fValue )
     124             : {
     125           0 :     mpEdValue->SetValue( fValue );
     126           0 : }
     127             : 
     128           0 : ScDPDateGroupEditHelper::ScDPDateGroupEditHelper(
     129             :         RadioButton* pRbAuto, RadioButton* pRbMan, DateField* pEdValue, const Date& rNullDate ) :
     130             :     ScDPGroupEditHelper( pRbAuto, pRbMan, pEdValue ),
     131             :     mpEdValue( pEdValue ),
     132           0 :     maNullDate( rNullDate )
     133             : {
     134           0 : }
     135             : 
     136           0 : bool ScDPDateGroupEditHelper::ImplGetValue( double& rfValue ) const
     137             : {
     138           0 :     rfValue = mpEdValue->GetDate() - maNullDate;
     139           0 :     return true;
     140             : }
     141             : 
     142           0 : void ScDPDateGroupEditHelper::ImplSetValue( double fValue )
     143             : {
     144           0 :     Date aDate( maNullDate );
     145           0 :     aDate += static_cast< sal_Int32 >( fValue );
     146           0 :     mpEdValue->SetDate( aDate );
     147           0 : }
     148             : 
     149           0 : ScDPNumGroupDlg::ScDPNumGroupDlg( vcl::Window* pParent, const ScDPNumGroupInfo& rInfo ) :
     150             :     ModalDialog     ( pParent, "PivotTableGroupByNumber", "modules/scalc/ui/groupbynumber.ui" ),
     151             :     mpRbAutoStart   ( get<RadioButton>("auto_start") ),
     152             :     mpRbManStart    ( get<RadioButton>("manual_start") ),
     153             :     mpEdStart       ( get<ScDoubleField> ("edit_start") ),
     154             :     mpRbAutoEnd     ( get<RadioButton> ( "auto_end" ) ),
     155             :     mpRbManEnd      ( get<RadioButton> ("manual_end") ),
     156             :     mpEdEnd         ( get<ScDoubleField>( "edit_end") ),
     157             :     mpEdBy          ( get<ScDoubleField> ("edit_by") ),
     158             :     maStartHelper   ( mpRbAutoStart, mpRbManStart, mpEdStart ),
     159           0 :     maEndHelper     ( mpRbAutoEnd, mpRbManEnd, mpEdEnd )
     160             : {
     161             : 
     162           0 :     maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
     163           0 :     maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
     164           0 :     mpEdBy->SetValue( (rInfo.mfStep <= 0.0) ? 1.0 : rInfo.mfStep );
     165             : 
     166             :     /*  Set the initial focus, currently it is somewhere after calling all the radio
     167             :         button click handlers. Now the first enabled editable control is focused. */
     168           0 :     if( mpEdStart->IsEnabled() )
     169           0 :         mpEdStart->GrabFocus();
     170           0 :     else if( mpEdEnd->IsEnabled() )
     171           0 :         mpEdEnd->GrabFocus();
     172             :     else
     173           0 :         mpEdBy->GrabFocus();
     174           0 : }
     175             : 
     176           0 : ScDPNumGroupDlg::~ScDPNumGroupDlg()
     177             : {
     178           0 :     disposeOnce();
     179           0 : }
     180             : 
     181           0 : void ScDPNumGroupDlg::dispose()
     182             : {
     183           0 :     mpRbAutoStart.clear();
     184           0 :     mpRbManStart.clear();
     185           0 :     mpEdStart.clear();
     186           0 :     mpRbAutoEnd.clear();
     187           0 :     mpRbManEnd.clear();
     188           0 :     mpEdEnd.clear();
     189           0 :     mpEdBy.clear();
     190           0 :     ModalDialog::dispose();
     191           0 : }
     192             : 
     193             : 
     194           0 : ScDPNumGroupInfo ScDPNumGroupDlg::GetGroupInfo() const
     195             : {
     196           0 :     ScDPNumGroupInfo aInfo;
     197           0 :     aInfo.mbEnable = true;
     198           0 :     aInfo.mbDateValues = false;
     199           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     200           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     201             : 
     202             :     // get values and silently auto-correct them, if they are not valid
     203             :     // TODO: error messages in OK event?
     204           0 :     aInfo.mfStart = maStartHelper.GetValue();
     205           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     206           0 :     if( !mpEdBy->GetValue( aInfo.mfStep ) || (aInfo.mfStep <= 0.0) )
     207           0 :         aInfo.mfStep = 1.0;
     208           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     209           0 :         aInfo.mfEnd = aInfo.mfStart + aInfo.mfStep;
     210             : 
     211           0 :     return aInfo;
     212             : }
     213             : 
     214           0 : ScDPDateGroupDlg::ScDPDateGroupDlg( vcl::Window* pParent,
     215             :         const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, const Date& rNullDate ) :
     216             :     ModalDialog( pParent, "PivotTableGroupByDate", "modules/scalc/ui/groupbydate.ui" ),
     217             :     mpRbAutoStart   ( get<RadioButton>("auto_start") ),
     218             :     mpRbManStart    ( get<RadioButton>("manual_start") ),
     219             :     mpEdStart       ( get<DateField>("start_date") ),
     220             :     mpRbAutoEnd     ( get<RadioButton>("auto_end") ),
     221             :     mpRbManEnd      ( get<RadioButton>("manual_end") ),
     222             :     mpEdEnd         ( get<DateField>("end_date") ),
     223             :     mpRbNumDays     ( get<RadioButton>("days") ),
     224             :     mpRbUnits       ( get<RadioButton>("intervals") ),
     225             :     mpEdNumDays     ( get<NumericField>("days_value") ),
     226             :     mpLbUnits       ( get<SvxCheckListBox>("interval_list") ),
     227             :     mpBtnOk         ( get<OKButton>("ok") ),
     228             :     maStartHelper   ( mpRbAutoStart, mpRbManStart, mpEdStart, rNullDate ),
     229           0 :     maEndHelper     ( mpRbAutoEnd, mpRbManEnd, mpEdEnd, rNullDate )
     230             : {
     231             :     static const size_t nCount = sizeof( nDatePartResIds ) / sizeof( nDatePartResIds[0] );
     232           0 :     for( size_t nIdx = 0 ; nIdx < nCount; ++nIdx )
     233           0 :         mpLbUnits->InsertEntry( ScGlobal::GetRscString( nDatePartResIds[nIdx] ) );
     234             : 
     235           0 :     mpEdStart->SetShowDateCentury( true );
     236           0 :     mpEdEnd->SetShowDateCentury( true );
     237             : 
     238           0 :     maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
     239           0 :     maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
     240             : 
     241           0 :     if( nDatePart == 0 )
     242           0 :         nDatePart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
     243           0 :     for( size_t nIdx = 0; nIdx < nCount; ++nIdx )
     244           0 :         mpLbUnits->CheckEntryPos( static_cast< sal_uInt16 >( nIdx ), (nDatePart & spnDateParts[ nIdx ]) != 0 );
     245             : 
     246           0 :     if( rInfo.mbDateValues )
     247             :     {
     248           0 :         mpRbNumDays->Check();
     249           0 :         ClickHdl( mpRbNumDays );
     250             : 
     251           0 :         double fNumDays = rInfo.mfStep;
     252           0 :         if( fNumDays < 1.0 )
     253           0 :             fNumDays = 1.0;
     254           0 :         else if( fNumDays > 32767.0 )
     255           0 :             fNumDays = 32767.0;
     256           0 :         mpEdNumDays->SetValue( static_cast< long >( fNumDays ) );
     257             :     }
     258             :     else
     259             :     {
     260           0 :         mpRbUnits->Check();
     261           0 :         ClickHdl( mpRbUnits );
     262             :     }
     263             : 
     264             :     /*  Set the initial focus, currently it is somewhere after calling all the radio
     265             :         button click handlers. Now the first enabled editable control is focused. */
     266           0 :     if( mpEdStart->IsEnabled() )
     267           0 :         mpEdStart->GrabFocus();
     268           0 :     else if( mpEdEnd->IsEnabled() )
     269           0 :         mpEdEnd->GrabFocus();
     270           0 :     else if( mpEdNumDays->IsEnabled() )
     271           0 :         mpEdNumDays->GrabFocus();
     272           0 :     else if( mpLbUnits->IsEnabled() )
     273           0 :         mpLbUnits->GrabFocus();
     274             : 
     275           0 :     mpRbNumDays->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     276           0 :     mpRbUnits->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     277           0 :     mpLbUnits->SetCheckButtonHdl( LINK( this, ScDPDateGroupDlg, CheckHdl ) );
     278           0 : }
     279             : 
     280           0 : ScDPDateGroupDlg::~ScDPDateGroupDlg()
     281             : {
     282           0 :     disposeOnce();
     283           0 : }
     284             : 
     285           0 : void ScDPDateGroupDlg::dispose()
     286             : {
     287           0 :     mpRbAutoStart.clear();
     288           0 :     mpRbManStart.clear();
     289           0 :     mpEdStart.clear();
     290           0 :     mpRbAutoEnd.clear();
     291           0 :     mpRbManEnd.clear();
     292           0 :     mpEdEnd.clear();
     293           0 :     mpRbNumDays.clear();
     294           0 :     mpRbUnits.clear();
     295           0 :     mpEdNumDays.clear();
     296           0 :     mpLbUnits.clear();
     297           0 :     mpBtnOk.clear();
     298           0 :     ModalDialog::dispose();
     299           0 : }
     300             : 
     301           0 : ScDPNumGroupInfo ScDPDateGroupDlg::GetGroupInfo() const
     302             : {
     303           0 :     ScDPNumGroupInfo aInfo;
     304           0 :     aInfo.mbEnable = true;
     305           0 :     aInfo.mbDateValues = mpRbNumDays->IsChecked();
     306           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     307           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     308             : 
     309             :     // get values and silently auto-correct them, if they are not valid
     310             :     // TODO: error messages in OK event?
     311           0 :     aInfo.mfStart = maStartHelper.GetValue();
     312           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     313           0 :     sal_Int64 nNumDays = mpEdNumDays->GetValue();
     314           0 :     aInfo.mfStep = static_cast<double>( aInfo.mbDateValues ? nNumDays : 0L );
     315           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     316           0 :         aInfo.mfEnd = aInfo.mfStart + nNumDays;
     317             : 
     318           0 :     return aInfo;
     319             : }
     320             : 
     321           0 : sal_Int32 ScDPDateGroupDlg::GetDatePart() const
     322             : {
     323             :     // return DAYS for special "number of days" mode
     324           0 :     if( mpRbNumDays->IsChecked() )
     325           0 :         return com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
     326             : 
     327             :     // return listbox contents for "units" mode
     328           0 :     sal_Int32 nDatePart = 0;
     329           0 :     for( sal_uLong nIdx = 0, nCount = mpLbUnits->GetEntryCount(); nIdx < nCount; ++nIdx )
     330           0 :         if( mpLbUnits->IsChecked( static_cast< sal_uInt16 >( nIdx ) ) )
     331           0 :             nDatePart |= spnDateParts[ nIdx ];
     332           0 :     return nDatePart;
     333             : }
     334             : 
     335           0 : IMPL_LINK( ScDPDateGroupDlg, ClickHdl, RadioButton*, pButton )
     336             : {
     337           0 :     if( pButton == mpRbNumDays )
     338             :     {
     339           0 :         mpLbUnits->Disable();
     340             :         // enable and set focus to edit field on clicking "num of days" radio button
     341           0 :         mpEdNumDays->Enable();
     342           0 :         mpEdNumDays->GrabFocus();
     343           0 :         mpBtnOk->Enable();
     344             :     }
     345           0 :     else if( pButton == mpRbUnits )
     346             :     {
     347           0 :         mpEdNumDays->Disable();
     348             :         // enable and set focus to listbox on clicking "units" radio button
     349           0 :         mpLbUnits->Enable();
     350           0 :         mpLbUnits->GrabFocus();
     351             :         // disable OK button if no date part selected
     352           0 :         CheckHdl( mpLbUnits );
     353             :     }
     354           0 :     return 0;
     355             : }
     356             : 
     357           0 : IMPL_LINK( ScDPDateGroupDlg, CheckHdl, SvxCheckListBox*, pListBox )
     358             : {
     359             :     // enable/disable OK button on modifying check list box
     360           0 :     if( pListBox == mpLbUnits )
     361           0 :         mpBtnOk->Enable( mpLbUnits->GetCheckedEntryCount() > 0 );
     362           0 :     return 0;
     363           0 : }
     364             : 
     365             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11