kspread Library API Documentation

kspread_dlg_series.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
00003              (C) 2002-2003 Norbert Andres <nandres@web.de>
00004              (C) 2002 John Dailey <dailey@vt.edu>
00005              (C) 1999-2002 Laurent Montel <montel@kde.org>
00006              (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
00007              (C) 2000-2001 Werner Trobin <trobin@kde.org>
00008              (C) 1998-2000 Torben Weis <weis@kde.org>
00009    
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Library General Public
00012    License as published by the Free Software Foundation; either
00013    version 2 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Library General Public License for more details.
00019 
00020    You should have received a copy of the GNU Library General Public License
00021    along with this library; see the file COPYING.LIB.  If not, write to
00022    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023    Boston, MA 02111-1307, USA.
00024 */
00025 
00026 
00027 #include "kspread_dlg_series.h"
00028 #include "kspread_doc.h"
00029 #include "kspread_editors.h"
00030 #include "kspread_sheet.h"
00031 #include "kspread_view.h"
00032 
00033 #include <qlayout.h>
00034 #include <klocale.h>
00035 #include <qlabel.h>
00036 
00037 #include <qbuttongroup.h>
00038 #include <qgroupbox.h>
00039 #include <kmessagebox.h>
00040 #include <knumvalidator.h>
00041 
00042 #include <qradiobutton.h>
00043 #include <qcheckbox.h>
00044 #include <qlineedit.h>
00045 #include <qwhatsthis.h>
00046 #include <knuminput.h>
00047 
00048 
00049 KSpreadSeriesDlg::KSpreadSeriesDlg( KSpreadView* parent, const char* name,const QPoint &_marker)
00050   : KDialogBase( parent, name,TRUE,i18n("Series"),Ok|Cancel )
00051 {
00052   m_pView = parent;
00053   marker=_marker;
00054   QWidget *page = new QWidget( this );
00055   setMainWidget(page);
00056 
00057   QBoxLayout *grid1 = new QHBoxLayout(page);
00058   grid1->setSpacing( spacingHint() );
00059 
00060   QButtonGroup* gb1 = new QButtonGroup( 2, Qt::Vertical,
00061     i18n("Insert Values"), page );
00062   column = new QRadioButton( i18n("Vertical"), gb1 );
00063   QWhatsThis::add(column, i18n("Insert the series vertically, one below the other") );
00064   row = new QRadioButton( i18n("Horizontal"), gb1 );
00065   QWhatsThis::add(row, i18n("Insert the series horizontally, from left to right") );
00066 
00067   column->setChecked(true);
00068 
00069   QButtonGroup* gb2 = new QButtonGroup( 2, Qt::Vertical,
00070     i18n("Type"), page );
00071   linear = new QRadioButton( i18n("Linear (2,4,6,...)"), gb2 );
00072   QWhatsThis::add(linear, i18n("Generate a series from 'start' to 'end' and for each step add "
00073      "the value provided in step. This creates a series where each value "
00074      "is 'step' larger than the value before it.") );
00075   geometric = new QRadioButton( i18n("Geometric (2,4,8,...)"), gb2 );
00076   QWhatsThis::add(geometric, i18n("Generate a series from 'start' to 'end' and for each step multiply "
00077      "the value with the value provided in step. Using a step of 5 produces a list like: "
00078       "5, 25, 125, 625 since 5 multiplied by 5 (step) equals 25, and that multiplied by 5 equals 125, "
00079       "which multiplied by the same step-value of 5 equals 625.") );
00080 
00081   linear->setChecked(true);
00082 
00083   QGroupBox* gb = new QGroupBox( 1, Qt::Vertical, i18n("Parameters"), page );
00084   QWidget *params = new QWidget( gb );
00085   QGridLayout *params_layout = new QGridLayout( params, 3, 2 );
00086   params_layout->setSpacing( spacingHint() );
00087   params_layout->setAutoAdd( true );
00088 
00089   new QLabel( i18n( "Start value:" ), params );
00090   start=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
00091 
00092   new QLabel( i18n( "Stop value:" ), params );
00093   end=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
00094 
00095   new QLabel( i18n( "Step value:" ), params );
00096   step=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
00097  
00098   grid1->addWidget(gb);
00099 
00100   grid1->addWidget(gb1);
00101   grid1->addWidget(gb2);
00102 
00103   start->setFocus();
00104 
00105   connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00106 }
00107 
00108 
00109 void KSpreadSeriesDlg::slotOk()
00110 {
00111 
00112   Series mode=Column;  //same as Vertical
00113   Series type=Linear;  // same as Horizontal
00114   QString tmp;
00115   double dstep, dend, dstart;
00116   KSpreadSheet * m_pSheet;
00117   m_pSheet = m_pView->activeSheet();
00118 
00119   if(column->isChecked())
00120     mode = Column;
00121   else if(row->isChecked())
00122     mode = Row;
00123 
00124   if (linear->isChecked())
00125     type = Linear;
00126   else if (geometric->isChecked())
00127     type = Geometric;
00128 
00129   dstart = start->value();
00130   dend= end->value();
00131   dstep = step->value();
00132   if ( type == Geometric )
00133   {
00134       if  ( dstart < 0 || dend < 0 )
00135       {
00136           KMessageBox::error( this, i18n("End and start value must be positive.") );
00137           return;
00138       }
00139       if ( dstart > dend && dstep >= 1)
00140       {
00141         KMessageBox::error( this, i18n("End value must be greater than the start value or the step must be less than '1'.") );
00142         return;
00143       }
00144       if ( dstart == 0 || dend == 0 || dstep == 0)
00145       {
00146         KMessageBox::error( this, i18n("None of the Start, Stop or Step values may be equal to zero.") );
00147         return;
00148       }
00149       if ( dstep == 1)
00150       {
00151         KMessageBox::error( this, i18n("Step value must be different from 1") );
00152         return;
00153       }
00154   }
00155 
00156   if (dstep >= 0)
00157   {
00158       if (linear->isChecked() && dstep == 0)
00159       {
00160           KMessageBox::error( this, i18n("The step value must be greater than zero; "
00161                                          "otherwise, the linear series is infinite.") );
00162           step->setFocus();
00163           return;
00164       }
00165       /*      else if (geometric->isChecked() && dstep <= 1)
00166               {
00167               KMessageBox::error( this, i18n("The step value must be greater than one; "
00168                                        "otherwise, the geometric series is infinite.") );
00169                                        step->setFocus();
00170                                        return;
00171                                        }
00172       */
00173       else if ( type == Linear && dend < dstart )
00174       {
00175           KMessageBox::error( this,
00176                               i18n("If the start value is greater than the end value the step must be less than zero.") );
00177           return;
00178       }
00179   }
00180   else if (type != Linear)
00181   {
00182       KMessageBox::error( this, i18n("Step is negative.") );
00183       return;
00184   }
00185   else
00186   {
00187       if (dstart <= dend)
00188       {
00189         KMessageBox::error( this,
00190                             i18n("If the step is negative, the start value must be greater then the end value.") );
00191         return;
00192       }
00193   }
00194 
00195   //        double val_end = QMAX(dend, dstart);
00196   //        double val_start = QMIN(dend, dstart);
00197   m_pView->doc()->emitBeginOperation( false );
00198 
00199   m_pSheet->setSeries( marker, dstart, dend, dstep, mode, type );
00200 
00201   KSpreadCell * cell = m_pSheet->cellAt( marker.x(), marker.y() );
00202   if ( cell->text() != 0L )
00203     m_pView->editWidget()->setText( cell->text() );
00204   else
00205     m_pView->editWidget()->setText( "" );
00206 
00207   m_pView->slotUpdateView( m_pView->activeSheet() );
00208   accept();
00209 }
00210 
00211 
00212 #include "kspread_dlg_series.moc"
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:43:02 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003