LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - dpgroupdlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 160 0.0 %
Date: 2014-11-03 Functions: 0 23 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           0 :     mpRbAutoStart   ( get<RadioButton>("auto_start") ),
     152           0 :     mpRbManStart    ( get<RadioButton>("manual_start") ),
     153           0 :     mpEdStart       ( get<ScDoubleField> ("edit_start") ),
     154           0 :     mpRbAutoEnd     ( get<RadioButton> ( "auto_end" ) ),
     155           0 :     mpRbManEnd      ( get<RadioButton> ("manual_end") ),
     156           0 :     mpEdEnd         ( get<ScDoubleField>( "edit_end") ),
     157           0 :     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 : ScDPNumGroupInfo ScDPNumGroupDlg::GetGroupInfo() const
     177             : {
     178           0 :     ScDPNumGroupInfo aInfo;
     179           0 :     aInfo.mbEnable = true;
     180           0 :     aInfo.mbDateValues = false;
     181           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     182           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     183             : 
     184             :     // get values and silently auto-correct them, if they are not valid
     185             :     // TODO: error messages in OK event?
     186           0 :     aInfo.mfStart = maStartHelper.GetValue();
     187           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     188           0 :     if( !mpEdBy->GetValue( aInfo.mfStep ) || (aInfo.mfStep <= 0.0) )
     189           0 :         aInfo.mfStep = 1.0;
     190           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     191           0 :         aInfo.mfEnd = aInfo.mfStart + aInfo.mfStep;
     192             : 
     193           0 :     return aInfo;
     194             : }
     195             : 
     196           0 : ScDPDateGroupDlg::ScDPDateGroupDlg( vcl::Window* pParent,
     197             :         const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, const Date& rNullDate ) :
     198             :     ModalDialog( pParent, "PivotTableGroupByDate", "modules/scalc/ui/groupbydate.ui" ),
     199           0 :     mpRbAutoStart   ( get<RadioButton>("auto_start") ),
     200           0 :     mpRbManStart    ( get<RadioButton>("manual_start") ),
     201           0 :     mpEdStart       ( get<DateField>("start_date") ),
     202           0 :     mpRbAutoEnd     ( get<RadioButton>("auto_end") ),
     203           0 :     mpRbManEnd      ( get<RadioButton>("manual_end") ),
     204           0 :     mpEdEnd         ( get<DateField>("end_date") ),
     205           0 :     mpRbNumDays     ( get<RadioButton>("days") ),
     206           0 :     mpRbUnits       ( get<RadioButton>("intervals") ),
     207           0 :     mpEdNumDays     ( get<NumericField>("days_value") ),
     208           0 :     mpLbUnits       ( get<SvxCheckListBox>("interval_list") ),
     209           0 :     mpBtnOk         ( get<OKButton>("ok") ),
     210             :     maStartHelper   ( mpRbAutoStart, mpRbManStart, mpEdStart, rNullDate ),
     211           0 :     maEndHelper     ( mpRbAutoEnd, mpRbManEnd, mpEdEnd, rNullDate )
     212             : {
     213             :     static const size_t nCount = sizeof( nDatePartResIds ) / sizeof( nDatePartResIds[0] );
     214           0 :     for( size_t nIdx = 0 ; nIdx < nCount; ++nIdx )
     215           0 :         mpLbUnits->InsertEntry( ScGlobal::GetRscString( nDatePartResIds[nIdx] ) );
     216             : 
     217           0 :     mpEdStart->SetShowDateCentury( true );
     218           0 :     mpEdEnd->SetShowDateCentury( true );
     219             : 
     220           0 :     maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
     221           0 :     maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
     222             : 
     223           0 :     if( nDatePart == 0 )
     224           0 :         nDatePart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
     225           0 :     for( size_t nIdx = 0; nIdx < nCount; ++nIdx )
     226           0 :         mpLbUnits->CheckEntryPos( static_cast< sal_uInt16 >( nIdx ), (nDatePart & spnDateParts[ nIdx ]) != 0 );
     227             : 
     228           0 :     if( rInfo.mbDateValues )
     229             :     {
     230           0 :         mpRbNumDays->Check();
     231           0 :         ClickHdl( mpRbNumDays );
     232             : 
     233           0 :         double fNumDays = rInfo.mfStep;
     234           0 :         if( fNumDays < 1.0 )
     235           0 :             fNumDays = 1.0;
     236           0 :         else if( fNumDays > 32767.0 )
     237           0 :             fNumDays = 32767.0;
     238           0 :         mpEdNumDays->SetValue( static_cast< long >( fNumDays ) );
     239             :     }
     240             :     else
     241             :     {
     242           0 :         mpRbUnits->Check();
     243           0 :         ClickHdl( mpRbUnits );
     244             :     }
     245             : 
     246             :     /*  Set the initial focus, currently it is somewhere after calling all the radio
     247             :         button click handlers. Now the first enabled editable control is focused. */
     248           0 :     if( mpEdStart->IsEnabled() )
     249           0 :         mpEdStart->GrabFocus();
     250           0 :     else if( mpEdEnd->IsEnabled() )
     251           0 :         mpEdEnd->GrabFocus();
     252           0 :     else if( mpEdNumDays->IsEnabled() )
     253           0 :         mpEdNumDays->GrabFocus();
     254           0 :     else if( mpLbUnits->IsEnabled() )
     255           0 :         mpLbUnits->GrabFocus();
     256             : 
     257           0 :     mpRbNumDays->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     258           0 :     mpRbUnits->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     259           0 :     mpLbUnits->SetCheckButtonHdl( LINK( this, ScDPDateGroupDlg, CheckHdl ) );
     260           0 : }
     261             : 
     262           0 : ScDPNumGroupInfo ScDPDateGroupDlg::GetGroupInfo() const
     263             : {
     264           0 :     ScDPNumGroupInfo aInfo;
     265           0 :     aInfo.mbEnable = true;
     266           0 :     aInfo.mbDateValues = mpRbNumDays->IsChecked();
     267           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     268           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     269             : 
     270             :     // get values and silently auto-correct them, if they are not valid
     271             :     // TODO: error messages in OK event?
     272           0 :     aInfo.mfStart = maStartHelper.GetValue();
     273           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     274           0 :     sal_Int64 nNumDays = mpEdNumDays->GetValue();
     275           0 :     aInfo.mfStep = static_cast<double>( aInfo.mbDateValues ? nNumDays : 0L );
     276           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     277           0 :         aInfo.mfEnd = aInfo.mfStart + nNumDays;
     278             : 
     279           0 :     return aInfo;
     280             : }
     281             : 
     282           0 : sal_Int32 ScDPDateGroupDlg::GetDatePart() const
     283             : {
     284             :     // return DAYS for special "number of days" mode
     285           0 :     if( mpRbNumDays->IsChecked() )
     286           0 :         return com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
     287             : 
     288             :     // return listbox contents for "units" mode
     289           0 :     sal_Int32 nDatePart = 0;
     290           0 :     for( sal_uLong nIdx = 0, nCount = mpLbUnits->GetEntryCount(); nIdx < nCount; ++nIdx )
     291           0 :         if( mpLbUnits->IsChecked( static_cast< sal_uInt16 >( nIdx ) ) )
     292           0 :             nDatePart |= spnDateParts[ nIdx ];
     293           0 :     return nDatePart;
     294             : }
     295             : 
     296           0 : IMPL_LINK( ScDPDateGroupDlg, ClickHdl, RadioButton*, pButton )
     297             : {
     298           0 :     if( pButton == mpRbNumDays )
     299             :     {
     300           0 :         mpLbUnits->Disable();
     301             :         // enable and set focus to edit field on clicking "num of days" radio button
     302           0 :         mpEdNumDays->Enable();
     303           0 :         mpEdNumDays->GrabFocus();
     304           0 :         mpBtnOk->Enable();
     305             :     }
     306           0 :     else if( pButton == mpRbUnits )
     307             :     {
     308           0 :         mpEdNumDays->Disable();
     309             :         // enable and set focus to listbox on clicking "units" radio button
     310           0 :         mpLbUnits->Enable();
     311           0 :         mpLbUnits->GrabFocus();
     312             :         // disable OK button if no date part selected
     313           0 :         CheckHdl( mpLbUnits );
     314             :     }
     315           0 :     return 0;
     316             : }
     317             : 
     318           0 : IMPL_LINK( ScDPDateGroupDlg, CheckHdl, SvxCheckListBox*, pListBox )
     319             : {
     320             :     // enable/disable OK button on modifying check list box
     321           0 :     if( pListBox == mpLbUnits )
     322           0 :         mpBtnOk->Enable( mpLbUnits->GetCheckedEntryCount() > 0 );
     323           0 :     return 0;
     324           0 : }
     325             : 
     326             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10