kspread Library API Documentation

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