Salome HOME
Test EXPORTS definition with target name as suggested by cmake
[modules/visu.git] / src / GUITOOLS / VisuGUI_TableDlg.cxx
index 6987d52e7e0aa2d43e742181e46b97c200901131..5bf64aa48f39fac5986d9659211f75a0237abb4e 100644 (file)
@@ -1,26 +1,28 @@
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : VisuGUI_TableDlg.cxx
 //  Author : Vadim SANDLER
 //  Module : SALOME
-
+//
 #include "VisuGUI_TableDlg.h"
 
 #include "SUIT_Tools.h"
 
 #include "LightApp_Application.h"
 
+#include "CAM_Module.h"
+
 #include "SALOMEDSClient_Study.hxx"
 #include "SALOMEDSClient_GenericAttribute.hxx"
 #include "SALOMEDSClient_AttributeTableOfInteger.hxx"
 #include "SALOMEDSClient_AttributeTableOfReal.hxx"
 #include "SALOMEDSClient_StudyBuilder.hxx"
 
-#include <qlayout.h>
-#include <qvalidator.h>
-#include <qtable.h>
-#include <qtabwidget.h>
-#include <qvaluelist.h>
-#include <qmemarray.h>
-#include <qinputdialog.h>
-#include <qlabel.h>
+#include <QLayout>
+#include <QValidator>
+#include <QTableWidget>
+#include <QTabWidget>
+#include <QList>
+#include <QVector>
+#include <QInputDialog>
+#include <QLabel>
+#include <QIntValidator>
+#include <QDoubleValidator>
+#include <QKeyEvent>
+#include <QHeaderView>
+
 #include "utilities.h"
+
 using namespace std;
 
 #define MARGIN_SIZE       11
@@ -53,13 +63,72 @@ using namespace std;
 #define MIN_TABLE_WIDTH   200
 #define MIN_TABLE_HEIGHT  200
 
+NumDelegateItem::NumDelegateItem( QObject* parent, NumValidator mode )
+  : QItemDelegate( parent ),
+    myMode( mode )
+{
+}
+
+NumDelegateItem::~NumDelegateItem()
+{
+}
+
+QWidget * NumDelegateItem::createEditor( QWidget * parent,
+                                         const QStyleOptionViewItem & option,
+                                         const QModelIndex & index ) const
+{
+  QLineEdit *editor = new QLineEdit(parent);
+  switch ( myMode )
+  {
+  case NV_Int:
+    editor->setValidator( new QIntValidator( editor ) );
+    break;
+  case NV_Real:
+    editor->setValidator( new QDoubleValidator( editor ) );
+    break;
+  default:
+    editor->setText( "No validator!" );
+  }
+  
+  return editor;
+}
+
+void NumDelegateItem::setEditorData( QWidget * editor,
+                                     const QModelIndex & index ) const
+{
+  QLineEdit *aLE = qobject_cast<QLineEdit*>(editor);
+  if ( !aLE )
+    return;
+  
+  switch ( myMode )
+  {
+  case NV_Int:
+    {
+      int value = index.model()->data(index, Qt::DisplayRole).toInt();
+      aLE->setText( QString("%1").arg( value ) );
+      break;
+    }
+  case NV_Real:
+    {
+      double value = index.model()->data(index, Qt::DisplayRole).toDouble();
+      aLE->setText( QString("%1").arg( value ) );
+      break;
+    }
+  default:
+    aLE->setText( "No validator!!!" );
+  }  
+}
+
+
+
 
