kspread

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