1 /* This file is part of the KDE project
2 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 Copyright 2002-2003 Norbert Andres <nandres@web.de>
4 Copyright 2002 John Dailey <dailey@vt.edu>
5 Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
6 Copyright 1999-2005 Laurent Montel <montel@kde.org>
7 Copyright 1998-1999 Torben Weis <weis@kde.org>
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23 */
24
25 // Local
26 #include "ValidityDialog.h"
27
28 #include <QIntValidator>
29 #include <QDoubleValidator>
30 #include <QCheckBox>
31 #include <QPushButton>
32 #include <QLabel>
33 #include <QGridLayout>
34 #include <QFrame>
35
36 #include <kcombobox.h>
37 #include "SheetsDebug.h"
38 #include <klineedit.h>
39 #include <kmessagebox.h>
40 #include <ktextedit.h>
41
42 #include "CalculationSettings.h"
43 #include "Localization.h"
44 #include "Map.h"
45 #include "ui/Selection.h"
46 #include "Sheet.h"
47 #include "ValueParser.h"
48
49 // commands
50 #include "commands/ValidityCommand.h"
51
52 using namespace Calligra::Sheets;
53
54 Q_DECLARE_METATYPE(Conditional::Type)
Q_DECLARE_METATYPE(Validity::Action)55 Q_DECLARE_METATYPE(Validity::Action)
56 Q_DECLARE_METATYPE(Validity::Restriction)
57
58 ValidityDialog::ValidityDialog(QWidget* parent, Selection* selection)
59 : KPageDialog(parent)
60
61 {
62 setFaceType(Tabbed);
63 setWindowTitle(i18n("Validity"));
64 setModal(true);
65
66 QPushButton *clearAllButton = buttonBox()->addButton(i18n("Clear &All"), QDialogButtonBox::ActionRole);
67
68 m_selection = selection;
69
70 QFrame *page1 = new QFrame();
71 addPage(page1, i18n("&Criteria"));
72
73 QGridLayout* tmpGridLayout = new QGridLayout(page1);
74
75 QLabel *tmpQLabel = new QLabel(page1);
76 tmpQLabel->setText(i18n("Allow:"));
77 tmpGridLayout->addWidget(tmpQLabel, 0, 0);
78
79 chooseType = new KComboBox(page1);
80 tmpGridLayout->addWidget(chooseType, 0, 1);
81 chooseType->addItem(i18n("All"), QVariant::fromValue(Validity::None));
82 chooseType->addItem(i18n("Number"), QVariant::fromValue(Validity::Number));
83 chooseType->addItem(i18n("Integer"), QVariant::fromValue(Validity::Integer));
84 chooseType->addItem(i18n("Text"), QVariant::fromValue(Validity::Text));
85 chooseType->addItem(i18n("Date"), QVariant::fromValue(Validity::Date));
86 chooseType->addItem(i18n("Time"), QVariant::fromValue(Validity::Time));
87 chooseType->addItem(i18n("Text Length"), QVariant::fromValue(Validity::TextLength));
88 chooseType->addItem(i18n("List"), QVariant::fromValue(Validity::List));
89 chooseType->setCurrentIndex(0);
90
91 allowEmptyCell = new QCheckBox(i18n("Allow blanks"), page1);
92 tmpGridLayout->addWidget(allowEmptyCell, 1, 0, 1, 2);
93
94 chooseLabel = new QLabel(page1);
95 chooseLabel->setText(i18n("Data:"));
96 tmpGridLayout->addWidget(chooseLabel, 2, 0);
97
98 choose = new KComboBox(page1);
99 tmpGridLayout->addWidget(choose, 2, 1);
100 choose->addItem(i18n("equal to"), QVariant::fromValue(Conditional::Equal));
101 choose->addItem(i18n("greater than"), QVariant::fromValue(Conditional::Superior));
102 choose->addItem(i18n("less than"), QVariant::fromValue(Conditional::Inferior));
103 choose->addItem(i18n("equal to or greater than"), QVariant::fromValue(Conditional::SuperiorEqual));
104 choose->addItem(i18n("equal to or less than"), QVariant::fromValue(Conditional::InferiorEqual));
105 choose->addItem(i18n("between"), QVariant::fromValue(Conditional::Between));
106 choose->addItem(i18n("different from"), QVariant::fromValue(Conditional::Different));
107 choose->addItem(i18n("different to"), QVariant::fromValue(Conditional::DifferentTo));
108 choose->setCurrentIndex(0);
109
110 edit1 = new QLabel(page1);
111 edit1->setText(i18n("Minimum:"));
112 tmpGridLayout->addWidget(edit1, 3, 0);
113
114 val_min = new KLineEdit(page1);
115 tmpGridLayout->addWidget(val_min, 3, 1);
116 val_min->setValidator(new QDoubleValidator(val_min));
117
118 edit2 = new QLabel(page1);
119 edit2->setText(i18n("Maximum:"));
120 tmpGridLayout->addWidget(edit2, 4, 0);
121
122 val_max = new KLineEdit(page1);
123 tmpGridLayout->addWidget(val_max, 4, 1);
124 val_max->setValidator(new QDoubleValidator(val_max));
125
126 //Apply minimum width of column1 to avoid horizontal move when changing option
127 //A bit ugly to apply text always, but I couldn't get a label->QFontMetrix.boundingRect("text").width()
128 //to give mew the correct results - Philipp
129 edit2->setText(i18n("Date:"));
130 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
131 edit2->setText(i18n("Date minimum:"));
132 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
133 edit2->setText(i18n("Date maximum:"));
134 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
135 edit2->setText(i18n("Time:"));
136 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
137 edit2->setText(i18n("Time minimum:"));
138 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
139 edit2->setText(i18n("Time maximum:"));
140 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
141 edit2->setText(i18n("Minimum:"));
142 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
143 edit2->setText(i18n("Maximum:"));
144 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
145 edit2->setText(i18n("Number:"));
146 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0);
147
148 validityList = new KTextEdit(page1);
149 tmpGridLayout->addWidget(validityList, 2, 1, 3, 1);
150
151 validityLabelList = new QLabel(page1);
152 validityLabelList->setText(i18n("Entries:"));
153 tmpGridLayout->addWidget(validityLabelList, 2, 0, Qt::AlignTop);
154
155 tmpGridLayout->setRowStretch(5, 1);
156
157 QFrame *page2 = new QFrame();
158 addPage(page2, i18n("&Error Alert"));
159
160 tmpGridLayout = new QGridLayout(page2);
161
162 displayMessage = new QCheckBox(i18n("Show error message when invalid values are entered"), page2);
163 displayMessage->setChecked(true);
164 tmpGridLayout->addWidget(displayMessage, 0, 0, 1, 2);
165
166 tmpQLabel = new QLabel(page2);
167 tmpQLabel->setText(i18n("Action:"));
168 tmpGridLayout->addWidget(tmpQLabel, 1, 0);
169
170 chooseAction = new KComboBox(page2);
171 tmpGridLayout->addWidget(chooseAction, 1, 1);
172 chooseAction->addItem(i18n("Stop"), QVariant::fromValue(Validity::Stop));
173 chooseAction->addItem(i18n("Warning"), QVariant::fromValue(Validity::Warning));
174 chooseAction->addItem(i18n("Information"), QVariant::fromValue(Validity::Information));
175 chooseAction->setCurrentIndex(0);
176
177 tmpQLabel = new QLabel(page2);
178 tmpQLabel->setText(i18nc("Title of message", "Title:"));
179 tmpGridLayout->addWidget(tmpQLabel, 2, 0);
180
181 title = new KLineEdit(page2);
182 tmpGridLayout->addWidget(title, 2, 1);
183
184 tmpQLabel = new QLabel(page2);
185 tmpQLabel->setText(i18n("Message:"));
186 tmpGridLayout->addWidget(tmpQLabel, 3, 0, Qt::AlignTop);
187
188 message = new KTextEdit(page2);
189 tmpGridLayout->addWidget(message, 3, 1);
190
191 QFrame *page3 = new QFrame();
192 addPage(page3, i18n("Input Help"));
193
194 tmpGridLayout = new QGridLayout(page3);
195
196 displayHelp = new QCheckBox(i18n("Show input help when cell is selected"), page3);
197 displayMessage->setChecked(false);
198 tmpGridLayout->addWidget(displayHelp, 0, 0, 1, 2);
199
200 tmpQLabel = new QLabel(page3);
201 tmpQLabel->setText(i18nc("Title of message", "Title:"));
202 tmpGridLayout->addWidget(tmpQLabel, 1, 0);
203
204 titleHelp = new KLineEdit(page3);
205 tmpGridLayout->addWidget(titleHelp, 1, 1);
206
207 tmpQLabel = new QLabel(page3);
208 tmpQLabel->setText(i18n("Message:"));
209 tmpGridLayout->addWidget(tmpQLabel, 2, 0, Qt::AlignTop);
210
211 messageHelp = new KTextEdit(page3);
212 tmpGridLayout->addWidget(messageHelp, 2, 1);
213
214 connect(choose, SIGNAL(activated(int)), this, SLOT(changeIndexCond(int)));
215 connect(chooseType, SIGNAL(activated(int)), this, SLOT(changeIndexType(int)));
216 connect(this, SIGNAL(accepted()), SLOT(OkPressed()));
217 connect(clearAllButton, SIGNAL(clicked(bool)), SLOT(clearAllPressed()));
218
219 init();
220 }
221
displayOrNotListOfValidity(bool _displayList)222 void ValidityDialog::displayOrNotListOfValidity(bool _displayList)
223 {
224 if (_displayList) {
225 validityList->show();
226 validityLabelList->show();
227 chooseLabel->hide();
228 choose->hide();
229 edit1->hide();
230 val_min->hide();
231 edit2->hide();
232 val_max->hide();
233 static_cast<QGridLayout*>(validityList->parentWidget()->layout())->setRowStretch(5, 0);
234 } else {
235 validityList->hide();
236 validityLabelList->hide();
237 chooseLabel->show();
238 choose->show();
239 edit1->show();
240 val_min->show();
241 edit2->show();
242 val_max->show();
243 static_cast<QGridLayout*>(validityList->parentWidget()->layout())->setRowStretch(5, 1);
244 }
245 }
246
changeIndexType(int _index)247 void ValidityDialog::changeIndexType(int _index)
248 {
249 bool activate = (_index != 0);
250 allowEmptyCell->setEnabled(activate);
251 message->setEnabled(activate);
252 title->setEnabled(activate);
253 chooseAction->setEnabled(activate);
254 displayMessage->setEnabled(activate);
255 displayHelp->setEnabled(activate);
256 messageHelp->setEnabled(activate);
257 titleHelp->setEnabled(activate);
258 if (_index == 7)
259 displayOrNotListOfValidity(true);
260 else
261 displayOrNotListOfValidity(false);
262
263 switch (_index) {
264 case 0:
265 edit1->setText("");
266 edit2->setText("");
267 val_max->setEnabled(false);
268 val_min->setEnabled(false);
269 choose->setEnabled(false);
270 break;
271 case 1:
272 val_min->setEnabled(true);
273 choose->setEnabled(true);
274 val_min->setValidator(new QDoubleValidator(val_min));
275 val_max->setValidator(new QDoubleValidator(val_max));
276 if (choose->currentIndex() <= 4) {
277 edit1->setText(i18n("Number:"));
278 edit2->setText("");
279 val_max->setEnabled(false);
280 } else {
281 edit1->setText(i18n("Minimum:"));
282 edit2->setText(i18n("Maximum:"));
283 val_max->setEnabled(true);
284 }
285 break;
286 case 2:
287 case 6:
288 val_min->setEnabled(true);
289 choose->setEnabled(true);
290 val_min->setValidator(new QIntValidator(val_min));
291 val_max->setValidator(new QIntValidator(val_max));
292 if (choose->currentIndex() <= 4) {
293 edit1->setText(i18n("Number:"));
294 edit2->setText("");
295 val_max->setEnabled(false);
296 } else {
297 edit1->setText(i18n("Minimum:"));
298 edit2->setText(i18n("Maximum:"));
299 val_max->setEnabled(true);
300 }
301 break;
302
303 case 3:
304 edit1->setText("");
305 edit2->setText("");
306 val_max->setEnabled(false);
307 val_min->setEnabled(false);
308 choose->setEnabled(false);
309 break;
310 case 4:
311 edit1->setText(i18n("Date:"));
312 edit2->setText("");
313 val_min->setEnabled(true);
314 choose->setEnabled(true);
315
316 val_min->setValidator(0);
317 val_max->setValidator(0);
318 if (choose->currentIndex() <= 4) {
319 edit1->setText(i18n("Date:"));
320 edit2->setText("");
321 val_max->setEnabled(false);
322 } else {
323 edit1->setText(i18n("Date minimum:"));
324 edit2->setText(i18n("Date maximum:"));
325 val_max->setEnabled(true);
326 }
327 break;
328 case 5:
329 val_min->setEnabled(true);
330 choose->setEnabled(true);
331 val_min->setValidator(0);
332 val_max->setValidator(0);
333 if (choose->currentIndex() <= 4) {
334 edit1->setText(i18n("Time:"));
335 edit2->setText("");
336 val_max->setEnabled(false);
337 } else {
338 edit1->setText(i18n("Time minimum:"));
339 edit2->setText(i18n("Time maximum:"));
340 val_max->setEnabled(true);
341 }
342 break;
343 }
344 if (width() < sizeHint().width())
345 resize(sizeHint());
346 }
347
changeIndexCond(int _index)348 void ValidityDialog::changeIndexCond(int _index)
349 {
350 switch (_index) {
351 case 0:
352 case 1:
353 case 2:
354 case 3:
355 case 4:
356 val_max->setEnabled(false);
357 if (chooseType->currentIndex() == 1 || chooseType->currentIndex() == 2
358 || chooseType->currentIndex() == 6)
359 edit1->setText(i18n("Number:"));
360 else if (chooseType->currentIndex() == 3)
361 edit1->setText("");
362 else if (chooseType->currentIndex() == 4)
363 edit1->setText(i18n("Date:"));
364 else if (chooseType->currentIndex() == 5)
365 edit1->setText(i18n("Time:"));
366 edit2->setText("");
367 break;
368 case 5:
369 case 6:
370 val_max->setEnabled(true);
371 if (chooseType->currentIndex() == 1 || chooseType->currentIndex() == 2
372 || chooseType->currentIndex() == 6) {
373 edit1->setText(i18n("Minimum:"));
374 edit2->setText(i18n("Maximum:"));
375 } else if (chooseType->currentIndex() == 3) {
376 edit1->setText("");
377 edit2->setText("");
378 } else if (chooseType->currentIndex() == 4) {
379 edit1->setText(i18n("Date minimum:"));
380 edit2->setText(i18n("Date maximum:"));
381 } else if (chooseType->currentIndex() == 5) {
382 edit1->setText(i18n("Time minimum:"));
383 edit2->setText(i18n("Time maximum:"));
384 }
385 break;
386 }
387 }
388
init()389 void ValidityDialog::init()
390 {
391 const Map *const map = m_selection->activeSheet()->map();
392 const CalculationSettings *settings = map->calculationSettings();
393 const KLocale* locale = settings->locale();
394 Validity validity = Cell(m_selection->activeSheet(), m_selection->marker()).validity();
395 if (!validity.isEmpty()) {
396 message->setPlainText(validity.message());
397 title->setText(validity.title());
398 QString tmp;
399 switch (validity.restriction()) {
400 case Validity::None:
401 chooseType->setCurrentIndex(0);
402 break;
403 case Validity::Number:
404 chooseType->setCurrentIndex(1);
405 if (validity.condition() >= 5)
406 val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
407 val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
408 break;
409 case Validity::Integer:
410 chooseType->setCurrentIndex(2);
411 if (validity.condition() >= 5)
412 val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
413 val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
414 break;
415 case Validity::TextLength:
416 chooseType->setCurrentIndex(6);
417 if (validity.condition() >= 5)
418 val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
419 val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
420 break;
421 case Validity::Text:
422 chooseType->setCurrentIndex(3);
423 break;
424 case Validity::Date:
425 chooseType->setCurrentIndex(4);
426 val_min->setText(locale->formatDate(validity.minimumValue().asDate(settings), KLocale::ShortDate));
427 if (validity.condition() >= 5)
428 val_max->setText(locale->formatDate(validity.maximumValue().asDate(settings), KLocale::ShortDate));
429 break;
430 case Validity::Time:
431 chooseType->setCurrentIndex(5);
432 val_min->setText(locale->formatTime(validity.minimumValue().asTime(), true));
433 if (validity.condition() >= 5)
434 val_max->setText(locale->formatTime(validity.maximumValue().asTime(), true));
435 break;
436 case Validity::List: {
437 chooseType->setCurrentIndex(7);
438 const QStringList lst = validity.validityList();
439 QString tmp;
440 for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) {
441 tmp += (*it) + '\n';
442 }
443 validityList->setText(tmp);
444 }
445 break;
446 default :
447 chooseType->setCurrentIndex(0);
448 break;
449 }
450 chooseAction->setCurrentIndex(chooseAction->findData(QVariant::fromValue(validity.action())));
451 choose->setCurrentIndex(choose->findData(QVariant::fromValue(validity.condition())));
452 displayMessage->setChecked(validity.displayMessage());
453 allowEmptyCell->setChecked(validity.allowEmptyCell());
454 titleHelp->setText(validity.titleInfo());
455 messageHelp->setPlainText(validity.messageInfo());
456 displayHelp->setChecked(validity.displayValidationInformation());
457 }
458 changeIndexType(chooseType->currentIndex()) ;
459 changeIndexCond(choose->currentIndex()) ;
460 }
461
clearAllPressed()462 void ValidityDialog::clearAllPressed()
463 {
464 val_min->setText("");
465 val_max->setText("");
466 message->setPlainText("");
467 title->setText("");
468 displayMessage->setChecked(true);
469 allowEmptyCell->setChecked(false);
470 choose->setCurrentIndex(0);
471 chooseType->setCurrentIndex(0);
472 chooseAction->setCurrentIndex(0);
473 changeIndexType(0);
474 changeIndexCond(0);
475 messageHelp->setPlainText("");
476 titleHelp->setText("");
477 validityList->setText("");
478 displayHelp->setChecked(false);
479 }
480
OkPressed()481 void ValidityDialog::OkPressed()
482 {
483 const KLocale* locale = m_selection->activeSheet()->map()->calculationSettings()->locale();
484 const ValueParser *const parser = m_selection->activeSheet()->map()->parser();
485 Validity validity;
486 if (chooseType->currentIndex() == 1) {
487 bool ok;
488 val_min->text().toDouble(&ok);
489 if (! ok) {
490 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
491 val_min->setText("");
492 return;
493 }
494 val_max->text().toDouble(&ok);
495 if (! ok && choose->currentIndex() >= 5 && choose->currentIndex() < 7) {
496 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
497 val_max->setText("");
498 return;
499 }
500 } else if (chooseType->currentIndex() == 2 || chooseType->currentIndex() == 6) {
501 bool ok;
502 val_min->text().toInt(&ok);
503 if (! ok) {
504 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
505 val_min->setText("");
506 return;
507 }
508 val_max->text().toInt(&ok);
509 if (! ok && choose->currentIndex() >= 5 && choose->currentIndex() < 7) {
510 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
511 val_max->setText("");
512 return;
513 }
514 } else if (chooseType->currentIndex() == 5) {
515 if (!locale->readTime(val_min->text()).isValid()) {
516 KMessageBox::error(this , i18n("This is not a valid time."), i18n("Error"));
517 val_min->setText("");
518 return;
519 }
520 if (!locale->readTime(val_max->text()).isValid() && choose->currentIndex() >= 5) {
521 KMessageBox::error(this , i18n("This is not a valid time."), i18n("Error"));
522 val_max->setText("");
523 return;
524 }
525 } else if (chooseType->currentIndex() == 4) {
526 if (!locale->readDate(val_min->text()).isValid()) {
527 KMessageBox::error(this , i18n("This is not a valid date."), i18n("Error"));
528 val_min->setText("");
529 return;
530 }
531 if (!locale->readDate(val_max->text()).isValid() && choose->currentIndex() >= 5) {
532 KMessageBox::error(this , i18n("This is not a valid date."), i18n("Error"));
533 val_max->setText("");
534 return;
535 }
536 } else if (chooseType->currentIndex() == 7) {
537 //Nothing
538 }
539
540 if (chooseType->currentIndex() == 0) {//no validity
541 validity.setRestriction(Validity::None);
542 validity.setAction(Validity::Stop);
543 validity.setCondition(Conditional::Equal);
544 validity.setMessage(message->toPlainText());
545 validity.setTitle(title->text());
546 validity.setMinimumValue(Value());
547 validity.setMaximumValue(Value());
548 } else {
549 validity.setRestriction(chooseType->itemData(chooseType->currentIndex()).value<Validity::Restriction>());
550 validity.setAction(chooseAction->itemData(chooseAction->currentIndex()).value<Validity::Action>());
551 validity.setCondition(choose->itemData(choose->currentIndex()).value<Conditional::Type>());
552 validity.setMessage(message->toPlainText());
553 validity.setTitle(title->text());
554 validity.setMinimumValue(Value());
555 validity.setMaximumValue(Value());
556
557 if (chooseType->currentIndex() == 1) {
558 if (choose->currentIndex() < 5) {
559 validity.setMinimumValue(Value(val_min->text().toDouble()));
560 } else {
561 validity.setMinimumValue(Value(qMin(val_min->text().toDouble(), val_max->text().toDouble())));
562 validity.setMaximumValue(Value(qMax(val_max->text().toDouble(), val_min->text().toDouble())));
563 }
564 } else if (chooseType->currentIndex() == 2 || chooseType->currentIndex() == 6) {
565 if (choose->currentIndex() < 5) {
566 validity.setMinimumValue(Value(val_min->text().toInt()));
567 } else {
568 validity.setMinimumValue(Value(qMin(val_min->text().toInt(), val_max->text().toInt())));
569 validity.setMaximumValue(Value(qMax(val_max->text().toInt(), val_min->text().toInt())));
570 }
571 } else if (chooseType->currentIndex() == 4) {
572 const Value minValue = parser->tryParseDate(val_min->text());
573 const Value maxValue = parser->tryParseDate(val_max->text());
574 if (choose->currentIndex() < 5) {
575 validity.setMinimumValue(minValue);
576 } else {
577 if (minValue.less(maxValue)) {
578 validity.setMinimumValue(minValue);
579 validity.setMaximumValue(maxValue);
580 } else {
581 validity.setMinimumValue(maxValue);
582 validity.setMaximumValue(minValue);
583 }
584 }
585 } else if (chooseType->currentIndex() == 5) {
586 const Value minValue = parser->tryParseTime(val_min->text());
587 const Value maxValue = parser->tryParseTime(val_max->text());
588 if (choose->currentIndex() < 5) {
589 validity.setMinimumValue(minValue);
590 } else {
591 if (minValue.less(maxValue)) {
592 validity.setMaximumValue(maxValue);
593 validity.setMinimumValue(minValue);
594 } else {
595 validity.setMaximumValue(minValue);
596 validity.setMinimumValue(maxValue);
597 }
598 }
599 } else if (chooseType->currentIndex() == 7) {
600 validity.setValidityList(validityList->toPlainText().split('\n', QString::SkipEmptyParts));
601 }
602 }
603 validity.setDisplayMessage(displayMessage->isChecked());
604 validity.setAllowEmptyCell(allowEmptyCell->isChecked());
605 validity.setDisplayValidationInformation(displayHelp->isChecked());
606 validity.setMessageInfo(messageHelp->toPlainText());
607 validity.setTitleInfo(titleHelp->text());
608
609 ValidityCommand* manipulator = new ValidityCommand();
610 manipulator->setSheet(m_selection->activeSheet());
611 manipulator->setValidity(validity);
612 manipulator->add(*m_selection);
613 manipulator->execute(m_selection->canvas());
614
615 accept();
616 }
617