You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
6.9 KiB
214 lines
6.9 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
|
||
|
(C) 2002-2003 Norbert Andres <nandres@web.de>
|
||
|
(C) 2002 John Dailey <dailey@vt.edu>
|
||
|
(C) 1999-2002 Laurent Montel <montel@kde.org>
|
||
|
(C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
|
||
|
(C) 2000-2001 Werner Trobin <trobin@kde.org>
|
||
|
(C) 1998-2000 Torben Weis <weis@kde.org>
|
||
10 years ago
|
|
||
15 years ago
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
|
||
|
#include "kspread_dlg_series.h"
|
||
|
#include "kspread_doc.h"
|
||
|
#include "kspread_editors.h"
|
||
|
#include "kspread_sheet.h"
|
||
|
#include "kspread_view.h"
|
||
|
|
||
13 years ago
|
#include <tqlayout.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
14 years ago
|
#include <tqlabel.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqbuttongroup.h>
|
||
|
#include <tqgroupbox.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <knumvalidator.h>
|
||
|
|
||
14 years ago
|
#include <tqradiobutton.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqlineedit.h>
|
||
|
#include <tqwhatsthis.h>
|
||
15 years ago
|
#include <knuminput.h>
|
||
|
|
||
|
using namespace KSpread;
|
||
|
|
||
14 years ago
|
SeriesDlg::SeriesDlg( View* parent, const char* name,const TQPoint &_marker)
|
||
|
: KDialogBase( parent, name,TRUE,i18n("Series"),Ok|Cancel )
|
||
15 years ago
|
{
|
||
14 years ago
|
m_pView = parent;
|
||
15 years ago
|
marker=_marker;
|
||
14 years ago
|
TQWidget *page = new TQWidget( this );
|
||
15 years ago
|
setMainWidget(page);
|
||
|
|
||
14 years ago
|
TQBoxLayout *grid1 = new TQHBoxLayout(page);
|
||
15 years ago
|
grid1->setSpacing( spacingHint() );
|
||
|
|
||
14 years ago
|
TQButtonGroup* gb1 = new TQButtonGroup( 2, Qt::Vertical,
|
||
15 years ago
|
i18n("Insert Values"), page );
|
||
14 years ago
|
column = new TQRadioButton( i18n("Vertical"), gb1 );
|
||
|
TQWhatsThis::add(column, i18n("Insert the series vertically, one below the other") );
|
||
|
row = new TQRadioButton( i18n("Horizontal"), gb1 );
|
||
|
TQWhatsThis::add(row, i18n("Insert the series horizontally, from left to right") );
|
||
15 years ago
|
|
||
|
column->setChecked(true);
|
||
|
|
||
14 years ago
|
TQButtonGroup* gb2 = new TQButtonGroup( 2, Qt::Vertical,
|
||
15 years ago
|
i18n("Type"), page );
|
||
14 years ago
|
linear = new TQRadioButton( i18n("Linear (2,4,6,...)"), gb2 );
|
||
|
TQWhatsThis::add(linear, i18n("Generate a series from 'start' to 'end' and for each step add "
|
||
15 years ago
|
"the value provided in step. This creates a series where each value "
|
||
|
"is 'step' larger than the value before it.") );
|
||
14 years ago
|
geometric = new TQRadioButton( i18n("Geometric (2,4,8,...)"), gb2 );
|
||
|
TQWhatsThis::add(geometric, i18n("Generate a series from 'start' to 'end' and for each step multiply "
|
||
15 years ago
|
"the value with the value provided in step. Using a step of 5 produces a list like: "
|
||
|
"5, 25, 125, 625 since 5 multiplied by 5 (step) equals 25, and that multiplied by 5 equals 125, "
|
||
|
"which multiplied by the same step-value of 5 equals 625.") );
|
||
|
|
||
|
linear->setChecked(true);
|
||
|
|
||
14 years ago
|
TQGroupBox* gb = new TQGroupBox( 1, Qt::Vertical, i18n("Parameters"), page );
|
||
|
TQWidget *params = new TQWidget( gb );
|
||
|
TQGridLayout *params_layout = new TQGridLayout( params, 3, 2 );
|
||
15 years ago
|
params_layout->setSpacing( spacingHint() );
|
||
|
params_layout->setAutoAdd( true );
|
||
|
|
||
14 years ago
|
new TQLabel( i18n( "Start value:" ), params );
|
||
15 years ago
|
start=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
|
||
|
|
||
14 years ago
|
new TQLabel( i18n( "Stop value:" ), params );
|
||
15 years ago
|
end=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
|
||
|
|
||
14 years ago
|
new TQLabel( i18n( "Step value:" ), params );
|
||
15 years ago
|
step=new KDoubleNumInput(-999999.999, 999999.99, 0.0, 1.0, 3, params);
|
||
10 years ago
|
|
||
15 years ago
|
grid1->addWidget(gb);
|
||
|
|
||
|
grid1->addWidget(gb1);
|
||
|
grid1->addWidget(gb2);
|
||
|
|
||
|
start->setFocus();
|
||
|
|
||
14 years ago
|
connect( this, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( slotOk() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void SeriesDlg::slotOk()
|
||
|
{
|
||
|
|
||
10 years ago
|
Series mode=Column; //same as Qt::Vertical
|
||
|
Series type=Linear; // same as Qt::Horizontal
|
||
14 years ago
|
TQString tmp;
|
||
15 years ago
|
double dstep, dend, dstart;
|
||
|
Sheet * m_pSheet;
|
||
|
m_pSheet = m_pView->activeSheet();
|
||
|
|
||
|
if(column->isChecked())
|
||
|
mode = Column;
|
||
|
else if(row->isChecked())
|
||
|
mode = Row;
|
||
|
|
||
|
if (linear->isChecked())
|
||
|
type = Linear;
|
||
|
else if (geometric->isChecked())
|
||
|
type = Geometric;
|
||
|
|
||
|
dstart = start->value();
|
||
|
dend= end->value();
|
||
|
dstep = step->value();
|
||
|
if ( type == Geometric )
|
||
|
{
|
||
|
if ( dstart < 0 || dend < 0 )
|
||
|
{
|
||
|
KMessageBox::error( this, i18n("End and start value must be positive.") );
|
||
|
return;
|
||
|
}
|
||
|
if ( dstart > dend && dstep >= 1)
|
||
|
{
|
||
|
KMessageBox::error( this, i18n("End value must be greater than the start value or the step must be less than '1'.") );
|
||
|
return;
|
||
|
}
|
||
|
if ( dstart == 0 || dend == 0 || dstep == 0)
|
||
|
{
|
||
|
KMessageBox::error( this, i18n("None of the Start, Stop or Step values may be equal to zero.") );
|
||
|
return;
|
||
|
}
|
||
|
if ( dstep == 1)
|
||
|
{
|
||
|
KMessageBox::error( this, i18n("Step value must be different from 1") );
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (dstep >= 0)
|
||
|
{
|
||
|
if (linear->isChecked() && dstep == 0)
|
||
|
{
|
||
|
KMessageBox::error( this, i18n("The step value must be greater than zero; "
|
||
|
"otherwise, the linear series is infinite.") );
|
||
|
step->setFocus();
|
||
|
return;
|
||
|
}
|
||
|
/* else if (geometric->isChecked() && dstep <= 1)
|
||
|
{
|
||
|
KMessageBox::error( this, i18n("The step value must be greater than one; "
|
||
|
"otherwise, the geometric series is infinite.") );
|
||
|
step->setFocus();
|
||
|
return;
|
||
|
}
|
||
|
*/
|
||
|
else if ( type == Linear && dend < dstart )
|
||
|
{
|
||
|
KMessageBox::error( this,
|
||
|
i18n("If the start value is greater than the end value the step must be less than zero.") );
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
else if (type != Linear)
|
||
|
{
|
||
|
KMessageBox::error( this, i18n("Step is negative.") );
|
||
|
return;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (dstart <= dend)
|
||
|
{
|
||
|
KMessageBox::error( this,
|
||
|
i18n("If the step is negative, the start value must be greater then the end value.") );
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
// double val_end = TQMAX(dend, dstart);
|
||
|
// double val_start = TQMIN(dend, dstart);
|
||
15 years ago
|
m_pView->doc()->emitBeginOperation( false );
|
||
|
|
||
|
m_pSheet->setSeries( marker, dstart, dend, dstep, mode, type );
|
||
|
|
||
|
Cell * cell = m_pSheet->cellAt( marker.x(), marker.y() );
|
||
|
if ( cell->text() != 0L )
|
||
|
m_pView->editWidget()->setText( cell->text() );
|
||
|
else
|
||
|
m_pView->editWidget()->setText( "" );
|
||
|
|
||
|
m_pView->slotUpdateView( m_pView->activeSheet() );
|
||
|
accept();
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "kspread_dlg_series.moc"
|