-class VisuGUI_Table : public QTable {
+
+/*class VisuGUI_Table : public QTableWidget {
 public:
-  VisuGUI_Table( Orientation orient, QWidget* parent = 0, const char* name = 0 ) 
-    : QTable( parent, name ), myValidator( 0 ), myOrientation( orient ) {}
-  VisuGUI_Table( Orientation orient, int numRows, int numCols, QWidget* parent = 0, const char* name = 0 )
-    : QTable( numRows, numCols, parent, name ), myValidator( 0 ), myOrientation( orient ) {}
+  VisuGUI_Table( Orientation orient, QWidget* parent = 0 ) 
+    : QTableWidget( parent ), myValidator( 0 ), myOrientation( orient ) {}
+  VisuGUI_Table( Orientation orient, int numRows, int numCols, QWidget* parent = 0 )
+    : QTableWidget( numRows, numCols, parent ), myValidator( 0 ), myOrientation( orient ) {}
   
   void setValidator( QValidator* v = 0 ) { myValidator = v;  }
   bool isEditing() const { return QTable::isEditing(); }
@@ -67,7 +136,7 @@ public:
 protected:
   QWidget* createEditor ( int row, int col, bool initFromCell ) const
     {
-      bool testUnits = ( myOrientation == Horizontal && col == 0 ) || ( myOrientation == Vertical && row == 0 );
+      bool testUnits = ( myOrientation == Qt::Horizontal && col == 0 ) || ( myOrientation == Qt::Vertical && row == 0 );
       QWidget* wg = QTable::createEditor( row, col, initFromCell );
       if ( wg && wg->inherits("QLineEdit") && myValidator && !testUnits ) 
        (( QLineEdit*)wg)->setValidator( myValidator );
@@ -77,7 +146,7 @@ protected:
 protected:
   QValidator* myValidator;
   Orientation myOrientation;
-};
+  };*/
 
 /*!
   Constructor
@@ -86,12 +155,12 @@ VisuGUI_TableDlg::VisuGUI_TableDlg( QWidget* parent,
                                    _PTR(SObject) obj, 
                                    bool edit,
                                    int which,
-                                   Orientation orient,
+                                   Qt::Orientation orient,
                                    bool showColumnTitles )
-     : QDialog( parent, "", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+     : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
        myIntTable( 0 ), myRealTable( 0 )
 {
-  setCaption( edit ? tr( "EDIT_TABLE_TLT" ) : tr( "VIEW_TABLE_TLT" ) );
+  setWindowTitle( edit ? tr( "EDIT_TABLE_TLT" ) : tr( "VIEW_TABLE_TLT" ) );
   setSizeGripEnabled( true );
 
   myObject = obj;
@@ -113,17 +182,21 @@ VisuGUI_TableDlg::VisuGUI_TableDlg( QWidget* parent,
   QWidget* top;
   QVBoxLayout* tl;
   if ( bDoInt && bDoReal ) {
-    top = new QTabWidget( this, "TabWidget" );
-    ( ( QTabWidget* ) top) ->setMargin( MARGIN_SIZE );
+    top = new QTabWidget( this );
+    //( ( QTabWidget* ) top) ->setMargin( MARGIN_SIZE );
   }
   else {
-    top = new QWidget( this, "DumbWidget" );
+    top = new QWidget( this );
     tl  = new QVBoxLayout( top ); tl->setMargin( 0 ); tl->setSpacing( SPACING_SIZE );
   }
 
   if ( bDoInt ) {
     myIntTable = new VisuGUI_TableWidget( top, "myIntTable", edit, orient, showColumnTitles );
-    myIntTable->getTable()->setValidator( new QIntValidator( this ) );
+    //myIntTable->getTable()->setValidator( new QIntValidator( this ) );
+    //QAbstractItemDelegate* item = myIntTable->getTable()->itemDelegate();
+    myIntTable->getTable()->setItemDelegate( new NumDelegateItem( myIntTable, NumDelegateItem::NV_Int ) );
+    //item->deleteLater();
+                                 
     if ( bDoInt && bDoReal )
       ( ( QTabWidget* )top )->addTab( myIntTable, tr( "TABLE_OF_INTEGER_TLT" ) );
     else
@@ -131,15 +204,18 @@ VisuGUI_TableDlg::VisuGUI_TableDlg( QWidget* parent,
   }
   if ( bDoReal ) {
     myRealTable = new VisuGUI_TableWidget( top, "myRealTable", edit, orient, showColumnTitles );
-    myRealTable->getTable()->setValidator( new QDoubleValidator( this ) );
+    //myRealTable->getTable()->setValidator( new QDoubleValidator( this ) );
+    //QAbstractItemDelegate* item = myIntTable->getTable()->itemDelegate();
+    myRealTable->getTable()->setItemDelegate( new NumDelegateItem( myRealTable, NumDelegateItem::NV_Real ) );
+    //item->deleteLater();
     if ( bDoInt && bDoReal )
       ( ( QTabWidget* )top )->addTab( myRealTable, tr( "TABLE_OF_REAL_TLT" ) );
     else
       tl->addWidget( myRealTable );
   }
   if ( !bDoInt && !bDoReal ) {
-    QLabel *dumbLabel = new QLabel( tr( "ERR_TABLE_NOT_AVAILABLE" ), top, "DumbLabel" );
-    dumbLabel->setAlignment( AlignCenter );
+    QLabel *dumbLabel = new QLabel( tr( "ERR_TABLE_NOT_AVAILABLE" ), top );
+    dumbLabel->setAlignment( Qt::AlignCenter );
     tl->addWidget( dumbLabel );
   }
 
@@ -227,20 +303,20 @@ void VisuGUI_TableDlg::onOK()
              }
              if ( !bEmptyRow ) {  // Skip rows with no data !!!
                // set row title
-               tblIntAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : rowTitles[ i ].latin1() ); 
+               tblIntAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : (const char*)rowTitles[ i ].toLatin1() ); 
                // set row unit
-               tblIntAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : units[ i ].latin1() ); 
+               tblIntAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : (const char*)units[ i ].toLatin1() ); 
                nRow++;
              }
            }
            if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!!
              // column titles
              for ( i = 0; i < colTitles.count(); i++ )
-               tblIntAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : colTitles[ i ].latin1() );
+               tblIntAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : (const char*)colTitles[ i ].toLatin1() );
            }
          }
          // title
-         tblIntAttr->SetTitle( myIntTable->getTableTitle().latin1() );
+         tblIntAttr->SetTitle( (const char*)myIntTable->getTableTitle().toLatin1() );
        }
        if ( myRealTable ) {
          builder->RemoveAttribute( myObject, "AttributeTableOfReal" );
@@ -271,20 +347,20 @@ void VisuGUI_TableDlg::onOK()
              }
              if ( !bEmptyRow ) {  // Skip rows with no data !!!
                // set row title
-               tblRealAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : rowTitles[ i ].latin1() ); 
+               tblRealAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : (const char*)rowTitles[ i ].toLatin1() ); 
                // set row unit
-               tblRealAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : units[ i ].latin1() );
+               tblRealAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : (const char*)units[ i ].toLatin1() );
                nRow++;
              }
            }
            if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!!
              // column titles
              for ( i = 0; i < colTitles.count(); i++ )
-               tblRealAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : colTitles[ i ].latin1() );
+               tblRealAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : (const char*)colTitles[ i ].toLatin1() );
            }
          }
          // title
-         tblRealAttr->SetTitle( myRealTable->getTableTitle().latin1() );
+         tblRealAttr->SetTitle( (const char*)myRealTable->getTableTitle().toLatin1() );
        }
        if ( myIntTable || myRealTable)
          builder->CommitCommand(); // commit transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -295,7 +371,7 @@ void VisuGUI_TableDlg::onOK()
        MESSAGE("VisuGUI_TableDlg::onOK : Exception has been caught !!!");
        builder->AbortCommand();  // abort transaction  !!!!!!!!!!!!!!!!!!!!!!!!!!!
        done = false;
-       SUIT_MessageBox::error1 ( this, tr("ERR_ERROR"), tr("ERR_APP_EXCEPTION"), tr ("BUT_OK") );
+       SUIT_MessageBox::critical ( this, tr("ERR_ERROR"), tr("ERR_APP_EXCEPTION") );
       }
     }
   }
@@ -313,10 +389,15 @@ void VisuGUI_TableDlg::onHelp()
   if (app)
     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
   else {
-    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
-                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
-                          QObject::tr("BUT_OK"));
+               QString platform;
+#ifdef WIN32
+               platform = "winapplication";
+#else
+               platform = "application";
+#endif
+    SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
+                             QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
   }
 }
 
@@ -449,48 +530,69 @@ void VisuGUI_TableDlg::initDlg()
   }
 }
 
+/*!
+  Provides help on F1 button click
+*/
+void VisuGUI_TableDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 )
+    {
+      e->accept();
+      onHelp();
+    }
+}
+
 /*!
   Constructor
 */
 VisuGUI_TableWidget::VisuGUI_TableWidget( QWidget* parent, 
                                              const char* name, 
                                              bool edit, 
-                                             Orientation orient,
+                                             Qt::Orientation orient,
                                              bool showColumnTitles )
