kspread

kspread_dlg_sort.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Robert Knight <robertknight@gmail.com>
3 (C) 2002-2003 Norbert Andres <nandres@web.de>
4 (C) 2002 Ariya Hidayat <ariya@kde.org>
5 (C) 2002 John Dailey <dailey@vt.edu>
6 (C) 2002 Werner Trobin <trobin@kde.org>
7 (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
8 (C) 1999-2002 Laurent Montel <montel@kde.org>
9 (C) 2000 David Faure <faure@kde.org>
10 (C) 1998-2000 Torben Weis <weis@kde.org>
11
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Library General Public
14 License as published by the Free Software Foundation; either
15 version 2 of the License, or (at your option) any later version.
16
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
21
22 You should have received a copy of the GNU Library General Public License
23 along with this library; see the file COPYING.LIB. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
26*/
27
28
29#include <tqbuttongroup.h>
30#include <tqhbuttongroup.h>
31#include <tqcheckbox.h>
32#include <tqcombobox.h>
33#include <tqgroupbox.h>
34#include <tqlabel.h>
35#include <tqlayout.h>
36#include <tqlineedit.h>
37#include <tqpushbutton.h>
38#include <tqradiobutton.h>
39#include <tqrect.h>
40#include <tqtabwidget.h>
41#include <tqwidget.h>
42#include <tqvbox.h>
43
44#include <tdeconfig.h>
45#include <kdebug.h>
46#include <tdelocale.h>
47#include <tdemessagebox.h>
48
49#include "kspread_dlg_sort.h"
50#include "kspread_doc.h"
51#include "kspread_map.h"
52#include "kspread_sheet.h"
53#include "kspread_view.h"
54#include "kspread_util.h"
55#include "selection.h"
56
57using namespace KSpread;
58
59SortDialog::SortDialog( View * parent, const char * name,
60 bool modal )
61 : KDialogBase( parent, name, modal,"Sort",Ok|Cancel ),
62 m_pView( parent )
63{
64 if ( !name )
65 setName( "SortDialog" );
66
67 resize( 528, 316 );
68 setCaption( i18n( "Sorting" ) );
69 //setSizeGripEnabled( true );
70
71 TQVBox *page = makeVBoxMainWidget();
72
73 m_tabWidget = new TQTabWidget( page, "m_tabWidget" );
74
75 m_page1 = new TQWidget( m_tabWidget, "m_page1" );
76 TQGridLayout * page1Layout
77 = new TQGridLayout( m_page1, 1, 1, 11, 6, "page1Layout");
78
79//---------------- Sort Layout & Header Row/Column Toggle
80
81 //Sort orientation selector (for selecting Left-To-Right or Top-To-Bottom sorting of the selection)
82 TQGroupBox* layoutGroup = new TQGroupBox(2 , TQt::Vertical, m_page1, "layoutGroup");
83 layoutGroup->setTitle( i18n("Layout") );
84
85 TQHButtonGroup * orientationGroup = new TQHButtonGroup( layoutGroup, "orientationGroup" );
86 orientationGroup->setLineWidth(0);
87 orientationGroup->setMargin(0);
88 orientationGroup->layout()->setMargin(0);
89
90 m_sortColumn = new TQRadioButton( orientationGroup, "m_sortColumn" );
91 m_sortColumn->setText( i18n( "Sort &Rows" ) );
92
93 m_sortRow = new TQRadioButton( orientationGroup, "m_sortRow" );
94 m_sortRow->setText( i18n( "Sort &Columns" ) );
95
96 //First row / column contains header toggle
97 m_firstRowOrColHeader = new TQCheckBox( layoutGroup, "m_copyLayout" );
98 //m_firstRowOrColHeader->setText( i18n( "&First row contains headers" ) );
99 m_firstRowOrColHeader->setChecked(true);
100 page1Layout->addWidget(layoutGroup,0,0);
101
102//----------------
103
104 page1Layout->addRowSpacing(2,10);
105
106
107 TQGroupBox * sort1Box = new TQGroupBox( m_page1, "sort1Box" );
108 sort1Box->setTitle( i18n( "Sort By" ) );
109 sort1Box->setFlat(true);
110 sort1Box->setColumnLayout(0, TQt::Vertical );
111 sort1Box->layout()->setSpacing( KDialog::spacingHint() );
112 sort1Box->layout()->setMargin( KDialog::marginHint() );
113 TQHBoxLayout * sort1BoxLayout = new TQHBoxLayout( sort1Box->layout() );
114 sort1BoxLayout->setAlignment( TQt::AlignTop );
115
116 m_sortKey1 = new TQComboBox( false, sort1Box, "m_sortKey1" );
117 sort1BoxLayout->addWidget( m_sortKey1 );
118
119 m_sortOrder1 = new TQComboBox( false, sort1Box, "m_sortOrder1" );
120 m_sortOrder1->insertItem( i18n( "Ascending" ) );
121 m_sortOrder1->insertItem( i18n( "Descending" ) );
122 sort1BoxLayout->addWidget( m_sortOrder1 );
123
124 page1Layout->addWidget( sort1Box, 3, 0 );
125
126 TQGroupBox * sort2Box = new TQGroupBox( m_page1, "sort2Box" );
127 sort2Box->setTitle( i18n( "Then By" ) );
128 sort2Box->setFlat(true);
129 sort2Box->setColumnLayout(0, TQt::Vertical );
130 sort2Box->layout()->setSpacing( KDialog::spacingHint() );
131 sort2Box->layout()->setMargin( KDialog::marginHint() );
132 TQHBoxLayout * sort2BoxLayout = new TQHBoxLayout( sort2Box->layout() );
133 sort2BoxLayout->setAlignment( TQt::AlignTop );
134
135 m_sortKey2 = new TQComboBox( false, sort2Box, "m_sortKey2" );
136 m_sortKey2->insertItem( i18n( "None" ) );
137 sort2BoxLayout->addWidget( m_sortKey2 );
138
139 m_sortOrder2 = new TQComboBox( false, sort2Box, "m_sortOrder2" );
140 m_sortOrder2->insertItem( i18n( "Ascending" ) );
141 m_sortOrder2->insertItem( i18n( "Descending" ) );
142 sort2BoxLayout->addWidget( m_sortOrder2 );
143
144 page1Layout->addWidget( sort2Box, 4, 0 );
145
146 TQGroupBox * sort3Box = new TQGroupBox( m_page1, "sort3Box" );
147 sort3Box->setTitle( i18n( "Then By" ) );
148 sort3Box->setFlat(true);
149 sort3Box->setColumnLayout(0, TQt::Vertical );
150 sort3Box->layout()->setSpacing( KDialog::spacingHint() );
151 sort3Box->layout()->setMargin( KDialog::marginHint() );
152 TQHBoxLayout * sort3BoxLayout = new TQHBoxLayout( sort3Box->layout() );
153 sort3BoxLayout->setAlignment( TQt::AlignTop );
154
155 m_sortKey3 = new TQComboBox( false, sort3Box, "m_sortKey3" );
156 m_sortKey3->insertItem( i18n( "None" ) );
157 m_sortKey3->setEnabled( false );
158 sort3BoxLayout->addWidget( m_sortKey3 );
159
160 m_sortOrder3 = new TQComboBox( false, sort3Box, "m_sortOrder3" );
161 m_sortOrder3->insertItem( i18n( "Ascending" ) );
162 m_sortOrder3->insertItem( i18n( "Descending" ) );
163 m_sortOrder3->setEnabled( false );
164 sort3BoxLayout->addWidget( m_sortOrder3 );
165
166 page1Layout->addWidget( sort3Box, 5, 0 );
167 m_tabWidget->insertTab( m_page1, i18n( "Sort Criteria" ) );
168
169
170 //---------------- options page
171
172 m_page2 = new TQWidget( m_tabWidget, "m_page2" );
173 TQGridLayout * page2Layout = new TQGridLayout( m_page2, 1, 1, 11, 6, "page2Layout");
174 page2Layout->setAlignment(TQt::AlignTop);
175
176 TQGroupBox * firstKeyBox = new TQGroupBox( m_page2, "firstKeyBox" );
177 firstKeyBox->setTitle( i18n( "First Key" ) );
178 firstKeyBox->setColumnLayout(0, TQt::Vertical );
179 firstKeyBox->layout()->setSpacing( KDialog::spacingHint() );
180 firstKeyBox->layout()->setMargin( KDialog::marginHint() );
181 TQVBoxLayout * firstKeyBoxLayout = new TQVBoxLayout( firstKeyBox->layout() );
182 firstKeyBoxLayout->setAlignment( TQt::AlignTop );
183
184 m_useCustomLists = new TQCheckBox( firstKeyBox, "m_useCustomLists_2" );
185 m_useCustomLists->setText( i18n( "&Use custom list" ) );
186 firstKeyBoxLayout->addWidget( m_useCustomLists );
187
188 m_customList = new TQComboBox( false, firstKeyBox, "m_customList" );
189 m_customList->setEnabled( false );
190 m_customList->setMaximumSize( 230, 30 );
191 firstKeyBoxLayout->addWidget( m_customList );
192
193 page2Layout->addWidget( firstKeyBox, 0, 0 );
194
195
196 /*
197 This doesn't work properly, and as a bug report pointed out, it isn't that useful since it is easy
198 to just copy and paste the data and then sort the newly pasted data in place.
199 -- Robert Knight
200
201 TQGroupBox * resultToBox = new TQGroupBox( m_page2, "resultToBox" );
202 resultToBox->setTitle( i18n( "Location to Store Sort Results" ) );
203 resultToBox->setColumnLayout(0, TQt::Vertical );
204 resultToBox->layout()->setSpacing( KDialog::spacingHint() );
205 resultToBox->layout()->setMargin( KDialog::marginHint() );
206
207
208 TQHBoxLayout * resultToBoxLayout = new TQHBoxLayout( resultToBox->layout() );
209 resultToBoxLayout->setAlignment( TQt::AlignTop );
210
211 TQLabel * destinationSheet=new TQLabel(resultToBox,"destinationSheet");
212 destinationSheet->setText("Destination Sheet:");
213 resultToBoxLayout->addWidget(destinationSheet);
214
215 m_outputSheet = new TQComboBox( false, resultToBox, "m_outputSheet" );
216 resultToBoxLayout->addWidget( m_outputSheet );
217 TQSpacerItem * spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
218 resultToBoxLayout->addItem( spacer );
219
220 TQLabel * startingCellLabel = new TQLabel( resultToBox, "destinationCellLabel" );
221 startingCellLabel->setText( i18n( "Destination Cell:" ) );
222 resultToBoxLayout->addWidget( startingCellLabel );
223
224 m_outputCell = new TQLineEdit( resultToBox, "m_outputCell" );
225 m_outputCell->setMaximumSize( TQSize( 60, 32767 ) );
226 resultToBoxLayout->addWidget( m_outputCell );
227
228 page2Layout->addWidget( resultToBox, 1,0 );*/
229
230
231 m_tabWidget->insertTab( m_page2, i18n( "Options" ) );
232
233 TQHBoxLayout * Layout1 = new TQHBoxLayout( 0, 0, 6, "Layout1");
234 TQSpacerItem * spacer_2 = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding,
235 TQSizePolicy::Minimum );
236 Layout1->addItem( spacer_2 );
237
238
239 m_copyLayout = new TQCheckBox( m_page2, "m_copyLayout" );
240 m_copyLayout->setText( i18n( "Copy cell &formatting (Borders, Colours, Text Style)" ) );
241
242 page2Layout->addWidget( m_copyLayout, 1, 0 );
243
244 m_respectCase = new TQCheckBox( m_page2, "m_copyLayout" );
245 m_respectCase->setText( i18n( "Case sensitive sort" ) );
246 m_respectCase->setChecked( true );
247
248 page2Layout->addWidget( m_respectCase, 2,0 );
249
250 connect( m_sortKey2, TQ_SIGNAL( activated( int ) ), this,
251 TQ_SLOT( sortKey2textChanged( int ) ) );
252 connect( m_useCustomLists, TQ_SIGNAL( stateChanged(int) ), this,
253 TQ_SLOT( useCustomListsStateChanged(int) ) );
254 connect( m_firstRowOrColHeader, TQ_SIGNAL( stateChanged(int) ), this,
255 TQ_SLOT( firstRowHeaderChanged(int) ) );
256 connect( orientationGroup, TQ_SIGNAL( pressed(int) ), this,
257 TQ_SLOT( slotOrientationChanged(int) ) );
258
259 init();
260}
261
262TQRect SortDialog::sourceArea()
263{
264 return m_pView->selectionInfo()->selection();
265}
266
267SortDialog::Orientation SortDialog::guessDataOrientation()
268{
269 const TQRect selection=sourceArea();
270
271 if (selection.width() >= selection.height())
272 return SortColumns;
273 else
274 return SortRows;
275}
276
277SortDialog::~SortDialog()
278{
279 // no need to delete child widgets, TQt does it all for us
280}
281
282void SortDialog::init()
283{
284 TQStringList lst;
285 lst<<i18n("January");
286 lst<<i18n("February");
287 lst<<i18n("March");
288 lst<<i18n("April");
289 lst<<i18n("May");
290 lst<<i18n("June");
291 lst<<i18n("July");
292 lst<<i18n("August");
293 lst<<i18n("September");
294 lst<<i18n("October");
295 lst<<i18n("November");
296 lst<<i18n("December");
297
298 lst<<i18n("Monday");
299 lst<<i18n("Tuesday");
300 lst<<i18n("Wednesday");
301 lst<<i18n("Thursday");
302 lst<<i18n("Friday");
303 lst<<i18n("Saturday");
304 lst<<i18n("Sunday");
305
306 TDEConfig * config = Factory::global()->config();
307 config->setGroup( "Parameters" );
308 TQStringList other = config->readListEntry("Other list");
309 TQString tmp;
310 for ( TQStringList::Iterator it = other.begin(); it != other.end(); ++it )
311 {
312 if((*it) != "\\")
313 tmp += (*it) + ", ";
314 else if( it != other.begin())
315 {
316 tmp = tmp.left(tmp.length() - 2);
317 lst.append(tmp);
318 tmp = "";
319 }
320 }
321 m_customList->insertStringList(lst);
322
323 /*TQPtrList<Sheet> sheetList = m_pView->doc()->map()->sheetList();
324 for (unsigned int c = 0; c < sheetList.count(); ++c)
325 {
326 Sheet * t = sheetList.at(c);
327 if (!t)
328 continue;
329 m_outputSheet->insertItem( t->sheetName() );
330 }
331 m_outputSheet->setCurrentText( m_pView->activeSheet()->sheetName() );*/
332
333 TQRect r = sourceArea();
334 /*TQString cellArea;
335 cellArea += Cell::columnName(r.left());
336 cellArea += TQString::number( r.top() );
337 m_outputCell->setText( cellArea );*/
338
339 //If the top-most row or left-most column all contain text items (as opposed to numbers, dates etc.)
340 //then the dialog will guess that the top row (or left column) is a header.
341 //The user can always change this if we get this wrong.
342 bool selectionMayHaveHeader = true;
343
344 // Entire columns selected ?
345 if ( util_isColumnSelected(r) )
346 {
347 m_sortRow->setEnabled(false);
348 m_sortColumn->setChecked(true);
349
350 int right = r.right();
351 for (int i = r.left(); i <= right; ++i)
352 {
353 TQString guessName=m_pView->activeSheet()->guessColumnTitle(r,i);
354 TQString colName=i18n(" (Column %1)").arg(Cell::columnName(i));
355
356 if (!guessName.isEmpty())
357 {
358 m_listColumn += guessName + colName;
359 }
360 else
361 {
362 m_listColumn += i18n("Column %1").arg(Cell::columnName(i));
363
364 if ( i == r.left() )
365 selectionMayHaveHeader=false;
366 }
367 }
368 // m_listColumn += i18n("Column %1").arg(Cell::columnName(i));
369 }
370 // Entire rows selected ?
371 else if ( util_isRowSelected(r) )
372 {
373 m_sortColumn->setEnabled(false);
374 m_sortRow->setChecked(true);
375
376 int bottom = r.bottom();
377 for (int i = r.top(); i <= bottom; ++i)
378 {
379 TQString guessName=m_pView->activeSheet()->guessRowTitle(r,i);
380 TQString rowName=i18n(" (Row %1)").arg(i);
381
382 if (!guessName.isEmpty())
383 {
384 m_listRow += guessName + rowName;
385 }
386 else
387 {
388 m_listRow += i18n("Row %1").arg(i);
389
390 if ( i == r.top() )
391 selectionMayHaveHeader=false;
392 }
393 }
394 }
395 else
396 {
397 // Selection is only one row
398 if ( r.top() == r.bottom() )
399 {
400 m_sortColumn->setEnabled(false);
401 m_sortRow->setChecked(true);
402 }
403 // only one column
404 else if (r.left() == r.right())
405 {
406 m_sortRow->setEnabled(false);
407 m_sortColumn->setChecked(true);
408 }
409 else
410 {
411 if (guessDataOrientation() == SortColumns)
412 m_sortRow->setChecked(true);
413 else
414 m_sortColumn->setChecked(true);
415 }
416
417 int right = r.right();
418 int bottom = r.bottom();
419 for (int i = r.left(); i <= right; ++i)
420 {
421 TQString guessName=m_pView->activeSheet()->guessColumnTitle(r,i);
422 TQString colName=i18n(" (Column %1)").arg(Cell::columnName(i));
423
424 if (!guessName.isEmpty())
425 m_listColumn += guessName + colName;
426 else
427 {
428 m_listColumn += i18n("Column %1").arg(Cell::columnName(i));
429
430 if (i == r.left())
431 selectionMayHaveHeader=false;
432 }
433 }
434
435 for (int i = r.top(); i <= bottom; ++i)
436 {
437 TQString guessName=m_pView->activeSheet()->guessRowTitle(r,i);
438 TQString rowName=i18n(" (Row %1)").arg(i);
439
440 if (!guessName.isEmpty())
441 m_listRow += guessName + rowName;
442 else
443 {
444 m_listRow += i18n("Row %1").arg(i);
445
446 if (i == r.top())
447 selectionMayHaveHeader=false;
448 }
449 }
450 }
451
452 if ( selectionMayHaveHeader )
453 m_firstRowOrColHeader->setChecked( true );
454 else
455 m_firstRowOrColHeader->setChecked( false );
456
457 // Initialize the combo box
458 if ( m_sortRow->isChecked() )
459 {
460 slotOrientationChanged( SortRows );
461 }
462 else
463 {
464 slotOrientationChanged( SortColumns );
465 }
466}
467
468void SortDialog::slotOrientationChanged(int id)
469{
470 switch( id )
471 {
472 case SortColumns :
473 m_sortKey1->clear();
474 m_sortKey2->clear();
475 m_sortKey3->clear();
476 m_sortKey1->insertStringList(m_listColumn);
477 m_sortKey2->insertItem( i18n("None") );
478 m_sortKey2->insertStringList(m_listColumn);
479 m_sortKey3->insertItem( i18n("None") );
480 m_sortKey3->insertStringList(m_listColumn);
481 m_firstRowOrColHeader->setText( i18n( "&First row contains headers" ) );
482 break;
483
484 case SortRows :
485 m_sortKey1->clear();
486 m_sortKey2->clear();
487 m_sortKey3->clear();
488 m_sortKey1->insertStringList(m_listRow);
489 m_sortKey2->insertItem( i18n("None") );
490 m_sortKey2->insertStringList(m_listRow);
491 m_sortKey3->insertItem( i18n("None") );
492 m_sortKey3->insertStringList(m_listRow);
493 m_firstRowOrColHeader->setText( i18n( "&First column contains headers" ) );
494
495 /*if (m_firstRowOrColHeader->isChecked())
496 {
497 int k1 = m_sortKey1->currentItem();
498 int k2 = m_sortKey2->currentItem();
499 int k3 = m_sortKey3->currentItem();
500 m_sortKey1->removeItem( 0 );
501 m_sortKey2->removeItem( 1 ); // because there is "None" in there
502 m_sortKey3->removeItem( 1 );
503 if (k1 > 0)
504 m_sortKey1->setCurrentItem(--k1);
505 else
506 m_sortKey1->setCurrentItem( 0 );
507 if (k2 > 0)
508 m_sortKey2->setCurrentItem(--k2);
509 if (k3 > 0)
510 m_sortKey3->setCurrentItem(--k3);
511 }*/
512
513 break;
514
515 default :
516 kdDebug(36001) << "Error in signal : pressed(int id)" << endl;
517 break;
518 }
519}
520
521void SortDialog::slotOk()
522{
523 m_pView->doc()->emitBeginOperation( false );
524
525 Orientation sortOrientation;
526 if (m_sortRow->isChecked())
527 sortOrientation=SortColumns;
528 else
529 sortOrientation=SortRows;
530
531 Sheet * sheet = m_pView->activeSheet();
532 /*m_pView->doc()->map()->findSheet( m_outputSheet->currentText() );
533 if ( !sheet )
534 {
535 KMessageBox::error( this, i18n("The destination sheet does not exist.") );
536 m_outputSheet->setFocus();
537 m_tabWidget->setTabEnabled(m_page2, true);
538 m_pView->slotUpdateView( m_pView->activeSheet() );
539 return;
540 } */
541
542 /*if ( !outputPoint.isValid() || outputPoint.isSheetKnown() )
543 {
544 KMessageBox::error( this, i18n("The destination cell does not exist.") );
545 m_outputCell->setFocus();
546 m_tabWidget->setTabEnabled(m_page2, true);
547 m_pView->slotUpdateView( m_pView->activeSheet() );
548 return;
549 }*/
550 //outputPoint.setSheet(sheet);
551
552 TQRect sortArea = sourceArea();
553 Point outputPoint;
554 outputPoint.setPos(sortArea.topLeft());
555 outputPoint.setSheet(sheet);
556 bool hasHeader=m_firstRowOrColHeader->isChecked();
557
558 if ( hasHeader )
559 {
560 if (sortOrientation == SortColumns)
561 {
562 sortArea.setLeft( sortArea.left()+1 );
563 outputPoint.setColumn( outputPoint.column()+1 );
564 }
565 else
566 {
567 sortArea.setTop( sortArea.top()+1 );
568 outputPoint.setRow( outputPoint.row()+1 );
569 }
570 }
571
572 /*if ( sortArea.topLeft() != outputPoint.pos() )
573 {
574 int h = outputPoint.pos().y() + sortArea.height();
575 int w = outputPoint.pos().x() + sortArea.width();
576
577 if ( sortArea.contains(outputPoint.pos())
578 || ( w >= sortArea.left() && w <= sortArea.right() )
579 || ( h >= sortArea.top() && h <= sortArea.bottom() ) )
580 {
581 KMessageBox::error( this, i18n("If the destination and source regions are different, they must not overlap.") );
582 m_outputCell->setFocus();
583 m_pView->slotUpdateView( m_pView->activeSheet() );
584 // TODO: set right tab
585 return;
586 }
587 }*/
588
589 int key1 = 1;
590 int key2 = 0;
591 int key3 = 0;
592 TQStringList * firstKey = 0L;
593 Sheet::SortingOrder order1;
594 Sheet::SortingOrder order2;
595 Sheet::SortingOrder order3;
596
597 order1 = ( m_sortOrder1->currentItem() == 0 ? Sheet::Increase
598 : Sheet::Decrease );
599 order2 = ( m_sortOrder2->currentItem() == 0 ? Sheet::Increase
600 : Sheet::Decrease );
601 order3 = ( m_sortOrder3->currentItem() == 0 ? Sheet::Increase
602 : Sheet::Decrease );
603
604 if ( m_sortRow->isChecked() )
605 {
606 key1 = m_sortKey1->currentItem() + sortArea.top();
607 if (m_sortKey2->currentItem() > 0)
608 key2 = m_sortKey2->currentItem() + sortArea.top() - 1; // cause there is "None"
609 if (m_sortKey3->currentItem() > 0)
610 key3 = m_sortKey3->currentItem() + sortArea.top() - 1; // cause there is "None"
611 }
612 else
613 {
614 key1 = m_sortKey1->currentItem() + sortArea.left();
615 if (m_sortKey2->currentItem() > 0)
616 key2 = m_sortKey2->currentItem() + sortArea.left() - 1; // cause there is "None"
617 if (m_sortKey3->currentItem() > 0)
618 key3 = m_sortKey3->currentItem() + sortArea.left() - 1; // cause there is "None"
619
620 }
621 /*
622 if (m_firstRowOrColHeader->isChecked())
623 {
624 if (key1 >= 0)
625 ++key1;
626 if (key2 > 0)
627 ++key2;
628 if (key3 > 0)
629 ++key3;
630 }*/
631
632 if ( m_useCustomLists->isChecked() )
633 {
634 firstKey = new TQStringList();
635 TQString list = m_customList->currentText();
636 TQString tmp;
637 int l = list.length();
638 for ( int i = 0; i < l; ++i )
639 {
640 if ( list[i] == ',' )
641 {
642 firstKey->append( tmp.stripWhiteSpace() );
643 tmp = "";
644 }
645 else
646 tmp += list[i];
647 }
648 }
649
650
651
652 if (key1 == key2)
653 key2 = 0;
654
655 if (key1 == key3)
656 key3 = 0;
657
658 if (key2 == 0 && key3 > 0)
659 {
660 key2 = key3;
661 key3 = 0;
662 }
663
664
665
666 if ( m_sortRow->isChecked() )
667 {
668 m_pView->activeSheet()->sortByRow( sortArea/*sourceArea*/, key1, key2, key3,
669 order1, order2, order3,
670 firstKey, m_copyLayout->isChecked(),
671 false /*m_firstRowOrColHeader->isChecked()*/,
672 outputPoint, m_respectCase->isChecked() );
673 }
674 else if (m_sortColumn->isChecked())
675 {
676 m_pView->activeSheet()->sortByColumn( sortArea /*sourceArea*/, key1, key2, key3,
677 order1, order2, order3,
678 firstKey, m_copyLayout->isChecked(),
679 false/*m_firstRowOrColHeader->isChecked()*/,
680 outputPoint, m_respectCase->isChecked() );
681 }
682 else
683 {
684 kdDebug(36001) << "Err in radiobutton" << endl;
685 }
686
687 delete firstKey;
688 firstKey = 0L;
689
690 m_pView->slotUpdateView( m_pView->activeSheet() );
691 accept();
692}
693
694void SortDialog::sortKey2textChanged( int i )
695{
696 m_sortKey3->setEnabled( ( i!=0 ) );
697 m_sortOrder3->setEnabled( ( i!=0 ) );
698}
699
700void SortDialog::useCustomListsStateChanged( int state )
701{
702 if (state == 0)
703 m_customList->setEnabled(false);
704 else if (state == 2)
705 m_customList->setEnabled(true);
706}
707
708void SortDialog::firstRowHeaderChanged( int /*state*/ )
709{
710 /* if (m_sortColumn->isChecked())
711 return;
712
713 if (state == 0) // off
714 {
715 int k1 = m_sortKey1->currentItem();
716 int k2 = m_sortKey2->currentItem();
717 int k3 = m_sortKey3->currentItem();
718 m_sortKey1->clear();
719 m_sortKey2->clear();
720 m_sortKey3->clear();
721 m_sortKey1->insertStringList( m_listRow );
722 m_sortKey2->insertItem( i18n("None") );
723 m_sortKey2->insertStringList( m_listRow );
724 m_sortKey3->insertItem( i18n("None") );
725 m_sortKey3->insertStringList( m_listRow );
726
727 m_sortKey1->setCurrentItem(++k1);
728 m_sortKey2->setCurrentItem(++k2);
729 m_sortKey3->setCurrentItem(++k3);
730 }
731 else if (state == 2) // on
732 {
733 int k1 = m_sortKey1->currentItem();
734 int k2 = m_sortKey2->currentItem();
735 int k3 = m_sortKey3->currentItem();
736 m_sortKey1->removeItem( 0 );
737 m_sortKey2->removeItem( 1 ); // because there is "None" in there
738 m_sortKey3->removeItem( 1 );
739 if (k1 > 0)
740 m_sortKey1->setCurrentItem(--k1);
741 if (k2 > 0)
742 m_sortKey2->setCurrentItem(--k2);
743 if (k3 > 0)
744 m_sortKey3->setCurrentItem(--k3);
745 }*/
746}
747
748#include "kspread_dlg_sort.moc"
TQString columnName() const
Returns the column name of the cell.
Represents the position of a single cell in a workbook.
void setSheet(Sheet *sheet)
Sets the sheet which this point lies on.
void setPos(TQPoint pos)
Sets the position of this point (in rows and columns)
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39