Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_I / VISU_TableDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : VISU_TableDlg.cxx
21 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
22 //
23 #include "VISU_TableDlg.h"
24
25 #include "VISU_Table_i.hh"
26
27 #include "SUIT_Tools.h"
28 #include "SUIT_MessageBox.h"
29 #include "SUIT_ResourceMgr.h"
30 #include "SUIT_Session.h"
31
32 #include "LightApp_Application.h"
33
34 #include "CAM_Module.h"
35
36 #include "SALOMEDSClient_Study.hxx"
37 #include "SALOMEDSClient_GenericAttribute.hxx"
38 #include "SALOMEDSClient_AttributeTableOfInteger.hxx"
39 #include "SALOMEDSClient_AttributeTableOfReal.hxx"
40 #include "SALOMEDSClient_StudyBuilder.hxx"
41
42 #include <QLayout>
43 #include <QTableWidget>
44 #include <QTabWidget>
45 #include <QList>
46 #include <QInputDialog>
47 #include <QLabel>
48 #include <QIntValidator>
49 #include <QDoubleValidator>
50 #include <QKeyEvent>
51 #include <QHeaderView>
52 #include <QPushButton>
53 #include <QLineEdit>
54 #include <QCheckBox>
55 #include <QComboBox>
56
57 #include "utilities.h"
58
59 const int MARGIN_SIZE      = 11;
60 const int SPACING_SIZE     = 6;
61 const int MIN_TABLE_WIDTH  = 200;
62 const int MIN_TABLE_HEIGHT = 200;
63
64 NumDelegateItem::NumDelegateItem( QObject* parent, NumValidator mode )
65   : QItemDelegate( parent ),
66     myMode( mode )
67 {
68 }
69
70 NumDelegateItem::~NumDelegateItem()
71 {
72 }
73
74 QWidget* NumDelegateItem::createEditor( QWidget* parent,
75                                         const QStyleOptionViewItem& option,
76                                         const QModelIndex& index ) const
77 {
78   QLineEdit* editor = new QLineEdit( parent );
79   switch ( myMode )
80   {
81   case NV_Int:
82     editor->setValidator( new QIntValidator( editor ) );
83     break;
84   case NV_Real:
85     editor->setValidator( new QDoubleValidator( editor ) );
86     break;
87   default:
88     break;
89   }
90   return editor;
91 }
92
93 void NumDelegateItem::setEditorData( QWidget* editor,
94                                      const QModelIndex& index ) const
95 {
96   QLineEdit* aLE = qobject_cast<QLineEdit*>( editor );
97   if ( !aLE )
98     return;
99   
100   switch ( myMode )
101   {
102   case NV_Int:
103     {
104       int value = index.model()->data( index, Qt::DisplayRole ).toInt();
105       aLE->setText( QString("%1").arg( value ) );
106       break;
107     }
108   case NV_Real:
109     {
110       double value = index.model()->data(index, Qt::DisplayRole).toDouble();
111       aLE->setText( QString("%1").arg( value ) );
112       break;
113     }
114   default:
115     aLE->setText( index.model()->data( index, Qt::DisplayRole ).toString() );
116     break;
117   }
118 }
119
120 class VISU_TableDlg::WidgetCointainer : public QWidget
121 {
122 public:
123   WidgetCointainer( QWidget* parent, Qt::Orientation o, int lm, int tm, int rm, int bm, int s )
124   : QWidget( parent )
125   {
126     QLayout* l = o == Qt::Horizontal ? (QLayout*)( new QHBoxLayout( this ) ) : ( QLayout* )( new QVBoxLayout( this ) );
127     l->setContentsMargins( lm, tm, rm, bm ); 
128     l->setSpacing( s );
129     setLayout( l );
130   }
131   void addWidget( QWidget* w )
132   {
133     if ( w ) {
134       QHBoxLayout* hl = qobject_cast<QHBoxLayout*>( layout() );
135       QVBoxLayout* wl = qobject_cast<QVBoxLayout*>( layout() );
136       if      ( hl ) hl->addWidget( w );
137       else if ( wl ) wl->addWidget( w );
138     }
139   }
140   void addSpacing( int s )
141   {
142     if ( s > 0 ) {
143       QHBoxLayout* hl = qobject_cast<QHBoxLayout*>( layout() );
144       QVBoxLayout* wl = qobject_cast<QVBoxLayout*>( layout() );
145       if      ( hl ) hl->addSpacing( s );
146       else if ( wl ) wl->addSpacing( s );
147     }
148   }
149   void addStretch( int s )
150   {
151     if ( s >= 0 ) {
152       QHBoxLayout* hl = qobject_cast<QHBoxLayout*>( layout() );
153       QVBoxLayout* wl = qobject_cast<QVBoxLayout*>( layout() );
154       if      ( hl ) hl->addStretch( s );
155       else if ( wl ) wl->addStretch( s );
156     }
157   }
158 };
159
160 /*class VISU_Table : public QTableWidget {
161 public:
162   VISU_Table( Orientation orient, QWidget* parent = 0 ) 
163     : QTableWidget( parent ), myValidator( 0 ), myOrientation( orient ) {}
164   VISU_Table( Orientation orient, int numRows, int numCols, QWidget* parent = 0 )
165     : QTableWidget( numRows, numCols, parent ), myValidator( 0 ), myOrientation( orient ) {}
166   
167   void setValidator( QValidator* v = 0 ) { myValidator = v;  }
168   bool isEditing() const { return QTable::isEditing(); }
169   
170 protected:
171   QWidget* createEditor ( int row, int col, bool initFromCell ) const
172     {
173       bool testUnits = ( myOrientation == Qt::Horizontal && col == 0 ) || ( myOrientation == Qt::Vertical && row == 0 );
174       QWidget* wg = QTable::createEditor( row, col, initFromCell );
175       if ( wg && wg->inherits("QLineEdit") && myValidator && !testUnits ) 
176         (( QLineEdit*)wg)->setValidator( myValidator );
177       return wg;
178     }
179
180 protected:
181   QValidator* myValidator;
182   Orientation myOrientation;
183   };*/
184
185 QString VISU_TableDlg::tableTitle( int type )
186 {
187   QString tlt;
188   switch ( type ) {
189   case ttInt:  tlt = tr( "TABLE_OF_INTEGER_TLT" ); break;
190   case ttReal: tlt = tr( "TABLE_OF_REAL_TLT" );    break;
191   default:     tlt = tr( "TABLE_UNKNOWN_TLT" );    break;
192   }
193   return tlt;
194 }
195 /*!
196   Constructor
197 */
198 VISU_TableDlg::VISU_TableDlg( QWidget* parent, 
199                               _PTR(Study) study, 
200                               VISU::Table_i* table,
201                               bool allowEdition,
202                               int which,
203                               Qt::Orientation orient,
204                               bool showColumnTitles )
205   : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), 
206     myStudy( study ), myTable( table ), myEditCheck( 0 ), myUpdateCheck( 0 )
207 {
208   allowEdition = true; //////////////////////////////////
209   setWindowTitle( tr( "VIEW_TABLE_TLT" ) );
210   setSizeGripEnabled( true );
211
212   bool bHasIntTable = false;
213   bool bHasRealTable = false;
214   if ( myStudy && myTable ) {
215     _PTR(SObject) aSObject = myStudy->FindObjectID( myTable->GetObjectEntry() );
216     if ( aSObject ) {
217       _PTR(GenericAttribute) anAttr;
218       bHasIntTable  = aSObject->FindAttribute( anAttr, "AttributeTableOfInteger" );
219       bHasRealTable = aSObject->FindAttribute( anAttr, "AttributeTableOfReal" );
220     }
221   }
222
223   if ( allowEdition ) {
224     myEditCheck = new QCheckBox( tr( "ALLOW_EDIT_CHECK" ), this );
225     myUpdateCheck = new QCheckBox( tr( "DO_UPDATE_CHECK" ), this );
226     connect( myEditCheck, SIGNAL( toggled( bool ) ), myUpdateCheck, SLOT( setEnabled( bool ) ) );
227     myUpdateCheck->setEnabled( false );
228     myUpdateCheck->hide(); // the feature has been temporarily disabled
229   }
230
231   QWidget* top = 0;
232
233   if ( which == ttInt  || which == ttAll || which == ttAuto && bHasIntTable ) {
234     myTableMap[ ttInt ]  = new TableWidget( this, orient );
235     myTableMap[ ttInt ]->initialize( myStudy, myTable, ttInt );
236     myTableMap[ ttInt ]->setEditEnabled( false );
237     myTableMap[ ttInt ]->showColumnTitles( showColumnTitles );
238     if ( myEditCheck )
239       connect( myEditCheck, SIGNAL( toggled( bool ) ), myTableMap[ ttInt ], SLOT( setEditEnabled( bool ) ) );
240   }
241   if ( which == ttReal || which == ttAll || which == ttAuto && bHasRealTable ) {
242     myTableMap[ ttReal ] = new TableWidget( this, orient );
243     myTableMap[ ttReal ]->initialize( myStudy, myTable, ttReal );
244     myTableMap[ ttReal ]->setEditEnabled( false );
245     myTableMap[ ttReal ]->showColumnTitles( showColumnTitles );
246     if ( myEditCheck )
247       connect( myEditCheck, SIGNAL( toggled( bool ) ), myTableMap[ ttReal ], SLOT( setEditEnabled( bool ) ) );
248   }
249   
250   if ( myTableMap.count() > 1 ) {
251     QTabWidget* tw = new QTabWidget( this );
252     for ( int i = ttInt; i < ttAll; i++ ) {
253       if ( myTableMap.contains( i ) ) {
254         tw->addTab( myTableMap[ i ], tableTitle( i ) );
255         myTableMap[ i ]->layout()->setMargin( MARGIN_SIZE );
256       }
257     }
258     top = tw;
259   }
260   else if ( myTableMap.count() == 1 ) {
261     top = myTableMap[myTableMap.keys().first()];
262   }
263   else {
264     QLabel* dumbLabel = new QLabel( tr( "ERR_TABLE_NOT_AVAILABLE" ), this );
265     dumbLabel->setAlignment( Qt::AlignCenter );
266     top = dumbLabel;
267   }
268
269   myOKBtn   = new QPushButton( tr( "BUT_OK" ), this );
270   myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this );
271   
272   QHBoxLayout* btnLayout = new QHBoxLayout; 
273   btnLayout->setMargin( 0 );
274   btnLayout->setSpacing( SPACING_SIZE );
275   
276   btnLayout->addWidget( myOKBtn );
277   btnLayout->addStretch( 20 );
278   btnLayout->addWidget( myHelpBtn );
279   connect( myOKBtn,   SIGNAL( clicked() ), this, SLOT( close() ) );
280   connect( myHelpBtn, SIGNAL( clicked() ), this, SLOT( help()  ) );
281
282   QVBoxLayout* mainLayout = new QVBoxLayout( this );
283   mainLayout->setMargin( MARGIN_SIZE );
284   mainLayout->setSpacing( SPACING_SIZE );
285
286   if ( myEditCheck ) {
287     QHBoxLayout* checkLayout = new QHBoxLayout; 
288     checkLayout->setMargin( 0 );
289     checkLayout->setSpacing( SPACING_SIZE );
290     checkLayout->addWidget( myEditCheck );
291     checkLayout->addWidget( myUpdateCheck );
292     mainLayout->addLayout( checkLayout );
293
294     if ( LightApp_Application* app = ( LightApp_Application* )SUIT_Session::session()->activeApplication() ) {
295       int anEnableEditing = app->resourceMgr()->booleanValue( "VISU", "tables_enable_editing", false );
296       myEditCheck->setChecked( anEnableEditing );
297     }
298   }
299   mainLayout->addWidget( top );
300   mainLayout->addLayout( btnLayout );
301
302   resize( 500, 400 );
303   SUIT_Tools::centerWidget( this, parent );
304 }
305
306 /*!
307   Destructor
308 */
309 VISU_TableDlg::~VISU_TableDlg()
310 {
311 }
312
313 /*!
314   <OK> button slot, saves table(s)
315   Called only in create/edit mode ( <edit> parameter for constructor is true )
316 */
317 /*
318 void VISU_TableDlg::onOK()
319 {
320   myOKBtn->setFocus(); // accept possible changes
321   bool done = true;
322
323   if ( myObject ) {
324     _PTR(Study) study = myObject->GetStudy();
325     _PTR(AttributeTableOfInteger) tblIntAttr;
326     _PTR(AttributeTableOfReal)    tblRealAttr;
327
328     if ( study ) {
329       _PTR(StudyBuilder) builder = study->NewBuilder();
330       builder->NewCommand(); // start transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
331       try {
332         if ( myTableMap.contains( ttInt ) ) {
333           builder->RemoveAttribute( myObject, "AttributeTableOfInteger" );
334           tblIntAttr = builder->FindOrCreateAttribute( myObject, "AttributeTableOfInteger" );
335
336           int i;
337           int nbRows  = myTableMap[ ttInt ]->getNumRows();
338           int nbCols  = myTableMap[ ttInt ]->getNumCols();
339           QString tlt = myTableMap[ ttInt ]->getTableTitle();
340           QStringList rowTitles, colTitles, units;
341           myTableMap[ ttInt ]->getRowTitles( rowTitles );
342           myTableMap[ ttInt ]->getColTitles( colTitles );
343           myTableMap[ ttInt ]->getUnits( units );
344           
345           if ( nbRows > 0) {
346             // data
347             int nRow = 0;
348             tblIntAttr->SetNbColumns( nbCols );
349             for ( i = 0; i < nbRows; i++ ) {
350               QStringList data;
351               myTableMap[ ttInt ]->getRowData( i, data );
352               bool bEmptyRow = true;
353               for ( int j = 0; j < data.count(); j++ ) {
354                 if ( !data[ j ].isNull() ) {
355                   tblIntAttr->PutValue( data[ j ].toInt(), nRow+1, j+1 );
356                   bEmptyRow = false;
357                 }
358               }
359               if ( !bEmptyRow ) {  // Skip rows with no data !!!
360                 // set row title
361                 tblIntAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : (const char*)rowTitles[ i ].toLatin1() ); 
362                 // set row unit
363                 tblIntAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : (const char*)units[ i ].toLatin1() ); 
364                 nRow++;
365               }
366             }
367             if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!!
368               // column titles
369               for ( i = 0; i < colTitles.count(); i++ )
370                 tblIntAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : (const char*)colTitles[ i ].toLatin1() );
371             }
372           }
373           // title
374           tblIntAttr->SetTitle( (const char*)myTableMap[ ttInt ]->getTableTitle().toLatin1() );
375         }
376         if ( myTableMap.contains( ttReal ) ) {
377           builder->RemoveAttribute( myObject, "AttributeTableOfReal" );
378           tblRealAttr = builder->FindOrCreateAttribute( myObject, "AttributeTableOfReal" );
379
380           int i;
381           int nbRows  = myTableMap[ ttReal ]->getNumRows();
382           int nbCols  = myTableMap[ ttReal ]->getNumCols();
383           QString tlt = myTableMap[ ttReal ]->getTableTitle();
384           QStringList rowTitles, colTitles, units;
385           myTableMap[ ttReal ]->getRowTitles( rowTitles );
386           myTableMap[ ttReal ]->getColTitles( colTitles );
387           myTableMap[ ttReal ]->getUnits( units );
388           
389           if ( nbRows > 0) {
390             // data
391             int nRow = 0;
392             tblRealAttr->SetNbColumns( nbCols );
393             for ( i = 0; i < nbRows; i++ ) {
394               QStringList data;
395               myTableMap[ ttReal ]->getRowData( i, data );
396               bool bEmptyRow = true;
397               for ( int j = 0; j < data.count(); j++ ) {
398                 if ( !data[ j ].isNull() ) {
399                   tblRealAttr->PutValue( data[ j ].toDouble(), nRow+1, j+1 );
400                   bEmptyRow = false;
401                 }
402               }
403               if ( !bEmptyRow ) {  // Skip rows with no data !!!
404                 // set row title
405                 tblRealAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : (const char*)rowTitles[ i ].toLatin1() ); 
406                 // set row unit
407                 tblRealAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : (const char*)units[ i ].toLatin1() );
408                 nRow++;
409               }
410             }
411             if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!!
412               // column titles
413               for ( i = 0; i < colTitles.count(); i++ )
414                 tblRealAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : (const char*)colTitles[ i ].toLatin1() );
415             }
416           }
417           // title
418           tblRealAttr->SetTitle( (const char*)myTableMap[ ttReal ]->getTableTitle().toLatin1() );
419         }
420         if ( myTableMap.contains( ttInt ) || myTableMap.contains( ttReal ) )
421           builder->CommitCommand(); // commit transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!
422         else
423           builder->AbortCommand();  // abort transaction  !!!!!!!!!!!!!!!!!!!!!!!!!!!
424       }
425       catch( ... ) {
426         MESSAGE("VISU_TableDlg::onOK : Exception has been caught !!!");
427         builder->AbortCommand();  // abort transaction  !!!!!!!!!!!!!!!!!!!!!!!!!!!
428         done = false;
429         SUIT_MessageBox::critical ( this, tr("ERR_ERROR"), tr("ERR_APP_EXCEPTION") );
430       }
431     }
432   }
433   if ( done ) 
434     accept();
435 }
436 */
437
438 /*!
439   <Help> button slot, shows corresponding help page
440 */
441 void VISU_TableDlg::help()
442 {
443   QString aHelpFileName = "table_presentations_page.html";
444   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
445   if (app)
446     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
447   else {
448     QString platform;
449 #ifdef WIN32
450     platform = "winapplication";
451 #else
452     platform = "application";
453 #endif
454     SUIT_MessageBox::warning( this,
455                               QObject::tr("WRN_WARNING"),
456                               QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
457                               arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
458   }
459 }
460
461 /*!
462   Provides help on F1 button click
463 */
464 void VISU_TableDlg::keyPressEvent( QKeyEvent* e )
465 {
466   QDialog::keyPressEvent( e );
467   if ( e->isAccepted() )
468     return;
469
470   if ( e->key() == Qt::Key_F1 ) {
471     e->accept();
472     help();
473   }
474 }
475
476 /*!
477   Constructor
478 */
479 VISU_TableDlg::TableWidget::TableWidget( QWidget* parent, 
480                                          Qt::Orientation orientation )
481   : QWidget( parent ), myOrientation( orientation )
482 {
483   myTitleEdit = new QLineEdit( this );
484
485   myTable = new QTableWidget( 5, 5, this );
486   myTable->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
487   myTable->setMinimumSize( MIN_TABLE_WIDTH, MIN_TABLE_HEIGHT );
488   myTable->setSelectionMode( QAbstractItemView::SingleSelection );
489   myTable->setShowGrid( true );
490   myTable->horizontalHeader()->setMovable( false );
491   myTable->verticalHeader()->setMovable( false );
492   myTable->setDragEnabled( false );
493
494   myAdjustBtn    = new QPushButton( VISU_TableDlg::tr( "ADJUST_CELLS_BTN" ),  this );
495   myAddRowBtn    = new QPushButton( VISU_TableDlg::tr( "ADD_ROW_BTN" ),       this );
496   myDelRowBtn    = new QPushButton( VISU_TableDlg::tr( "REMOVE_ROW_BTN" ),    this );
497   myAddColBtn    = new QPushButton( VISU_TableDlg::tr( "ADD_COLUMN_BTN" ),    this );
498   myDelColBtn    = new QPushButton( VISU_TableDlg::tr( "REMOVE_COLUMN_BTN" ), this );
499   mySelectAllBtn = new QPushButton( VISU_TableDlg::tr( "SELECT_ALL_BTN" ),    this );
500   myClearBtn     = new QPushButton( VISU_TableDlg::tr( "CLEAR_BTN" ),         this );
501
502   mySortPolicyLabel = new QLabel( VISU_TableDlg::tr( "VISU_TABLES_SORT_POLICY" ), this );
503   mySortPolicyCombo = new QComboBox( this );
504   mySortPolicyCombo->insertItems( 0, QStringList() <<
505                                   VISU_TableDlg::tr( "VISU_TABLES_EMPTY_LOWEST" ) <<
506                                   VISU_TableDlg::tr( "VISU_TABLES_EMPTY_HIGHEST" ) <<
507                                   VISU_TableDlg::tr( "VISU_TABLES_EMPTY_FIRST" ) <<
508                                   VISU_TableDlg::tr( "VISU_TABLES_EMPTY_LAST" ) <<
509                                   VISU_TableDlg::tr( "VISU_TABLES_EMPTY_IGNORE" ) );
510
511   if ( LightApp_Application* app = ( LightApp_Application* )SUIT_Session::session()->activeApplication() ) {
512     int aSortPolicy = app->resourceMgr()->integerValue( "VISU", "tables_sort_policy", 3 );
513     mySortPolicyCombo->setCurrentIndex( aSortPolicy );
514   }
515
516   // the features has been temporarily disabled
517   myAddRowBtn->hide();
518   myDelRowBtn->hide();
519   myAddColBtn->hide();
520   myDelColBtn->hide();
521   mySelectAllBtn->hide();
522   myClearBtn->hide();
523
524   QVBoxLayout* btnLayout = new QVBoxLayout;
525   btnLayout->setMargin( 0 );
526   btnLayout->setSpacing( SPACING_SIZE );
527   btnLayout->addWidget( myAdjustBtn );
528   btnLayout->addStretch( 20 );
529   btnLayout->addWidget( myAddRowBtn );
530   btnLayout->addWidget( myDelRowBtn );
531   btnLayout->addWidget( myAddColBtn );
532   btnLayout->addWidget( myDelColBtn );
533   btnLayout->addStretch( 20 );
534   btnLayout->addWidget( mySelectAllBtn );
535   btnLayout->addWidget( myClearBtn );
536
537   QHBoxLayout* sortLayout = new QHBoxLayout;
538   sortLayout->setMargin( 0 );
539   sortLayout->setSpacing( SPACING_SIZE );
540   sortLayout->addWidget( mySortPolicyLabel );
541   sortLayout->addWidget( mySortPolicyCombo );
542   sortLayout->addStretch( 1 );
543
544   QGridLayout* mainLayout = new QGridLayout( this );
545   mainLayout->setMargin( 0 );
546   mainLayout->setSpacing( SPACING_SIZE );
547   mainLayout->addWidget( myTitleEdit, 0, 0, 1, 2 );
548   mainLayout->addWidget( myTable,     1, 0 );
549   mainLayout->addLayout( btnLayout,   1, 1 );
550   mainLayout->addLayout( sortLayout,  2, 0, 1, 2 );
551
552   connect( myTable, SIGNAL( itemSelectionChanged() ),
553            this, SLOT( updateButtonsState() ) );
554   connect( myTable, SIGNAL( currentItemChanged( QTableWidgetItem*, QTableWidgetItem* ) ),
555            this, SLOT( updateButtonsState() ) );
556   connect( myAddRowBtn,    SIGNAL( clicked() ),   this, SLOT( addRow() ) );
557   connect( myAddColBtn,    SIGNAL( clicked() ),   this, SLOT( addCol() ) );
558   connect( myDelRowBtn,    SIGNAL( clicked() ),   this, SLOT( delRow() ) );
559   connect( myDelColBtn,    SIGNAL( clicked() ),   this, SLOT( delCol() ) );
560   connect( myAdjustBtn,    SIGNAL( clicked() ),   this, SLOT( adjustTable() ) );
561   connect( mySelectAllBtn, SIGNAL( clicked() ),   this, SLOT( selectAll() ) );
562   connect( myClearBtn,     SIGNAL( clicked() ),   this, SLOT( clearTable() ) );
563   connect( myTable->horizontalHeader(), SIGNAL( sectionClicked( int ) ),
564            this, SLOT( columnClicked( int ) ) );
565   connect( myTable->verticalHeader(), SIGNAL( sectionClicked( int ) ),
566            this, SLOT( rowClicked( int ) ) );
567   myTable->horizontalHeader()->installEventFilter( this );
568   myTable->verticalHeader()->installEventFilter( this );
569   myTable->installEventFilter( this );
570
571   updateButtonsState();
572 }
573
574 /*!
575   Destructor
576 */
577 VISU_TableDlg::TableWidget::~TableWidget()
578 {
579 }
580
581 /*!
582   Initialize widget
583 */
584 void VISU_TableDlg::TableWidget::initialize( _PTR(Study) study, VISU::Table_i* table, int type )
585 {
586   myStudy = study;
587   myTableObj = table;
588   myType = type;
589
590   setUnitsTitle( VISU_TableDlg::tr( "UNITS_TLT" ) );
591   setEditEnabled( false );
592   showColumnTitles( false );
593
594   updateTableFromServant( true );
595   updateButtonsState();
596 }
597
598 void VISU_TableDlg::TableWidget::updateTableFromServant( bool adjust )
599 {
600   _PTR(SObject) aSObject = myStudy->FindObjectID( myTableObj->GetObjectEntry() );
601   if ( aSObject ) {
602     int i, j;
603     switch ( myType ) {
604     case ttInt:
605       myTable->setItemDelegate( new NumDelegateItem( this, NumDelegateItem::NV_Int ) );
606       if ( aSObject->FindAttribute( myAttr, "AttributeTableOfInteger" ) ) {
607         _PTR(AttributeTableOfInteger) intAttr  = myAttr;
608         try {
609           // title
610           setTableTitle( intAttr->GetTitle().c_str() );
611           // nb of rows & cols
612           int nbRows = intAttr->GetNbRows() ; 
613           int nbCols = intAttr->GetNbColumns();
614           setNumRows( nbRows );
615           setNumCols( nbCols );
616           // rows titles
617           QStringList strlist;
618           std::vector<std::string> titles = intAttr->GetRowTitles();
619           for ( i = 0; i < nbRows; i++ ) {
620             if ( titles.size() > 0 )
621               strlist.append( titles[i].c_str() );
622             else
623               strlist.append( "" );
624           }
625           setRowTitles( strlist );
626           // columns titles
627           strlist.clear();
628           titles = intAttr->GetColumnTitles();
629           for ( i = 0; i < nbCols; i++ ) {
630             if ( titles.size() > 0 )
631               strlist.append( titles[i].c_str() );
632             else
633               strlist.append( "" );
634           }
635           setColTitles( strlist );
636           // units
637           strlist.clear();
638           titles = intAttr->GetRowUnits();
639           if ( titles.size() > 0 ) {
640             for ( i = 0; i < nbRows; i++ )
641               strlist.append( titles[i].c_str() );
642             setUnits( strlist );
643           }
644           // data
645           for ( i = 1; i <= nbRows; i++ ) {
646             strlist.clear();
647             for ( j = 1; j <= nbCols; j++ ) {
648               if ( intAttr->HasValue( i, j ) )
649                 strlist.append( QString::number( intAttr->GetValue( i, j ) ) );
650               else
651                 strlist.append( QString::null );
652             }
653             setRowData( i-1, strlist );
654           }
655           if ( adjust ) adjustTable();
656         }
657         catch( ... ) {
658           MESSAGE("VISU_TableDlg::TableWidget::initialize : Exception has been caught !!!");
659         }
660       }
661       break;
662     case ttReal:
663       myTable->setItemDelegate( new NumDelegateItem( this, NumDelegateItem::NV_Real ) );
664       if ( aSObject->FindAttribute( myAttr, "AttributeTableOfReal" ) ) {
665         _PTR(AttributeTableOfReal) realAttr = myAttr;
666         try {
667           // title
668           setTableTitle( realAttr->GetTitle().c_str() );
669           // nb of rows & cols
670           int nbRows = realAttr->GetNbRows() ; 
671           int nbCols = realAttr->GetNbColumns();
672           setNumRows( nbRows );
673           setNumCols( nbCols );
674           // rows titles
675           QStringList strlist;
676           std::vector<std::string> titles = realAttr->GetRowTitles();
677           for ( i = 0; i < nbRows; i++ ) {
678             if ( titles.size() > 0 )
679               strlist.append( titles[i].c_str() );
680             else
681               strlist.append( "" );
682           }
683           setRowTitles( strlist );
684           // columns titles
685           strlist.clear();
686           titles = realAttr->GetColumnTitles();
687           for ( i = 0; i < nbCols; i++ ) {
688             if ( titles.size() > 0 )
689               strlist.append( titles[i].c_str() );
690             else
691               strlist.append( "" );
692           }
693           setColTitles( strlist );
694           // units
695           strlist.clear();
696           titles = realAttr->GetRowUnits();
697           if ( titles.size() > 0 ) {
698             for ( i = 0; i < nbRows; i++ )
699               strlist.append( titles[i].c_str() );
700             setUnits( strlist );
701           }
702           // data
703           for ( i = 1; i <= nbRows; i++ ) {
704             strlist.clear();
705             for ( j = 1; j <= nbCols; j++ ) {
706               if ( realAttr->HasValue( i, j ) )
707                 strlist.append( QString::number( realAttr->GetValue( i, j ) ) );
708               else
709                 strlist.append( QString::null );
710             }
711             setRowData( i-1, strlist );
712           }
713           if ( adjust ) adjustTable();
714         }
715         catch( ... ) {
716           MESSAGE("VISU_TableDlg::TableWidget::initialize : Exception has been caught !!!");
717         }
718       }
719       break;
720     default:
721       break;
722     }
723   }
724 }
725
726 /*!
727   Enable / disable editing
728 */
729 void VISU_TableDlg::TableWidget::setEditEnabled( bool enable )
730 {
731   if( !enable ) {
732     myTable->horizontalHeader()->setSortIndicatorShown( false );
733     myTable->verticalHeader()->setSortIndicatorShown( false );
734     //adjustTable();
735   }
736
737   mySortPolicyLabel->setEnabled( enable );
738   mySortPolicyCombo->setEnabled( enable );
739
740   // the rest features have been temporarily disabled
741   enable = false;
742
743   myTitleEdit->setReadOnly( !enable );
744   myTable->setEditTriggers( enable ? 
745                             QAbstractItemView::DoubleClicked   | 
746                             QAbstractItemView::SelectedClicked | 
747                             QAbstractItemView::EditKeyPressed  :
748                             QAbstractItemView::NoEditTriggers );
749   myAddRowBtn->setVisible( enable );
750   myDelRowBtn->setVisible( enable );
751   myAddColBtn->setVisible( enable );
752   myDelColBtn->setVisible( enable );
753   mySelectAllBtn->setVisible( enable );
754   myClearBtn->setVisible( enable );
755 }
756
757 /*!
758   Show / hide column titles
759 */
760 void VISU_TableDlg::TableWidget::showColumnTitles( bool showTitles )
761 {
762   if ( myOrientation == Qt::Horizontal )
763     myTable->horizontalHeader()->setVisible( showTitles );
764   else
765     myTable->verticalHeader()->setVisible( showTitles );
766 }
767   
768 /*!
769   Sets table title
770 */
771 void VISU_TableDlg::TableWidget::setTableTitle( const QString& title )
772 {
773   myTitleEdit->setText( title );
774 }
775
776 /*!
777   Gets table title
778 */
779 QString VISU_TableDlg::TableWidget::getTableTitle()
780 {
781   return myTitleEdit->text();
782 }
783
784 /*!
785   Sets total number of rows
786 */
787 void VISU_TableDlg::TableWidget::setNumRows( const int num )
788 {
789   myOrientation == Qt::Horizontal ? myTable->setRowCount( num ) : myTable->setColumnCount( num );
790 }
791
792 /*!
793   Gets total number of rows
794 */
795 int VISU_TableDlg::TableWidget::getNumRows()
796 {
797   return myOrientation == Qt::Horizontal ? myTable->rowCount() : myTable->columnCount();
798 }
799
800 /*!
801   Sets total number of columns
802 */
803 void VISU_TableDlg::TableWidget::setNumCols( const int num )
804 {
805   // !!! first column contains units !!!
806   myOrientation == Qt::Horizontal ? myTable->setColumnCount( num+1 ) : myTable->setRowCount( num+1 );
807 //  myOrientation == Qt::Horizontal ? myTable->setColumnReadOnly( 0, true ) : myTable->setRowReadOnly( 0, true );
808 }
809
810 /*!
811   Gets total number of columns
812 */
813 int VISU_TableDlg::TableWidget::getNumCols()
814 {
815   // !!! first column contains units !!!
816   return myOrientation == Qt::Horizontal ? myTable->columnCount()-1 : myTable->rowCount()-1;
817 }
818 /*!
819   Sets rows titles
820 */
821 void VISU_TableDlg::TableWidget::setRowTitles( QStringList& tlts )
822 {
823   QStringList aLabels;
824   for ( int i = 0; i < tlts.count(); i++ )
825     tlts[i].isNull() ? aLabels.append("") : aLabels.append( tlts[i] );
826
827   myOrientation == Qt::Horizontal ?
828     myTable->setVerticalHeaderLabels( aLabels ) :
829     myTable->setHorizontalHeaderLabels( aLabels );
830     
831     //  myTable->verticalHeader()->setLabel( i, tlts[i] ) : 
832     //myTable->horizontalHeader()->setLabel( i, tlts[i] );
833   //}
834 }
835 /*!
836   Gets rows titles
837 */
838 void VISU_TableDlg::TableWidget::getRowTitles( QStringList& tlts )
839 {
840   tlts.clear();
841   if ( myOrientation == Qt::Horizontal ) {
842     for ( int i = 0; i < myTable->rowCount(); i++ ) {
843       tlts.append( myTable->verticalHeaderItem(i) ? myTable->verticalHeaderItem(i)->text() : "" );
844     }
845   }
846   else {
847     for ( int i = 0; i < myTable->columnCount(); i++ ) {
848       tlts.append( myTable->horizontalHeaderItem(i) ? myTable->horizontalHeaderItem(i)->text() : "" );
849     }
850   }
851 }
852 /*!
853   Sets columns titles
854 */
855 void VISU_TableDlg::TableWidget::setColTitles( QStringList& tlts )
856 {
857   QStringList aLabels;
858
859   // !!! first column contains units !!!
860   aLabels.append(""); // it'll be initialized below - in setUnitsTitle() method
861
862   for ( int i = 0; i < tlts.count(); i++ )
863     tlts[i].isNull() ? aLabels.append("") : aLabels.append( tlts[i] );
864
865   myOrientation == Qt::Horizontal ?
866     myTable->setHorizontalHeaderLabels( aLabels ) :
867     myTable->setVerticalHeaderLabels( aLabels );
868   
869   setUnitsTitle( VISU_TableDlg::tr( "UNITS_TLT" ) );
870 }
871 /*!
872   Sets columns titles
873 */
874 void VISU_TableDlg::TableWidget::getColTitles( QStringList& tlts )
875 {
876   // !!! first column contains units !!!
877   tlts.clear();
878   if ( myOrientation == Qt::Horizontal ) {
879     for ( int i = 1; i < myTable->columnCount(); i++ ) {
880       tlts.append( myTable->horizontalHeaderItem(i) ? myTable->horizontalHeaderItem(i)->text() : "" );
881     }    
882   }
883   else {
884     for ( int i = 1; i < myTable->rowCount(); i++ ) {
885       tlts.append( myTable->verticalHeaderItem(i) ? myTable->verticalHeaderItem(i)->text() : "" );
886     }
887   }
888 }
889 /*!
890   Sets units title
891 */
892 void VISU_TableDlg::TableWidget::setUnitsTitle( const QString& tlt ) {
893   // !!! first column contains units !!!
894   myTable->model()->setHeaderData( 0, myOrientation, QVariant(tlt.isNull() ? "" : tlt), Qt::DisplayRole );
895 }
896 /*!
897   Sets units
898 */
899 void VISU_TableDlg::TableWidget::setUnits( QStringList& units )
900 {
901   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
902   if ( aModel )
903   {
904     QModelIndex anIndex;
905     for ( int i = 0; i < units.count(); i++ )
906     {
907       myOrientation == Qt::Horizontal ?
908         anIndex = aModel->index( i, 0 ) :
909         anIndex = aModel->index( 0, i );
910
911       aModel->setData( anIndex, QVariant( units[i].isNull() ? "" : units[i] ) );      
912     }
913   }
914 }
915 /*!
916   Gets units
917 */
918 void VISU_TableDlg::TableWidget::getUnits( QStringList& units )
919 {
920   units.clear();
921   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
922   if ( aModel )
923   {
924     if ( myOrientation == Qt::Horizontal )
925     {
926       for ( int i = 0; i < myTable->rowCount(); i++ )
927         units.append( aModel->index( i, 0 ).data().toString() );
928     }
929     else {
930       for ( int i = 0; i < myTable->columnCount(); i++ )
931         units.append( aModel->index( 0, i ).data().toString() );
932     }
933   }
934 }
935 /*!
936   Sets row data
937 */
938 void VISU_TableDlg::TableWidget::setRowData( int row, QStringList& data )
939 {
940   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
941   if ( aModel )
942   {
943     QModelIndex anIndex; 
944     if ( row >= 0 && row < getNumRows() ) {
945       for ( int i = 0; i < data.count(); i++ )
946       {
947         myOrientation == Qt::Horizontal ? anIndex = aModel->index( row, i+1 ) :
948                                           anIndex = aModel->index( i+1, row );
949         aModel->setData( anIndex, QVariant( data[i] ) );
950           
951       }
952     }
953   }
954 }
955 /*!
956   Gets row data
957 */
958 void VISU_TableDlg::TableWidget::getRowData( int row, QStringList& data )
959 {
960   data.clear();
961   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
962   if ( aModel )
963   {
964     if ( row >= 0 && row < getNumRows() )
965     {
966       if ( myOrientation == Qt::Horizontal )
967       {
968         for ( int i = 1; i < myTable->columnCount(); i++ )
969           data.append( aModel->index( row, i ).data().toString() );
970       }
971       else {
972         for ( int i = 1; i < myTable->rowCount(); i++ )
973           data.append( aModel->index( i, row ).data().toString() );
974       }
975     }
976   }
977 }
978 /*!
979   Adjusts table cell to see contents, <Adjust Cells> button slot
980 */
981 void VISU_TableDlg::TableWidget::adjustTable()
982 {
983   myTable->resizeRowsToContents();
984   myTable->resizeColumnsToContents();
985 }
986 /*!
987   Called when selection changed in table
988 */
989 void VISU_TableDlg::TableWidget::updateButtonsState()
990 {
991   if ( myTable->editTriggers() == QAbstractItemView::NoEditTriggers )
992     return;
993   bool bDR = false; // <Delete Row(s)>
994   bool bDC = false; // <Delete Column(s)>
995   bool bSA = false; // <Select All>
996   bool bCT = false; // <Clear>
997   int i;
998   //TO DO column/row selection check
999   /*int c = myOrientation == Qt::Horizontal ? 0 : 1;
1000   for ( i = c; i < myTable->rowCount(); i++ ) {
1001     
1002     if ( myTable->isRowSelected( i, true ) )
1003       bDR = true;
1004     else 
1005       bSA = true;
1006   }
1007   c = myOrientation == Qt::Horizontal ? 1 : 0;
1008   for ( i = c; i < myTable->columnCount(); i++ ) {
1009     if ( myTable->isColumnSelected( i, true ) )
1010       bDC = true;
1011     else 
1012       bSA = true;
1013       }*/
1014   /*int nbSel = myTable->numSelections();
1015   for ( i = 0; i < nbSel; i++ ) {
1016     QTableSelection ts = myTable->selection( i );
1017     for ( int j = ts.topRow(); j < ts.bottomRow()+1; j++) {
1018       for ( int k = ts.leftCol(); k < ts.rightCol()+1; k++) {
1019         if ( myTable->item( j, k ) )
1020           bCT = true;
1021       }
1022     }
1023     }*/
1024   QList<QTableWidgetItem*> aSelection = myTable->selectedItems();
1025   QList<QTableWidgetItem*>::ConstIterator anIt = aSelection.constBegin(),
1026     anEndIt = aSelection.constEnd();
1027   for ( ; anIt !=  anEndIt; anIt++ )
1028   {
1029     if( *anIt )
1030     {
1031       bCT = true;
1032       break;
1033     }
1034   }
1035   
1036   if ( myTable->item( myTable->currentRow(), myTable->currentColumn() ) )
1037     bCT = true;
1038   myDelRowBtn->setEnabled( bDR );
1039   myDelColBtn->setEnabled( bDC );
1040   mySelectAllBtn->setEnabled( bSA );
1041   myClearBtn->setEnabled( bCT );
1042 }
1043 /*!
1044   <Add row> button slot
1045 */
1046 void VISU_TableDlg::TableWidget::addRow()
1047 {
1048   myTable->insertRow( myTable->rowCount() );
1049   updateButtonsState();
1050 }
1051 /*!
1052   <Add column> button slot
1053 */
1054 void VISU_TableDlg::TableWidget::addCol()
1055 {
1056   myTable->insertColumn( myTable->columnCount() );
1057   updateButtonsState();
1058 }
1059 /*!
1060   <Delete row(s)> button slot
1061 */
1062 void VISU_TableDlg::TableWidget::delRow()
1063 {
1064   //TODO
1065   /*int c = myOrientation == Qt::Horizontal ? 0 : 1;
1066   QList<int> il;
1067   int i;
1068   for ( i = c; i < myTable->rowCount(); i++ )
1069     if ( myTable->isRowSelected( i, true ) )
1070       il.append( i );
1071   if ( il.count() > 0 ) {
1072     QMemArray<int> ildel( il.count() );
1073     for ( i = 0; i < il.count(); i++ )
1074       ildel[ i ] = il[ i ];
1075     myTable->removeRows( ildel );
1076     }*/
1077   
1078   updateButtonsState();
1079 }
1080 /*!
1081   <Delete column(s)> button slot
1082 */
1083 void VISU_TableDlg::TableWidget::delCol()
1084 {
1085   //TODO
1086   /*int c = myOrientation == Qt::Horizontal ? 1 : 0;
1087   QValueList<int> il;
1088   int i;
1089   for ( i = c; i < myTable->numCols(); i++ )
1090     if ( myTable->isColumnSelected( i, true ) )
1091       il.append( i );
1092   if ( il.count() > 0 ) {
1093     QMemArray<int> ildel( il.count() );
1094     for ( i = 0; i < il.count(); i++ )
1095       ildel[ i ] = il[ i ];
1096     myTable->removeColumns( ildel );
1097     }*/
1098   updateButtonsState();
1099 }
1100 /*!
1101   <Select All> button slot
1102 */
1103 void VISU_TableDlg::TableWidget::selectAll()
1104 {
1105   /*myTable->clearSelection();
1106   QTableSelection ts;
1107   ts.init( 0, 0 ); ts.expandTo( myTable->numRows()-1, myTable->numCols()-1 );
1108   myTable->addSelection( ts );*/
1109   myTable->selectAll();
1110   updateButtonsState();
1111 }
1112 /*!
1113   <Clear> button slot
1114 */
1115 void VISU_TableDlg::TableWidget::clearTable()
1116 {
1117   /*int nbSel = myTable->numSelections();
1118   for ( int i = 0; i < nbSel; i++ ) {
1119     QTableSelection ts = myTable->selection( i );
1120     for ( int j = ts.topRow(); j < ts.bottomRow()+1; j++) {
1121       if ( myOrientation == Qt::Vertical && j == 0 ) {
1122 //      continue;      // UNITS
1123       }
1124       for ( int k = ts.leftCol(); k < ts.rightCol()+1; k++) {
1125         if ( myOrientation == Qt::Horizontal && k == 0 ) {
1126 //        continue;   // UNITS
1127         }
1128         myTable->clearCell( j, k );
1129       }
1130     }
1131   }
1132   if ( nbSel == 0 )
1133     myTable->clearCell( myTable->currentRow(), myTable->currentColumn() );
1134     myTable->clearSelection();*/
1135   myTable->clearContents();
1136   updateButtonsState();
1137 }
1138 /*!
1139   Column clicked slot
1140 */
1141 void VISU_TableDlg::TableWidget::columnClicked( int column )
1142 {
1143   if ( myTableObj && mySortPolicyCombo->isEnabled() ) {
1144     myTableObj->SortByRow( column + 1,
1145                            ( VISU::SortOrder )myTable->horizontalHeader()->sortIndicatorOrder(),
1146                            ( VISU::SortPolicy )mySortPolicyCombo->currentIndex() );
1147     myTable->horizontalHeader()->setSortIndicatorShown( true );
1148     myTable->verticalHeader()->setSortIndicatorShown( false );
1149     updateTableFromServant( false );
1150   }
1151 }
1152 /*!
1153   Row clicked slot
1154 */
1155 void VISU_TableDlg::TableWidget::rowClicked( int row )
1156 {
1157   /* the feature has been temporarily disabled
1158   if ( myTableObj && mySortPolicyCombo->isEnabled() && row > 0 ) { // first row contains units
1159     myTableObj->SortByColumn( row,
1160                               ( VISU::SortOrder )myTable->verticalHeader()->sortIndicatorOrder(),
1161                               ( VISU::SortPolicy )mySortPolicyCombo->currentIndex() );
1162     myTable->horizontalHeader()->setSortIndicatorShown( false );
1163     myTable->verticalHeader()->setSortIndicatorShown( true );
1164     updateTableFromServant( false );
1165   }
1166   */
1167 }
1168 /*!
1169   Event filter - handles titles editing
1170 */
1171 bool VISU_TableDlg::TableWidget::eventFilter( QObject* o, QEvent* e )
1172 {
1173   if ( e->type() == QEvent::MouseButtonDblClick) {
1174     //TODO
1175     /*QMouseEvent* me = ( QMouseEvent* )e;
1176     if ( me->button() == Qt::LeftButton && (myTable->editTriggers() != QAbstractItemView::NoEditTriggers ) ) {
1177       if ( o == myTable->horizontalHeader() ) {
1178         for ( int i = 0; i < myTable->horizontalHeader()->count(); i++ ) {
1179           QRect rect = myTable->horizontalHeader()->sectionRect( i );
1180           rect.addCoords( 1, 1, -1, -1 );
1181           if ( rect.contains( myTable->horizontalHeader()->mapFromGlobal( me->globalPos() ) ) ) {
1182             if ( myOrientation == Qt::Vertical || i != 0 ) {
1183               bool bOk;
1184               QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ), 
1185                                                    tr( "TITLE_LBL" ),
1186                                                    QLineEdit::Normal,
1187                                                    myTable->horizontalHeader()->label( i ),
1188                                                    &bOk,
1189                                                    this );
1190               if ( bOk && !tlt.isNull() )
1191                 myTable->horizontalHeader()->setLabel( i, tlt );
1192               break;
1193             }
1194           }
1195         }
1196       }
1197       if ( o == myTable->verticalHeader() ) {
1198         for ( int i = 0; i < myTable->verticalHeader()->count(); i++ ) {
1199           QRect rect = myTable->verticalHeader()->sectionRect( i );
1200           rect.addCoords( 1, 1, -1, -1 );
1201           if ( rect.contains( myTable->verticalHeader()->mapFromGlobal( me->globalPos() ) ) ) {
1202             if ( myOrientation == Qt::Horizontal || i != 0 ) {
1203               bool bOk;
1204               QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ), 
1205                                                    tr( "TITLE_LBL" ),
1206                                                    QLineEdit::Normal,
1207                                                    myTable->verticalHeader()->label( i ),
1208                                                    &bOk,
1209                                                    this );
1210               if ( bOk && !tlt.isNull() )
1211                 myTable->verticalHeader()->setLabel( i, tlt );
1212               break;
1213             }
1214           }
1215         }
1216       }
1217       }*/    
1218   }     
1219   else if ( e->type() == QEvent::KeyRelease && o == myTable ) {
1220     QKeyEvent* ke = (QKeyEvent*)e;
1221     if ( ke->key() == Qt::Key_Delete && (myTable->editTriggers() != QAbstractItemView::NoEditTriggers) ) {
1222       clearTable();
1223     }
1224     else if ( ke->key() == Qt::Key_Backspace && (myTable->editTriggers() != QAbstractItemView::NoEditTriggers) ) {
1225       clearTable();
1226       int i = myTable->currentRow();
1227       int j = myTable->currentColumn() - 1;
1228       if ( j < 0 ) { j = myTable->columnCount()-1; i--; }
1229       if ( i >= 0 && j >= 0 )
1230         myTable->setCurrentCell( i, j );
1231     }
1232   }
1233   return QWidget::eventFilter( o, e );
1234 }