File indexing completed on 2024-05-12 16:35:27
0001 /* This file is part of the KDE project 0002 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 Copyright 2002-2003 Norbert Andres <nandres@web.de> 0004 Copyright 2002 John Dailey <dailey@vt.edu> 0005 Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de> 0006 Copyright 1999-2005 Laurent Montel <montel@kde.org> 0007 Copyright 1998-1999 Torben Weis <weis@kde.org> 0008 0009 This library is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU Library General Public 0011 License as published by the Free Software Foundation; either 0012 version 2 of the License, or (at your option) any later version. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Library General Public License for more details. 0018 0019 You should have received a copy of the GNU Library General Public License 0020 along with this library; see the file COPYING.LIB. If not, write to 0021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 Boston, MA 02110-1301, USA. 0023 */ 0024 0025 // Local 0026 #include "ValidityDialog.h" 0027 0028 #include <QIntValidator> 0029 #include <QDoubleValidator> 0030 #include <QCheckBox> 0031 #include <QPushButton> 0032 #include <QLabel> 0033 #include <QGridLayout> 0034 #include <QFrame> 0035 0036 #include <kcombobox.h> 0037 #include "SheetsDebug.h" 0038 #include <klineedit.h> 0039 #include <kmessagebox.h> 0040 #include <ktextedit.h> 0041 0042 #include "CalculationSettings.h" 0043 #include "Localization.h" 0044 #include "Map.h" 0045 #include "ui/Selection.h" 0046 #include "Sheet.h" 0047 #include "ValueParser.h" 0048 0049 // commands 0050 #include "commands/ValidityCommand.h" 0051 0052 using namespace Calligra::Sheets; 0053 0054 Q_DECLARE_METATYPE(Conditional::Type) 0055 Q_DECLARE_METATYPE(Validity::Action) 0056 Q_DECLARE_METATYPE(Validity::Restriction) 0057 0058 ValidityDialog::ValidityDialog(QWidget* parent, Selection* selection) 0059 : KPageDialog(parent) 0060 0061 { 0062 setFaceType(Tabbed); 0063 setWindowTitle(i18n("Validity")); 0064 setModal(true); 0065 0066 QPushButton *clearAllButton = buttonBox()->addButton(i18n("Clear &All"), QDialogButtonBox::ActionRole); 0067 0068 m_selection = selection; 0069 0070 QFrame *page1 = new QFrame(); 0071 addPage(page1, i18n("&Criteria")); 0072 0073 QGridLayout* tmpGridLayout = new QGridLayout(page1); 0074 0075 QLabel *tmpQLabel = new QLabel(page1); 0076 tmpQLabel->setText(i18n("Allow:")); 0077 tmpGridLayout->addWidget(tmpQLabel, 0, 0); 0078 0079 chooseType = new KComboBox(page1); 0080 tmpGridLayout->addWidget(chooseType, 0, 1); 0081 chooseType->addItem(i18n("All"), QVariant::fromValue(Validity::None)); 0082 chooseType->addItem(i18n("Number"), QVariant::fromValue(Validity::Number)); 0083 chooseType->addItem(i18n("Integer"), QVariant::fromValue(Validity::Integer)); 0084 chooseType->addItem(i18n("Text"), QVariant::fromValue(Validity::Text)); 0085 chooseType->addItem(i18n("Date"), QVariant::fromValue(Validity::Date)); 0086 chooseType->addItem(i18n("Time"), QVariant::fromValue(Validity::Time)); 0087 chooseType->addItem(i18n("Text Length"), QVariant::fromValue(Validity::TextLength)); 0088 chooseType->addItem(i18n("List"), QVariant::fromValue(Validity::List)); 0089 chooseType->setCurrentIndex(0); 0090 0091 allowEmptyCell = new QCheckBox(i18n("Allow blanks"), page1); 0092 tmpGridLayout->addWidget(allowEmptyCell, 1, 0, 1, 2); 0093 0094 chooseLabel = new QLabel(page1); 0095 chooseLabel->setText(i18n("Data:")); 0096 tmpGridLayout->addWidget(chooseLabel, 2, 0); 0097 0098 choose = new KComboBox(page1); 0099 tmpGridLayout->addWidget(choose, 2, 1); 0100 choose->addItem(i18n("equal to"), QVariant::fromValue(Conditional::Equal)); 0101 choose->addItem(i18n("greater than"), QVariant::fromValue(Conditional::Superior)); 0102 choose->addItem(i18n("less than"), QVariant::fromValue(Conditional::Inferior)); 0103 choose->addItem(i18n("equal to or greater than"), QVariant::fromValue(Conditional::SuperiorEqual)); 0104 choose->addItem(i18n("equal to or less than"), QVariant::fromValue(Conditional::InferiorEqual)); 0105 choose->addItem(i18n("between"), QVariant::fromValue(Conditional::Between)); 0106 choose->addItem(i18n("different from"), QVariant::fromValue(Conditional::Different)); 0107 choose->addItem(i18n("different to"), QVariant::fromValue(Conditional::DifferentTo)); 0108 choose->setCurrentIndex(0); 0109 0110 edit1 = new QLabel(page1); 0111 edit1->setText(i18n("Minimum:")); 0112 tmpGridLayout->addWidget(edit1, 3, 0); 0113 0114 val_min = new KLineEdit(page1); 0115 tmpGridLayout->addWidget(val_min, 3, 1); 0116 val_min->setValidator(new QDoubleValidator(val_min)); 0117 0118 edit2 = new QLabel(page1); 0119 edit2->setText(i18n("Maximum:")); 0120 tmpGridLayout->addWidget(edit2, 4, 0); 0121 0122 val_max = new KLineEdit(page1); 0123 tmpGridLayout->addWidget(val_max, 4, 1); 0124 val_max->setValidator(new QDoubleValidator(val_max)); 0125 0126 //Apply minimum width of column1 to avoid horizontal move when changing option 0127 //A bit ugly to apply text always, but I couldn't get a label->QFontMetrix.boundingRect("text").width() 0128 //to give mew the correct results - Philipp 0129 edit2->setText(i18n("Date:")); 0130 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0131 edit2->setText(i18n("Date minimum:")); 0132 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0133 edit2->setText(i18n("Date maximum:")); 0134 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0135 edit2->setText(i18n("Time:")); 0136 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0137 edit2->setText(i18n("Time minimum:")); 0138 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0139 edit2->setText(i18n("Time maximum:")); 0140 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0141 edit2->setText(i18n("Minimum:")); 0142 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0143 edit2->setText(i18n("Maximum:")); 0144 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0145 edit2->setText(i18n("Number:")); 0146 tmpGridLayout->addItem(new QSpacerItem(edit2->width(), 0), 0, 0); 0147 0148 validityList = new KTextEdit(page1); 0149 tmpGridLayout->addWidget(validityList, 2, 1, 3, 1); 0150 0151 validityLabelList = new QLabel(page1); 0152 validityLabelList->setText(i18n("Entries:")); 0153 tmpGridLayout->addWidget(validityLabelList, 2, 0, Qt::AlignTop); 0154 0155 tmpGridLayout->setRowStretch(5, 1); 0156 0157 QFrame *page2 = new QFrame(); 0158 addPage(page2, i18n("&Error Alert")); 0159 0160 tmpGridLayout = new QGridLayout(page2); 0161 0162 displayMessage = new QCheckBox(i18n("Show error message when invalid values are entered"), page2); 0163 displayMessage->setChecked(true); 0164 tmpGridLayout->addWidget(displayMessage, 0, 0, 1, 2); 0165 0166 tmpQLabel = new QLabel(page2); 0167 tmpQLabel->setText(i18n("Action:")); 0168 tmpGridLayout->addWidget(tmpQLabel, 1, 0); 0169 0170 chooseAction = new KComboBox(page2); 0171 tmpGridLayout->addWidget(chooseAction, 1, 1); 0172 chooseAction->addItem(i18n("Stop"), QVariant::fromValue(Validity::Stop)); 0173 chooseAction->addItem(i18n("Warning"), QVariant::fromValue(Validity::Warning)); 0174 chooseAction->addItem(i18n("Information"), QVariant::fromValue(Validity::Information)); 0175 chooseAction->setCurrentIndex(0); 0176 0177 tmpQLabel = new QLabel(page2); 0178 tmpQLabel->setText(i18nc("Title of message", "Title:")); 0179 tmpGridLayout->addWidget(tmpQLabel, 2, 0); 0180 0181 title = new KLineEdit(page2); 0182 tmpGridLayout->addWidget(title, 2, 1); 0183 0184 tmpQLabel = new QLabel(page2); 0185 tmpQLabel->setText(i18n("Message:")); 0186 tmpGridLayout->addWidget(tmpQLabel, 3, 0, Qt::AlignTop); 0187 0188 message = new KTextEdit(page2); 0189 tmpGridLayout->addWidget(message, 3, 1); 0190 0191 QFrame *page3 = new QFrame(); 0192 addPage(page3, i18n("Input Help")); 0193 0194 tmpGridLayout = new QGridLayout(page3); 0195 0196 displayHelp = new QCheckBox(i18n("Show input help when cell is selected"), page3); 0197 displayMessage->setChecked(false); 0198 tmpGridLayout->addWidget(displayHelp, 0, 0, 1, 2); 0199 0200 tmpQLabel = new QLabel(page3); 0201 tmpQLabel->setText(i18nc("Title of message", "Title:")); 0202 tmpGridLayout->addWidget(tmpQLabel, 1, 0); 0203 0204 titleHelp = new KLineEdit(page3); 0205 tmpGridLayout->addWidget(titleHelp, 1, 1); 0206 0207 tmpQLabel = new QLabel(page3); 0208 tmpQLabel->setText(i18n("Message:")); 0209 tmpGridLayout->addWidget(tmpQLabel, 2, 0, Qt::AlignTop); 0210 0211 messageHelp = new KTextEdit(page3); 0212 tmpGridLayout->addWidget(messageHelp, 2, 1); 0213 0214 connect(choose, SIGNAL(activated(int)), this, SLOT(changeIndexCond(int))); 0215 connect(chooseType, SIGNAL(activated(int)), this, SLOT(changeIndexType(int))); 0216 connect(this, SIGNAL(accepted()), SLOT(OkPressed())); 0217 connect(clearAllButton, SIGNAL(clicked(bool)), SLOT(clearAllPressed())); 0218 0219 init(); 0220 } 0221 0222 void ValidityDialog::displayOrNotListOfValidity(bool _displayList) 0223 { 0224 if (_displayList) { 0225 validityList->show(); 0226 validityLabelList->show(); 0227 chooseLabel->hide(); 0228 choose->hide(); 0229 edit1->hide(); 0230 val_min->hide(); 0231 edit2->hide(); 0232 val_max->hide(); 0233 static_cast<QGridLayout*>(validityList->parentWidget()->layout())->setRowStretch(5, 0); 0234 } else { 0235 validityList->hide(); 0236 validityLabelList->hide(); 0237 chooseLabel->show(); 0238 choose->show(); 0239 edit1->show(); 0240 val_min->show(); 0241 edit2->show(); 0242 val_max->show(); 0243 static_cast<QGridLayout*>(validityList->parentWidget()->layout())->setRowStretch(5, 1); 0244 } 0245 } 0246 0247 void ValidityDialog::changeIndexType(int _index) 0248 { 0249 bool activate = (_index != 0); 0250 allowEmptyCell->setEnabled(activate); 0251 message->setEnabled(activate); 0252 title->setEnabled(activate); 0253 chooseAction->setEnabled(activate); 0254 displayMessage->setEnabled(activate); 0255 displayHelp->setEnabled(activate); 0256 messageHelp->setEnabled(activate); 0257 titleHelp->setEnabled(activate); 0258 if (_index == 7) 0259 displayOrNotListOfValidity(true); 0260 else 0261 displayOrNotListOfValidity(false); 0262 0263 switch (_index) { 0264 case 0: 0265 edit1->setText(""); 0266 edit2->setText(""); 0267 val_max->setEnabled(false); 0268 val_min->setEnabled(false); 0269 choose->setEnabled(false); 0270 break; 0271 case 1: 0272 val_min->setEnabled(true); 0273 choose->setEnabled(true); 0274 val_min->setValidator(new QDoubleValidator(val_min)); 0275 val_max->setValidator(new QDoubleValidator(val_max)); 0276 if (choose->currentIndex() <= 4) { 0277 edit1->setText(i18n("Number:")); 0278 edit2->setText(""); 0279 val_max->setEnabled(false); 0280 } else { 0281 edit1->setText(i18n("Minimum:")); 0282 edit2->setText(i18n("Maximum:")); 0283 val_max->setEnabled(true); 0284 } 0285 break; 0286 case 2: 0287 case 6: 0288 val_min->setEnabled(true); 0289 choose->setEnabled(true); 0290 val_min->setValidator(new QIntValidator(val_min)); 0291 val_max->setValidator(new QIntValidator(val_max)); 0292 if (choose->currentIndex() <= 4) { 0293 edit1->setText(i18n("Number:")); 0294 edit2->setText(""); 0295 val_max->setEnabled(false); 0296 } else { 0297 edit1->setText(i18n("Minimum:")); 0298 edit2->setText(i18n("Maximum:")); 0299 val_max->setEnabled(true); 0300 } 0301 break; 0302 0303 case 3: 0304 edit1->setText(""); 0305 edit2->setText(""); 0306 val_max->setEnabled(false); 0307 val_min->setEnabled(false); 0308 choose->setEnabled(false); 0309 break; 0310 case 4: 0311 edit1->setText(i18n("Date:")); 0312 edit2->setText(""); 0313 val_min->setEnabled(true); 0314 choose->setEnabled(true); 0315 0316 val_min->setValidator(0); 0317 val_max->setValidator(0); 0318 if (choose->currentIndex() <= 4) { 0319 edit1->setText(i18n("Date:")); 0320 edit2->setText(""); 0321 val_max->setEnabled(false); 0322 } else { 0323 edit1->setText(i18n("Date minimum:")); 0324 edit2->setText(i18n("Date maximum:")); 0325 val_max->setEnabled(true); 0326 } 0327 break; 0328 case 5: 0329 val_min->setEnabled(true); 0330 choose->setEnabled(true); 0331 val_min->setValidator(0); 0332 val_max->setValidator(0); 0333 if (choose->currentIndex() <= 4) { 0334 edit1->setText(i18n("Time:")); 0335 edit2->setText(""); 0336 val_max->setEnabled(false); 0337 } else { 0338 edit1->setText(i18n("Time minimum:")); 0339 edit2->setText(i18n("Time maximum:")); 0340 val_max->setEnabled(true); 0341 } 0342 break; 0343 } 0344 if (width() < sizeHint().width()) 0345 resize(sizeHint()); 0346 } 0347 0348 void ValidityDialog::changeIndexCond(int _index) 0349 { 0350 switch (_index) { 0351 case 0: 0352 case 1: 0353 case 2: 0354 case 3: 0355 case 4: 0356 val_max->setEnabled(false); 0357 if (chooseType->currentIndex() == 1 || chooseType->currentIndex() == 2 0358 || chooseType->currentIndex() == 6) 0359 edit1->setText(i18n("Number:")); 0360 else if (chooseType->currentIndex() == 3) 0361 edit1->setText(""); 0362 else if (chooseType->currentIndex() == 4) 0363 edit1->setText(i18n("Date:")); 0364 else if (chooseType->currentIndex() == 5) 0365 edit1->setText(i18n("Time:")); 0366 edit2->setText(""); 0367 break; 0368 case 5: 0369 case 6: 0370 val_max->setEnabled(true); 0371 if (chooseType->currentIndex() == 1 || chooseType->currentIndex() == 2 0372 || chooseType->currentIndex() == 6) { 0373 edit1->setText(i18n("Minimum:")); 0374 edit2->setText(i18n("Maximum:")); 0375 } else if (chooseType->currentIndex() == 3) { 0376 edit1->setText(""); 0377 edit2->setText(""); 0378 } else if (chooseType->currentIndex() == 4) { 0379 edit1->setText(i18n("Date minimum:")); 0380 edit2->setText(i18n("Date maximum:")); 0381 } else if (chooseType->currentIndex() == 5) { 0382 edit1->setText(i18n("Time minimum:")); 0383 edit2->setText(i18n("Time maximum:")); 0384 } 0385 break; 0386 } 0387 } 0388 0389 void ValidityDialog::init() 0390 { 0391 const Map *const map = m_selection->activeSheet()->map(); 0392 const CalculationSettings *settings = map->calculationSettings(); 0393 const KLocale* locale = settings->locale(); 0394 Validity validity = Cell(m_selection->activeSheet(), m_selection->marker()).validity(); 0395 if (!validity.isEmpty()) { 0396 message->setPlainText(validity.message()); 0397 title->setText(validity.title()); 0398 QString tmp; 0399 switch (validity.restriction()) { 0400 case Validity::None: 0401 chooseType->setCurrentIndex(0); 0402 break; 0403 case Validity::Number: 0404 chooseType->setCurrentIndex(1); 0405 if (validity.condition() >= 5) 0406 val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat()))); 0407 val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat()))); 0408 break; 0409 case Validity::Integer: 0410 chooseType->setCurrentIndex(2); 0411 if (validity.condition() >= 5) 0412 val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat()))); 0413 val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat()))); 0414 break; 0415 case Validity::TextLength: 0416 chooseType->setCurrentIndex(6); 0417 if (validity.condition() >= 5) 0418 val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat()))); 0419 val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat()))); 0420 break; 0421 case Validity::Text: 0422 chooseType->setCurrentIndex(3); 0423 break; 0424 case Validity::Date: 0425 chooseType->setCurrentIndex(4); 0426 val_min->setText(locale->formatDate(validity.minimumValue().asDate(settings), KLocale::ShortDate)); 0427 if (validity.condition() >= 5) 0428 val_max->setText(locale->formatDate(validity.maximumValue().asDate(settings), KLocale::ShortDate)); 0429 break; 0430 case Validity::Time: 0431 chooseType->setCurrentIndex(5); 0432 val_min->setText(locale->formatTime(validity.minimumValue().asTime(), true)); 0433 if (validity.condition() >= 5) 0434 val_max->setText(locale->formatTime(validity.maximumValue().asTime(), true)); 0435 break; 0436 case Validity::List: { 0437 chooseType->setCurrentIndex(7); 0438 const QStringList lst = validity.validityList(); 0439 QString tmp; 0440 for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) { 0441 tmp += (*it) + '\n'; 0442 } 0443 validityList->setText(tmp); 0444 } 0445 break; 0446 default : 0447 chooseType->setCurrentIndex(0); 0448 break; 0449 } 0450 chooseAction->setCurrentIndex(chooseAction->findData(QVariant::fromValue(validity.action()))); 0451 choose->setCurrentIndex(choose->findData(QVariant::fromValue(validity.condition()))); 0452 displayMessage->setChecked(validity.displayMessage()); 0453 allowEmptyCell->setChecked(validity.allowEmptyCell()); 0454 titleHelp->setText(validity.titleInfo()); 0455 messageHelp->setPlainText(validity.messageInfo()); 0456 displayHelp->setChecked(validity.displayValidationInformation()); 0457 } 0458 changeIndexType(chooseType->currentIndex()) ; 0459 changeIndexCond(choose->currentIndex()) ; 0460 } 0461 0462 void ValidityDialog::clearAllPressed() 0463 { 0464 val_min->setText(""); 0465 val_max->setText(""); 0466 message->setPlainText(""); 0467 title->setText(""); 0468 displayMessage->setChecked(true); 0469 allowEmptyCell->setChecked(false); 0470 choose->setCurrentIndex(0); 0471 chooseType->setCurrentIndex(0); 0472 chooseAction->setCurrentIndex(0); 0473 changeIndexType(0); 0474 changeIndexCond(0); 0475 messageHelp->setPlainText(""); 0476 titleHelp->setText(""); 0477 validityList->setText(""); 0478 displayHelp->setChecked(false); 0479 } 0480 0481 void ValidityDialog::OkPressed() 0482 { 0483 const KLocale* locale = m_selection->activeSheet()->map()->calculationSettings()->locale(); 0484 const ValueParser *const parser = m_selection->activeSheet()->map()->parser(); 0485 Validity validity; 0486 if (chooseType->currentIndex() == 1) { 0487 bool ok; 0488 val_min->text().toDouble(&ok); 0489 if (! ok) { 0490 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error")); 0491 val_min->setText(""); 0492 return; 0493 } 0494 val_max->text().toDouble(&ok); 0495 if (! ok && choose->currentIndex() >= 5 && choose->currentIndex() < 7) { 0496 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error")); 0497 val_max->setText(""); 0498 return; 0499 } 0500 } else if (chooseType->currentIndex() == 2 || chooseType->currentIndex() == 6) { 0501 bool ok; 0502 val_min->text().toInt(&ok); 0503 if (! ok) { 0504 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error")); 0505 val_min->setText(""); 0506 return; 0507 } 0508 val_max->text().toInt(&ok); 0509 if (! ok && choose->currentIndex() >= 5 && choose->currentIndex() < 7) { 0510 KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error")); 0511 val_max->setText(""); 0512 return; 0513 } 0514 } else if (chooseType->currentIndex() == 5) { 0515 if (!locale->readTime(val_min->text()).isValid()) { 0516 KMessageBox::error(this , i18n("This is not a valid time."), i18n("Error")); 0517 val_min->setText(""); 0518 return; 0519 } 0520 if (!locale->readTime(val_max->text()).isValid() && choose->currentIndex() >= 5) { 0521 KMessageBox::error(this , i18n("This is not a valid time."), i18n("Error")); 0522 val_max->setText(""); 0523 return; 0524 } 0525 } else if (chooseType->currentIndex() == 4) { 0526 if (!locale->readDate(val_min->text()).isValid()) { 0527 KMessageBox::error(this , i18n("This is not a valid date."), i18n("Error")); 0528 val_min->setText(""); 0529 return; 0530 } 0531 if (!locale->readDate(val_max->text()).isValid() && choose->currentIndex() >= 5) { 0532 KMessageBox::error(this , i18n("This is not a valid date."), i18n("Error")); 0533 val_max->setText(""); 0534 return; 0535 } 0536 } else if (chooseType->currentIndex() == 7) { 0537 //Nothing 0538 } 0539 0540 if (chooseType->currentIndex() == 0) {//no validity 0541 validity.setRestriction(Validity::None); 0542 validity.setAction(Validity::Stop); 0543 validity.setCondition(Conditional::Equal); 0544 validity.setMessage(message->toPlainText()); 0545 validity.setTitle(title->text()); 0546 validity.setMinimumValue(Value()); 0547 validity.setMaximumValue(Value()); 0548 } else { 0549 validity.setRestriction(chooseType->itemData(chooseType->currentIndex()).value<Validity::Restriction>()); 0550 validity.setAction(chooseAction->itemData(chooseAction->currentIndex()).value<Validity::Action>()); 0551 validity.setCondition(choose->itemData(choose->currentIndex()).value<Conditional::Type>()); 0552 validity.setMessage(message->toPlainText()); 0553 validity.setTitle(title->text()); 0554 validity.setMinimumValue(Value()); 0555 validity.setMaximumValue(Value()); 0556 0557 if (chooseType->currentIndex() == 1) { 0558 if (choose->currentIndex() < 5) { 0559 validity.setMinimumValue(Value(val_min->text().toDouble())); 0560 } else { 0561 validity.setMinimumValue(Value(qMin(val_min->text().toDouble(), val_max->text().toDouble()))); 0562 validity.setMaximumValue(Value(qMax(val_max->text().toDouble(), val_min->text().toDouble()))); 0563 } 0564 } else if (chooseType->currentIndex() == 2 || chooseType->currentIndex() == 6) { 0565 if (choose->currentIndex() < 5) { 0566 validity.setMinimumValue(Value(val_min->text().toInt())); 0567 } else { 0568 validity.setMinimumValue(Value(qMin(val_min->text().toInt(), val_max->text().toInt()))); 0569 validity.setMaximumValue(Value(qMax(val_max->text().toInt(), val_min->text().toInt()))); 0570 } 0571 } else if (chooseType->currentIndex() == 4) { 0572 const Value minValue = parser->tryParseDate(val_min->text()); 0573 const Value maxValue = parser->tryParseDate(val_max->text()); 0574 if (choose->currentIndex() < 5) { 0575 validity.setMinimumValue(minValue); 0576 } else { 0577 if (minValue.less(maxValue)) { 0578 validity.setMinimumValue(minValue); 0579 validity.setMaximumValue(maxValue); 0580 } else { 0581 validity.setMinimumValue(maxValue); 0582 validity.setMaximumValue(minValue); 0583 } 0584 } 0585 } else if (chooseType->currentIndex() == 5) { 0586 const Value minValue = parser->tryParseTime(val_min->text()); 0587 const Value maxValue = parser->tryParseTime(val_max->text()); 0588 if (choose->currentIndex() < 5) { 0589 validity.setMinimumValue(minValue); 0590 } else { 0591 if (minValue.less(maxValue)) { 0592 validity.setMaximumValue(maxValue); 0593 validity.setMinimumValue(minValue); 0594 } else { 0595 validity.setMaximumValue(minValue); 0596 validity.setMinimumValue(maxValue); 0597 } 0598 } 0599 } else if (chooseType->currentIndex() == 7) { 0600 validity.setValidityList(validityList->toPlainText().split('\n', QString::SkipEmptyParts)); 0601 } 0602 } 0603 validity.setDisplayMessage(displayMessage->isChecked()); 0604 validity.setAllowEmptyCell(allowEmptyCell->isChecked()); 0605 validity.setDisplayValidationInformation(displayHelp->isChecked()); 0606 validity.setMessageInfo(messageHelp->toPlainText()); 0607 validity.setTitleInfo(titleHelp->text()); 0608 0609 ValidityCommand* manipulator = new ValidityCommand(); 0610 manipulator->setSheet(m_selection->activeSheet()); 0611 manipulator->setValidity(validity); 0612 manipulator->add(*m_selection); 0613 manipulator->execute(m_selection->canvas()); 0614 0615 accept(); 0616 }