kspread Library API Documentation

kspread_dlg_conditional.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
00003              (C) 2002-2003 Philipp Mueller <philipp.mueller@gmx.de>
00004              (C) 2002 John Dailey <dailey@vt.edu>
00005              (C) 1999-2001 Laurent Montel <montel@kde.org>
00006 
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_conditional.h"
00025 #include "kspread_condition.h"
00026 
00027 #include "kspread_canvas.h"
00028 #include "kspread_cell.h"
00029 #include "kspread_doc.h"
00030 #include "kspread_selection.h"
00031 #include "kspread_sheet.h"
00032 #include "kspread_style.h"
00033 #include "kspread_style_manager.h"
00034 #include "kspread_view.h"
00035 
00036 #include <kcombobox.h>
00037 #include <kdebug.h>
00038 #include <klineedit.h>
00039 #include <klocale.h>
00040 #include <kmessagebox.h>
00041 
00042 #include <koGlobal.h>
00043 
00044 #include <qgroupbox.h>
00045 #include <qlabel.h>
00046 #include <qlayout.h>
00047 
00048 KSpreadConditionalWidget::KSpreadConditionalWidget( QWidget* parent, const char* name, WFlags fl )
00049     : QWidget( parent, name, fl )
00050 {
00051   QGridLayout * Form1Layout = new QGridLayout( this, 1, 1, 11, 6, "Form1Layout");
00052 
00053   QGroupBox * groupBox1_3 = new QGroupBox( this, "groupBox1_3" );
00054   groupBox1_3->setColumnLayout(0, Qt::Vertical );
00055   groupBox1_3->layout()->setSpacing( KDialog::spacingHint() );
00056   groupBox1_3->layout()->setMargin( KDialog::marginHint() );
00057   QGridLayout * groupBox1_3Layout = new QGridLayout( groupBox1_3->layout() );
00058   groupBox1_3Layout->setAlignment( Qt::AlignTop );
00059 
00060   QLabel * textLabel1_3 = new QLabel( groupBox1_3, "textLabel1_3" );
00061   groupBox1_3Layout->addWidget( textLabel1_3, 0, 0 );
00062 
00063   m_condition_3 = new QComboBox( false, groupBox1_3, "m_condition_3" );
00064   groupBox1_3Layout->addWidget( m_condition_3, 0, 1 );
00065 
00066   m_firstValue_3 = new KLineEdit( groupBox1_3, "m_firstValue_3" );
00067   m_firstValue_3->setEnabled( false );
00068   groupBox1_3Layout->addWidget( m_firstValue_3, 0, 2 );
00069 
00070   m_secondValue_3 = new KLineEdit( groupBox1_3, "m_secondValue_3" );
00071   m_secondValue_3->setEnabled( false );
00072   groupBox1_3Layout->addWidget( m_secondValue_3, 0, 3 );
00073 
00074   m_style_3 = new QComboBox( false, groupBox1_3, "m_style_3" );
00075   m_style_3->setEnabled( false );
00076   groupBox1_3Layout->addWidget( m_style_3, 1, 1 );
00077 
00078   QLabel * textLabel2_3 = new QLabel( groupBox1_3, "textLabel2_3" );
00079   groupBox1_3Layout->addWidget( textLabel2_3, 1, 0 );
00080 
00081   QSpacerItem * spacer = new QSpacerItem( 41, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00082   groupBox1_3Layout->addItem( spacer, 1, 2 );
00083   QSpacerItem * spacer_2 = new QSpacerItem( 61, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00084   groupBox1_3Layout->addItem( spacer_2, 1, 3 );
00085 
00086   Form1Layout->addWidget( groupBox1_3, 2, 0 );
00087 
00088   QGroupBox * groupBox1_2 = new QGroupBox( this, "groupBox1_2" );
00089   groupBox1_2->setColumnLayout(0, Qt::Vertical );
00090   groupBox1_2->layout()->setSpacing( KDialog::spacingHint() );
00091   groupBox1_2->layout()->setMargin( KDialog::marginHint() );
00092 
00093   QGridLayout * groupBox1_2Layout = new QGridLayout( groupBox1_2->layout() );
00094   groupBox1_2Layout->setAlignment( Qt::AlignTop );
00095 
00096   QLabel * textLabel1_2 = new QLabel( groupBox1_2, "textLabel1_2" );
00097   groupBox1_2Layout->addWidget( textLabel1_2, 0, 0 );
00098 
00099   QLabel * textLabel2_2 = new QLabel( groupBox1_2, "textLabel2_2" );
00100   groupBox1_2Layout->addWidget( textLabel2_2, 1, 0 );
00101 
00102   m_condition_2 = new QComboBox( false, groupBox1_2, "m_condition_2" );
00103   groupBox1_2Layout->addWidget( m_condition_2, 0, 1 );
00104 
00105   m_style_2 = new QComboBox( false, groupBox1_2, "m_style_2" );
00106   m_style_2->setEnabled( false );
00107   groupBox1_2Layout->addWidget( m_style_2, 1, 1 );
00108 
00109   m_firstValue_2 = new KLineEdit( groupBox1_2, "m_firstValue_2" );
00110   m_firstValue_2->setEnabled( false );
00111   groupBox1_2Layout->addWidget( m_firstValue_2, 0, 2 );
00112 
00113   m_secondValue_2 = new KLineEdit( groupBox1_2, "m_secondValue_2" );
00114   m_secondValue_2->setEnabled( false );
00115 
00116   groupBox1_2Layout->addWidget( m_secondValue_2, 0, 3 );
00117 
00118   QSpacerItem * spacer_3 = new QSpacerItem( 41, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00119   groupBox1_2Layout->addItem( spacer_3, 1, 2 );
00120   QSpacerItem * spacer_4 = new QSpacerItem( 61, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00121   groupBox1_2Layout->addItem( spacer_4, 1, 3 );
00122   Form1Layout->addWidget( groupBox1_2, 1, 0 );
00123 
00124   QGroupBox * groupBox1_1 = new QGroupBox( this, "groupBox1_1" );
00125   groupBox1_1->setColumnLayout(0, Qt::Vertical );
00126   groupBox1_1->layout()->setSpacing( KDialog::spacingHint() );
00127   groupBox1_1->layout()->setMargin( KDialog::marginHint() );
00128 
00129   QGridLayout * groupBox1_1Layout = new QGridLayout( groupBox1_1->layout() );
00130   groupBox1_1Layout->setAlignment( Qt::AlignTop );
00131 
00132   QLabel * textLabel1_1 = new QLabel( groupBox1_1, "textLabel1_2_2" );
00133   groupBox1_1Layout->addWidget( textLabel1_1, 0, 0 );
00134 
00135   QLabel * textLabel2_1 = new QLabel( groupBox1_1, "textLabel2_2_2" );
00136   groupBox1_1Layout->addWidget( textLabel2_1, 1, 0 );
00137 
00138   m_condition_1 = new QComboBox( false, groupBox1_1, "m_condition_1" );
00139   groupBox1_1Layout->addWidget( m_condition_1, 0, 1 );
00140 
00141   m_style_1 = new QComboBox( false, groupBox1_1, "m_style_1" );
00142   m_style_1->setEnabled( false );
00143   groupBox1_1Layout->addWidget( m_style_1, 1, 1 );
00144 
00145   m_firstValue_1 = new KLineEdit( groupBox1_1, "m_firstValue_1" );
00146   m_firstValue_1->setEnabled( false );
00147   groupBox1_1Layout->addWidget( m_firstValue_1, 0, 2 );
00148 
00149   m_secondValue_1 = new KLineEdit( groupBox1_1, "m_secondValue_1" );
00150   m_secondValue_1->setEnabled( false );
00151   groupBox1_1Layout->addWidget( m_secondValue_1, 0, 3 );
00152 
00153   QSpacerItem * spacer_5 = new QSpacerItem( 41, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00154   groupBox1_1Layout->addItem( spacer_5, 1, 2 );
00155   QSpacerItem * spacer_6 = new QSpacerItem( 61, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00156   groupBox1_1Layout->addItem( spacer_6, 1, 3 );
00157 
00158   Form1Layout->addWidget( groupBox1_1, 0, 0 );
00159   resize( QSize(702, 380).expandedTo( minimumSizeHint() ) );
00160   clearWState( WState_Polished );
00161 
00162   QStringList list;
00163   list += i18n( "<none>" );
00164   list += i18n( "equal to" );
00165   list += i18n( "greater than" );
00166   list += i18n( "less than" );
00167   list += i18n( "equal to or greater than" );
00168   list += i18n( "equal to or less than" );
00169   list += i18n( "between" );
00170   list += i18n( "outside range" );
00171   list += i18n( "different to" );
00172 
00173   m_condition_1->clear();
00174   m_condition_2->clear();
00175   m_condition_3->clear();
00176   m_condition_1->insertStringList( list );
00177   m_condition_2->insertStringList( list );
00178   m_condition_3->insertStringList( list );
00179 
00180   groupBox1_1->setTitle( i18n( "First Condition" ) );
00181   groupBox1_2->setTitle( i18n( "Second Condition" ) );
00182   groupBox1_3->setTitle( i18n( "Third Condition" ) );
00183   textLabel1_1->setText( i18n( "Cell is" ) );
00184   textLabel1_2->setText( i18n( "Cell is" ) );
00185   textLabel1_3->setText( i18n( "Cell is" ) );
00186   textLabel2_1->setText( i18n( "Cell style" ) );
00187   textLabel2_2->setText( i18n( "Cell style" ) );
00188   textLabel2_3->setText( i18n( "Cell style" ) );
00189 
00190   connect( m_condition_1, SIGNAL( highlighted( const QString & ) ), this, SLOT( slotTextChanged1( const QString & ) ) );
00191   connect( m_condition_2, SIGNAL( highlighted( const QString & ) ), this, SLOT( slotTextChanged2( const QString & ) ) );
00192   connect( m_condition_3, SIGNAL( highlighted( const QString & ) ), this, SLOT( slotTextChanged3( const QString & ) ) );
00193 }
00194 
00195 KSpreadConditionalWidget::~KSpreadConditionalWidget()
00196 {
00197 }
00198 
00199 void KSpreadConditionalWidget::slotTextChanged1( const QString & text )
00200 {
00201   if ( text == i18n( "<none>" ) )
00202   {
00203     m_firstValue_1->setEnabled( false );
00204     m_secondValue_1->setEnabled( false );
00205     m_style_1->setEnabled( false );
00206   }
00207   else
00208   {
00209     m_condition_2->setEnabled( true );
00210     m_style_1->setEnabled( true );
00211     if ( ( text == i18n( "between" ) ) || ( text == i18n( "different from" ) ) )
00212     {
00213       m_firstValue_1->setEnabled( true );
00214       m_secondValue_1->setEnabled( true );
00215     }
00216     else
00217     {
00218       m_firstValue_1->setEnabled( true );
00219       m_secondValue_1->setEnabled( false );
00220     }
00221   }
00222 }
00223 
00224 void KSpreadConditionalWidget::slotTextChanged2( const QString & text )
00225 {
00226   if ( text == i18n( "<none>" ) )
00227   {
00228     m_firstValue_2->setEnabled( false );
00229     m_secondValue_2->setEnabled( false );
00230     m_style_2->setEnabled( false );
00231   }
00232   else
00233   {
00234     m_condition_3->setEnabled( true );
00235     m_style_2->setEnabled( true );
00236     if ( ( text == i18n( "between" ) ) || ( text == i18n( "different from" ) ) )
00237     {
00238       m_firstValue_2->setEnabled( true );
00239       m_secondValue_2->setEnabled( true );
00240     }
00241     else
00242     {
00243       m_firstValue_2->setEnabled( true );
00244       m_secondValue_2->setEnabled( false );
00245     }
00246   }
00247 }
00248 
00249 void KSpreadConditionalWidget::slotTextChanged3( const QString & text )
00250 {
00251   if ( text == i18n( "<none>" ) )
00252   {
00253     m_firstValue_3->setEnabled( false );
00254     m_secondValue_3->setEnabled( false );
00255     m_style_3->setEnabled( false );
00256   }
00257   else
00258   {
00259     m_style_3->setEnabled( true );
00260     if ( ( text == i18n( "between" ) ) || ( text == i18n( "different from" ) ) )
00261     {
00262       m_firstValue_3->setEnabled( true );
00263       m_secondValue_3->setEnabled( true );
00264     }
00265     else
00266     {
00267       m_firstValue_3->setEnabled( true );
00268       m_secondValue_3->setEnabled( false );
00269     }
00270   }
00271 }
00272 
00278 KSpreadConditionalDlg::KSpreadConditionalDlg( KSpreadView * parent, const char * name,
00279                                               const QRect & marker )
00280   : KDialogBase( parent, name, true, "", KDialogBase::Ok | KDialogBase::Cancel,
00281                  KDialogBase::Ok, false ),
00282     m_view( parent ),
00283     m_dlg( new KSpreadConditionalWidget( this ) ),
00284     m_marker( marker )
00285 {
00286   QStringList list( m_view->doc()->styleManager()->styleNames() );
00287 
00288   m_dlg->m_style_1->insertStringList( list );
00289   m_dlg->m_style_2->insertStringList( list );
00290   m_dlg->m_style_3->insertStringList( list );
00291 
00292   setCaption( i18n( "Conditional Cell Attributes" ) );
00293   setButtonBoxOrientation( Vertical );
00294   setMainWidget( m_dlg );
00295 
00296   init();
00297 }
00298 
00299 void KSpreadConditionalDlg::init()
00300 {
00301   QValueList<KSpreadConditional> conditionList;
00302   QValueList<KSpreadConditional> otherList;
00303   bool found;
00304   int numCondition;
00305 
00306   QValueList<KSpreadConditional>::iterator it1;
00307   QValueList<KSpreadConditional>::iterator it2;
00308 
00309   KSpreadCell * obj = m_view->activeSheet()->cellAt( m_marker.left(),
00310                                                      m_marker.top() );
00311 
00312   conditionList = obj->conditionList();
00313   /* this is the list, but only display the conditions common to all selected
00314      cells*/
00315 
00316   for ( int x = m_marker.left(); x <= m_marker.right(); x++ )
00317   {
00318     for ( int y = m_marker.top(); y <= m_marker.bottom(); y++ )
00319     {
00320       KSpreadCell * obj2 = m_view->activeSheet()->cellAt( x, y );
00321       otherList = obj2->conditionList();
00322 
00323       it1 = conditionList.begin();
00324       while ( it1 != conditionList.end() )
00325       {
00326         kdDebug() << "Here" << endl;
00327     found = false;
00328     for ( it2 = otherList.begin(); !found && it2 != otherList.end(); ++it2 )
00329     {
00330           kdDebug() << "Found: " << found << endl;
00331       found = ( (*it1).val1 == (*it2).val1 &&
00332                     (*it1).val2 == (*it2).val2 &&
00333                     (*it1).cond == (*it2).cond );
00334 
00335           if ( (*it1).strVal1 && !(*it2).strVal1 )
00336             found = false;
00337           if ( !(*it1).strVal1 && (*it2).strVal1 )
00338             found = false;
00339           if ( (*it1).strVal1 && (*it2).strVal1
00340                && ( *(*it1).strVal1 != *(*it2).strVal1 ) )
00341             found = false;
00342           if ( !found )
00343             continue;
00344 
00345           if ( (*it1).strVal2 && !(*it2).strVal2 )
00346             found = false;
00347           if ( !(*it1).strVal2 && (*it2).strVal2 )
00348             found = false;
00349           if ( (*it1).strVal2 && (*it2).strVal2
00350                && ( *(*it1).strVal2 != *(*it2).strVal2 ) )
00351             found = false;
00352           if ( !found )
00353             continue;
00354 
00355           if ( (*it1).colorcond && !(*it2).colorcond )
00356             found = false;
00357           if ( !(*it1).colorcond && (*it2).colorcond )
00358             found = false;
00359           if ( (*it1).colorcond && (*it2).colorcond
00360                && ( *(*it1).colorcond != *(*it2).colorcond ) )
00361             found = false;
00362           if ( !found )
00363             continue;
00364 
00365           if ( (*it1).fontcond && !(*it2).fontcond )
00366             found = false;
00367           if ( !(*it1).fontcond && (*it2).fontcond )
00368             found = false;
00369           if ( (*it1).fontcond && (*it2).fontcond
00370                && ( *(*it1).fontcond != *(*it2).fontcond ) )
00371             found = false;
00372           if ( !found )
00373             continue;
00374 
00375           if ( (*it1).styleName && !(*it2).styleName )
00376             found = false;
00377           if ( !(*it1).styleName && (*it2).styleName )
00378             found = false;
00379           if ( (*it1).styleName && (*it2).styleName
00380                && ( *(*it1).styleName != *(*it2).styleName ) )
00381             found = false;
00382     }
00383 
00384     if ( !found )  /* if it's not here, don't display this condition */
00385     {
00386       it1 = conditionList.remove( it1 );
00387     }
00388     else
00389     {
00390       ++it1;
00391     }
00392       }
00393     }
00394   }
00395 
00396   kdDebug() << "Conditions: " << conditionList.size() << endl;
00397 
00398   m_dlg->m_condition_2->setEnabled( false );
00399   m_dlg->m_condition_3->setEnabled( false );
00400 
00401   m_dlg->m_style_1->setEnabled( false );
00402   m_dlg->m_style_2->setEnabled( false );
00403   m_dlg->m_style_3->setEnabled( false );
00404 
00405   numCondition = 0;
00406   for ( it1 = conditionList.begin(); numCondition < 3 && it1 != conditionList.end(); ++it1 )
00407   {
00408     init( *it1, numCondition );
00409 
00410     ++numCondition;
00411   }
00412 }
00413 
00414 void KSpreadConditionalDlg::init( KSpreadConditional const & tmp, int numCondition )
00415 {
00416   kdDebug() << "Adding " << numCondition << endl;
00417   QComboBox * cb  = 0;
00418   QComboBox * sb  = 0;
00419   KLineEdit * kl1 = 0;
00420   KLineEdit * kl2 = 0;
00421   QString value;
00422 
00423   switch( numCondition )
00424   {
00425    case 0:
00426     cb  = m_dlg->m_condition_1;
00427     sb  = m_dlg->m_style_1;
00428     kl1 = m_dlg->m_firstValue_1;
00429     kl2 = m_dlg->m_secondValue_1;
00430     break;
00431    case 1:
00432     cb  = m_dlg->m_condition_2;
00433     sb  = m_dlg->m_style_2;
00434     kl1 = m_dlg->m_firstValue_2;
00435     kl2 = m_dlg->m_secondValue_2;
00436     break;
00437    case 2:
00438     cb  = m_dlg->m_condition_3;
00439     sb  = m_dlg->m_style_3;
00440     kl1 = m_dlg->m_firstValue_3;
00441     kl2 = m_dlg->m_secondValue_3;
00442     break;
00443   }
00444 
00445   if ( tmp.styleName )
00446   {
00447     sb->setCurrentText( *tmp.styleName );
00448     sb->setEnabled( true );
00449   }
00450 
00451   switch( tmp.cond )
00452   {
00453    case None :
00454     break;
00455 
00456    case Equal :
00457     cb->setCurrentItem( 1 );
00458     break;
00459 
00460    case Superior :
00461     cb->setCurrentItem( 2 );
00462     break;
00463 
00464    case Inferior :
00465     cb->setCurrentItem( 3 );
00466     break;
00467 
00468    case SuperiorEqual :
00469     cb->setCurrentItem( 4 );
00470     break;
00471 
00472    case InferiorEqual :
00473     cb->setCurrentItem( 5 );
00474     break;
00475 
00476    case Between :
00477     cb->setCurrentItem(6);
00478 
00479     if ( tmp.strVal2 )
00480       kl2->setText( *tmp.strVal2 );
00481     else
00482     {
00483       value = value.setNum( tmp.val2 );
00484       kl2->setText( value );
00485     }
00486     break;
00487 
00488    case Different :
00489     cb->setCurrentItem(7);
00490     if ( tmp.strVal2 )
00491       kl2->setText( *tmp.strVal2 );
00492     else
00493     {
00494       value = value.setNum( tmp.val2 );
00495       kl2->setText( value );
00496     }
00497     break;
00498    case DifferentTo :
00499     cb->setCurrentItem(8);
00500     break;
00501   }
00502 
00503   if ( tmp.cond != None )
00504   {
00505     kl1->setEnabled( true );
00506 
00507     if ( tmp.strVal1 )
00508       kl1->setText( *tmp.strVal1 );
00509     else
00510     {
00511       value = value.setNum( tmp.val1 );
00512       kl1->setText( value );
00513     }
00514   }
00515 }
00516 
00517 Conditional KSpreadConditionalDlg::typeOfCondition( QComboBox const * const cb ) const
00518 {
00519   Conditional result = None;
00520   switch( cb->currentItem() )
00521   {
00522    case 0 :
00523     result = None;
00524     break;
00525    case 1 :
00526     result = Equal;
00527     break;
00528    case 2 :
00529     result = Superior;
00530     break;
00531    case 3 :
00532     result = Inferior;
00533     break;
00534    case 4 :
00535     result = SuperiorEqual;
00536     break;
00537    case 5 :
00538     result = InferiorEqual;
00539     break;
00540    case 6 :
00541     result = Between;
00542     break;
00543    case 7 :
00544     result = Different;
00545     break;
00546    case 8 :
00547     result = DifferentTo;
00548     break;
00549    default:
00550     kdDebug(36001) << "Error in list" << endl;
00551     break;
00552   }
00553 
00554   return result;
00555 }
00556 
00557 bool KSpreadConditionalDlg::checkInputData( KLineEdit const * const edit1,
00558                                             KLineEdit const * const edit2 )
00559 {
00560   bool b1 = false;
00561   bool b2 = false;
00562 
00563   if ( !edit2->isEnabled() )
00564     return true;
00565 
00566   edit1->text().toDouble( &b1 );
00567   edit2->text().toDouble( &b2 );
00568 
00569   if ( b1 != b2 )
00570   {
00571     if ( b1 )
00572       KMessageBox::sorry( 0, i18n( "If the first value is a number, the second value also has to be a number." ) );
00573     else
00574       KMessageBox::sorry( 0, i18n( "If the first value is a string, the second value also has to be a string." ) );
00575     return false;
00576   }
00577 
00578   return true;
00579 }
00580 
00581 bool KSpreadConditionalDlg::checkInputData()
00582 {
00583   if ( m_dlg->m_firstValue_1->isEnabled() && !checkInputData( m_dlg->m_firstValue_1, m_dlg->m_secondValue_1 ) )
00584     return false;
00585   if ( m_dlg->m_firstValue_2->isEnabled() && !checkInputData( m_dlg->m_firstValue_2, m_dlg->m_secondValue_2 ) )
00586     return false;
00587   if ( m_dlg->m_firstValue_3->isEnabled() && !checkInputData( m_dlg->m_firstValue_3, m_dlg->m_secondValue_3 ) )
00588     return false;
00589 
00590   return true;
00591 }
00592 
00593 bool KSpreadConditionalDlg::getCondition( KSpreadConditional & newCondition, const QComboBox * cb,
00594                                           const KLineEdit * edit1, const KLineEdit * edit2,
00595                                           const QComboBox * sb, KSpreadStyle * style )
00596 {
00597   if ( !cb->isEnabled() )
00598     return false;
00599 
00600   newCondition.cond = typeOfCondition( cb );
00601   if ( newCondition.cond == None )
00602     return false;
00603 
00604   bool ok = false;
00605   double d1 = edit1->text().toDouble( &ok );
00606   double d2 = 0.0;
00607   QString * s1 = 0;
00608   QString * s2 = 0;
00609   QString * sn = 0;
00610 
00611   if ( ok )
00612   {
00613     if ( edit2->isEnabled() )
00614       d2 = edit2->text().toDouble( &ok );
00615     // values are already checked...
00616   }
00617   else
00618   {
00619     d1 = 0.0;
00620     s1 = new QString( edit1->text() );
00621 
00622     if ( edit2->isEnabled() )
00623       s2 = new QString( edit2->text() );
00624   }
00625   sn = new QString( sb->currentText() );
00626 
00627   newCondition.val1      = d1;
00628   newCondition.val2      = d2;
00629   newCondition.strVal1   = s1;
00630   newCondition.strVal2   = s2;
00631   newCondition.fontcond  = 0;
00632   newCondition.colorcond = 0;
00633   newCondition.styleName = sn;
00634   newCondition.style     = style;
00635 
00636   return true;
00637 }
00638 
00639 void KSpreadConditionalDlg::slotOk()
00640 {
00641   kdDebug() << "slotOk" << endl;
00642 
00643   if ( !checkInputData() )
00644     return;
00645 
00646   kdDebug() << "Input data is valid" << endl;
00647 
00648   m_view->doc()->emitBeginOperation( false );
00649   KSpreadStyleManager * manager = m_view->doc()->styleManager();
00650 
00651   QValueList<KSpreadConditional> newList;
00652 
00653   KSpreadConditional newCondition;
00654 
00655   if ( getCondition( newCondition, m_dlg->m_condition_1, m_dlg->m_firstValue_1,
00656                      m_dlg->m_secondValue_1, m_dlg->m_style_1, manager->style( m_dlg->m_style_1->currentText() ) ) )
00657     newList.append( newCondition );
00658 
00659   if ( getCondition( newCondition, m_dlg->m_condition_2, m_dlg->m_firstValue_2,
00660                      m_dlg->m_secondValue_2, m_dlg->m_style_2, manager->style( m_dlg->m_style_2->currentText() ) ) )
00661     newList.append( newCondition );
00662 
00663   if ( getCondition( newCondition, m_dlg->m_condition_3, m_dlg->m_firstValue_3,
00664                      m_dlg->m_secondValue_3, m_dlg->m_style_3, manager->style( m_dlg->m_style_3->currentText() ) ) )
00665     newList.append( newCondition );
00666 
00667   kdDebug() << "Setting conditional list" << endl;
00668   m_view->activeSheet()->setConditional( m_view->selectionInfo(), newList );
00669   m_view->slotUpdateView( m_view->activeSheet(), m_view->selectionInfo()->selection() );
00670 
00671   accept();
00672 }
00673 
00674 #include "kspread_dlg_conditional.moc"
00675 
00676 
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:42:54 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003