00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 using namespace KSpread;
00049
00050 SeriesDlg::SeriesDlg( View* parent, const char* name,const QPoint &_marker)
00051 : KDialogBase( parent, name,TRUE,i18n("Series"),Ok|Cancel )
00052 {
00053 m_pView = parent;
00054 marker=_marker;
00055 QWidget *page = new QWidget( this );
00056 setMainWidget(page);
00057
00058 QBoxLayout *grid1 = new QHBoxLayout(page);
00059 grid1->setSpacing( spacingHint() );
00060
00061 QButtonGroup* gb1 = new QButtonGroup( 2, Qt::Vertical,
00062 i18n("Insert Values"), page );
00063 column = new QRadioButton( i18n("Vertical"), gb1 );
00064 QWhatsThis::add(column, i18n("Insert the series vertically, one below the other") );
00065 row = new QRadioButton( i18n("Horizontal"), gb1 );
00066 QWhatsThis::add(row, i18n("Insert the series horizontally, from left to right") );
00067
00068 column->setChecked(true);
00069
00070 QButtonGroup* gb2 = new QButtonGroup( 2, Qt::Vertical,
00071 i18n("Type"), page );
00072 linear = new QRadioButton( i18n("Linear (2,4,6,...)"), gb2 );
00073 QWhatsThis::add(linear, i18n("Generate a series from 'start' to 'end' and for each step add "
00074 "the value provided in step. This creates a series where each value "
00075 "is 'step' larger than the value before it.") );
00076 geometric = new QRadioButton( i18n("Geometric (2,4,8,...)"), gb2 );
00077 QWhatsThis::add(geometric, i18n("Generate a series from 'start' to 'end' and for each step multiply "
00078 "the value with the value provided in step. Using a step of 5 produces a list like: "
00079 "5, 25, 125, 625 since 5 multiplied by 5 (step) equals 25, and that multiplied by 5 equals 125, "
00080 "which multiplied by the same step-value of 5 equals 625.") );
00081
00082 linear->setChecked(true);
00083
00084 QGroupBox* gb = new QGroupBox( 1, Qt::Vertical, i18n("Parameters"), page );
00085 QWidget *params = new QWidget( gb );
00086 QGridLayout *params_layout = new QGridLayout( params, 3, 2 );
00087 params_layout->setSpacing( spacingHint() );
00088 params_layout->setAutoAdd( true );
00089
00090 new QLabel( i18n( "Start value:" ), params );
00091 start=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
00092
00093 new QLabel( i18n( "Stop value:" ), params );
00094 end=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
00095
00096 new QLabel( i18n( "Step value:" ), params );
00097 step=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
00098
00099 grid1->addWidget(gb);
00100
00101 grid1->addWidget(gb1);
00102 grid1->addWidget(gb2);
00103
00104 start->setFocus();
00105
00106 connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00107 }
00108
00109
00110 void SeriesDlg::slotOk()
00111 {
00112
00113 Series mode=Column;
00114 Series type=Linear;
00115 QString tmp;
00116 double dstep, dend, dstart;
00117 Sheet * m_pSheet;
00118 m_pSheet = m_pView->activeSheet();
00119
00120 if(column->isChecked())
00121 mode = Column;
00122 else if(row->isChecked())
00123 mode = Row;
00124
00125 if (linear->isChecked())
00126 type = Linear;
00127 else if (geometric->isChecked())
00128 type = Geometric;
00129
00130 dstart = start->value();
00131 dend= end->value();
00132 dstep = step->value();
00133 if ( type == Geometric )
00134 {
00135 if ( dstart < 0 || dend < 0 )
00136 {
00137 KMessageBox::error( this, i18n("End and start value must be positive.") );
00138 return;
00139 }
00140 if ( dstart > dend && dstep >= 1)
00141 {
00142 KMessageBox::error( this, i18n("End value must be greater than the start value or the step must be less than '1'.") );
00143 return;
00144 }
00145 if ( dstart == 0 || dend == 0 || dstep == 0)
00146 {
00147 KMessageBox::error( this, i18n("None of the Start, Stop or Step values may be equal to zero.") );
00148 return;
00149 }
00150 if ( dstep == 1)
00151 {
00152 KMessageBox::error( this, i18n("Step value must be different from 1") );
00153 return;
00154 }
00155 }
00156
00157 if (dstep >= 0)
00158 {
00159 if (linear->isChecked() && dstep == 0)
00160 {
00161 KMessageBox::error( this, i18n("The step value must be greater than zero; "
00162 "otherwise, the linear series is infinite.") );
00163 step->setFocus();
00164 return;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174 else if ( type == Linear && dend < dstart )
00175 {
00176 KMessageBox::error( this,
00177 i18n("If the start value is greater than the end value the step must be less than zero.") );
00178 return;
00179 }
00180 }
00181 else if (type != Linear)
00182 {
00183 KMessageBox::error( this, i18n("Step is negative.") );
00184 return;
00185 }
00186 else
00187 {
00188 if (dstart <= dend)
00189 {
00190 KMessageBox::error( this,
00191 i18n("If the step is negative, the start value must be greater then the end value.") );
00192 return;
00193 }
00194 }
00195
00196
00197
00198 m_pView->doc()->emitBeginOperation( false );
00199
00200 m_pSheet->setSeries( marker, dstart, dend, dstep, mode, type );
00201
00202 Cell * cell = m_pSheet->cellAt( marker.x(), marker.y() );
00203 if ( cell->text() != 0L )
00204 m_pView->editWidget()->setText( cell->text() );
00205 else
00206 m_pView->editWidget()->setText( "" );
00207
00208 m_pView->slotUpdateView( m_pView->activeSheet() );
00209 accept();
00210 }
00211
00212
00213 #include "kspread_dlg_series.moc"