24#include "kspread_dlg_conditional.h"
25#include "kspread_condition.h"
27#include "kspread_canvas.h"
28#include "kspread_cell.h"
29#include "kspread_doc.h"
31#include "kspread_sheet.h"
32#include "kspread_style.h"
33#include "kspread_style_manager.h"
34#include "kspread_view.h"
40#include <tdemessagebox.h>
44#include <tqgroupbox.h>
50ConditionalWidget::ConditionalWidget( TQWidget* parent,
const char* name, WFlags fl )
51 : TQWidget( parent, name, fl )
53 TQGridLayout * Form1Layout =
new TQGridLayout(
this, 1, 1, 11, 6,
"Form1Layout");
55 TQGroupBox * groupBox1_3 =
new TQGroupBox(
this,
"groupBox1_3" );
56 groupBox1_3->setColumnLayout(0, TQt::Vertical );
57 groupBox1_3->layout()->setSpacing( KDialog::spacingHint() );
58 groupBox1_3->layout()->setMargin( KDialog::marginHint() );
59 TQGridLayout * groupBox1_3Layout =
new TQGridLayout( groupBox1_3->layout() );
60 groupBox1_3Layout->setAlignment( TQt::AlignTop );
62 TQLabel * textLabel1_3 =
new TQLabel( groupBox1_3,
"textLabel1_3" );
63 groupBox1_3Layout->addWidget( textLabel1_3, 0, 0 );
65 m_condition_3 =
new TQComboBox(
false, groupBox1_3,
"m_condition_3" );
66 groupBox1_3Layout->addWidget( m_condition_3, 0, 1 );
68 m_firstValue_3 =
new KLineEdit( groupBox1_3,
"m_firstValue_3" );
69 m_firstValue_3->setEnabled(
false );
70 groupBox1_3Layout->addWidget( m_firstValue_3, 0, 2 );
72 m_secondValue_3 =
new KLineEdit( groupBox1_3,
"m_secondValue_3" );
73 m_secondValue_3->setEnabled(
false );
74 groupBox1_3Layout->addWidget( m_secondValue_3, 0, 3 );
76 m_style_3 =
new TQComboBox(
false, groupBox1_3,
"m_style_3" );
77 m_style_3->setEnabled(
false );
78 groupBox1_3Layout->addWidget( m_style_3, 1, 1 );
80 TQLabel * textLabel2_3 =
new TQLabel( groupBox1_3,
"textLabel2_3" );
81 groupBox1_3Layout->addWidget( textLabel2_3, 1, 0 );
83 TQSpacerItem * spacer =
new TQSpacerItem( 41, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
84 groupBox1_3Layout->addItem( spacer, 1, 2 );
85 TQSpacerItem * spacer_2 =
new TQSpacerItem( 61, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
86 groupBox1_3Layout->addItem( spacer_2, 1, 3 );
88 Form1Layout->addWidget( groupBox1_3, 2, 0 );
90 TQGroupBox * groupBox1_2 =
new TQGroupBox(
this,
"groupBox1_2" );
91 groupBox1_2->setColumnLayout(0, TQt::Vertical );
92 groupBox1_2->layout()->setSpacing( KDialog::spacingHint() );
93 groupBox1_2->layout()->setMargin( KDialog::marginHint() );
95 TQGridLayout * groupBox1_2Layout =
new TQGridLayout( groupBox1_2->layout() );
96 groupBox1_2Layout->setAlignment( TQt::AlignTop );
98 TQLabel * textLabel1_2 =
new TQLabel( groupBox1_2,
"textLabel1_2" );
99 groupBox1_2Layout->addWidget( textLabel1_2, 0, 0 );
101 TQLabel * textLabel2_2 =
new TQLabel( groupBox1_2,
"textLabel2_2" );
102 groupBox1_2Layout->addWidget( textLabel2_2, 1, 0 );
104 m_condition_2 =
new TQComboBox(
false, groupBox1_2,
"m_condition_2" );
105 groupBox1_2Layout->addWidget( m_condition_2, 0, 1 );
107 m_style_2 =
new TQComboBox(
false, groupBox1_2,
"m_style_2" );
108 m_style_2->setEnabled(
false );
109 groupBox1_2Layout->addWidget( m_style_2, 1, 1 );
111 m_firstValue_2 =
new KLineEdit( groupBox1_2,
"m_firstValue_2" );
112 m_firstValue_2->setEnabled(
false );
113 groupBox1_2Layout->addWidget( m_firstValue_2, 0, 2 );
115 m_secondValue_2 =
new KLineEdit( groupBox1_2,
"m_secondValue_2" );
116 m_secondValue_2->setEnabled(
false );
118 groupBox1_2Layout->addWidget( m_secondValue_2, 0, 3 );
120 TQSpacerItem * spacer_3 =
new TQSpacerItem( 41, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
121 groupBox1_2Layout->addItem( spacer_3, 1, 2 );
122 TQSpacerItem * spacer_4 =
new TQSpacerItem( 61, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
123 groupBox1_2Layout->addItem( spacer_4, 1, 3 );
124 Form1Layout->addWidget( groupBox1_2, 1, 0 );
126 TQGroupBox * groupBox1_1 =
new TQGroupBox(
this,
"groupBox1_1" );
127 groupBox1_1->setColumnLayout(0, TQt::Vertical );
128 groupBox1_1->layout()->setSpacing( KDialog::spacingHint() );
129 groupBox1_1->layout()->setMargin( KDialog::marginHint() );
131 TQGridLayout * groupBox1_1Layout =
new TQGridLayout( groupBox1_1->layout() );
132 groupBox1_1Layout->setAlignment( TQt::AlignTop );
134 TQLabel * textLabel1_1 =
new TQLabel( groupBox1_1,
"textLabel1_2_2" );
135 groupBox1_1Layout->addWidget( textLabel1_1, 0, 0 );
137 TQLabel * textLabel2_1 =
new TQLabel( groupBox1_1,
"textLabel2_2_2" );
138 groupBox1_1Layout->addWidget( textLabel2_1, 1, 0 );
140 m_condition_1 =
new TQComboBox(
false, groupBox1_1,
"m_condition_1" );
141 groupBox1_1Layout->addWidget( m_condition_1, 0, 1 );
143 m_style_1 =
new TQComboBox(
false, groupBox1_1,
"m_style_1" );
144 m_style_1->setEnabled(
false );
145 groupBox1_1Layout->addWidget( m_style_1, 1, 1 );
147 m_firstValue_1 =
new KLineEdit( groupBox1_1,
"m_firstValue_1" );
148 m_firstValue_1->setEnabled(
false );
149 groupBox1_1Layout->addWidget( m_firstValue_1, 0, 2 );
151 m_secondValue_1 =
new KLineEdit( groupBox1_1,
"m_secondValue_1" );
152 m_secondValue_1->setEnabled(
false );
153 groupBox1_1Layout->addWidget( m_secondValue_1, 0, 3 );
155 TQSpacerItem * spacer_5 =
new TQSpacerItem( 41, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
156 groupBox1_1Layout->addItem( spacer_5, 1, 2 );
157 TQSpacerItem * spacer_6 =
new TQSpacerItem( 61, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
158 groupBox1_1Layout->addItem( spacer_6, 1, 3 );
160 Form1Layout->addWidget( groupBox1_1, 0, 0 );
161 resize( TQSize(702, 380).expandedTo( minimumSizeHint() ) );
162 clearWState( WState_Polished );
165 list += i18n(
"<none>" );
166 list += i18n(
"equal to" );
167 list += i18n(
"greater than" );
168 list += i18n(
"less than" );
169 list += i18n(
"equal to or greater than" );
170 list += i18n(
"equal to or less than" );
171 list += i18n(
"between" );
172 list += i18n(
"outside range" );
173 list += i18n(
"different to" );
175 m_condition_1->clear();
176 m_condition_2->clear();
177 m_condition_3->clear();
178 m_condition_1->insertStringList( list );
179 m_condition_2->insertStringList( list );
180 m_condition_3->insertStringList( list );
182 groupBox1_1->setTitle( i18n(
"First Condition" ) );
183 groupBox1_2->setTitle( i18n(
"Second Condition" ) );
184 groupBox1_3->setTitle( i18n(
"Third Condition" ) );
185 textLabel1_1->setText( i18n(
"Cell is" ) );
186 textLabel1_2->setText( i18n(
"Cell is" ) );
187 textLabel1_3->setText( i18n(
"Cell is" ) );
188 textLabel2_1->setText( i18n(
"Cell style" ) );
189 textLabel2_2->setText( i18n(
"Cell style" ) );
190 textLabel2_3->setText( i18n(
"Cell style" ) );
192 connect( m_condition_1, TQ_SIGNAL( highlighted(
const TQString & ) ),
this, TQ_SLOT( slotTextChanged1(
const TQString & ) ) );
193 connect( m_condition_2, TQ_SIGNAL( highlighted(
const TQString & ) ),
this, TQ_SLOT( slotTextChanged2(
const TQString & ) ) );
194 connect( m_condition_3, TQ_SIGNAL( highlighted(
const TQString & ) ),
this, TQ_SLOT( slotTextChanged3(
const TQString & ) ) );
197ConditionalWidget::~ConditionalWidget()
201void ConditionalWidget::slotTextChanged1(
const TQString & text )
203 if ( text == i18n(
"<none>" ) )
205 m_firstValue_1->setEnabled(
false );
206 m_secondValue_1->setEnabled(
false );
207 m_style_1->setEnabled(
false );
211 m_condition_2->setEnabled(
true );
212 m_style_1->setEnabled(
true );
213 if ( ( text == i18n(
"between" ) ) || ( text == i18n(
"different from" ) ) )
215 m_firstValue_1->setEnabled(
true );
216 m_secondValue_1->setEnabled(
true );
220 m_firstValue_1->setEnabled(
true );
221 m_secondValue_1->setEnabled(
false );
226void ConditionalWidget::slotTextChanged2(
const TQString & text )
228 if ( text == i18n(
"<none>" ) )
230 m_firstValue_2->setEnabled(
false );
231 m_secondValue_2->setEnabled(
false );
232 m_style_2->setEnabled(
false );
236 m_condition_3->setEnabled(
true );
237 m_style_2->setEnabled(
true );
238 if ( ( text == i18n(
"between" ) ) || ( text == i18n(
"different from" ) ) )
240 m_firstValue_2->setEnabled(
true );
241 m_secondValue_2->setEnabled(
true );
245 m_firstValue_2->setEnabled(
true );
246 m_secondValue_2->setEnabled(
false );
251void ConditionalWidget::slotTextChanged3(
const TQString & text )
253 if ( text == i18n(
"<none>" ) )
255 m_firstValue_3->setEnabled(
false );
256 m_secondValue_3->setEnabled(
false );
257 m_style_3->setEnabled(
false );
261 m_style_3->setEnabled(
true );
262 if ( ( text == i18n(
"between" ) ) || ( text == i18n(
"different from" ) ) )
264 m_firstValue_3->setEnabled(
true );
265 m_secondValue_3->setEnabled(
true );
269 m_firstValue_3->setEnabled(
true );
270 m_secondValue_3->setEnabled(
false );
279ConditionalDialog::ConditionalDialog(
View * parent,
const char * name,
280 const TQRect & marker )
281 : KDialogBase( parent, name, true,
"", KDialogBase::Ok | KDialogBase::Cancel,
282 KDialogBase::Ok, false ),
284 m_dlg( new ConditionalWidget( this ) ),
287 TQStringList list( m_view->doc()->styleManager()->styleNames() );
289 m_dlg->m_style_1->insertStringList( list );
290 m_dlg->m_style_2->insertStringList( list );
291 m_dlg->m_style_3->insertStringList( list );
293 setCaption( i18n(
"Conditional Cell Attributes" ) );
294 setButtonBoxOrientation(TQt::Vertical );
295 setMainWidget( m_dlg );
300void ConditionalDialog::init()
302 TQValueList<Conditional> conditionList;
303 TQValueList<Conditional> otherList;
307 TQValueList<Conditional>::iterator it1;
308 TQValueList<Conditional>::iterator it2;
310 Cell * obj = m_view->activeSheet()->cellAt( m_marker.left(),
317 for (
int x = m_marker.left(); x <= m_marker.right(); x++ )
319 for (
int y = m_marker.top(); y <= m_marker.bottom(); y++ )
321 Cell * obj2 = m_view->activeSheet()->cellAt( x, y );
324 it1 = conditionList.begin();
325 while ( it1 != conditionList.end() )
327 kdDebug() <<
"Here" << endl;
329 for ( it2 = otherList.begin(); !found && it2 != otherList.end(); ++it2 )
331 kdDebug() <<
"Found: " << found << endl;
332 found = ( (*it1).val1 == (*it2).val1 &&
333 (*it1).val2 == (*it2).val2 &&
334 (*it1).cond == (*it2).cond );
336 if ( (*it1).strVal1 && !(*it2).strVal1 )
338 if ( !(*it1).strVal1 && (*it2).strVal1 )
340 if ( (*it1).strVal1 && (*it2).strVal1
341 && ( *(*it1).strVal1 != *(*it2).strVal1 ) )
346 if ( (*it1).strVal2 && !(*it2).strVal2 )
348 if ( !(*it1).strVal2 && (*it2).strVal2 )
350 if ( (*it1).strVal2 && (*it2).strVal2
351 && ( *(*it1).strVal2 != *(*it2).strVal2 ) )
356 if ( (*it1).colorcond && !(*it2).colorcond )
358 if ( !(*it1).colorcond && (*it2).colorcond )
360 if ( (*it1).colorcond && (*it2).colorcond
361 && ( *(*it1).colorcond != *(*it2).colorcond ) )
366 if ( (*it1).fontcond && !(*it2).fontcond )
368 if ( !(*it1).fontcond && (*it2).fontcond )
370 if ( (*it1).fontcond && (*it2).fontcond
371 && ( *(*it1).fontcond != *(*it2).fontcond ) )
376 if ( (*it1).styleName && !(*it2).styleName )
378 if ( !(*it1).styleName && (*it2).styleName )
380 if ( (*it1).styleName && (*it2).styleName
381 && ( *(*it1).styleName != *(*it2).styleName ) )
387 it1 = conditionList.remove( it1 );
397 kdDebug() <<
"Conditions: " << conditionList.size() << endl;
399 m_dlg->m_condition_2->setEnabled(
false );
400 m_dlg->m_condition_3->setEnabled(
false );
402 m_dlg->m_style_1->setEnabled(
false );
403 m_dlg->m_style_2->setEnabled(
false );
404 m_dlg->m_style_3->setEnabled(
false );
407 for ( it1 = conditionList.begin(); numCondition < 3 && it1 != conditionList.end(); ++it1 )
409 init( *it1, numCondition );
415void ConditionalDialog::init(
Conditional const & tmp,
int numCondition )
417 kdDebug() <<
"Adding " << numCondition << endl;
424 switch( numCondition )
427 cb = m_dlg->m_condition_1;
428 sb = m_dlg->m_style_1;
429 kl1 = m_dlg->m_firstValue_1;
430 kl2 = m_dlg->m_secondValue_1;
433 cb = m_dlg->m_condition_2;
434 sb = m_dlg->m_style_2;
435 kl1 = m_dlg->m_firstValue_2;
436 kl2 = m_dlg->m_secondValue_2;
439 cb = m_dlg->m_condition_3;
440 sb = m_dlg->m_style_3;
441 kl1 = m_dlg->m_firstValue_3;
442 kl2 = m_dlg->m_secondValue_3;
450 sb->setCurrentText( *tmp.styleName );
451 sb->setEnabled(
true );
456 case Conditional::None :
459 case Conditional::Equal :
460 cb->setCurrentItem( 1 );
463 case Conditional::Superior :
464 cb->setCurrentItem( 2 );
467 case Conditional::Inferior :
468 cb->setCurrentItem( 3 );
471 case Conditional::SuperiorEqual :
472 cb->setCurrentItem( 4 );
475 case Conditional::InferiorEqual :
476 cb->setCurrentItem( 5 );
479 case Conditional::Between :
480 cb->setCurrentItem(6);
483 kl2->setText( *tmp.strVal2 );
486 value = value.setNum( tmp.val2 );
487 kl2->setText( value );
491 case Conditional::Different :
492 cb->setCurrentItem(7);
494 kl2->setText( *tmp.strVal2 );
497 value = value.setNum( tmp.val2 );
498 kl2->setText( value );
501 case Conditional::DifferentTo :
502 cb->setCurrentItem(8);
506 if ( tmp.cond != Conditional::None )
508 kl1->setEnabled(
true );
511 kl1->setText( *tmp.strVal1 );
514 value = value.setNum( tmp.val1 );
515 kl1->setText( value );
520Conditional::Type ConditionalDialog::typeOfCondition( TQComboBox
const *
const cb )
const
522 Conditional::Type result = Conditional::None;
523 switch( cb->currentItem() )
526 result = Conditional::None;
529 result = Conditional::Equal;
532 result = Conditional::Superior;
535 result = Conditional::Inferior;
538 result = Conditional::SuperiorEqual;
541 result = Conditional::InferiorEqual;
544 result = Conditional::Between;
547 result = Conditional::Different;
550 result = Conditional::DifferentTo;
553 kdDebug(36001) <<
"Error in list" << endl;
560bool ConditionalDialog::checkInputData( KLineEdit
const *
const edit1,
561 KLineEdit
const *
const edit2 )
566 if ( !edit2->isEnabled() )
569 edit1->text().toDouble( &b1 );
570 edit2->text().toDouble( &b2 );
575 KMessageBox::sorry( 0, i18n(
"If the first value is a number, the second value also has to be a number." ) );
577 KMessageBox::sorry( 0, i18n(
"If the first value is a string, the second value also has to be a string." ) );
584bool ConditionalDialog::checkInputData()
586 if ( m_dlg->m_firstValue_1->isEnabled() && !checkInputData( m_dlg->m_firstValue_1, m_dlg->m_secondValue_1 ) )
588 if ( m_dlg->m_firstValue_2->isEnabled() && !checkInputData( m_dlg->m_firstValue_2, m_dlg->m_secondValue_2 ) )
590 if ( m_dlg->m_firstValue_3->isEnabled() && !checkInputData( m_dlg->m_firstValue_3, m_dlg->m_secondValue_3 ) )
596bool ConditionalDialog::getCondition(
Conditional & newCondition,
const TQComboBox * cb,
597 const KLineEdit * edit1,
const KLineEdit * edit2,
598 const TQComboBox * sb,
Style * style )
600 if ( !cb->isEnabled() )
603 newCondition.cond = typeOfCondition( cb );
604 if ( newCondition.cond == Conditional::None )
608 double d1 = edit1->text().toDouble( &ok );
616 if ( edit2->isEnabled() )
617 d2 = edit2->text().toDouble( &ok );
623 s1 =
new TQString( edit1->text() );
625 if ( edit2->isEnabled() )
626 s2 =
new TQString( edit2->text() );
628 sn =
new TQString( sb->currentText() );
630 newCondition.val1 = d1;
631 newCondition.val2 = d2;
632 newCondition.strVal1 = s1;
633 newCondition.strVal2 = s2;
634 newCondition.fontcond = 0;
635 newCondition.colorcond = 0;
636 newCondition.styleName = sn;
637 newCondition.style = style;
642void ConditionalDialog::slotOk()
644 kdDebug() <<
"slotOk" << endl;
646 if ( !checkInputData() )
649 kdDebug() <<
"Input data is valid" << endl;
651 m_view->doc()->emitBeginOperation(
false );
652 StyleManager * manager = m_view->doc()->styleManager();
654 TQValueList<Conditional> newList;
656 Conditional newCondition;
658 if ( getCondition( newCondition, m_dlg->m_condition_1, m_dlg->m_firstValue_1,
659 m_dlg->m_secondValue_1, m_dlg->m_style_1, manager->style( m_dlg->m_style_1->currentText() ) ) )
660 newList.append( newCondition );
662 if ( getCondition( newCondition, m_dlg->m_condition_2, m_dlg->m_firstValue_2,
663 m_dlg->m_secondValue_2, m_dlg->m_style_2, manager->style( m_dlg->m_style_2->currentText() ) ) )
664 newList.append( newCondition );
666 if ( getCondition( newCondition, m_dlg->m_condition_3, m_dlg->m_firstValue_3,
667 m_dlg->m_secondValue_3, m_dlg->m_style_3, manager->style( m_dlg->m_style_3->currentText() ) ) )
668 newList.append( newCondition );
670 kdDebug() <<
"Setting conditional list" << endl;
671 m_view->activeSheet()->setConditional( m_view->selectionInfo(), newList );
672 m_view->slotUpdateView( m_view->activeSheet(), *m_view->selectionInfo() );
677#include "kspread_dlg_conditional.moc"
TQValueList< Conditional > conditionList() const
Gets a copy of the list of current conditions.
Structure to indicate the condition we're testing on a cell and the special font and color that will ...
The Style class represents a cell style.
The View class displays a KSpread document.