kspread

kspread_dlg_csv.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
3 (C) 2002-2003 Ariya Hidayat <ariya@kde.org>
4 (C) 2002 Laurent Montel <montel@kde.org>
5 (C) 1999 David Faure <faure@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21*/
22
23#include <tqbuttongroup.h>
24#include <tqcheckbox.h>
25#include <tqclipboard.h>
26#include <tqcombobox.h>
27#include <tqlabel.h>
28#include <tqlineedit.h>
29#include <tqmime.h>
30#include <tqpushbutton.h>
31#include <tqradiobutton.h>
32#include <tqtable.h>
33#include <tqlayout.h>
34
35#include <tdeapplication.h>
36#include <kdebug.h>
37#include <kdialogbase.h>
38#include <tdefiledialog.h>
39#include <tdelocale.h>
40#include <tdemessagebox.h>
41
42#include <kspread_cell.h>
43#include <kspread_doc.h>
44#include <kspread_sheet.h>
45#include <kspread_undo.h>
46#include <kspread_view.h>
47
48#include "kspread_dlg_csv.h"
49
50using namespace KSpread;
51
52CSVDialog::CSVDialog( View * parent, const char * name, TQRect const & rect, Mode mode)
53 : KDialogBase( parent, name, true, TQString(), Ok|Cancel ),
54 m_pView( parent ),
55 m_cancelled( false ),
56 m_adjustRows( 0 ),
57 m_startline( 0 ),
58 m_textquote( '"' ),
59 m_delimiter( "," ),
60 m_targetRect( rect ),
61 m_mode( mode )
62{
63 if ( !name )
64 setName( "CSV" );
65
66 setSizeGripEnabled( true );
67
68 TQWidget* page = new TQWidget( this );
69 setMainWidget( page );
70 // MyDialogLayout = new TQGridLayout( page, 4, 4, marginHint(), spacingHint(), "MyDialogLayout");
71 MyDialogLayout = new TQGridLayout( page, 1, 1, 11, 6, "MyDialogLayout");
72
73 // Limit the range
74 int column = m_targetRect.left();
75 Cell* lastCell = m_pView->activeSheet()->getLastCellColumn( column );
76 if( lastCell )
77 if( m_targetRect.bottom() > lastCell->row() )
78 m_targetRect.setBottom( lastCell->row() );
79
80 m_sheet = new TQTable( page, "m_table" );
81 //m_sheet->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)5, (TQSizePolicy::SizeType)7, 0, 0, m_sheet->sizePolicy().hasHeightForWidth() ) );
82 m_sheet->setNumRows( 0 );
83 m_sheet->setNumCols( 0 );
84
85 MyDialogLayout->addMultiCellWidget( m_sheet, 3, 3, 0, 3 );
86
87 // Delimiter: comma, semicolon, tab, space, other
88 m_delimiterBox = new TQButtonGroup( page, "m_delimiterBox" );
89 m_delimiterBox->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1, (TQSizePolicy::SizeType)1, 0, 0, m_delimiterBox->sizePolicy().hasHeightForWidth() ) );
90 m_delimiterBox->setTitle( i18n( "Delimiter" ) );
91 m_delimiterBox->setColumnLayout(0, TQt::Vertical );
92 m_delimiterBox->layout()->setSpacing( KDialog::spacingHint() );
93 m_delimiterBox->layout()->setMargin( KDialog::marginHint() );
94 m_delimiterBoxLayout = new TQGridLayout( m_delimiterBox->layout() );
95 m_delimiterBoxLayout->setAlignment( TQt::AlignTop );
96 MyDialogLayout->addMultiCellWidget( m_delimiterBox, 0, 2, 0, 0 );
97
98 m_ignoreDuplicates = new TQCheckBox( page, "m_ignoreDuplicates" );
99 m_ignoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) );
100
101 MyDialogLayout->addMultiCellWidget( m_ignoreDuplicates, 2, 2, 2, 3 );
102
103 m_radioComma = new TQRadioButton( m_delimiterBox, "m_radioComma" );
104 m_radioComma->setText( i18n( "Comma" ) );
105 m_radioComma->setChecked( true );
106 m_delimiterBoxLayout->addWidget( m_radioComma, 0, 0 );
107
108 m_radioSemicolon = new TQRadioButton( m_delimiterBox, "m_radioSemicolon" );
109 m_radioSemicolon->setText( i18n( "Semicolon" ) );
110 m_delimiterBoxLayout->addWidget( m_radioSemicolon, 0, 1 );
111
112 m_radioTab = new TQRadioButton( m_delimiterBox, "m_radioTab" );
113 m_radioTab->setText( i18n( "Tabulator" ) );
114 m_delimiterBoxLayout->addWidget( m_radioTab, 1, 0 );
115
116 m_radioSpace = new TQRadioButton( m_delimiterBox, "m_radioSpace" );
117 m_radioSpace->setText( i18n( "Space" ) );
118 m_delimiterBoxLayout->addWidget( m_radioSpace, 1, 1 );
119
120 m_radioOther = new TQRadioButton( m_delimiterBox, "m_radioOther" );
121 m_radioOther->setText( i18n( "Other" ) );
122 m_delimiterBoxLayout->addWidget( m_radioOther, 0, 2 );
123
124 m_delimiterEdit = new TQLineEdit( m_delimiterBox, "m_delimiterEdit" );
125 m_delimiterEdit->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)0, (TQSizePolicy::SizeType)0, 0, 0, m_delimiterEdit->sizePolicy().hasHeightForWidth() ) );
126 m_delimiterEdit->setMaximumSize( TQSize( 30, 32767 ) );
127 m_delimiterBoxLayout->addWidget( m_delimiterEdit, 1, 2 );
128
129
130 // Format: number, text, currency,
131 m_formatBox = new TQButtonGroup( page, "m_formatBox" );
132 m_formatBox->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1, (TQSizePolicy::SizeType)1, 0, 0, m_formatBox->sizePolicy().hasHeightForWidth() ) );
133 m_formatBox->setTitle( i18n( "Format" ) );
134 m_formatBox->setColumnLayout(0, TQt::Vertical );
135 m_formatBox->layout()->setSpacing( KDialog::spacingHint() );
136 m_formatBox->layout()->setMargin( KDialog::marginHint() );
137 m_formatBoxLayout = new TQGridLayout( m_formatBox->layout() );
138 m_formatBoxLayout->setAlignment( TQt::AlignTop );
139 MyDialogLayout->addMultiCellWidget( m_formatBox, 0, 2, 1, 1 );
140
141 m_radioNumber = new TQRadioButton( m_formatBox, "m_radioNumber" );
142 m_radioNumber->setText( i18n( "Number" ) );
143 m_formatBoxLayout->addMultiCellWidget( m_radioNumber, 1, 1, 0, 1 );
144
145 m_radioText = new TQRadioButton( m_formatBox, "m_radioText" );
146 m_radioText->setText( i18n( "Text" ) );
147 m_radioText->setChecked( true );
148 m_formatBoxLayout->addWidget( m_radioText, 0, 0 );
149
150 m_radioCurrency = new TQRadioButton( m_formatBox, "m_radioCurrency" );
151 m_radioCurrency->setText( i18n( "Currency" ) );
152 m_formatBoxLayout->addMultiCellWidget( m_radioCurrency, 0, 0, 1, 2 );
153
154 m_radioDate = new TQRadioButton( m_formatBox, "m_radioDate" );
155 m_radioDate->setText( i18n( "Date" ) );
156 m_formatBoxLayout->addWidget( m_radioDate, 1, 2 );
157
158 m_comboLine = new TQComboBox( false, page, "m_comboLine" );
159 m_comboLine->insertItem( i18n( "1" ) );
160 m_comboLine->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1, (TQSizePolicy::SizeType)0, 0, 0, m_comboLine->sizePolicy().hasHeightForWidth() ) );
161
162 MyDialogLayout->addWidget( m_comboLine, 1, 3 );
163
164 m_comboQuote = new TQComboBox( false, page, "m_comboQuote" );
165 m_comboQuote->insertItem( i18n( "\"" ) );
166 m_comboQuote->insertItem( i18n( "'" ) );
167 m_comboQuote->insertItem( i18n( "None" ) );
168 m_comboQuote->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1, (TQSizePolicy::SizeType)0, 0, 0, m_comboQuote->sizePolicy().hasHeightForWidth() ) );
169
170 MyDialogLayout->addWidget( m_comboQuote, 1, 2 );
171 TQSpacerItem* spacer_2 = new TQSpacerItem( 0, 0, TQSizePolicy::Minimum, TQSizePolicy::Preferred );
172 MyDialogLayout->addItem( spacer_2, 2, 3 );
173
174 TextLabel3 = new TQLabel( page, "TextLabel3" );
175 TextLabel3->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1, (TQSizePolicy::SizeType)0, 0, 0, TextLabel3->sizePolicy().hasHeightForWidth() ) );
176 TextLabel3->setText( i18n( "Start at line:" ) );
177
178 MyDialogLayout->addWidget( TextLabel3, 0, 3 );
179
180 TextLabel2 = new TQLabel( page, "TextLabel2" );
181 TextLabel2->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)1, (TQSizePolicy::SizeType)0, 0, 0, TextLabel2->sizePolicy().hasHeightForWidth() ) );
182 TextLabel2->setText( i18n( "Textquote:" ) );
183
184 MyDialogLayout->addWidget( TextLabel2, 0, 2 );
185
186 if ( m_mode == Clipboard )
187 {
188 setCaption( i18n( "Inserting From Clipboard" ) );
189 TQMimeSource * mime = TQApplication::clipboard()->data();
190 if ( !mime )
191 {
192 KMessageBox::information( this, i18n("There is no data in the clipboard.") );
193 m_cancelled = true;
194 return;
195 }
196
197 if ( !mime->provides( "text/plain" ) )
198 {
199 KMessageBox::information( this, i18n("There is no usable data in the clipboard.") );
200 m_cancelled = true;
201 return;
202 }
203 m_fileArray = TQByteArray(mime->encodedData( "text/plain" ) );
204 }
205 else if ( mode == File )
206 {
207 setCaption( i18n( "Inserting Text File" ) );
208 TQString file = KFileDialog::getOpenFileName(":",
209 "text/plain",
210 this);
211 //cancel action !
212 if ( file.isEmpty() )
213 {
214 actionButton( Ok )->setEnabled( false );
215 m_cancelled = true;
216 return;
217 }
218 TQFile in(file);
219 if (!in.open(IO_ReadOnly))
220 {
221 KMessageBox::sorry( this, i18n("Cannot open input file.") );
222 in.close();
223 actionButton( Ok )->setEnabled( false );
224 m_cancelled = true;
225 return;
226 }
227 m_fileArray = TQByteArray(in.size());
228 in.readBlock(m_fileArray.data(), in.size());
229 in.close();
230 }
231 else
232 {
233 setCaption( i18n( "Text to Columns" ) );
234 m_data = "";
235 Cell * cell;
236 Sheet * sheet = m_pView->activeSheet();
237 int col = m_targetRect.left();
238 for (int i = m_targetRect.top(); i <= m_targetRect.bottom(); ++i)
239 {
240 cell = sheet->cellAt( col, i );
241 if ( !cell->isEmpty() && !cell->isDefault() )
242 {
243 m_data += cell->strOutText();
244 }
245 m_data += "\n";
246 }
247 }
248
249 fillSheet();
250 fillComboBox();
251
252 resize(sizeHint());
253
254 m_sheet->setSelectionMode(TQTable::NoSelection);
255
256 connect(m_formatBox, TQ_SIGNAL(clicked(int)),
257 this, TQ_SLOT(formatClicked(int)));
258 connect(m_delimiterBox, TQ_SIGNAL(clicked(int)),
259 this, TQ_SLOT(delimiterClicked(int)));
260 connect(m_delimiterEdit, TQ_SIGNAL(returnPressed()),
261 this, TQ_SLOT(returnPressed()));
262 connect(m_delimiterEdit, TQ_SIGNAL(textChanged ( const TQString & )),
263 this, TQ_SLOT(textChanged ( const TQString & ) ));
264 connect(m_comboLine, TQ_SIGNAL(activated(const TQString&)),
265 this, TQ_SLOT(lineSelected(const TQString&)));
266 connect(m_comboQuote, TQ_SIGNAL(activated(const TQString&)),
267 this, TQ_SLOT(textquoteSelected(const TQString&)));
268 connect(m_sheet, TQ_SIGNAL(currentChanged(int, int)),
269 this, TQ_SLOT(currentCellChanged(int, int)));
270 connect(m_ignoreDuplicates, TQ_SIGNAL(stateChanged(int)),
271 this, TQ_SLOT(ignoreDuplicatesChanged(int)));
272}
273
274CSVDialog::~CSVDialog()
275{
276 // no need to delete child widgets, TQt does it all for us
277}
278
279bool CSVDialog::cancelled()
280{
281 return m_cancelled;
282}
283
284void CSVDialog::fillSheet()
285{
286 int row, column;
287 bool lastCharDelimiter = false;
288 bool ignoreDups = m_ignoreDuplicates->isChecked();
289 enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD,
290 S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START;
291
292 TQChar x;
293 TQString field = "";
294
295 for (row = 0; row < m_sheet->numRows(); ++row)
296 for (column = 0; column < m_sheet->numCols(); ++column)
297 m_sheet->clearCell(row, column);
298
299 row = column = 1;
300 if (m_mode != Column)
301 {
302 m_mode = Column;
303 m_data = TQString(m_fileArray);
304 m_fileArray.resize(0);
305 }
306
307 TQTextStream inputStream(m_data, IO_ReadOnly);
308 inputStream.setEncoding(TQTextStream::Locale);
309
310 while (!inputStream.atEnd())
311 {
312 inputStream >> x; // read one char
313
314 if (x == '\r') inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly
315
316 switch (state)
317 {
318 case S_START :
319 if (x == m_textquote)
320 {
321 state = S_QUOTED_FIELD;
322 }
323 else if (x == m_delimiter)
324 {
325 if ((ignoreDups == false) || (lastCharDelimiter == false))
326 ++column;
327 lastCharDelimiter = true;
328 }
329 else if (x == '\n')
330 {
331 ++row;
332 column = 1;
333 }
334 else
335 {
336 field += x;
337 state = S_MAYBE_NORMAL_FIELD;
338 }
339 break;
340 case S_QUOTED_FIELD :
341 if (x == m_textquote)
342 {
343 state = S_MAYBE_END_OF_QUOTED_FIELD;
344 }
345 else if (x == '\n')
346 {
347 setText(row - m_startline, column, field);
348 field = "";
349 if (x == '\n')
350 {
351 ++row;
352 column = 1;
353 }
354 else
355 {
356 if ((ignoreDups == false) || (lastCharDelimiter == false))
357 ++column;
358 lastCharDelimiter = true;
359 }
360 state = S_START;
361 }
362 else
363 {
364 field += x;
365 }
366 break;
367 case S_MAYBE_END_OF_QUOTED_FIELD :
368 if (x == m_textquote)
369 {
370 field += x;
371 state = S_QUOTED_FIELD;
372 }
373 else if (x == m_delimiter || x == '\n')
374 {
375 setText(row - m_startline, column, field);
376 field = "";
377 if (x == '\n')
378 {
379 ++row;
380 column = 1;
381 }
382 else
383 {
384 if ((ignoreDups == false) || (lastCharDelimiter == false))
385 ++column;
386 lastCharDelimiter = true;
387 }
388 state = S_START;
389 }
390 else
391 {
392 state = S_END_OF_QUOTED_FIELD;
393 }
394 break;
395 case S_END_OF_QUOTED_FIELD :
396 if (x == m_delimiter || x == '\n')
397 {
398 setText(row - m_startline, column, field);
399 field = "";
400 if (x == '\n')
401 {
402 ++row;
403 column = 1;
404 }
405 else
406 {
407 if ((ignoreDups == false) || (lastCharDelimiter == false))
408 ++column;
409 lastCharDelimiter = true;
410 }
411 state = S_START;
412 }
413 else
414 {
415 state = S_END_OF_QUOTED_FIELD;
416 }
417 break;
418 case S_MAYBE_NORMAL_FIELD :
419 if (x == m_textquote)
420 {
421 field = "";
422 state = S_QUOTED_FIELD;
423 break;
424 }
425 case S_NORMAL_FIELD :
426 if (x == m_delimiter || x == '\n')
427 {
428 setText(row - m_startline, column, field);
429 field = "";
430 if (x == '\n')
431 {
432 ++row;
433 column = 1;
434 }
435 else
436 {
437 if ((ignoreDups == false) || (lastCharDelimiter == false))
438 ++column;
439 lastCharDelimiter = true;
440 }
441 state = S_START;
442 }
443 else
444 {
445 field += x;
446 }
447 }
448 if (x != m_delimiter)
449 lastCharDelimiter = false;
450 }
451
452 // file with only one line without '\n'
453 if (field.length() > 0)
454 {
455 setText(row - m_startline, column, field);
456 ++row;
457 field = "";
458 }
459
460 adjustRows( row - m_startline );
461
462 for (column = 0; column < m_sheet->numCols(); ++column)
463 {
464 TQString header = m_sheet->horizontalHeader()->label(column);
465 if (header != i18n("Text") && header != i18n("Number") &&
466 header != i18n("Date") && header != i18n("Currency"))
467 m_sheet->horizontalHeader()->setLabel(column, i18n("Text"));
468
469 m_sheet->adjustColumn(column);
470 }
471}
472
473void CSVDialog::fillComboBox()
474{
475 m_comboLine->clear();
476 for (int row = 0; row < m_sheet->numRows(); ++row)
477 m_comboLine->insertItem(TQString::number(row + 1), row);
478}
479
480void CSVDialog::setText(int row, int col, const TQString& text)
481{
482 if (row < 1) // skipped by the user
483 return;
484
485 if (m_sheet->numRows() < row) {
486 m_sheet->setNumRows(row+5000); /* We add 5000 at a time to limit recalculations */
487 m_adjustRows=1;
488 }
489
490 if (m_sheet->numCols() < col)
491 m_sheet->setNumCols(col);
492
493 m_sheet->setText(row - 1, col - 1, text);
494}
495
496/*
497 * Called after the first fillSheet() when number of rows are unknown.
498 */
499void CSVDialog::adjustRows(int iRows)
500{
501 if (m_adjustRows)
502 {
503 m_sheet->setNumRows( iRows );
504 m_adjustRows=0;
505 }
506}
507
508void CSVDialog::returnPressed()
509{
510 if (m_delimiterBox->id(m_delimiterBox->selected()) != 4)
511 return;
512
513 m_delimiter = m_delimiterEdit->text();
514 fillSheet();
515}
516
517void CSVDialog::textChanged ( const TQString & )
518{
519 m_radioOther->setChecked ( true );
520 delimiterClicked(4); // other
521}
522
523void CSVDialog::formatClicked(int id)
524{
525 TQString header;
526
527 switch (id)
528 {
529 case 1: // text
530 header = i18n("Text");
531 break;
532 case 0: // number
533 header = i18n("Number");
534 break;
535 case 3: // date
536 header = i18n("Date");
537 break;
538 case 2: // currency
539 header = i18n("Currency");
540 break;
541 }
542
543 m_sheet->horizontalHeader()->setLabel(m_sheet->currentColumn(), header);
544}
545
546void CSVDialog::delimiterClicked(int id)
547{
548 switch (id)
549 {
550 case 0: // comma
551 m_delimiter = ",";
552 break;
553 case 4: // other
554 m_delimiter = m_delimiterEdit->text();
555 break;
556 case 2: // tab
557 m_delimiter = "\t";
558 break;
559 case 3: // space
560 m_delimiter = " ";
561 break;
562 case 1: // semicolon
563 m_delimiter = ";";
564 break;
565 }
566
567 fillSheet();
568}
569
570void CSVDialog::textquoteSelected(const TQString& mark)
571{
572 if (mark == i18n("none"))
573 m_textquote = 0;
574 else
575 m_textquote = mark[0];
576
577 fillSheet();
578}
579
580void CSVDialog::lineSelected(const TQString& line)
581{
582 m_startline = line.toInt() - 1;
583 fillSheet();
584}
585
586void CSVDialog::currentCellChanged(int, int col)
587{
588 int id;
589 TQString header = m_sheet->horizontalHeader()->label(col);
590
591 if (header == i18n("Text"))
592 id = 1;
593 else if (header == i18n("Number"))
594 id = 0;
595 else if (header == i18n("Date"))
596 id = 3;
597 else
598 id = 2;
599
600 m_formatBox->setButton(id);
601}
602
603void CSVDialog::accept()
604{
605 Sheet * sheet = m_pView->activeSheet();
606 TQString csv_delimiter = TQString();
607 Cell * cell;
608
609 int numRows = m_sheet->numRows();
610 int numCols = m_sheet->numCols();
611
612 if (numRows == 0)
613 ++numRows;
614
615 if ( (numCols > m_targetRect.width()) && (m_targetRect.width() > 1) )
616 {
617 numCols = m_targetRect.width();
618 }
619 else
620 m_targetRect.setRight( m_targetRect.left() + numCols );
621
622 if ( (numRows > m_targetRect.height()) && (m_targetRect.height() > 1) )
623 numRows = m_targetRect.height();
624 else
625 m_targetRect.setBottom( m_targetRect.top() + numRows );
626
627 if ( numRows == 1 && numCols == 1)
628 {
629 Doc * doc = m_pView->doc();
630 cell = sheet->nonDefaultCell( m_targetRect.left(), m_targetRect.top() );
631 if ( !doc->undoLocked() )
632 {
633 UndoSetText * undo = new UndoSetText( doc, sheet , cell->text(), m_targetRect.left(),
634 m_targetRect.top(), cell->formatType() );
635 doc->addCommand( undo );
636 }
637 }
638 else
639 {
640 UndoChangeAreaTextCell * undo = new UndoChangeAreaTextCell( m_pView->doc(), sheet , m_targetRect );
641 m_pView->doc()->addCommand( undo );
642 }
643
644 m_pView->doc()->emitBeginOperation();
645
646 int i;
647 int left = m_targetRect.left();
648 int top = m_targetRect.top();
649
650 TQMemArray<double> widths( numCols );
651 for ( i = 0; i < numCols; ++i )
652 {
653 ColumnFormat * c = sheet->nonDefaultColumnFormat( left + i );
654 widths[i] = c->dblWidth();
655 }
656
657 for (int row = 0; row < numRows; ++row)
658 {
659 for (int col = 0; col < numCols; ++col)
660 {
661 cell = sheet->nonDefaultCell( left + col, top + row );
662 cell->setCellText( getText( row, col ) );
663
664 TQFontMetrics fm = sheet->painter().fontMetrics();
665 double w = fm.width( cell->strOutText() );
666 if ( w == 0.0 )
667 {
668 TQFontMetrics fm( cell->format()->textFont( left + col, top + row ) );
669 w = fm.width('x') * (double) getText( row, col ).length();
670 }
671
672 if ( w > widths[col] )
673 widths[col] = w;
674
675 cell->format()->setFormatType(Generic_format);
676 /*
677 Disabling this code for now, everything will use Generic formatting,
678 hoping for the best (Tomas)
679 //### FIXME: long term solution is to allow to select Generic format ("autodetect") in the dialog and make it the default
680
681 switch (getHeader(col))
682 {
683 case TEXT:
684 break;
685 case NUMBER:
686 cell->format()->setFormatType(Number_format);
687 cell->setPrecision(2);
688 break;
689 case DATE:
690 cell->format()->setFormatType(ShortDate_format);
691 break;
692 case CURRENCY:
693 cell->format()->setFormatType(Money_format);
694 break;
695 }
696 */
697 }
698 }
699
700 for ( i = 0; i < numCols; ++i )
701 {
702 ColumnFormat * c = sheet->nonDefaultColumnFormat( left + i );
703 c->setDblWidth( widths[i] );
704 sheet->emit_updateColumn( c, left + i );
705 }
706
707 m_pView->slotUpdateView( sheet );
708 TQDialog::accept();
709}
710
711int CSVDialog::getHeader(int col)
712{
713 TQString header = m_sheet->horizontalHeader()->label(col);
714
715 if (header == i18n("Text"))
716 return TEXT;
717 else if (header == i18n("Number"))
718 return NUMBER;
719 else if (header == i18n("Currency"))
720 return CURRENCY;
721 else
722 return DATE;
723}
724
725TQString CSVDialog::getText(int row, int col)
726{
727 return m_sheet->text(row, col);
728}
729
730void CSVDialog::ignoreDuplicatesChanged(int)
731{
732 fillSheet();
733}
734
735#include "kspread_dlg_csv.moc"
For every cell in the spread sheet there is a Cell object.
FormatType formatType() const
Return the format of this cell.
TQString text() const
Return the text the user entered.
int row() const
Returns the cell's row.
bool isEmpty() const
Returns true if this cell has no content, i.e no text and no formula.
void setCellText(const TQString &_text, bool asString=false)
The high-level method for setting text, when the user inputs it.
Format * format() const
Returns the format object of this cell.
bool isDefault() const
Returns true if this is a default cell (with row and column equal to zero).
This class holds the data that makes up a spreadsheet.
Definition kspread_doc.h:98
bool undoLocked() const
Returns true if undo buffer is locked.
void emitBeginOperation(bool waitCursor)
Functions to begin a kspread 'operation'.
void addCommand(KCommand *command)
Adds a command to the command history.
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39