-     : QWidget( parent, name ), myOrientation( orient )
+     : QWidget( parent ), myOrientation( orient )
 {
   QGridLayout* mainLayout = new QGridLayout( this );
   mainLayout->setMargin( 0 );
   mainLayout->setSpacing( SPACING_SIZE );
 
-  myTitleEdit = new QLineEdit( this, "TitleEdit" );
-  myTitleEdit->setAlignment( AlignCenter );
+  myTitleEdit = new QLineEdit( this );
+  myTitleEdit->setAlignment( Qt::AlignCenter );
   myTitleEdit->setReadOnly( !edit );
   QFont fnt = myTitleEdit->font();
   fnt.setBold( true ); 
   myTitleEdit->setFont( fnt );
 
-  myTable = new VisuGUI_Table( orient, this, "Table" );
-  myTable->setNumRows( 5 );
-  myTable->setNumCols( 5 );
+  //myTable = new VisuGUI_Table( orient, this );
+  myTable = new QTableWidget( 5, 5, this );
+  //myTable->setNumRows( 5 );
+  //myTable->setNumCols( 5 );
   myTable->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
   myTable->setMinimumSize( MIN_TABLE_WIDTH, MIN_TABLE_HEIGHT );
-  myTable->setSelectionMode( QTable::Single );
+  myTable->setSelectionMode( QAbstractItemView::SingleSelection );
   myTable->setShowGrid( true );
-  myTable->setColumnMovingEnabled( false );
-  myTable->setRowMovingEnabled( false );
-  myTable->setReadOnly( !edit );
+  myTable->horizontalHeader()->setMovable( false );
+  myTable->verticalHeader()->setMovable( false );
+  //myTable->setColumnMovingEnabled( false );
+  //myTable->setRowMovingEnabled( false );
   myTable->setDragEnabled( false );
+  //myTable->setReadOnly( !edit );
+  myTable->setEditTriggers( edit ? QAbstractItemView::AllEditTriggers : QAbstractItemView::NoEditTriggers );
+
   setUnitsTitle( tr( "UNITS_TLT" ) );
 
   if ( !showColumnTitles ) {
-    if ( myOrientation == Horizontal ) {
+    if ( myOrientation == Qt::Horizontal ) {
       myTable->horizontalHeader()->hide();
-      myTable->setTopMargin( 0 );
+      //myTable->setTopMargin( 0 );
     }
     else {
       myTable->verticalHeader()->hide();
-      myTable->setLeftMargin( 0 );
+      //myTable->setLeftMargin( 0 );
     }
   }
 
@@ -498,13 +600,13 @@ VisuGUI_TableWidget::VisuGUI_TableWidget( QWidget* parent,
   mainLayout->addWidget( myTable, 1, 0 );
 
   if ( edit ) {
-    myAddRowBtn    = new QPushButton( tr( "ADD_ROW_BTN" ), this, "AddRowBtn" );
-    myDelRowBtn    = new QPushButton( tr( "REMOVE_ROW_BTN" ), this, "DelRowBtn" );
-    myAddColBtn    = new QPushButton( tr( "ADD_COLUMN_BTN" ), this, "AddColBtn" );
-    myDelColBtn    = new QPushButton( tr( "REMOVE_COLUMN_BTN" ), this, "DelColBtn" );
-    myAdjustBtn    = new QPushButton( tr( "ADJUST_CELLS_BTN" ), this, "AdjustBtn" );
-    mySelectAllBtn = new QPushButton( tr( "SELECT_ALL_BTN" ), this, "SelectAllBtn" );
-    myClearBtn     = new QPushButton( tr( "CLEAR_BTN"), this, "ClearBtn" );
+    myAddRowBtn    = new QPushButton( tr( "ADD_ROW_BTN" ), this );
+    myDelRowBtn    = new QPushButton( tr( "REMOVE_ROW_BTN" ), this );
+    myAddColBtn    = new QPushButton( tr( "ADD_COLUMN_BTN" ), this );
+    myDelColBtn    = new QPushButton( tr( "REMOVE_COLUMN_BTN" ), this );
+    myAdjustBtn    = new QPushButton( tr( "ADJUST_CELLS_BTN" ), this );
+    mySelectAllBtn = new QPushButton( tr( "SELECT_ALL_BTN" ), this );
+    myClearBtn     = new QPushButton( tr( "CLEAR_BTN"), this );
     QVBoxLayout* btnLayout = new QVBoxLayout; btnLayout->setMargin( 0 ); btnLayout->setSpacing( SPACING_SIZE );
     btnLayout->addWidget( myAddRowBtn );
     btnLayout->addWidget( myDelRowBtn );
@@ -556,14 +658,14 @@ QString VisuGUI_TableWidget::getTableTitle()
 */
 void VisuGUI_TableWidget::setNumRows( const int num )
 {
-  myOrientation == Horizontal ? myTable->setNumRows( num ) : myTable->setNumCols( num );
+  myOrientation == Qt::Horizontal ? myTable->setRowCount( num ) : myTable->setColumnCount( num );
 }
 /*!
   Gets total number of rows
 */
 int VisuGUI_TableWidget::getNumRows()
 {
-  return myOrientation == Horizontal ? myTable->numRows() : myTable->numCols();
+  return myOrientation == Qt::Horizontal ? myTable->rowCount() : myTable->columnCount();
 }
 /*!
   Sets total number of columns
@@ -571,8 +673,8 @@ int VisuGUI_TableWidget::getNumRows()
 void VisuGUI_TableWidget::setNumCols( const int num )
 {
   // !!! first column contains units !!!
-  myOrientation == Horizontal ? myTable->setNumCols( num+1 ) : myTable->setNumRows( num+1 );
-//  myOrientation == Horizontal ? myTable->setColumnReadOnly( 0, true ) : myTable->setRowReadOnly( 0, true );
+  myOrientation == Qt::Horizontal ? myTable->setColumnCount( num+1 ) : myTable->setRowCount( num+1 );
+//  myOrientation == Qt::Horizontal ? myTable->setColumnReadOnly( 0, true ) : myTable->setRowReadOnly( 0, true );
 }
 /*!
   Gets total number of columns
@@ -580,18 +682,24 @@ void VisuGUI_TableWidget::setNumCols( const int num )
 int VisuGUI_TableWidget::getNumCols()
 {
   // !!! first column contains units !!!
-  return myOrientation == Horizontal ? myTable->numCols()-1 : myTable->numRows()-1;
+  return myOrientation == Qt::Horizontal ? myTable->columnCount()-1 : myTable->rowCount()-1;
 }
 /*!
   Sets rows titles
 */
 void VisuGUI_TableWidget::setRowTitles( QStringList& tlts )
 {
-  for ( int i = 0; i < tlts.count(); i++ ) {
-    myOrientation == Horizontal ? 
-      myTable->verticalHeader()->setLabel( i, tlts[i] ) : 
-      myTable->horizontalHeader()->setLabel( i, tlts[i] );
-  }
+  QStringList aLabels;
+  for ( int i = 0; i < tlts.count(); i++ )
+    tlts[i].isNull() ? aLabels.append("") : aLabels.append( tlts[i] );
+
+  myOrientation == Qt::Horizontal ?
+    myTable->setVerticalHeaderLabels( aLabels ) :
+    myTable->setHorizontalHeaderLabels( aLabels );
+    
+    //  myTable->verticalHeader()->setLabel( i, tlts[i] ) : 
+    //myTable->horizontalHeader()->setLabel( i, tlts[i] );
+  //}
 }
 /*!
   Gets rows titles
@@ -599,14 +707,14 @@ void VisuGUI_TableWidget::setRowTitles( QStringList& tlts )
 void VisuGUI_TableWidget::getRowTitles( QStringList& tlts )
 {
   tlts.clear();
-  if ( myOrientation == Horizontal ) {
-    for ( int i = 0; i < myTable->numRows(); i++ ) {
-      tlts.append( myTable->verticalHeader()->label( i ) );
+  if ( myOrientation == Qt::Horizontal ) {
+    for ( int i = 0; i < myTable->rowCount(); i++ ) {
+      tlts.append( myTable->verticalHeaderItem(i) ? myTable->verticalHeaderItem(i)->text() : "" );
     }
   }
   else {
-    for ( int i = 0; i < myTable->numCols(); i++ ) {
-      tlts.append( myTable->horizontalHeader()->label( i ) );
+    for ( int i = 0; i < myTable->columnCount(); i++ ) {
+      tlts.append( myTable->horizontalHeaderItem(i) ? myTable->horizontalHeaderItem(i)->text() : "" );
     }
   }
 }
@@ -615,12 +723,18 @@ void VisuGUI_TableWidget::getRowTitles( QStringList& tlts )
 */
 void VisuGUI_TableWidget::setColTitles( QStringList& tlts )
 {
+  QStringList aLabels;
+
   // !!! first column contains units !!!
-  for ( int i = 0; i < tlts.count(); i++ ) {
-    myOrientation == Horizontal ? 
-      myTable->horizontalHeader()->setLabel( i+1, tlts[i].isNull() ? "" : tlts[i] ) :
-      myTable->verticalHeader()->setLabel( i+1, tlts[i].isNull() ? "" : tlts[i] );
-  }
+  aLabels.append(""); // it'll be initialized below - in setUnitsTitle() method
+
+  for ( int i = 0; i < tlts.count(); i++ )
+    tlts[i].isNull() ? aLabels.append("") : aLabels.append( tlts[i] );
+
+  myOrientation == Qt::Horizontal ?
+    myTable->setHorizontalHeaderLabels( aLabels ) :
+    myTable->setVerticalHeaderLabels( aLabels );
+  
   setUnitsTitle( tr( "UNITS_TLT" ) );
 }
 /*!
@@ -630,14 +744,14 @@ void VisuGUI_TableWidget::getColTitles( QStringList& tlts )
 {
   // !!! first column contains units !!!
   tlts.clear();
-  if ( myOrientation == Horizontal ) {
-    for ( int i = 1; i < myTable->numCols(); i++ ) {
-      tlts.append( myTable->horizontalHeader()->label( i ) );
-    }
+  if ( myOrientation == Qt::Horizontal ) {
+    for ( int i = 1; i < myTable->columnCount(); i++ ) {
+      tlts.append( myTable->horizontalHeaderItem(i) ? myTable->horizontalHeaderItem(i)->text() : "" );
+    }    
   }
   else {
-    for ( int i = 1; i < myTable->numRows(); i++ ) {
-      tlts.append( myTable->verticalHeader()->label( i ) );
+    for ( int i = 1; i < myTable->rowCount(); i++ ) {
+      tlts.append( myTable->verticalHeaderItem(i) ? myTable->verticalHeaderItem(i)->text() : "" );
     }
   }
 }
@@ -646,15 +760,25 @@ void VisuGUI_TableWidget::getColTitles( QStringList& tlts )
 */
 void VisuGUI_TableWidget::setUnitsTitle( const QString& tlt ) {
   // !!! first column contains units !!!
-  myOrientation == Horizontal ? myTable->horizontalHeader()->setLabel( 0, tlt.isNull() ? "" : tlt ) : myTable->verticalHeader()->setLabel( 0, tlt.isNull() ? "" : tlt );
+  myTable->model()->setHeaderData( 0, myOrientation, QVariant(tlt.isNull() ? "" : tlt), Qt::DisplayRole );
 }
 /*!
   Sets units
 */
 void VisuGUI_TableWidget::setUnits( QStringList& units )
 {
-  for ( int i = 0; i < units.count(); i++ ) {
-    myOrientation == Horizontal ? myTable->setText( i, 0, units[i].isNull() ? "" : units[i] ) : myTable->setText( 0, i, units[i].isNull() ? "" : units[i] );
+  QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
+  if ( aModel )
+  {
+    QModelIndex anIndex;
+    for ( int i = 0; i < units.count(); i++ )
+    {
+      myOrientation == Qt::Horizontal ?
+        anIndex = aModel->index( i, 0 ) :
+        anIndex = aModel->index( 0, i );
+
+      aModel->setData( anIndex, QVariant( units[i].isNull() ? "" : units[i] ) );      
+    }
   }
 }
 /*!
@@ -663,13 +787,18 @@ void VisuGUI_TableWidget::setUnits( QStringList& units )
 void VisuGUI_TableWidget::getUnits( QStringList& units )
 {
   units.clear();
-  if ( myOrientation == Horizontal ) {
-    for ( int i = 0; i < myTable->numRows(); i++ )
-      units.append( myTable->text( i, 0 ).isNull() ? QString("") : myTable->text( i, 0 ) );
-  }
-  else {
-    for ( int i = 0; i < myTable->numCols(); i++ )
-      units.append( myTable->text( 0, i ).isNull() ? QString("") : myTable->text( 0, i ) );
+  QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
+  if ( aModel )
+  {
+    if ( myOrientation == Qt::Horizontal )
+    {
+      for ( int i = 0; i < myTable->rowCount(); i++ )
+        units.append( aModel->index( i, 0 ).data().toString() );
+    }
+    else {
+      for ( int i = 0; i < myTable->columnCount(); i++ )
+        units.append( aModel->index( 0, i ).data().toString() );
+    }
   }
 }
 /*!
@@ -677,15 +806,17 @@ void VisuGUI_TableWidget::getUnits( QStringList& units )
 */
 void VisuGUI_TableWidget::setRowData( int row, QStringList& data )
 {
-  if ( row >= 0 && row < getNumRows() ) {
-    for ( int i = 0; i < data.count(); i++ ) {
-      if ( data[i].isNull() ) {
-       myOrientation == Horizontal ? myTable->clearCell( row, i+1 ) :
-                                     myTable->clearCell( i+1, row );
-      }
-      else {
-       myOrientation == Horizontal ? myTable->setText( row, i+1, data[i] ) :
-                                     myTable->setText( i+1, row, data[i] );
+  QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
+  if ( aModel )
+  {
+    QModelIndex anIndex; 
+    if ( row >= 0 && row < getNumRows() ) {
+      for ( int i = 0; i < data.count(); i++ )
+      {
+        myOrientation == Qt::Horizontal ? anIndex = aModel->index( row, i+1 ) :
+                                          anIndex = aModel->index( i+1, row );
+        aModel->setData( anIndex, QVariant( data[i] ) );
+          
       }
     }
   }
@@ -696,14 +827,20 @@ void VisuGUI_TableWidget::setRowData( int row, QStringList& data )
 void VisuGUI_TableWidget::getRowData( int row, QStringList& data )
 {
   data.clear();
-  if ( row >= 0 && row < getNumRows() ) {
-    if ( myOrientation == Horizontal ) {
-      for ( int i = 1; i < myTable->numCols(); i++ )
-       data.append( myTable->text( row, i ) );
-    }
-    else {
-      for ( int i = 1; i < myTable->numRows(); i++ )
-       data.append( myTable->text( i, row ) );
+  QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myTable->model() );
+  if ( aModel )
+  {
+    if ( row >= 0 && row < getNumRows() )
+    {
+      if ( myOrientation == Qt::Horizontal )
+      {
+        for ( int i = 1; i < myTable->columnCount(); i++ )
+          data.append( aModel->index( row, i ).data().toString() );
+      }
+      else {
+        for ( int i = 1; i < myTable->rowCount(); i++ )
+          data.append( aModel->index( i, row ).data().toString() );
+      }
     }
   }
 }
@@ -712,39 +849,38 @@ void VisuGUI_TableWidget::getRowData( int row, QStringList& data )
 */
 void VisuGUI_TableWidget::adjustTable()
 {
-  int i;
-  for ( i = 0; i < myTable->numRows(); i++ )
-    myTable->adjustRow( i );
-  for ( i = 0; i < myTable->numCols(); i++ )
-    myTable->adjustColumn( i );
+  myTable->resizeRowsToContents();
+  myTable->resizeColumnsToContents();
 }
 /*!
   Called when selection changed in table
 */
 void VisuGUI_TableWidget::updateButtonsState()
 {
-  if ( myTable->isReadOnly() )
+  if ( myTable->editTriggers() == QAbstractItemView::NoEditTriggers )
     return;
   bool bDR = false; // <Delete Row(s)>
   bool bDC = false; // <Delete Column(s)>
   bool bSA = false; // <Select All>
   bool bCT = false; // <Clear>
   int i;
-  int c = myOrientation == Horizontal ? 0 : 1;
-  for ( i = c; i < myTable->numRows(); i++ ) {
+  //TO DO column/row selection check
+  /*int c = myOrientation == Qt::Horizontal ? 0 : 1;
+  for ( i = c; i < myTable->rowCount(); i++ ) {
+    
     if ( myTable->isRowSelected( i, true ) )
       bDR = true;
     else 
       bSA = true;
   }
-  c = myOrientation == Horizontal ? 1 : 0;
-  for ( i = c; i < myTable->numCols(); i++ ) {
+  c = myOrientation == Qt::Horizontal ? 1 : 0;
+  for ( i = c; i < myTable->columnCount(); i++ ) {
     if ( myTable->isColumnSelected( i, true ) )
       bDC = true;
     else 
       bSA = true;
-  }
-  int nbSel = myTable->numSelections();
+      }*/
+  /*int nbSel = myTable->numSelections();
   for ( i = 0; i < nbSel; i++ ) {
     QTableSelection ts = myTable->selection( i );
     for ( int j = ts.topRow(); j < ts.bottomRow()+1; j++) {
@@ -753,7 +889,19 @@ void VisuGUI_TableWidget::updateButtonsState()
          bCT = true;
       }
     }
+    }*/
+  QList<QTableWidgetItem*> aSelection = myTable->selectedItems();
+  QList<QTableWidgetItem*>::ConstIterator anIt = aSelection.constBegin(),
+    anEndIt = aSelection.constEnd();
+  for ( ; anIt !=  anEndIt; anIt++ )
+  {
+    if( *anIt )
+    {
+      bCT = true;
+      break;
+    }
   }
+  
   if ( myTable->item( myTable->currentRow(), myTable->currentColumn() ) )
     bCT = true;
   myDelRowBtn->setEnabled( bDR );
@@ -766,7 +914,7 @@ void VisuGUI_TableWidget::updateButtonsState()
 */
 void VisuGUI_TableWidget::addRow()
 {
-  myTable->insertRows( myTable->numRows(), 1 );
+  myTable->insertRow( myTable->rowCount() );
   updateButtonsState();
 }
 /*!
@@ -774,7 +922,7 @@ void VisuGUI_TableWidget::addRow()
 */
 void VisuGUI_TableWidget::addCol()
 {
-  myTable->insertColumns( myTable->numCols(), 1 );
+  myTable->insertColumn( myTable->columnCount() );
   updateButtonsState();
 }
 /*!
@@ -782,10 +930,11 @@ void VisuGUI_TableWidget::addCol()
 */
 void VisuGUI_TableWidget::delRow()
 {
-  int c = myOrientation == Horizontal ? 0 : 1;
-  QValueList<int> il;
+  //TODO
+  /*int c = myOrientation == Qt::Horizontal ? 0 : 1;
+  QList<int> il;
   int i;
-  for ( i = c; i < myTable->numRows(); i++ )
+  for ( i = c; i < myTable->rowCount(); i++ )
     if ( myTable->isRowSelected( i, true ) )
       il.append( i );
   if ( il.count() > 0 ) {
@@ -793,7 +942,8 @@ void VisuGUI_TableWidget::delRow()
     for ( i = 0; i < il.count(); i++ )
       ildel[ i ] = il[ i ];
     myTable->removeRows( ildel );
-  }
+    }*/
+  
   updateButtonsState();
 }
 /*!
@@ -801,7 +951,8 @@ void VisuGUI_TableWidget::delRow()
 */
 void VisuGUI_TableWidget::delCol()
 {
-  int c = myOrientation == Horizontal ? 1 : 0;
+  //TODO
+  /*int c = myOrientation == Qt::Horizontal ? 1 : 0;
   QValueList<int> il;
   int i;
   for ( i = c; i < myTable->numCols(); i++ )
@@ -812,7 +963,7 @@ void VisuGUI_TableWidget::delCol()
     for ( i = 0; i < il.count(); i++ )
       ildel[ i ] = il[ i ];
     myTable->removeColumns( ildel );
-  }
+    }*/
   updateButtonsState();
 }
 /*!
@@ -820,10 +971,11 @@ void VisuGUI_TableWidget::delCol()
 */
 void VisuGUI_TableWidget::selectAll()
 {
-  myTable->clearSelection();
+  /*myTable->clearSelection();
   QTableSelection ts;
   ts.init( 0, 0 ); ts.expandTo( myTable->numRows()-1, myTable->numCols()-1 );
-  myTable->addSelection( ts );
+  myTable->addSelection( ts );*/
+  myTable->selectAll();
   updateButtonsState();
 }
 /*!
@@ -831,15 +983,15 @@ void VisuGUI_TableWidget::selectAll()
 */
 void VisuGUI_TableWidget::clearTable()
 {
-  int nbSel = myTable->numSelections();
+  /*int nbSel = myTable->numSelections();
   for ( int i = 0; i < nbSel; i++ ) {
     QTableSelection ts = myTable->selection( i );
     for ( int j = ts.topRow(); j < ts.bottomRow()+1; j++) {
-      if ( myOrientation == Vertical && j == 0 ) {
+      if ( myOrientation == Qt::Vertical && j == 0 ) {
 //     continue;      // UNITS
       }
       for ( int k = ts.leftCol(); k < ts.rightCol()+1; k++) {
-       if ( myOrientation == Horizontal && k == 0 ) {
+       if ( myOrientation == Qt::Horizontal && k == 0 ) {
 //       continue;   // UNITS
        }
        myTable->clearCell( j, k );
@@ -848,7 +1000,8 @@ void VisuGUI_TableWidget::clearTable()
   }
   if ( nbSel == 0 )
     myTable->clearCell( myTable->currentRow(), myTable->currentColumn() );
-  myTable->clearSelection();
+    myTable->clearSelection();*/
+  myTable->clearContents();
   updateButtonsState();
 }
 /*!
@@ -857,14 +1010,15 @@ void VisuGUI_TableWidget::clearTable()
 bool VisuGUI_TableWidget::eventFilter( QObject* o, QEvent* e )
 {
   if ( e->type() == QEvent::MouseButtonDblClick) {
-    QMouseEvent* me = ( QMouseEvent* )e;
-    if ( me->button() == LeftButton && !myTable->isReadOnly() ) {
+    //TODO
+    /*QMouseEvent* me = ( QMouseEvent* )e;
+    if ( me->button() == Qt::LeftButton && (myTable->editTriggers() != QAbstractItemView::NoEditTriggers ) ) {
       if ( o == myTable->horizontalHeader() ) {
        for ( int i = 0; i < myTable->horizontalHeader()->count(); i++ ) {
          QRect rect = myTable->horizontalHeader()->sectionRect( i );
          rect.addCoords( 1, 1, -1, -1 );
          if ( rect.contains( myTable->horizontalHeader()->mapFromGlobal( me->globalPos() ) ) ) {
-           if ( myOrientation == Vertical || i != 0 ) {
+           if ( myOrientation == Qt::Vertical || i != 0 ) {
              bool bOk;
              QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ), 
                                                   tr( "TITLE_LBL" ),
@@ -884,7 +1038,7 @@ bool VisuGUI_TableWidget::eventFilter( QObject* o, QEvent* e )
          QRect rect = myTable->verticalHeader()->sectionRect( i );
          rect.addCoords( 1, 1, -1, -1 );
          if ( rect.contains( myTable->verticalHeader()->mapFromGlobal( me->globalPos() ) ) ) {
-           if ( myOrientation == Horizontal || i != 0 ) {
+           if ( myOrientation == Qt::Horizontal || i != 0 ) {
              bool bOk;
              QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ), 
                                                   tr( "TITLE_LBL" ),
@@ -899,24 +1053,21 @@ bool VisuGUI_TableWidget::eventFilter( QObject* o, QEvent* e )
          }
        }
       }
-    }    
-  }
+      }*/    
+  }     
   else if ( e->type() == QEvent::KeyRelease && o == myTable ) {
     QKeyEvent* ke = (QKeyEvent*)e;
-    if ( ke->key() == Key_Delete && !myTable->isEditing() ) {
+    if ( ke->key() == Qt::Key_Delete && (myTable->editTriggers() != QAbstractItemView::NoEditTriggers) ) {
       clearTable();
     }
-    else if ( ke->key() == Key_Backspace && !myTable->isEditing() ) {
+    else if ( ke->key() == Qt::Key_Backspace && (myTable->editTriggers() != QAbstractItemView::NoEditTriggers) ) {
       clearTable();
       int i = myTable->currentRow();
       int j = myTable->currentColumn() - 1;
-      if ( j < 0 ) { j = myTable->numCols()-1; i--; }
+      if ( j < 0 ) { j = myTable->columnCount()-1; i--; }
       if ( i >= 0 && j >= 0 )
        myTable->setCurrentCell( i, j );
     }
   }
   return QWidget::eventFilter( o, e );
 }
-
-
-