kspread

kspread_dlg_validity.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
00003              (C) 2002 John Dailey <dailey@vt.edu>
00004              (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
00005              (C) 1999-2005 Laurent Montel <montel@kde.org>
00006              (C) 1998-1999 Torben Weis <weis@kde.org>
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 
00024 #include "kspread_dlg_validity.h"
00025 #include "kspread_canvas.h"
00026 #include "kspread_doc.h"
00027 #include "kspread_locale.h"
00028 #include "kspread_sheet.h"
00029 #include "kspread_view.h"
00030 
00031 #include <qlayout.h>
00032 #include <qbuttongroup.h>
00033 #include <knumvalidator.h>
00034 #include <kdebug.h>
00035 #include <kmessagebox.h>
00036 
00037 #include <qcombobox.h>
00038 #include <qlineedit.h>
00039 #include <qpushbutton.h>
00040 #include <qlabel.h>
00041 #include <qtextedit.h>
00042 #include <qcheckbox.h>
00043 
00044 using namespace KSpread;
00045 
00046 DlgValidity::DlgValidity(View* parent,const char* name , const QRect &_marker )
00047   :KDialogBase(KDialogBase::Tabbed, i18n("Validity"),User2|User1|Cancel, User1, parent, name,true,false,KStdGuiItem::ok(),i18n("Clear &All"))
00048 
00049 {
00050   m_pView=parent;
00051   marker=_marker;
00052   QFrame *page1 = addPage(i18n("&Values"));
00053   QVBoxLayout *lay1 = new QVBoxLayout( page1, KDialogBase::marginHint(), KDialogBase::spacingHint() );
00054 
00055   QGroupBox* tmpQButtonGroup;
00056   tmpQButtonGroup = new QGroupBox( 0, Qt::Vertical, i18n("Validity Criteria"), page1, "ButtonGroup_1" );
00057   tmpQButtonGroup->layout()->setSpacing(KDialog::spacingHint());
00058   tmpQButtonGroup->layout()->setMargin(KDialog::marginHint());
00059   QGridLayout *grid1 = new QGridLayout(tmpQButtonGroup->layout(),4,2);
00060 
00061   QLabel *tmpQLabel = new QLabel( tmpQButtonGroup, "Label_1" );
00062   tmpQLabel->setText(i18n("Allow:" ));
00063   grid1->addWidget(tmpQLabel,0,0);
00064 
00065   chooseType=new QComboBox(tmpQButtonGroup);
00066   grid1->addWidget(chooseType,0,1);
00067   QStringList listType;
00068   listType+=i18n("All");
00069   listType+=i18n("Number");
00070   listType+=i18n("Integer");
00071   listType+=i18n("Text");
00072   listType+=i18n("Date");
00073   listType+=i18n("Time");
00074   listType+=i18n("Text Length");
00075   listType+=i18n("List");
00076   chooseType->insertStringList(listType);
00077   chooseType->setCurrentItem(0);
00078 
00079   allowEmptyCell = new QCheckBox( i18n( "Allow blanks" ), tmpQButtonGroup );
00080   grid1->addWidget(allowEmptyCell,1,0);
00081 
00082   tmpQLabel = new QLabel( tmpQButtonGroup, "Label_2" );
00083   tmpQLabel->setText(i18n("Data:" ));
00084   grid1->addWidget(tmpQLabel,2,0);
00085 
00086   choose=new QComboBox(tmpQButtonGroup);
00087   grid1->addWidget(choose,2,1);
00088   QStringList list;
00089   list+=i18n("equal to");
00090   list+=i18n("greater than");
00091   list+=i18n("less than");
00092   list+=i18n("equal to or greater than");
00093   list+=i18n("equal to or less than");
00094   list+=i18n("between");
00095   list+=i18n("different from");
00096   list+=i18n("different to");
00097   choose->insertStringList(list);
00098   choose->setCurrentItem(0);
00099 
00100   edit1 = new QLabel( tmpQButtonGroup, "Label_3" );
00101   edit1->setText(i18n("Minimum:" ));
00102   grid1->addWidget(edit1,3,0);
00103 
00104   val_min=new QLineEdit(tmpQButtonGroup);
00105   grid1->addWidget(val_min,3,1);
00106   val_min->setValidator( new KFloatValidator( val_min ) );
00107 
00108   edit2 = new QLabel( tmpQButtonGroup, "Label_4" );
00109   edit2->setText(i18n("Maximum:" ));
00110   grid1->addWidget(edit2,4,0);
00111 
00112   val_max=new QLineEdit(tmpQButtonGroup);
00113   grid1->addWidget(val_max,4,1);
00114   val_max->setValidator( new KFloatValidator( val_max ) );
00115   lay1->addWidget(tmpQButtonGroup);
00116 
00117   //Apply minimum width of column1 to avoid horizontal move when changing option
00118   //A bit ugly to apply text always, but I couldn't get a label->QFontMetrix.boundingRect("text").width()
00119   //to give mew the correct results - Philipp
00120   edit2->setText( i18n( "Date:" ) );
00121   grid1->addColSpacing( 0, edit2->width() );
00122   edit2->setText( i18n( "Date minimum:" ) );
00123   grid1->addColSpacing( 0, edit2->width() );
00124   edit2->setText( i18n( "Date maximum:" ) );
00125   grid1->addColSpacing( 0, edit2->width() );
00126   edit2->setText( i18n( "Time:" ) );
00127   grid1->addColSpacing( 0, edit2->width() );
00128   edit2->setText( i18n( "Time minimum:" ) );
00129   grid1->addColSpacing( 0, edit2->width() );
00130   edit2->setText( i18n( "Time maximum:" ) );
00131   grid1->addColSpacing( 0, edit2->width() );
00132   edit2->setText( i18n( "Minimum:" ) );
00133   grid1->addColSpacing( 0, edit2->width() );
00134   edit2->setText( i18n( "Maximum:" ) );
00135   grid1->addColSpacing( 0, edit2->width() );
00136   edit2->setText( i18n( "Number:" ) );
00137   grid1->addColSpacing( 0, edit2->width() );
00138 
00139   validityList = new QTextEdit( tmpQButtonGroup );
00140   grid1->addMultiCellWidget(validityList,2, 4,1, 1);
00141 
00142   validityLabelList = new QLabel( tmpQButtonGroup, "Label_Label_List" );
00143   validityLabelList->setText(i18n("Entries:" ));
00144   grid1->addWidget(validityLabelList,2,0);
00145 
00146   QFrame *page2 = addPage(i18n("&Error Alert"));
00147 
00148   lay1 = new QVBoxLayout( page2, KDialogBase::marginHint(), KDialogBase::spacingHint() );
00149 
00150   tmpQButtonGroup = new QButtonGroup( 0, Qt::Vertical, i18n("Contents"), page2, "ButtonGroup_2" );
00151   tmpQButtonGroup->layout()->setSpacing(KDialog::spacingHint());
00152   tmpQButtonGroup->layout()->setMargin(KDialog::marginHint());
00153   QGridLayout *grid2 = new QGridLayout(tmpQButtonGroup->layout(),5,2);
00154 
00155   displayMessage = new QCheckBox(i18n( "Show error message when invalid values are entered" ),tmpQButtonGroup );
00156   displayMessage->setChecked( true );
00157   grid2->addMultiCellWidget(displayMessage,0, 0,0, 1);
00158 
00159   tmpQLabel = new QLabel( tmpQButtonGroup, "Label_5" );
00160   tmpQLabel->setText(i18n("Action:" ));
00161   grid2->addWidget(tmpQLabel,1,0);
00162 
00163   chooseAction=new QComboBox(tmpQButtonGroup);
00164   grid2->addWidget(chooseAction,1,1);
00165   QStringList list2;
00166   list2+=i18n("Stop");
00167   list2+=i18n("Warning");
00168   list2+=i18n("Information");
00169   chooseAction->insertStringList(list2);
00170   chooseAction->setCurrentItem(0);
00171   tmpQLabel = new QLabel( tmpQButtonGroup, "Label_6" );
00172   tmpQLabel->setText(i18n("Title:" ));
00173   grid2->addWidget(tmpQLabel,2,0);
00174 
00175   title=new QLineEdit(  tmpQButtonGroup);
00176   grid2->addWidget(title,2,1);
00177 
00178   tmpQLabel = new QLabel( tmpQButtonGroup, "Label_7" );
00179   tmpQLabel->setText(i18n("Message:" ));
00180   grid2->addWidget(tmpQLabel,3,0);
00181 
00182   message =new QTextEdit( tmpQButtonGroup);
00183   grid2->addMultiCellWidget(message,3, 4,1, 1);
00184   lay1->addWidget(tmpQButtonGroup);
00185   message->setTextFormat( Qt::PlainText );
00186 
00187   QFrame *page3 = addPage(i18n("Input Help"));
00188   lay1 = new QVBoxLayout( page3, KDialogBase::marginHint(), KDialogBase::spacingHint() );
00189 
00190   tmpQButtonGroup = new QButtonGroup( 0, Qt::Vertical, i18n("Contents"), page3, "ButtonGroup_2" );
00191   tmpQButtonGroup->layout()->setSpacing(KDialog::spacingHint());
00192   tmpQButtonGroup->layout()->setMargin(KDialog::marginHint());
00193 
00194   QGridLayout *grid3 = new QGridLayout(tmpQButtonGroup->layout(),5,2);
00195 
00196   displayHelp = new QCheckBox(i18n( "Show input help when cell is selected" ),tmpQButtonGroup );
00197   displayMessage->setChecked( false );
00198   grid3->addMultiCellWidget(displayHelp,0, 0,0, 1);
00199 
00200   tmpQLabel = new QLabel( tmpQButtonGroup, "Label_6" );
00201   tmpQLabel->setText(i18n("Title:" ));
00202   grid3->addWidget(tmpQLabel,2,0);
00203 
00204   titleHelp=new QLineEdit(  tmpQButtonGroup);
00205   grid3->addWidget(titleHelp,2,1);
00206 
00207   tmpQLabel = new QLabel( tmpQButtonGroup, "Label_7" );
00208   tmpQLabel->setText(i18n("Message:" ));
00209   grid3->addWidget(tmpQLabel,3,0);
00210 
00211   messageHelp =new QTextEdit( tmpQButtonGroup);
00212   grid3->addMultiCellWidget(messageHelp,3, 4,1, 1);
00213   lay1->addWidget(tmpQButtonGroup);
00214   messageHelp->setTextFormat( Qt::PlainText );
00215 
00216 
00217   connect(choose,SIGNAL(activated(int )),this,SLOT(changeIndexCond(int)));
00218   connect(chooseType,SIGNAL(activated(int )),this,SLOT(changeIndexType(int)));
00219   connect( this, SIGNAL(user1Clicked()), SLOT(OkPressed()) );
00220   connect( this, SIGNAL(user2Clicked()), SLOT(clearAllPressed()) );
00221   init();
00222 }
00223 
00224 void DlgValidity::displayOrNotListOfValidity( bool _displayList)
00225 {
00226     if ( _displayList )
00227     {
00228         validityList->show();
00229         validityLabelList->show();
00230         edit1->hide();
00231         val_min->hide();
00232         edit2->hide();
00233         val_max->hide();
00234     }
00235     else
00236     {
00237         validityList->hide();
00238         validityLabelList->hide();
00239         edit1->show();
00240         val_min->show();
00241         edit2->show();
00242         val_max->show();
00243     }
00244 }
00245 
00246 void DlgValidity::changeIndexType(int _index)
00247 {
00248     bool activate = ( _index!=0 );
00249     message->setEnabled(activate);
00250     title->setEnabled(activate);
00251     chooseAction->setEnabled( activate );
00252     displayHelp->setEnabled(activate);
00253     messageHelp->setEnabled(activate);
00254     titleHelp->setEnabled(activate);
00255     if ( _index == 7 )
00256         displayOrNotListOfValidity( true );
00257     else
00258         displayOrNotListOfValidity( false );
00259 
00260     switch(_index)
00261     {
00262     case 0:
00263         edit1->setText("");
00264         edit2->setText("");
00265         val_max->setEnabled(false);
00266         val_min->setEnabled(false);
00267         edit1->setEnabled(false);
00268         edit2->setEnabled(false);
00269         choose->setEnabled(false);
00270         break;
00271     case 1:
00272         val_min->setEnabled(true);
00273         edit1->setEnabled(true);
00274         choose->setEnabled(true);
00275         val_min->setValidator( new KFloatValidator( val_min ) );
00276         val_max->setValidator( new KFloatValidator( val_max ) );
00277         if( choose->currentItem()<=4)
00278         {
00279             edit1->setText(i18n("Number:"));
00280             edit2->setText("");
00281             edit2->setEnabled(false);
00282             val_max->setEnabled(false);
00283         }
00284         else
00285         {
00286             edit1->setText(i18n("Minimum:" ));
00287             edit2->setText(i18n("Maximum:" ));
00288             edit2->setEnabled(true);
00289             val_max->setEnabled(true);
00290         }
00291         break;
00292     case 2:
00293     case 6:
00294         val_min->setEnabled(true);
00295         edit1->setEnabled(true);
00296         choose->setEnabled(true);
00297         val_min->setValidator( new KIntValidator( val_min ) );
00298         val_max->setValidator( new KIntValidator( val_max ) );
00299         if( choose->currentItem()<=4)
00300         {
00301             edit1->setText(i18n("Number:"));
00302             edit2->setText("");
00303             edit2->setEnabled(false);
00304             val_max->setEnabled(false);
00305         }
00306         else
00307         {
00308             edit1->setText(i18n("Minimum:" ));
00309             edit2->setText(i18n("Maximum:" ));
00310             edit2->setEnabled(true);
00311             val_max->setEnabled(true);
00312         }
00313         break;
00314 
00315     case 3:
00316         edit1->setText("");
00317         edit2->setText("");
00318         val_max->setEnabled(false);
00319         val_min->setEnabled(false);
00320         choose->setEnabled(false);
00321         edit1->setEnabled(false);
00322         edit2->setEnabled(false);
00323         break;
00324     case 4:
00325         edit1->setText(i18n("Date:"));
00326         edit2->setText("");
00327         val_min->setEnabled(true);
00328         edit1->setEnabled(true);
00329         choose->setEnabled(true);
00330 
00331         val_min->clearValidator();
00332         val_max->clearValidator();
00333         if( choose->currentItem()<=4)
00334         {
00335             edit1->setText(i18n("Date:"));
00336             edit2->setText("");
00337             edit2->setEnabled(false);
00338             val_max->setEnabled(false);
00339         }
00340         else
00341         {
00342             edit1->setText(i18n("Date minimum:"));
00343             edit2->setText(i18n("Date maximum:"));
00344             edit2->setEnabled(true);
00345             val_max->setEnabled(true);
00346         }
00347         break;
00348     case 5:
00349         val_min->setEnabled(true);
00350         edit1->setEnabled(true);
00351         choose->setEnabled(true);
00352         val_min->clearValidator();
00353         val_max->clearValidator();
00354         if( choose->currentItem()<=4)
00355         {
00356             edit1->setText(i18n("Time:"));
00357             edit2->setText("");
00358             edit2->setEnabled(false);
00359             val_max->setEnabled(false);
00360         }
00361         else
00362         {
00363             edit1->setText(i18n("Time minimum:"));
00364             edit2->setText(i18n("Time maximum:"));
00365             edit2->setEnabled(true);
00366             val_max->setEnabled(true);
00367         }
00368         break;
00369     }
00370     if ( width() < sizeHint().width() )
00371         resize( sizeHint() );
00372 }
00373 
00374 void DlgValidity::changeIndexCond(int _index)
00375 {
00376   switch(_index)
00377   {
00378    case 0:
00379    case 1:
00380    case 2:
00381    case 3:
00382    case 4:
00383     val_max->setEnabled(false);
00384     if(chooseType->currentItem()==1 ||chooseType->currentItem()==2
00385        ||chooseType->currentItem()==6)
00386       edit1->setText(i18n("Number:"));
00387     else if( chooseType->currentItem()==3)
00388       edit1->setText("");
00389     else if( chooseType->currentItem()==4)
00390       edit1->setText(i18n("Date:"));
00391     else if( chooseType->currentItem()==5)
00392       edit1->setText(i18n("Time:"));
00393     edit2->setText("");
00394     edit2->setEnabled(false);
00395     break;
00396    case 5:
00397    case 6:
00398     val_max->setEnabled(true);
00399     edit2->setEnabled(true);
00400     edit1->setEnabled(true);
00401     if(chooseType->currentItem()==1 || chooseType->currentItem()==2
00402        || chooseType->currentItem()==6)
00403     {
00404       edit1->setText(i18n("Minimum:" ));
00405       edit2->setText(i18n("Maximum:" ));
00406     }
00407     else if(chooseType->currentItem()==3)
00408     {
00409       edit1->setText("");
00410       edit2->setText("");
00411     }
00412     else if(chooseType->currentItem()==4)
00413     {
00414       edit1->setText(i18n("Date minimum:"));
00415       edit2->setText(i18n("Date maximum:"));
00416     }
00417     else if(chooseType->currentItem()==5)
00418     {
00419       edit1->setText(i18n("Time minimum:"));
00420       edit2->setText(i18n("Time maximum:"));
00421     }
00422     break;
00423   }
00424 }
00425 
00426 void DlgValidity::init()
00427 {
00428   Cell *c = m_pView->activeSheet()->cellAt( marker.left(), marker.top() );
00429   Validity * tmpValidity=c->getValidity(0);
00430   if(tmpValidity!=0)
00431   {
00432     message->setText(tmpValidity->message);
00433     title->setText(tmpValidity->title);
00434     QString tmp;
00435     switch( tmpValidity->m_restriction)
00436     {
00437      case Restriction::None:
00438       chooseType->setCurrentItem(0);
00439       break;
00440      case Restriction::Number:
00441       chooseType->setCurrentItem(1);
00442       if(tmpValidity->m_cond >=5 )
00443         val_max->setText(tmp.setNum(tmpValidity->valMax));
00444       val_min->setText(tmp.setNum(tmpValidity->valMin));
00445       break;
00446      case Restriction::Integer:
00447       chooseType->setCurrentItem(2);
00448       if(tmpValidity->m_cond >=5 )
00449         val_max->setText(tmp.setNum(tmpValidity->valMax));
00450       val_min->setText(tmp.setNum(tmpValidity->valMin));
00451       break;
00452      case Restriction::TextLength:
00453       chooseType->setCurrentItem(6);
00454       if(tmpValidity->m_cond >=5 )
00455         val_max->setText(tmp.setNum(tmpValidity->valMax));
00456       val_min->setText(tmp.setNum(tmpValidity->valMin));
00457       break;
00458      case Restriction::Text:
00459       chooseType->setCurrentItem(3);
00460       break;
00461      case Restriction::Date:
00462       chooseType->setCurrentItem(4);
00463       val_min->setText(m_pView->doc()->locale()->formatDate(tmpValidity->dateMin,true));
00464       if(tmpValidity->m_cond >=5 )
00465         val_max->setText(m_pView->doc()->locale()->formatDate(tmpValidity->dateMax,true));
00466       break;
00467      case Restriction::Time:
00468       chooseType->setCurrentItem(5);
00469       val_min->setText(m_pView->doc()->locale()->formatTime(tmpValidity->timeMin,true));
00470       if(tmpValidity->m_cond >=5 )
00471         val_max->setText(m_pView->doc()->locale()->formatTime(tmpValidity->timeMax,true));
00472       break;
00473      case Restriction::List:
00474      {
00475          chooseType->setCurrentItem(7);
00476          QStringList lst =tmpValidity->listValidity;
00477          QString tmp;
00478          for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
00479              tmp +=( *it )+"\n";
00480          }
00481          validityList->setText( tmp );
00482      }
00483       break;
00484      default :
00485       chooseType->setCurrentItem(0);
00486       break;
00487     }
00488     switch (tmpValidity->m_action)
00489     {
00490       case Action::Stop:
00491       chooseAction->setCurrentItem(0);
00492       break;
00493       case Action::Warning:
00494       chooseAction->setCurrentItem(1);
00495       break;
00496       case Action::Information:
00497       chooseAction->setCurrentItem(2);
00498       break;
00499      default :
00500       chooseAction->setCurrentItem(0);
00501       break;
00502     }
00503     switch ( tmpValidity->m_cond )
00504     {
00505       case Conditional::Equal:
00506       choose->setCurrentItem(0);
00507       break;
00508       case Conditional::Superior:
00509       choose->setCurrentItem(1);
00510       break;
00511       case Conditional::Inferior:
00512       choose->setCurrentItem(2);
00513       break;
00514       case Conditional::SuperiorEqual:
00515       choose->setCurrentItem(3);
00516       break;
00517       case Conditional::InferiorEqual:
00518       choose->setCurrentItem(4);
00519       break;
00520       case Conditional::Between:
00521       choose->setCurrentItem(5);
00522       break;
00523       case Conditional::Different:
00524       choose->setCurrentItem(6);
00525       break;
00526       case Conditional::DifferentTo:
00527       choose->setCurrentItem(7);
00528       break;
00529      default :
00530       choose->setCurrentItem(0);
00531       break;
00532     }
00533     displayMessage->setChecked( tmpValidity->displayMessage );
00534     allowEmptyCell->setChecked( tmpValidity->allowEmptyCell );
00535     titleHelp->setText( tmpValidity->titleInfo );
00536     messageHelp->setText( tmpValidity->messageInfo );
00537     displayHelp->setChecked( tmpValidity->displayValidationInformation );
00538   }
00539   changeIndexType(chooseType->currentItem()) ;
00540   changeIndexCond(choose->currentItem()) ;
00541 }
00542 
00543 void DlgValidity::clearAllPressed()
00544 {
00545   val_min->setText("");
00546   val_max->setText("");
00547   message->setText("");
00548   title->setText("");
00549   displayMessage->setChecked( true );
00550   allowEmptyCell->setChecked( false );
00551   choose->setCurrentItem(0);
00552   chooseType->setCurrentItem(0);
00553   chooseAction->setCurrentItem(0);
00554   changeIndexType(0);
00555   changeIndexCond(0);
00556   messageHelp->setText("" );
00557   titleHelp->setText( "" );
00558   validityList->setText( "" );
00559   displayHelp->setChecked( false );
00560 }
00561 
00562 void DlgValidity::OkPressed()
00563 {
00564   if( chooseType->currentItem()==1)
00565   {
00566     bool ok;
00567     val_min->text().toDouble(&ok);
00568     if(! ok)
00569     {
00570       KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
00571       val_min->setText("");
00572       return;
00573     }
00574     val_max->text().toDouble(&ok);
00575     if(! ok && choose->currentItem() >=5 && choose->currentItem()< 7)
00576     {
00577       KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
00578       val_max->setText("");
00579       return;
00580     }
00581   }
00582   else if( chooseType->currentItem()==2 || chooseType->currentItem()==6)
00583   {
00584     bool ok;
00585     val_min->text().toInt(&ok);
00586     if(! ok)
00587     {
00588       KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
00589       val_min->setText("");
00590       return;
00591     }
00592     val_max->text().toInt(&ok);
00593     if(! ok && choose->currentItem() >=5 && choose->currentItem()< 7)
00594     {
00595       KMessageBox::error( this , i18n("This is not a valid value."),i18n("Error"));
00596       val_max->setText("");
00597       return;
00598     }
00599   }
00600   else  if(  chooseType->currentItem()==5)
00601   {
00602     if(! m_pView->doc()->locale()->readTime(val_min->text()).isValid())
00603     {
00604       KMessageBox::error( this , i18n("This is not a valid time."),i18n("Error"));
00605       val_min->setText("");
00606       return;
00607     }
00608     if(! m_pView->doc()->locale()->readTime(val_max->text()).isValid() && choose->currentItem()  >=5)
00609     {
00610       KMessageBox::error( this , i18n("This is not a valid time."),i18n("Error"));
00611       val_max->setText("");
00612       return;
00613     }
00614   }
00615   else  if(  chooseType->currentItem()==4)
00616   {
00617     if(! m_pView->doc()->locale()->readDate(val_min->text()).isValid())
00618     {
00619       KMessageBox::error( this , i18n("This is not a valid date."),i18n("Error"));
00620       val_min->setText("");
00621       return;
00622     }
00623     if(! m_pView->doc()->locale()->readDate(val_max->text()).isValid() && choose->currentItem()  >=5 )
00624     {
00625       KMessageBox::error( this , i18n("This is not a valid date."),i18n("Error"));
00626       val_max->setText("");
00627       return;
00628     }
00629   }
00630   else if ( chooseType->currentItem()==7 )
00631   {
00632       //Nothing
00633   }
00634 
00635   if( chooseType->currentItem()==0)
00636   {//no validity
00637     result.m_restriction=Restriction::None;
00638     result.m_action=Action::Stop;
00639     result.m_cond=Conditional::Equal;
00640     result.message=message->text();
00641     result.title=title->text();
00642     result.valMin=0;
00643     result.valMax=0;
00644     result.timeMin=QTime(0,0,0);
00645     result.timeMax=QTime(0,0,0);
00646     result.dateMin=QDate(0,0,0);
00647     result.dateMax=QDate(0,0,0);
00648   }
00649   else
00650   {
00651     switch( chooseType->currentItem())
00652     {
00653      case 0:
00654       result.m_restriction=Restriction::None;
00655       break;
00656      case 1:
00657       result.m_restriction=Restriction::Number;
00658       break;
00659      case 2:
00660       result.m_restriction=Restriction::Integer;
00661       break;
00662      case 3:
00663       result.m_restriction=Restriction::Text;
00664       break;
00665      case 4:
00666       result.m_restriction=Restriction::Date;
00667       break;
00668      case 5:
00669       result.m_restriction=Restriction::Time;
00670       break;
00671      case 6:
00672       result.m_restriction=Restriction::TextLength;
00673       break;
00674      case 7:
00675       result.m_restriction=Restriction::List;
00676       break;
00677 
00678      default :
00679       break;
00680     }
00681     switch (chooseAction->currentItem())
00682     {
00683      case 0:
00684        result.m_action=Action::Stop;
00685       break;
00686      case 1:
00687        result.m_action=Action::Warning;
00688       break;
00689      case 2:
00690        result.m_action=Action::Information;
00691       break;
00692      default :
00693       break;
00694     }
00695     switch ( choose->currentItem())
00696     {
00697      case 0:
00698        result.m_cond=Conditional::Equal;
00699       break;
00700      case 1:
00701        result.m_cond=Conditional::Superior;
00702       break;
00703      case 2:
00704        result.m_cond=Conditional::Inferior;
00705       break;
00706      case 3:
00707        result.m_cond=Conditional::SuperiorEqual;
00708       break;
00709      case 4:
00710        result.m_cond=Conditional::InferiorEqual;
00711       break;
00712      case 5:
00713        result.m_cond=Conditional::Between;
00714       break;
00715      case 6:
00716        result.m_cond=Conditional::Different;
00717       break;
00718      case 7:
00719        result.m_cond=Conditional::DifferentTo;
00720       break;
00721      default :
00722       break;
00723     }
00724     result.message=message->text();
00725     result.title=title->text();
00726     result.valMin=0;
00727     result.valMax=0;
00728     result.timeMin=QTime(0,0,0);
00729     result.timeMax=QTime(0,0,0);
00730     result.dateMin=QDate(0,0,0);
00731     result.dateMax=QDate(0,0,0);
00732 
00733     if( chooseType->currentItem()==1)
00734     {
00735       if(choose->currentItem()  <5)
00736       {
00737         result.valMin=val_min->text().toDouble();
00738       }
00739       else
00740       {
00741         result.valMin=QMIN(val_min->text().toDouble(),val_max->text().toDouble());
00742         result.valMax=QMAX(val_max->text().toDouble(),val_min->text().toDouble());
00743       }
00744     }
00745     else if( chooseType->currentItem()==2 || chooseType->currentItem()==6)
00746     {
00747       if(choose->currentItem()  <5)
00748       {
00749         result.valMin=val_min->text().toInt();
00750       }
00751       else
00752       {
00753         result.valMin=QMIN(val_min->text().toInt(),val_max->text().toInt());
00754         result.valMax=QMAX(val_max->text().toInt(),val_min->text().toInt());
00755       }
00756     }
00757     else  if(  chooseType->currentItem()==4)
00758     {
00759       if(choose->currentItem()  <5)
00760       {
00761         result.dateMin=m_pView->doc()->locale()->readDate(val_min->text());
00762       }
00763       else
00764       {
00765         if(m_pView->doc()->locale()->readDate(val_min->text())<m_pView->doc()->locale()->readDate(val_max->text()))
00766         {
00767           result.dateMin=m_pView->doc()->locale()->readDate(val_min->text());
00768           result.dateMax=m_pView->doc()->locale()->readDate(val_max->text());
00769         }
00770         else
00771         {
00772           result.dateMin=m_pView->doc()->locale()->readDate(val_max->text());
00773           result.dateMax=m_pView->doc()->locale()->readDate(val_min->text());
00774         }
00775       }
00776     }
00777     else  if(  chooseType->currentItem()==5)
00778     {
00779       if(choose->currentItem()  <5)
00780       {
00781         result.timeMin=m_pView->doc()->locale()->readTime(val_min->text());
00782       }
00783       else
00784       {
00785         if(m_pView->doc()->locale()->readTime(val_min->text())<m_pView->doc()->locale()->readTime(val_max->text()))
00786         {
00787           result.timeMax=m_pView->doc()->locale()->readTime(val_max->text());
00788           result.timeMin=m_pView->doc()->locale()->readTime(val_min->text());
00789         }
00790         else
00791         {
00792           result.timeMax=m_pView->doc()->locale()->readTime(val_min->text());
00793           result.timeMin=m_pView->doc()->locale()->readTime(val_max->text());
00794         }
00795       }
00796     }
00797     else if ( chooseType->currentItem()==7 )
00798     {
00799         result.listValidity=QStringList::split( "\n", validityList->text() );
00800     }
00801   }
00802   result.displayMessage = displayMessage->isChecked();
00803   result.allowEmptyCell = allowEmptyCell->isChecked();
00804   result.displayValidationInformation = displayHelp->isChecked();
00805   result.messageInfo= messageHelp->text();
00806   result.titleInfo = titleHelp->text();
00807 
00808   m_pView->doc()->emitBeginOperation( false );
00809   m_pView->activeSheet()->setValidity( m_pView->selectionInfo(),  result);
00810   m_pView->slotUpdateView( m_pView->activeSheet() );
00811   accept();
00812 }
00813 
00814 #include "kspread_dlg_validity.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys