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   }
00445 
00446   if ( tmp.styleName )
00447   {
00448     sb->setCurrentText( *tmp.styleName );
00449     sb->setEnabled( true );
00450   }
00451 
00452   switch( tmp.cond )
00453   {
00454     case Conditional::None :
00455     break;
00456 
00457     case Conditional::Equal :
00458     cb->setCurrentItem( 1 );
00459     break;
00460 
00461     case Conditional::Superior :
00462     cb->setCurrentItem( 2 );
00463     break;
00464 
00465     case Conditional::Inferior :
00466     cb->setCurrentItem( 3 );
00467     break;
00468 
00469     case Conditional::SuperiorEqual :
00470     cb->setCurrentItem( 4 );
00471     break;
00472 
00473     case Conditional::InferiorEqual :
00474     cb->setCurrentItem( 5 );
00475     break;
00476 
00477     case Conditional::Between :
00478     cb->setCurrentItem(6);
00479 
00480     if ( tmp.strVal2 )
00481       kl2->setText( *tmp.strVal2 );
00482     else
00483     {
00484       value = value.setNum( tmp.val2 );
00485       kl2->setText( value );
00486     }
00487     break;
00488 
00489     case Conditional::Different :
00490     cb->setCurrentItem(7);
00491     if ( tmp.strVal2 )
00492       kl2->setText( *tmp.strVal2 );
00493     else
00494     {
00495       value = value.setNum( tmp.val2 );
00496       kl2->setText( value );
00497     }
00498     break;
00499     case Conditional::DifferentTo :
00500     cb->setCurrentItem(8);
00501     break;
00502   }
00503 
00504   if ( tmp.cond != Conditional::None )
00505   {
00506     kl1->setEnabled( true );
00507 
00508     if ( tmp.strVal1 )
00509       kl1->setText( *tmp.strVal1 );
00510     else
00511     {
00512       value = value.setNum( tmp.val1 );
00513       kl1->setText( value );
00514     }
00515   }
00516 }
00517 
00518 Conditional::Type ConditionalDialog::typeOfCondition( QComboBox const * const cb ) const
00519 {
00520   Conditional::Type result = Conditional::None;
00521   switch( cb->currentItem() )
00522   {
00523    case 0 :
00524      result = Conditional::None;
00525     break;
00526    case 1 :
00527      result = Conditional::Equal;
00528     break;
00529    case 2 :
00530      result = Conditional::Superior;
00531     break;
00532    case 3 :
00533      result = Conditional::Inferior;
00534     break;
00535    case 4 :
00536      result = Conditional::SuperiorEqual;
00537     break;
00538    case 5 :
00539      result = Conditional::InferiorEqual;
00540     break;
00541    case 6 :
00542      result = Conditional::Between;
00543     break;
00544    case 7 :
00545      result = Conditional::Different;
00546     break;
00547    case 8 :
00548      result = Conditional::DifferentTo;
00549     break;
00550    default:
00551     kdDebug(36001) << "Error in list" << endl;
00552     break;
00553   }
00554 
00555   return result;
00556 }
00557 
00558 bool ConditionalDialog::checkInputData( KLineEdit const * const edit1,
00559                                             KLineEdit const * const edit2 )
00560 {
00561   bool b1 = false;
00562   bool b2 = false;
00563 
00564   if ( !edit2->isEnabled() )
00565     return true;
00566 
00567   edit1->text().toDouble( &b1 );
00568   edit2->text().toDouble( &b2 );
00569 
00570   if ( b1 != b2 )
00571   {
00572     if ( b1 )
00573       KMessageBox::sorry( 0, i18n( "If the first value is a number, the second value also has to be a number." ) );
00574     else
00575       KMessageBox::sorry( 0, i18n( "If the first value is a string, the second value also has to be a string." ) );
00576     return false;
00577   }
00578 
00579   return true;
00580 }
00581 
00582 bool ConditionalDialog::checkInputData()
00583 {
00584   if ( m_dlg->m_firstValue_1->isEnabled() && !checkInputData( m_dlg->m_firstValue_1, m_dlg->m_secondValue_1 ) )
00585     return false;
00586   if ( m_dlg->m_firstValue_2->isEnabled() && !checkInputData( m_dlg->m_firstValue_2, m_dlg->m_secondValue_2 ) )
00587     return false;
00588   if ( m_dlg->m_firstValue_3->isEnabled() && !checkInputData( m_dlg->m_firstValue_3, m_dlg->m_secondValue_3 ) )
00589     return false;
00590 
00591   return true;
00592 }
00593 
00594 bool ConditionalDialog::getCondition( Conditional & newCondition, const QComboBox * cb,
00595                                           const KLineEdit * edit1, const KLineEdit * edit2,
00596                                           const QComboBox * sb, Style * style )
00597 {
00598   if ( !cb->isEnabled() )
00599     return false;
00600 
00601   newCondition.cond = typeOfCondition( cb );
00602   if ( newCondition.cond == Conditional::None )
00603     return false;
00604 
00605   bool ok = false;
00606   double d1 = edit1->text().toDouble( &ok );
00607   double d2 = 0.0;
00608   QString * s1 = 0;
00609   QString * s2 = 0;
00610   QString * sn = 0;
00611 
00612   if ( ok )
00613   {
00614     if ( edit2->isEnabled() )
00615       d2 = edit2->text().toDouble( &ok );
00616     // values are already checked...
00617   }
00618   else
00619   {
00620     d1 = 0.0;
00621     s1 = new QString( edit1->text() );
00622 
00623     if ( edit2->isEnabled() )
00624       s2 = new QString( edit2->text() );
00625   }
00626   sn = new QString( sb->currentText() );
00627 
00628   newCondition.val1      = d1;
00629   newCondition.val2      = d2;
00630   newCondition.strVal1   = s1;
00631   newCondition.strVal2   = s2;
00632   newCondition.fontcond  = 0;
00633   newCondition.colorcond = 0;
00634   newCondition.styleName = sn;
00635   newCondition.style     = style;
00636 
00637   return true;
00638 }
00639 
00640 void ConditionalDialog::slotOk()
00641 {
00642   kdDebug() << "slotOk" << endl;
00643 
00644   if ( !checkInputData() )
00645     return;
00646 
00647   kdDebug() << "Input data is valid" << endl;
00648 
00649   m_view->doc()->emitBeginOperation( false );
00650   StyleManager * manager = m_view->doc()->styleManager();
00651 
00652   QValueList<Conditional> newList;
00653 
00654   Conditional newCondition;
00655 
00656   if ( getCondition( newCondition, m_dlg->m_condition_1, m_dlg->m_firstValue_1,
00657                      m_dlg->m_secondValue_1, m_dlg->m_style_1, manager->style( m_dlg->m_style_1->currentText() ) ) )
00658     newList.append( newCondition );
00659 
00660   if ( getCondition( newCondition, m_dlg->m_condition_2, m_dlg->m_firstValue_2,
00661                      m_dlg->m_secondValue_2, m_dlg->m_style_2, manager->style( m_dlg->m_style_2->currentText() ) ) )
00662     newList.append( newCondition );
00663 
00664   if ( getCondition( newCondition, m_dlg->m_condition_3, m_dlg->m_firstValue_3,
00665                      m_dlg->m_secondValue_3, m_dlg->m_style_3, manager->style( m_dlg->m_style_3->currentText() ) ) )
00666     newList.append( newCondition );
00667 
00668   kdDebug() << "Setting conditional list" << endl;
00669   m_view->activeSheet()->setConditional( m_view->selectionInfo(), newList );
00670   m_view->slotUpdateView( m_view->activeSheet(), *m_view->selectionInfo() );
00671 
00672   accept();
00673 }
00674 
00675 #include "kspread_dlg_conditional.moc"
00676 
00677 
KDE Home | KDE Accessibility Home | Description of Access Keys