kspread

kspread_dlg_validity.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
3 (C) 2002 John Dailey <dailey@vt.edu>
4 (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
5 (C) 1999-2005 Laurent Montel <montel@kde.org>
6 (C) 1998-1999 Torben Weis <weis@kde.org>
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
24#include "kspread_dlg_validity.h"
25#include "kspread_canvas.h"
26#include "kspread_doc.h"
27#include "kspread_locale.h"
28#include "kspread_sheet.h"
29#include "kspread_view.h"
30
31#include <tqlayout.h>
32#include <tqbuttongroup.h>
33#include <knumvalidator.h>
34#include <kdebug.h>
35#include <tdemessagebox.h>
36
37#include <tqcombobox.h>
38#include <tqlineedit.h>
39#include <tqpushbutton.h>
40#include <tqlabel.h>
41#include <tqtextedit.h>
42#include <tqcheckbox.h>
43
44using namespace KSpread;
45
46DlgValidity::DlgValidity(View* parent,const char* name , const TQRect &_marker )
47 :KDialogBase(KDialogBase::Tabbed, i18n("Validity"),User2|User1|Cancel, User1, parent, name,true,false,KStdGuiItem::ok(),i18n("Clear &All"))
48
49{
50 m_pView=parent;
51 marker=_marker;
52 TQFrame *page1 = addPage(i18n("&Values"));
53 TQVBoxLayout *lay1 = new TQVBoxLayout( page1, KDialogBase::marginHint(), KDialogBase::spacingHint() );
54
55 TQGroupBox* tmpTQButtonGroup;
56 tmpTQButtonGroup = new TQGroupBox( 0, TQt::Vertical, i18n("Validity Criteria"), page1, "ButtonGroup_1" );
57 tmpTQButtonGroup->layout()->setSpacing(KDialog::spacingHint());
58 tmpTQButtonGroup->layout()->setMargin(KDialog::marginHint());
59 TQGridLayout *grid1 = new TQGridLayout(tmpTQButtonGroup->layout(),4,2);
60
61 TQLabel *tmpTQLabel = new TQLabel( tmpTQButtonGroup, "Label_1" );
62 tmpTQLabel->setText(i18n("Allow:" ));
63 grid1->addWidget(tmpTQLabel,0,0);
64
65 chooseType=new TQComboBox(tmpTQButtonGroup);
66 grid1->addWidget(chooseType,0,1);
67 TQStringList listType;
68 listType+=i18n("All");
69 listType+=i18n("Number");
70 listType+=i18n("Integer");
71 listType+=i18n("Text");
72 listType+=i18n("Date");
73 listType+=i18n("Time");
74 listType+=i18n("Text Length");
75 listType+=i18n("List");
76 chooseType->insertStringList(listType);
77 chooseType->setCurrentItem(0);
78
79 allowEmptyCell = new TQCheckBox( i18n( "Allow blanks" ), tmpTQButtonGroup );
80 grid1->addWidget(allowEmptyCell,1,0);
81
82 tmpTQLabel = new TQLabel( tmpTQButtonGroup, "Label_2" );
83 tmpTQLabel->setText(i18n("Data:" ));
84 grid1->addWidget(tmpTQLabel,2,0);
85
86 choose=new TQComboBox(tmpTQButtonGroup);
87 grid1->addWidget(choose,2,1);
88 TQStringList list;
89 list+=i18n("equal to");
90 list+=i18n("greater than");
91 list+=i18n("less than");
92 list+=i18n("equal to or greater than");
93 list+=i18n("equal to or less than");
94 list+=i18n("between");
95 list+=i18n("different from");
96 list+=i18n("different to");
97 choose->insertStringList(list);
98 choose->setCurrentItem(0);
99
100 edit1 = new TQLabel( tmpTQButtonGroup, "Label_3" );
101 edit1->setText(i18n("Minimum:" ));
102 grid1->addWidget(edit1,3,0);
103
104 val_min=new TQLineEdit(tmpTQButtonGroup);
105 grid1->addWidget(val_min,3,1);
106 val_min->setValidator( new KFloatValidator( val_min ) );
107
108 edit2 = new TQLabel( tmpTQButtonGroup, "Label_4" );
109 edit2->setText(i18n("Maximum:" ));
110 grid1->addWidget(edit2,4,0);
111
112 val_max=new TQLineEdit(tmpTQButtonGroup);
113 grid1->addWidget(val_max,4,1);
114 val_max->setValidator( new KFloatValidator( val_max ) );
115 lay1->addWidget(tmpTQButtonGroup);
116
117 //Apply minimum width of column1 to avoid horizontal move when changing option
118 //A bit ugly to apply text always, but I couldn't get a label->TQFontMetrix.boundingRect("text").width()
119 //to give mew the correct results - Philipp
120 edit2->setText( i18n( "Date:" ) );
121 grid1->addColSpacing( 0, edit2->width() );
122 edit2->setText( i18n( "Date minimum:" ) );
123 grid1->addColSpacing( 0, edit2->width() );
124 edit2->setText( i18n( "Date maximum:" ) );
125 grid1->addColSpacing( 0, edit2->width() );
126 edit2->setText( i18n( "Time:" ) );
127 grid1->addColSpacing( 0, edit2->width() );
128 edit2->setText( i18n( "Time minimum:" ) );
129 grid1->addColSpacing( 0, edit2->width() );
130 edit2->setText( i18n( "Time maximum:" ) );
131 grid1->addColSpacing( 0, edit2->width() );
132 edit2->setText( i18n( "Minimum:" ) );
133 grid1->addColSpacing( 0, edit2->width() );
134 edit2->setText( i18n( "Maximum:" ) );
135 grid1->addColSpacing( 0, edit2->width() );
136 edit2->setText( i18n( "Number:" ) );
137 grid1->addColSpacing( 0, edit2->width() );
138
139 validityList = new TQTextEdit( tmpTQButtonGroup );
140 grid1->addMultiCellWidget(validityList,2, 4,1, 1);
141
142 validityLabelList = new TQLabel( tmpTQButtonGroup, "Label_Label_List" );
143 validityLabelList->setText(i18n("Entries:" ));
144 grid1->addWidget(validityLabelList,2,0);
145
146 TQFrame *page2 = addPage(i18n("&Error Alert"));
147
148 lay1 = new TQVBoxLayout( page2, KDialogBase::marginHint(), KDialogBase::spacingHint() );
149
150 tmpTQButtonGroup = new TQButtonGroup( 0, TQt::Vertical, i18n("Contents"), page2, "ButtonGroup_2" );
151 tmpTQButtonGroup->layout()->setSpacing(KDialog::spacingHint());
152 tmpTQButtonGroup->layout()->setMargin(KDialog::marginHint());
153 TQGridLayout *grid2 = new TQGridLayout(tmpTQButtonGroup->layout(),5,2);
154
155 displayMessage = new TQCheckBox(i18n( "Show error message when invalid values are entered" ),tmpTQButtonGroup );
156 displayMessage->setChecked( true );
157 grid2->addMultiCellWidget(displayMessage,0, 0,0, 1);
158
159 tmpTQLabel = new TQLabel( tmpTQButtonGroup, "Label_5" );
160 tmpTQLabel->setText(i18n("Action:" ));
161 grid2->addWidget(tmpTQLabel,1,0);
162
163 chooseAction=new TQComboBox(tmpTQButtonGroup);
164 grid2->addWidget(chooseAction,1,1);
165 TQStringList list2;
166 list2+=i18n("Stop");
167 list2+=i18n("Warning");
168 list2+=i18n("Information");
169 chooseAction->insertStringList(list2);
170 chooseAction->setCurrentItem(0);
171 tmpTQLabel = new TQLabel( tmpTQButtonGroup, "Label_6" );
172 tmpTQLabel->setText(i18n("Title:" ));
173 grid2->addWidget(tmpTQLabel,2,0);
174
175 title=new TQLineEdit( tmpTQButtonGroup);
176 grid2->addWidget(title,2,1);
177
178 tmpTQLabel = new TQLabel( tmpTQButtonGroup, "Label_7" );
179 tmpTQLabel->setText(i18n("Message:" ));
180 grid2->addWidget(tmpTQLabel,3,0);
181
182 message =new TQTextEdit( tmpTQButtonGroup);
183 grid2->addMultiCellWidget(message,3, 4,1, 1);
184 lay1->addWidget(tmpTQButtonGroup);
185 message->setTextFormat( TQt::PlainText );
186
187 TQFrame *page3 = addPage(i18n("Input Help"));
188 lay1 = new TQVBoxLayout( page3, KDialogBase::marginHint(), KDialogBase::spacingHint() );
189
190 tmpTQButtonGroup = new TQButtonGroup( 0, TQt::Vertical, i18n("Contents"), page3, "ButtonGroup_2" );
191 tmpTQButtonGroup->layout()->setSpacing(KDialog::spacingHint());
192 tmpTQButtonGroup->layout()->setMargin(KDialog::marginHint());
193
194 TQGridLayout *grid3 = new TQGridLayout(tmpTQButtonGroup->layout(),5,2);
195
196 displayHelp = new TQCheckBox(i18n( "Show input help when cell is selected" ),tmpTQButtonGroup );
197 displayMessage->setChecked( false );
198 grid3->addMultiCellWidget(displayHelp,0, 0,0, 1);
199
200 tmpTQLabel = new TQLabel( tmpTQButtonGroup, "Label_6" );
201 tmpTQLabel->setText(i18n("Title:" ));
202 grid3->addWidget(tmpTQLabel,2,0);
203
204 titleHelp=new TQLineEdit( tmpTQButtonGroup);
205 grid3->addWidget(titleHelp,2,1);
206
207 tmpTQLabel = new TQLabel( tmpTQButtonGroup, "Label_7" );
208 tmpTQLabel->setText(i18n("Message:" ));
209 grid3->addWidget(tmpTQLabel,3,0);
210
211 messageHelp =new TQTextEdit( tmpTQButtonGroup);
212 grid3->addMultiCellWidget(messageHelp,3, 4,1, 1);
213 lay1->addWidget(tmpTQButtonGroup);
214 messageHelp->setTextFormat( TQt::PlainText );
215
216
217 connect(choose,TQ_SIGNAL(activated(int )),this,TQ_SLOT(changeIndexCond(int)));
218 connect(chooseType,TQ_SIGNAL(activated(int )),this,TQ_SLOT(changeIndexType(int)));
219 connect( this, TQ_SIGNAL(user1Clicked()), TQ_SLOT(OkPressed()) );
220 connect( this, TQ_SIGNAL(user2Clicked()), TQ_SLOT(clearAllPressed()) );
221 init();
222}
223
224void DlgValidity::displayOrNotListOfValidity( bool _displayList)
225{
226 if ( _displayList )
227 {
228 validityList->show();
229 validityLabelList->show();
230 edit1->hide();
231 val_min->hide();
232 edit2->hide();
233 val_max->hide();
234 }
235 else
236 {
237 validityList->hide();
238 validityLabelList->hide();
239 edit1->show();
240 val_min->show();
241 edit2->show();
242 val_max->show();
243 }
244}
245
246void DlgValidity::changeIndexType(int _index)
247{
248 bool activate = ( _index!=0 );
249 message->setEnabled(activate);
250 title->setEnabled(activate);
251 chooseAction->setEnabled( activate );
252 displayHelp->setEnabled(activate);
253 messageHelp->setEnabled(activate);
254 titleHelp->setEnabled(activate);
255 if ( _index == 7 )
256 displayOrNotListOfValidity( true );
257 else
258 displayOrNotListOfValidity( false );
259
260 switch(_index)
261 {
262 case 0:
263 edit1->setText("");
264 edit2->setText("");
265 val_max->setEnabled(false);
266 val_min->setEnabled(false);
267 edit1->setEnabled(false);
268 edit2->setEnabled(false);
269 choose->setEnabled(false);
270 break;
271 case 1:
272 val_min->setEnabled(true);
273 edit1->setEnabled(true);
274 choose->setEnabled(true);
275 val_min->setValidator( new KFloatValidator( val_min ) );
276 val_max->setValidator( new KFloatValidator( val_max ) );
277 if( choose->currentItem()<=4)
278 {
279 edit1->setText(i18n("Number:"));
280 edit2->setText("");
281 edit2->setEnabled(false);
282 val_max->setEnabled(false);
283 }
284 else
285 {
286 edit1->setText(i18n("Minimum:" ));
287 edit2->setText(i18n("Maximum:" ));
288 edit2->setEnabled(true);
289 val_max->setEnabled(true);
290 }
291 break;
292 case 2:
293 case 6:
294 val_min->setEnabled(true);
295 edit1->setEnabled(true);
296 choose->setEnabled(true);
297 val_min->setValidator( new KIntValidator( val_min ) );
298 val_max->setValidator( new KIntValidator( val_max ) );
299 if( choose->currentItem()<=4)
300 {
301 edit1->setText(i18n("Number:"));
302 edit2->setText("");
303 edit2->setEnabled(false);
304 val_max->setEnabled(false);
305 }
306 else
307 {
308 edit1->setText(i18n("Minimum:" ));
309 edit2->setText(i18n("Maximum:" ));
310 edit2->setEnabled(true);
311 val_max->setEnabled(true);
312 }
313 break;
314
315 case 3:
316 edit1->setText("");
317 edit2->setText("");
318 val_max->setEnabled(false);
319 val_min->setEnabled(false);
320 choose->setEnabled(false);
321 edit1->setEnabled(false);
322 edit2->setEnabled(false);
323 break;
324 case 4:
325 edit1->setText(i18n("Date:"));
326 edit2->setText("");
327 val_min->setEnabled(true);
328 edit1->setEnabled(true);
329 choose->setEnabled(true);
330
331 val_min->clearValidator();
332 val_max->clearValidator();
333 if( choose->currentItem()<=4)
334 {
335 edit1->setText(i18n("Date:"));
336 edit2->setText("");
337 edit2->setEnabled(false);
338 val_max->setEnabled(false);
339 }
340 else
341 {
342 edit1->setText(i18n("Date minimum:"));
343 edit2->setText(i18n("Date maximum:"));
344 edit2->setEnabled(true);
345 val_max->setEnabled(true);
346 }
347 break;
348 case 5:
349 val_min->setEnabled(true);
350 edit1->setEnabled(true);
351 choose->setEnabled(true);
352 val_min->clearValidator();
353 val_max->clearValidator();
354 if( choose->currentItem()<=4)
355 {
356 edit1->setText(i18n("Time:"));
357 edit2->setText("");
358 edit2->setEnabled(false);
359 val_max->setEnabled(false);
360 }
361 else
362 {
363 edit1->setText(i18n("Time minimum:"));
364 edit2->setText(i18n("Time maximum:"));
365 edit2->setEnabled(true);
366 val_max->setEnabled(true);
367 }
368 break;
369 }
370 if ( width() < sizeHint().width() )
371 resize( sizeHint() );
372}
373
374void DlgValidity::changeIndexCond(int _index)
375{
376 switch(_index)
377 {
378 case 0:
379 case 1:
380 case 2:
381 case 3:
382 case 4:
383 val_max->setEnabled(false);
384 if(chooseType->currentItem()==1 ||chooseType->currentItem()==2
385 ||chooseType->currentItem()==6)
386 edit1->setText(i18n("Number:"));
387 else if( chooseType->currentItem()==3)
388 edit1->setText("");
389 else if( chooseType->currentItem()==4)
390 edit1->setText(i18n("Date:"));
391 else if( chooseType->currentItem()==5)
392 edit1->setText(i18n("Time:"));
393 edit2->setText("");
394 edit2->setEnabled(false);
395 break;
396 case 5:
397 case 6:
398 val_max->setEnabled(true);
399 edit2->setEnabled(true);
400 edit1->setEnabled(true);
401 if(chooseType->currentItem()==1 || chooseType->currentItem()==2
402 || chooseType->currentItem()==6)
403 {
404 edit1->setText(i18n("Minimum:" ));
405 edit2->setText(i18n("Maximum:" ));
406 }
407 else if(chooseType->currentItem()==3)
408 {
409 edit1->setText("");
410 edit2->setText("");
411 }
412 else if(chooseType->currentItem()==4)
413 {
414 edit1->setText(i18n("Date minimum:"));
415 edit2->setText(i18n("Date maximum:"));
416 }
417 else if(chooseType->currentItem()==5)
418 {
419 edit1->setText(i18n("Time minimum:"));
420 edit2->setText(i18n("Time maximum:"));
421 }
422 break;
423 }
424}
425
426void DlgValidity::init()
427{
428 Cell *c = m_pView->activeSheet()->cellAt( marker.left(), marker.top() );
429 Validity * tmpValidity=c->getValidity(0);
430 if(tmpValidity!=0)
431 {
432 message->setText(tmpValidity->message);
433 title->setText(tmpValidity->title);
434 TQString tmp;
435 switch( tmpValidity->m_restriction)
436 {
438 chooseType->setCurrentItem(0);
439 break;
441 chooseType->setCurrentItem(1);
442 if(tmpValidity->m_cond >=5 )
443 val_max->setText(tmp.setNum(tmpValidity->valMax));
444 val_min->setText(tmp.setNum(tmpValidity->valMin));
445 break;
447 chooseType->setCurrentItem(2);
448 if(tmpValidity->m_cond >=5 )
449 val_max->setText(tmp.setNum(tmpValidity->valMax));
450 val_min->setText(tmp.setNum(tmpValidity->valMin));
451 break;
453 chooseType->setCurrentItem(6);
454 if(tmpValidity->m_cond >=5 )
455 val_max->setText(tmp.setNum(tmpValidity->valMax));
456 val_min->setText(tmp.setNum(tmpValidity->valMin));
457 break;
459 chooseType->setCurrentItem(3);
460 break;
462 chooseType->setCurrentItem(4);
463 val_min->setText(m_pView->doc()->locale()->formatDate(tmpValidity->dateMin,true));
464 if(tmpValidity->m_cond >=5 )
465 val_max->setText(m_pView->doc()->locale()->formatDate(tmpValidity->dateMax,true));
466 break;
468 chooseType->setCurrentItem(5);
469 val_min->setText(m_pView->doc()->locale()->formatTime(tmpValidity->timeMin,true));
470 if(tmpValidity->m_cond >=5 )
471 val_max->setText(m_pView->doc()->locale()->formatTime(tmpValidity->timeMax,true));
472 break;
474 {
475 chooseType->setCurrentItem(7);
476 TQStringList lst =tmpValidity->listValidity;
477 TQString tmp;
478 for ( TQStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
479 tmp +=( *it )+"\n";
480 }
481 validityList->setText( tmp );
482 }
483 break;
484 default :
485 chooseType->setCurrentItem(0);
486 break;
487 }
488 switch (tmpValidity->m_action)
489 {
490 case Action::Stop:
491 chooseAction->setCurrentItem(0);
492 break;
493 case Action::Warning:
494 chooseAction->setCurrentItem(1);
495 break;
496 case Action::Information:
497 chooseAction->setCurrentItem(2);
498 break;
499 default :
500 chooseAction->setCurrentItem(0);
501 break;
502 }
503 switch ( tmpValidity->m_cond )
504 {
505 case Conditional::Equal:
506 choose->setCurrentItem(0);
507 break;
508 case Conditional::Superior:
509 choose->setCurrentItem(1);
510 break;
511 case Conditional::Inferior:
512 choose->setCurrentItem(2);
513 break;
514 case Conditional::SuperiorEqual:
515 choose->setCurrentItem(3);
516 break;
517 case Conditional::InferiorEqual:
518 choose->setCurrentItem(4);
519 break;
520 case Conditional::Between:
521 choose->setCurrentItem(5);
522 break;
523 case Conditional::Different:
524 choose->setCurrentItem(6);
525 break;
526 case Conditional::DifferentTo:
527 choose->setCurrentItem(7);
528 break;
529 default :
530 choose->setCurrentItem(0);
531 break;
532 }
533 displayMessage->setChecked( tmpValidity->displayMessage );
534 allowEmptyCell->setChecked( tmpValidity->allowEmptyCell );
535 titleHelp->setText( tmpValidity->titleInfo );
536 messageHelp->setText( tmpValidity->messageInfo );
537 displayHelp->setChecked( tmpValidity->displayValidationInformation );
538 }
539 changeIndexType(chooseType->currentItem()) ;
540 changeIndexCond(choose->currentItem()) ;
541}
542
543void DlgValidity::clearAllPressed()
544{
545 val_min->setText("");
546 val_max->setText("");
547 message->setText("");
548 title->setText("");
549 displayMessage->setChecked( true );
550 allowEmptyCell->setChecked( false );
551 choose->setCurrentItem(0);
552 chooseType->setCurrentItem(0);
553 chooseAction->setCurrentItem(0);
554 changeIndexType(0);
555 changeIndexCond(0);
556 messageHelp->setText("" );
557 titleHelp->setText( "" );
558 validityList->setText( "" );
559 displayHelp->setChecked( false );
560}
561
562void DlgValidity::OkPressed()
563{
564 if( chooseType->currentItem()==1)
565 {
566 bool ok;
567 val_min->text().toDouble(&ok);
568 if(! ok)
569 {
570 KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
571 val_min->setText("");
572 return;
573 }
574 val_max->text().toDouble(&ok);
575 if(! ok && choose->currentItem() >=5 && choose->currentItem()< 7)
576 {
577 KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
578 val_max->setText("");
579 return;
580 }
581 }
582 else if( chooseType->currentItem()==2 || chooseType->currentItem()==6)
583 {
584 bool ok;
585 val_min->text().toInt(&ok);
586 if(! ok)
587 {
588 KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
589 val_min->setText("");
590 return;
591 }
592 val_max->text().toInt(&ok);
593 if(! ok && choose->currentItem() >=5 && choose->currentItem()< 7)
594 {
595 KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
596 val_max->setText("");
597 return;
598 }
599 }
600 else if( chooseType->currentItem()==5)
601 {
602 if(! m_pView->doc()->locale()->readTime(val_min->text()).isValid())
603 {
604 KMessageBox::error( this , i18n("This is not a valid time."),i18n("Error"));
605 val_min->setText("");
606 return;
607 }
608 if(! m_pView->doc()->locale()->readTime(val_max->text()).isValid() && choose->currentItem() >=5)
609 {
610 KMessageBox::error( this , i18n("This is not a valid time."),i18n("Error"));
611 val_max->setText("");
612 return;
613 }
614 }
615 else if( chooseType->currentItem()==4)
616 {
617 if(! m_pView->doc()->locale()->readDate(val_min->text()).isValid())
618 {
619 KMessageBox::error( this , i18n("This is not a valid date."),i18n("Error"));
620 val_min->setText("");
621 return;
622 }
623 if(! m_pView->doc()->locale()->readDate(val_max->text()).isValid() && choose->currentItem() >=5 )
624 {
625 KMessageBox::error( this , i18n("This is not a valid date."),i18n("Error"));
626 val_max->setText("");
627 return;
628 }
629 }
630 else if ( chooseType->currentItem()==7 )
631 {
632 //Nothing
633 }
634
635 if( chooseType->currentItem()==0)
636 {//no validity
637 result.m_restriction=Restriction::None;
638 result.m_action=Action::Stop;
639 result.m_cond=Conditional::Equal;
640 result.message=message->text();
641 result.title=title->text();
642 result.valMin=0;
643 result.valMax=0;
644 result.timeMin=TQTime(0,0,0);
645 result.timeMax=TQTime(0,0,0);
646 result.dateMin=TQDate(0,0,0);
647 result.dateMax=TQDate(0,0,0);
648 }
649 else
650 {
651 switch( chooseType->currentItem())
652 {
653 case 0:
654 result.m_restriction=Restriction::None;
655 break;
656 case 1:
657 result.m_restriction=Restriction::Number;
658 break;
659 case 2:
660 result.m_restriction=Restriction::Integer;
661 break;
662 case 3:
663 result.m_restriction=Restriction::Text;
664 break;
665 case 4:
666 result.m_restriction=Restriction::Date;
667 break;
668 case 5:
669 result.m_restriction=Restriction::Time;
670 break;
671 case 6:
672 result.m_restriction=Restriction::TextLength;
673 break;
674 case 7:
675 result.m_restriction=Restriction::List;
676 break;
677
678 default :
679 break;
680 }
681 switch (chooseAction->currentItem())
682 {
683 case 0:
684 result.m_action=Action::Stop;
685 break;
686 case 1:
687 result.m_action=Action::Warning;
688 break;
689 case 2:
690 result.m_action=Action::Information;
691 break;
692 default :
693 break;
694 }
695 switch ( choose->currentItem())
696 {
697 case 0:
698 result.m_cond=Conditional::Equal;
699 break;
700 case 1:
701 result.m_cond=Conditional::Superior;
702 break;
703 case 2:
704 result.m_cond=Conditional::Inferior;
705 break;
706 case 3:
707 result.m_cond=Conditional::SuperiorEqual;
708 break;
709 case 4:
710 result.m_cond=Conditional::InferiorEqual;
711 break;
712 case 5:
713 result.m_cond=Conditional::Between;
714 break;
715 case 6:
716 result.m_cond=Conditional::Different;
717 break;
718 case 7:
719 result.m_cond=Conditional::DifferentTo;
720 break;
721 default :
722 break;
723 }
724 result.message=message->text();
725 result.title=title->text();
726 result.valMin=0;
727 result.valMax=0;
728 result.timeMin=TQTime(0,0,0);
729 result.timeMax=TQTime(0,0,0);
730 result.dateMin=TQDate(0,0,0);
731 result.dateMax=TQDate(0,0,0);
732
733 if( chooseType->currentItem()==1)
734 {
735 if(choose->currentItem() <5)
736 {
737 result.valMin=val_min->text().toDouble();
738 }
739 else
740 {
741 result.valMin=TQMIN(val_min->text().toDouble(),val_max->text().toDouble());
742 result.valMax=TQMAX(val_max->text().toDouble(),val_min->text().toDouble());
743 }
744 }
745 else if( chooseType->currentItem()==2 || chooseType->currentItem()==6)
746 {
747 if(choose->currentItem() <5)
748 {
749 result.valMin=val_min->text().toInt();
750 }
751 else
752 {
753 result.valMin=TQMIN(val_min->text().toInt(),val_max->text().toInt());
754 result.valMax=TQMAX(val_max->text().toInt(),val_min->text().toInt());
755 }
756 }
757 else if( chooseType->currentItem()==4)
758 {
759 if(choose->currentItem() <5)
760 {
761 result.dateMin=m_pView->doc()->locale()->readDate(val_min->text());
762 }
763 else
764 {
765 if(m_pView->doc()->locale()->readDate(val_min->text())<m_pView->doc()->locale()->readDate(val_max->text()))
766 {
767 result.dateMin=m_pView->doc()->locale()->readDate(val_min->text());
768 result.dateMax=m_pView->doc()->locale()->readDate(val_max->text());
769 }
770 else
771 {
772 result.dateMin=m_pView->doc()->locale()->readDate(val_max->text());
773 result.dateMax=m_pView->doc()->locale()->readDate(val_min->text());
774 }
775 }
776 }
777 else if( chooseType->currentItem()==5)
778 {
779 if(choose->currentItem() <5)
780 {
781 result.timeMin=m_pView->doc()->locale()->readTime(val_min->text());
782 }
783 else
784 {
785 if(m_pView->doc()->locale()->readTime(val_min->text())<m_pView->doc()->locale()->readTime(val_max->text()))
786 {
787 result.timeMax=m_pView->doc()->locale()->readTime(val_max->text());
788 result.timeMin=m_pView->doc()->locale()->readTime(val_min->text());
789 }
790 else
791 {
792 result.timeMax=m_pView->doc()->locale()->readTime(val_min->text());
793 result.timeMin=m_pView->doc()->locale()->readTime(val_max->text());
794 }
795 }
796 }
797 else if ( chooseType->currentItem()==7 )
798 {
799 result.listValidity=TQStringList::split( "\n", validityList->text() );
800 }
801 }
802 result.displayMessage = displayMessage->isChecked();
803 result.allowEmptyCell = allowEmptyCell->isChecked();
804 result.displayValidationInformation = displayHelp->isChecked();
805 result.messageInfo= messageHelp->text();
806 result.titleInfo = titleHelp->text();
807
808 m_pView->doc()->emitBeginOperation( false );
809 m_pView->activeSheet()->setValidity( m_pView->selectionInfo(), result);
810 m_pView->slotUpdateView( m_pView->activeSheet() );
811 accept();
812}
813
814#include "kspread_dlg_validity.moc"
The View class displays a KSpread document.
@ Text
Restrict to texts.
@ Date
Restrict to dates.
@ Number
Restrict to numbers.
@ Integer
Restrict to integers.
@ List
Restrict to lists.
@ TextLength
Restrict text length.
@ None
No restriction.
@ Time
Restrict to times.
The KSpread namespace.
Definition commands.h:39