kspread

kspread_dlg_series.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
3 (C) 2002-2003 Norbert Andres <nandres@web.de>
4 (C) 2002 John Dailey <dailey@vt.edu>
5 (C) 1999-2002 Laurent Montel <montel@kde.org>
6 (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
7 (C) 2000-2001 Werner Trobin <trobin@kde.org>
8 (C) 1998-2000 Torben Weis <weis@kde.org>
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24*/
25
26
27#include "kspread_dlg_series.h"
28#include "kspread_doc.h"
29#include "kspread_editors.h"
30#include "kspread_sheet.h"
31#include "kspread_view.h"
32
33#include <tqlayout.h>
34#include <tdelocale.h>
35#include <tqlabel.h>
36
37#include <tqbuttongroup.h>
38#include <tqgroupbox.h>
39#include <tdemessagebox.h>
40#include <knumvalidator.h>
41
42#include <tqradiobutton.h>
43#include <tqcheckbox.h>
44#include <tqlineedit.h>
45#include <tqwhatsthis.h>
46#include <knuminput.h>
47
48using namespace KSpread;
49
50SeriesDlg::SeriesDlg( View* parent, const char* name,const TQPoint &_marker)
51 : KDialogBase( parent, name,true,i18n("Series"),Ok|Cancel )
52{
53 m_pView = parent;
54 marker=_marker;
55 TQWidget *page = new TQWidget( this );
56 setMainWidget(page);
57
58 TQBoxLayout *grid1 = new TQHBoxLayout(page);
59 grid1->setSpacing( spacingHint() );
60
61 TQButtonGroup* gb1 = new TQButtonGroup( 2, TQt::Vertical,
62 i18n("Insert Values"), page );
63 column = new TQRadioButton( i18n("Vertical"), gb1 );
64 TQWhatsThis::add(column, i18n("Insert the series vertically, one below the other") );
65 row = new TQRadioButton( i18n("Horizontal"), gb1 );
66 TQWhatsThis::add(row, i18n("Insert the series horizontally, from left to right") );
67
68 column->setChecked(true);
69
70 TQButtonGroup* gb2 = new TQButtonGroup( 2, TQt::Vertical,
71 i18n("Type"), page );
72 linear = new TQRadioButton( i18n("Linear (2,4,6,...)"), gb2 );
73 TQWhatsThis::add(linear, i18n("Generate a series from 'start' to 'end' and for each step add "
74 "the value provided in step. This creates a series where each value "
75 "is 'step' larger than the value before it.") );
76 geometric = new TQRadioButton( i18n("Geometric (2,4,8,...)"), gb2 );
77 TQWhatsThis::add(geometric, i18n("Generate a series from 'start' to 'end' and for each step multiply "
78 "the value with the value provided in step. Using a step of 5 produces a list like: "
79 "5, 25, 125, 625 since 5 multiplied by 5 (step) equals 25, and that multiplied by 5 equals 125, "
80 "which multiplied by the same step-value of 5 equals 625.") );
81
82 linear->setChecked(true);
83
84 TQGroupBox* gb = new TQGroupBox( 1, TQt::Vertical, i18n("Parameters"), page );
85 TQWidget *params = new TQWidget( gb );
86 TQGridLayout *params_layout = new TQGridLayout( params, 3, 2 );
87 params_layout->setSpacing( spacingHint() );
88 params_layout->setAutoAdd( true );
89
90 new TQLabel( i18n( "Start value:" ), params );
91 start=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
92
93 new TQLabel( i18n( "Stop value:" ), params );
94 end=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
95
96 new TQLabel( i18n( "Step value:" ), params );
97 step=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
98
99 grid1->addWidget(gb);
100
101 grid1->addWidget(gb1);
102 grid1->addWidget(gb2);
103
104 start->setFocus();
105
106 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( slotOk() ) );
107}
108
109
110void SeriesDlg::slotOk()
111{
112
113 Series mode=Column; //same as Vertical
114 Series type=Linear; // same as Horizontal
115 TQString tmp;
116 double dstep, dend, dstart;
117 Sheet * m_pSheet;
118 m_pSheet = m_pView->activeSheet();
119
120 if(column->isChecked())
121 mode = Column;
122 else if(row->isChecked())
123 mode = Row;
124
125 if (linear->isChecked())
126 type = Linear;
127 else if (geometric->isChecked())
128 type = Geometric;
129
130 dstart = start->value();
131 dend= end->value();
132 dstep = step->value();
133 if ( type == Geometric )
134 {
135 if ( dstart < 0 || dend < 0 )
136 {
137 KMessageBox::error( this, i18n("End and start value must be positive.") );
138 return;
139 }
140 if ( dstart > dend && dstep >= 1)
141 {
142 KMessageBox::error( this, i18n("End value must be greater than the start value or the step must be less than '1'.") );
143 return;
144 }
145 if ( dstart == 0 || dend == 0 || dstep == 0)
146 {
147 KMessageBox::error( this, i18n("None of the Start, Stop or Step values may be equal to zero.") );
148 return;
149 }
150 if ( dstep == 1)
151 {
152 KMessageBox::error( this, i18n("Step value must be different from 1") );
153 return;
154 }
155 }
156
157 if (dstep >= 0)
158 {
159 if (linear->isChecked() && dstep == 0)
160 {
161 KMessageBox::error( this, i18n("The step value must be greater than zero; "
162 "otherwise, the linear series is infinite.") );
163 step->setFocus();
164 return;
165 }
166 /* else if (geometric->isChecked() && dstep <= 1)
167 {
168 KMessageBox::error( this, i18n("The step value must be greater than one; "
169 "otherwise, the geometric series is infinite.") );
170 step->setFocus();
171 return;
172 }
173 */
174 else if ( type == Linear && dend < dstart )
175 {
176 KMessageBox::error( this,
177 i18n("If the start value is greater than the end value the step must be less than zero.") );
178 return;
179 }
180 }
181 else if (type != Linear)
182 {
183 KMessageBox::error( this, i18n("Step is negative.") );
184 return;
185 }
186 else
187 {
188 if (dstart <= dend)
189 {
190 KMessageBox::error( this,
191 i18n("If the step is negative, the start value must be greater then the end value.") );
192 return;
193 }
194 }
195
196 // double val_end = TQMAX(dend, dstart);
197 // double val_start = TQMIN(dend, dstart);
198 m_pView->doc()->emitBeginOperation( false );
199
200 m_pSheet->setSeries( marker, dstart, dend, dstep, mode, type );
201
202 Cell * cell = m_pSheet->cellAt( marker.x(), marker.y() );
203 if ( cell->text() != 0L )
204 m_pView->editWidget()->setText( cell->text() );
205 else
206 m_pView->editWidget()->setText( "" );
207
208 m_pView->slotUpdateView( m_pView->activeSheet() );
209 accept();
210}
211
212
213#include "kspread_dlg_series.moc"
For every cell in the spread sheet there is a Cell object.
TQString text() const
Return the text the user entered.
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39