1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VisuGUI_TableDlg.cxx
8 // Author : Vadim SANDLER
11 #include "VisuGUI_TableDlg.h"
13 #include "SUIT_Tools.h"
14 #include "SUIT_MessageBox.h"
16 #include "SALOMEDSClient_Study.hxx"
17 #include "SALOMEDSClient_GenericAttribute.hxx"
18 #include "SALOMEDSClient_AttributeTableOfInteger.hxx"
19 #include "SALOMEDSClient_AttributeTableOfReal.hxx"
20 #include "SALOMEDSClient_StudyBuilder.hxx"
23 #include <qvalidator.h>
25 #include <qtabwidget.h>
26 #include <qvaluelist.h>
27 #include <qmemarray.h>
28 #include <qinputdialog.h>
30 #include "utilities.h"
33 #define MARGIN_SIZE 11
34 #define SPACING_SIZE 6
36 #define MIN_TABLE_WIDTH 200
37 #define MIN_TABLE_HEIGHT 200
40 class VisuGUI_Table : public QTable {
42 VisuGUI_Table( Orientation orient, QWidget* parent = 0, const char* name = 0 )
43 : QTable( parent, name ), myValidator( 0 ), myOrientation( orient ) {}
44 VisuGUI_Table( Orientation orient, int numRows, int numCols, QWidget* parent = 0, const char* name = 0 )
45 : QTable( numRows, numCols, parent, name ), myValidator( 0 ), myOrientation( orient ) {}
47 void setValidator( QValidator* v = 0 ) { myValidator = v; }
48 bool isEditing() const { return QTable::isEditing(); }
51 QWidget* createEditor ( int row, int col, bool initFromCell ) const
53 bool testUnits = ( myOrientation == Horizontal && col == 0 ) || ( myOrientation == Vertical && row == 0 );
54 QWidget* wg = QTable::createEditor( row, col, initFromCell );
55 if ( wg && wg->inherits("QLineEdit") && myValidator && !testUnits )
56 (( QLineEdit*)wg)->setValidator( myValidator );
61 QValidator* myValidator;
62 Orientation myOrientation;
68 VisuGUI_TableDlg::VisuGUI_TableDlg( QWidget* parent,
73 bool showColumnTitles )
74 : QDialog( parent, "", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
75 myIntTable( 0 ), myRealTable( 0 )
77 setCaption( edit ? tr( "EDIT_TABLE_TLT" ) : tr( "VIEW_TABLE_TLT" ) );
78 setSizeGripEnabled( true );
81 bool bHasIntTable = false;
82 bool bHasRealTable = false;
84 _PTR(GenericAttribute) anAttr;
85 bHasIntTable = myObject->FindAttribute( anAttr, "AttributeTableOfInteger");
86 bHasRealTable = myObject->FindAttribute( anAttr, "AttributeTableOfReal");
89 QVBoxLayout* mainLayout = new QVBoxLayout( this );
90 mainLayout->setMargin( MARGIN_SIZE );
91 mainLayout->setSpacing( SPACING_SIZE );
93 bool bDoInt = which == ttInt || which == ttBoth || which == ttAuto && bHasIntTable;
94 bool bDoReal = which == ttReal || which == ttBoth || which == ttAuto && bHasRealTable;
98 if ( bDoInt && bDoReal ) {
99 top = new QTabWidget( this, "TabWidget" );
100 ( ( QTabWidget* ) top) ->setMargin( MARGIN_SIZE );
103 top = new QWidget( this, "DumbWidget" );
104 tl = new QVBoxLayout( top ); tl->setMargin( 0 ); tl->setSpacing( SPACING_SIZE );
108 myIntTable = new VisuGUI_TableWidget( top, "myIntTable", edit, orient, showColumnTitles );
109 myIntTable->getTable()->setValidator( new QIntValidator( this ) );
110 if ( bDoInt && bDoReal )
111 ( ( QTabWidget* )top )->addTab( myIntTable, tr( "TABLE_OF_INTEGER_TLT" ) );
113 tl->addWidget( myIntTable );
116 myRealTable = new VisuGUI_TableWidget( top, "myRealTable", edit, orient, showColumnTitles );
117 myRealTable->getTable()->setValidator( new QDoubleValidator( this ) );
118 if ( bDoInt && bDoReal )
119 ( ( QTabWidget* )top )->addTab( myRealTable, tr( "TABLE_OF_REAL_TLT" ) );
121 tl->addWidget( myRealTable );
123 if ( !bDoInt && !bDoReal ) {
124 QLabel *dumbLabel = new QLabel( tr( "ERR_TABLE_NOT_AVAILABLE" ), top, "DumbLabel" );
125 dumbLabel->setAlignment( AlignCenter );
126 tl->addWidget( dumbLabel );
129 QHBoxLayout* btnLayout = new QHBoxLayout;
130 btnLayout->setMargin( 0 ); btnLayout->setSpacing( SPACING_SIZE );
132 myOKBtn = new QPushButton( tr( "BUT_OK" ), this );
134 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
135 btnLayout->addWidget( myOKBtn );
136 btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
137 btnLayout->addWidget( myCancelBtn );
138 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( onOK() ) );
139 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
142 btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
143 btnLayout->addWidget( myOKBtn );
144 btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
145 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
148 mainLayout->addWidget( top );
149 mainLayout->addLayout( btnLayout );
153 SUIT_Tools::centerWidget( this, parent );
159 VisuGUI_TableDlg::~VisuGUI_TableDlg()
164 <OK> button slot, saves table(s)
165 Called only in create/edit mode ( <edit> parameter for constructor is true )
167 void VisuGUI_TableDlg::onOK()
169 myOKBtn->setFocus(); // accept possible changes
173 _PTR(Study) study = myObject->GetStudy();
174 _PTR(AttributeTableOfInteger) tblIntAttr;
175 _PTR(AttributeTableOfReal) tblRealAttr;
178 _PTR(StudyBuilder) builder = study->NewBuilder();
179 builder->NewCommand(); // start transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
182 builder->RemoveAttribute( myObject, "AttributeTableOfInteger" );
183 tblIntAttr = builder->FindOrCreateAttribute( myObject, "AttributeTableOfInteger" );
186 int nbRows = myIntTable->getNumRows();
187 int nbCols = myIntTable->getNumCols();
188 QString tlt = myIntTable->getTableTitle();
189 QStringList rowTitles, colTitles, units;
190 myIntTable->getRowTitles( rowTitles );
191 myIntTable->getColTitles( colTitles );
192 myIntTable->getUnits( units );
197 tblIntAttr->SetNbColumns( nbCols );
198 for ( i = 0; i < nbRows; i++ ) {
200 myIntTable->getRowData( i, data );
201 bool bEmptyRow = true;
202 for ( int j = 0; j < data.count(); j++ ) {
203 if ( !data[ j ].isNull() ) {
204 tblIntAttr->PutValue( data[ j ].toInt(), nRow+1, j+1 );
208 if ( !bEmptyRow ) { // Skip rows with no data !!!
210 tblIntAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : rowTitles[ i ].latin1() );
212 tblIntAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : units[ i ].latin1() );
216 if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!!
218 for ( i = 0; i < colTitles.count(); i++ )
219 tblIntAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : colTitles[ i ].latin1() );
223 tblIntAttr->SetTitle( myIntTable->getTableTitle().latin1() );
226 builder->RemoveAttribute( myObject, "AttributeTableOfReal" );
227 tblRealAttr = builder->FindOrCreateAttribute( myObject, "AttributeTableOfReal" );
230 int nbRows = myRealTable->getNumRows();
231 int nbCols = myRealTable->getNumCols();
232 QString tlt = myRealTable->getTableTitle();
233 QStringList rowTitles, colTitles, units;
234 myRealTable->getRowTitles( rowTitles );
235 myRealTable->getColTitles( colTitles );
236 myRealTable->getUnits( units );
241 tblRealAttr->SetNbColumns( nbCols );
242 for ( i = 0; i < nbRows; i++ ) {
244 myRealTable->getRowData( i, data );
245 bool bEmptyRow = true;
246 for ( int j = 0; j < data.count(); j++ ) {
247 if ( !data[ j ].isNull() ) {
248 tblRealAttr->PutValue( data[ j ].toDouble(), nRow+1, j+1 );
252 if ( !bEmptyRow ) { // Skip rows with no data !!!
254 tblRealAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? "" : rowTitles[ i ].latin1() );
256 tblRealAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? "" : units[ i ].latin1() );
260 if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!!
262 for ( i = 0; i < colTitles.count(); i++ )
263 tblRealAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? "" : colTitles[ i ].latin1() );
267 tblRealAttr->SetTitle( myRealTable->getTableTitle().latin1() );
269 if ( myIntTable || myRealTable)
270 builder->CommitCommand(); // commit transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!
272 builder->AbortCommand(); // abort transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!
275 MESSAGE("VisuGUI_TableDlg::onOK : Exception has been caught !!!");
276 builder->AbortCommand(); // abort transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!
278 SUIT_MessageBox::error1 ( this, tr("ERR_ERROR"), tr("ERR_APP_EXCEPTION"), tr ("BUT_OK") );
287 Populates table with data
289 void VisuGUI_TableDlg::initDlg()
293 _PTR(GenericAttribute) anAttr;
294 _PTR(AttributeTableOfInteger) tblIntAttr;
295 _PTR(AttributeTableOfReal) tblRealAttr;
296 if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger") ) {
299 if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal") ) {
300 tblRealAttr = anAttr;
303 if ( tblIntAttr && myIntTable ) {
306 myIntTable->setTableTitle( tblIntAttr->GetTitle().c_str() );
308 int nbRows = tblIntAttr->GetNbRows() ;
309 int nbCols = tblIntAttr->GetNbColumns();
310 myIntTable->setNumRows( nbRows );
311 myIntTable->setNumCols( nbCols );
314 vector<string> rowTitles = tblIntAttr->GetRowTitles();
315 for ( i = 0; i < nbRows; i++ ) {
316 if ( rowTitles.size() > 0 )
317 strlist.append( rowTitles[i].c_str() );
319 strlist.append( "" );
321 myIntTable->setRowTitles( strlist );
324 vector<string> colTitles = tblIntAttr->GetColumnTitles();
325 for ( i = 0; i < nbCols; i++ ) {
326 if ( colTitles.size() > 0 )
327 strlist.append( colTitles[i].c_str() );
329 strlist.append( "" );
331 myIntTable->setColTitles( strlist );
334 vector<string> rowUnits = tblIntAttr->GetRowUnits();
335 if ( rowUnits.size() > 0 ) {
336 for ( i = 0; i < nbRows; i++ )
337 strlist.append( rowUnits[i].c_str() );
338 myIntTable->setUnits( strlist );
341 for ( i = 1; i <= nbRows; i++ ) {
343 for ( j = 1; j <= nbCols; j++ ) {
344 if ( tblIntAttr->HasValue( i, j ) )
345 strlist.append( QString::number( tblIntAttr->GetValue( i, j ) ) );
347 strlist.append( QString::null );
349 myIntTable->setRowData( i-1, strlist );
351 myIntTable->adjustTable();
354 MESSAGE("VisuGUI_TableDlg::initDlg : Exception has been caught !!!");
358 if ( tblRealAttr && myRealTable ) {
361 myRealTable->setTableTitle( tblRealAttr->GetTitle().c_str() );
363 int nbRows = tblRealAttr->GetNbRows() ;
364 int nbCols = tblRealAttr->GetNbColumns();
365 myRealTable->setNumRows( nbRows );
366 myRealTable->setNumCols( nbCols );
369 vector<string> rowTitles = tblRealAttr->GetRowTitles();
370 for ( i = 0; i < nbRows; i++ ) {
371 if ( rowTitles.size() > 0 )
372 strlist.append( rowTitles[i].c_str() );
374 strlist.append( "" );
376 myRealTable->setRowTitles( strlist );
379 vector<string> colTitles = tblRealAttr->GetColumnTitles();
380 for ( i = 0; i < nbCols; i++ ) {
381 if ( colTitles.size() > 0 )
382 strlist.append( colTitles[i].c_str() );
384 strlist.append( "" );
386 myRealTable->setColTitles( strlist );
389 vector<string> rowUnits = tblRealAttr->GetRowUnits();
390 if ( rowUnits.size() > 0 ) {
391 for ( i = 0; i < nbRows; i++ )
392 strlist.append( rowUnits[i].c_str() );
393 myRealTable->setUnits( strlist );
396 for ( i = 1; i <= nbRows; i++ ) {
398 for ( j = 1; j <= nbCols; j++ ) {
399 if ( tblRealAttr->HasValue( i, j ) )
400 strlist.append( QString::number( tblRealAttr->GetValue( i, j ) ) );
402 strlist.append( QString::null );
404 myRealTable->setRowData( i-1, strlist );
406 myRealTable->adjustTable();
409 MESSAGE("VisuGUI_TableDlg::initDlg : Exception has been caught !!!");
418 VisuGUI_TableWidget::VisuGUI_TableWidget( QWidget* parent,
422 bool showColumnTitles )
423 : QWidget( parent, name ), myOrientation( orient )
425 QGridLayout* mainLayout = new QGridLayout( this );
426 mainLayout->setMargin( 0 );
427 mainLayout->setSpacing( SPACING_SIZE );
429 myTitleEdit = new QLineEdit( this, "TitleEdit" );
430 myTitleEdit->setAlignment( AlignCenter );
431 myTitleEdit->setReadOnly( !edit );
432 QFont fnt = myTitleEdit->font();
434 myTitleEdit->setFont( fnt );
436 myTable = new VisuGUI_Table( orient, this, "Table" );
437 myTable->setNumRows( 5 );
438 myTable->setNumCols( 5 );
439 myTable->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
440 myTable->setMinimumSize( MIN_TABLE_WIDTH, MIN_TABLE_HEIGHT );
441 myTable->setSelectionMode( QTable::Single );
442 myTable->setShowGrid( true );
443 myTable->setColumnMovingEnabled( false );
444 myTable->setRowMovingEnabled( false );
445 myTable->setReadOnly( !edit );
446 myTable->setDragEnabled( false );
447 setUnitsTitle( tr( "UNITS_TLT" ) );
449 if ( !showColumnTitles ) {
450 if ( myOrientation == Horizontal ) {
451 myTable->horizontalHeader()->hide();
452 myTable->setTopMargin( 0 );
455 myTable->verticalHeader()->hide();
456 myTable->setLeftMargin( 0 );
460 mainLayout->addWidget( myTitleEdit, 0, 0 );
461 mainLayout->addWidget( myTable, 1, 0 );
464 myAddRowBtn = new QPushButton( tr( "ADD_ROW_BTN" ), this, "AddRowBtn" );
465 myDelRowBtn = new QPushButton( tr( "REMOVE_ROW_BTN" ), this, "DelRowBtn" );
466 myAddColBtn = new QPushButton( tr( "ADD_COLUMN_BTN" ), this, "AddColBtn" );
467 myDelColBtn = new QPushButton( tr( "REMOVE_COLUMN_BTN" ), this, "DelColBtn" );
468 myAdjustBtn = new QPushButton( tr( "ADJUST_CELLS_BTN" ), this, "AdjustBtn" );
469 mySelectAllBtn = new QPushButton( tr( "SELECT_ALL_BTN" ), this, "SelectAllBtn" );
470 myClearBtn = new QPushButton( tr( "CLEAR_BTN"), this, "ClearBtn" );
471 QVBoxLayout* btnLayout = new QVBoxLayout; btnLayout->setMargin( 0 ); btnLayout->setSpacing( SPACING_SIZE );
472 btnLayout->addWidget( myAddRowBtn );
473 btnLayout->addWidget( myDelRowBtn );
474 btnLayout->addWidget( myAddColBtn );
475 btnLayout->addWidget( myDelColBtn );
476 btnLayout->addStretch();
477 btnLayout->addWidget( myAdjustBtn );
478 btnLayout->addStretch();
479 btnLayout->addWidget( mySelectAllBtn );
480 btnLayout->addWidget( myClearBtn );
481 mainLayout->addLayout( btnLayout, 1, 1 );
482 connect( myTable, SIGNAL( selectionChanged() ), this, SLOT( updateButtonsState() ) );
483 connect( myTable, SIGNAL( currentChanged( int, int) ), this, SLOT( updateButtonsState() ) );
484 connect( myAddRowBtn, SIGNAL( clicked() ), this, SLOT( addRow() ) );
485 connect( myAddColBtn, SIGNAL( clicked() ), this, SLOT( addCol() ) );
486 connect( myDelRowBtn, SIGNAL( clicked() ), this, SLOT( delRow() ) );
487 connect( myDelColBtn, SIGNAL( clicked() ), this, SLOT( delCol() ) );
488 connect( myAdjustBtn, SIGNAL( clicked() ), this, SLOT( adjustTable() ) );
489 connect( mySelectAllBtn, SIGNAL( clicked() ), this, SLOT( selectAll() ) );
490 connect( myClearBtn, SIGNAL( clicked() ), this, SLOT( clearTable() ) );
491 myTable->horizontalHeader()->installEventFilter( this );
492 myTable->verticalHeader()->installEventFilter( this );
493 myTable->installEventFilter( this );
495 updateButtonsState();
500 VisuGUI_TableWidget::~VisuGUI_TableWidget()
506 void VisuGUI_TableWidget::setTableTitle( const QString& title )
508 myTitleEdit->setText( title );
513 QString VisuGUI_TableWidget::getTableTitle()
515 return myTitleEdit->text();
518 Sets total number of rows
520 void VisuGUI_TableWidget::setNumRows( const int num )
522 myOrientation == Horizontal ? myTable->setNumRows( num ) : myTable->setNumCols( num );
525 Gets total number of rows
527 int VisuGUI_TableWidget::getNumRows()
529 return myOrientation == Horizontal ? myTable->numRows() : myTable->numCols();
532 Sets total number of columns
534 void VisuGUI_TableWidget::setNumCols( const int num )
536 // !!! first column contains units !!!
537 myOrientation == Horizontal ? myTable->setNumCols( num+1 ) : myTable->setNumRows( num+1 );
538 // myOrientation == Horizontal ? myTable->setColumnReadOnly( 0, true ) : myTable->setRowReadOnly( 0, true );
541 Gets total number of columns
543 int VisuGUI_TableWidget::getNumCols()
545 // !!! first column contains units !!!
546 return myOrientation == Horizontal ? myTable->numCols()-1 : myTable->numRows()-1;
551 void VisuGUI_TableWidget::setRowTitles( QStringList& tlts )
553 for ( int i = 0; i < tlts.count(); i++ ) {
554 myOrientation == Horizontal ?
555 myTable->verticalHeader()->setLabel( i, tlts[i] ) :
556 myTable->horizontalHeader()->setLabel( i, tlts[i] );
562 void VisuGUI_TableWidget::getRowTitles( QStringList& tlts )
565 if ( myOrientation == Horizontal ) {
566 for ( int i = 0; i < myTable->numRows(); i++ ) {
567 tlts.append( myTable->verticalHeader()->label( i ) );
571 for ( int i = 0; i < myTable->numCols(); i++ ) {
572 tlts.append( myTable->horizontalHeader()->label( i ) );
579 void VisuGUI_TableWidget::setColTitles( QStringList& tlts )
581 // !!! first column contains units !!!
582 for ( int i = 0; i < tlts.count(); i++ ) {
583 myOrientation == Horizontal ?
584 myTable->horizontalHeader()->setLabel( i+1, tlts[i].isNull() ? "" : tlts[i] ) :
585 myTable->verticalHeader()->setLabel( i+1, tlts[i].isNull() ? "" : tlts[i] );
587 setUnitsTitle( tr( "UNITS_TLT" ) );
592 void VisuGUI_TableWidget::getColTitles( QStringList& tlts )
594 // !!! first column contains units !!!
596 if ( myOrientation == Horizontal ) {
597 for ( int i = 1; i < myTable->numCols(); i++ ) {
598 tlts.append( myTable->horizontalHeader()->label( i ) );
602 for ( int i = 1; i < myTable->numRows(); i++ ) {
603 tlts.append( myTable->verticalHeader()->label( i ) );
610 void VisuGUI_TableWidget::setUnitsTitle( const QString& tlt ) {
611 // !!! first column contains units !!!
612 myOrientation == Horizontal ? myTable->horizontalHeader()->setLabel( 0, tlt.isNull() ? "" : tlt ) : myTable->verticalHeader()->setLabel( 0, tlt.isNull() ? "" : tlt );
617 void VisuGUI_TableWidget::setUnits( QStringList& units )
619 for ( int i = 0; i < units.count(); i++ ) {
620 myOrientation == Horizontal ? myTable->setText( i, 0, units[i].isNull() ? "" : units[i] ) : myTable->setText( 0, i, units[i].isNull() ? "" : units[i] );
626 void VisuGUI_TableWidget::getUnits( QStringList& units )
629 if ( myOrientation == Horizontal ) {
630 for ( int i = 0; i < myTable->numRows(); i++ )
631 units.append( myTable->text( i, 0 ).isNull() ? QString("") : myTable->text( i, 0 ) );
634 for ( int i = 0; i < myTable->numCols(); i++ )
635 units.append( myTable->text( 0, i ).isNull() ? QString("") : myTable->text( 0, i ) );
641 void VisuGUI_TableWidget::setRowData( int row, QStringList& data )
643 if ( row >= 0 && row < getNumRows() ) {
644 for ( int i = 0; i < data.count(); i++ ) {
645 if ( data[i].isNull() ) {
646 myOrientation == Horizontal ? myTable->clearCell( row, i+1 ) :
647 myTable->clearCell( i+1, row );
650 myOrientation == Horizontal ? myTable->setText( row, i+1, data[i] ) :
651 myTable->setText( i+1, row, data[i] );
659 void VisuGUI_TableWidget::getRowData( int row, QStringList& data )
662 if ( row >= 0 && row < getNumRows() ) {
663 if ( myOrientation == Horizontal ) {
664 for ( int i = 1; i < myTable->numCols(); i++ )
665 data.append( myTable->text( row, i ) );
668 for ( int i = 1; i < myTable->numRows(); i++ )
669 data.append( myTable->text( i, row ) );
674 Adjusts table cell to see contents, <Adjust Cells> button slot
676 void VisuGUI_TableWidget::adjustTable()
679 for ( i = 0; i < myTable->numRows(); i++ )
680 myTable->adjustRow( i );
681 for ( i = 0; i < myTable->numCols(); i++ )
682 myTable->adjustColumn( i );
685 Called when selection changed in table
687 void VisuGUI_TableWidget::updateButtonsState()
689 if ( myTable->isReadOnly() )
691 bool bDR = false; // <Delete Row(s)>
692 bool bDC = false; // <Delete Column(s)>
693 bool bSA = false; // <Select All>
694 bool bCT = false; // <Clear>
696 int c = myOrientation == Horizontal ? 0 : 1;
697 for ( i = c; i < myTable->numRows(); i++ ) {
698 if ( myTable->isRowSelected( i, true ) )
703 c = myOrientation == Horizontal ? 1 : 0;
704 for ( i = c; i < myTable->numCols(); i++ ) {
705 if ( myTable->isColumnSelected( i, true ) )
710 int nbSel = myTable->numSelections();
711 for ( i = 0; i < nbSel; i++ ) {
712 QTableSelection ts = myTable->selection( i );
713 for ( int j = ts.topRow(); j < ts.bottomRow()+1; j++) {
714 for ( int k = ts.leftCol(); k < ts.rightCol()+1; k++) {
715 if ( myTable->item( j, k ) )
720 if ( myTable->item( myTable->currentRow(), myTable->currentColumn() ) )
722 myDelRowBtn->setEnabled( bDR );
723 myDelColBtn->setEnabled( bDC );
724 mySelectAllBtn->setEnabled( bSA );
725 myClearBtn->setEnabled( bCT );
728 <Add row> button slot
730 void VisuGUI_TableWidget::addRow()
732 myTable->insertRows( myTable->numRows(), 1 );
733 updateButtonsState();
736 <Add column> button slot
738 void VisuGUI_TableWidget::addCol()
740 myTable->insertColumns( myTable->numCols(), 1 );
741 updateButtonsState();
744 <Delete row(s)> button slot
746 void VisuGUI_TableWidget::delRow()
748 int c = myOrientation == Horizontal ? 0 : 1;
751 for ( i = c; i < myTable->numRows(); i++ )
752 if ( myTable->isRowSelected( i, true ) )
754 if ( il.count() > 0 ) {
755 QMemArray<int> ildel( il.count() );
756 for ( i = 0; i < il.count(); i++ )
757 ildel[ i ] = il[ i ];
758 myTable->removeRows( ildel );
760 updateButtonsState();
763 <Delete column(s)> button slot
765 void VisuGUI_TableWidget::delCol()
767 int c = myOrientation == Horizontal ? 1 : 0;
770 for ( i = c; i < myTable->numCols(); i++ )
771 if ( myTable->isColumnSelected( i, true ) )
773 if ( il.count() > 0 ) {
774 QMemArray<int> ildel( il.count() );
775 for ( i = 0; i < il.count(); i++ )
776 ildel[ i ] = il[ i ];
777 myTable->removeColumns( ildel );
779 updateButtonsState();
782 <Select All> button slot
784 void VisuGUI_TableWidget::selectAll()
786 myTable->clearSelection();
788 ts.init( 0, 0 ); ts.expandTo( myTable->numRows()-1, myTable->numCols()-1 );
789 myTable->addSelection( ts );
790 updateButtonsState();
795 void VisuGUI_TableWidget::clearTable()
797 int nbSel = myTable->numSelections();
798 for ( int i = 0; i < nbSel; i++ ) {
799 QTableSelection ts = myTable->selection( i );
800 for ( int j = ts.topRow(); j < ts.bottomRow()+1; j++) {
801 if ( myOrientation == Vertical && j == 0 ) {
802 // continue; // UNITS
804 for ( int k = ts.leftCol(); k < ts.rightCol()+1; k++) {
805 if ( myOrientation == Horizontal && k == 0 ) {
806 // continue; // UNITS
808 myTable->clearCell( j, k );
813 myTable->clearCell( myTable->currentRow(), myTable->currentColumn() );
814 myTable->clearSelection();
815 updateButtonsState();
818 Event filter - handles titles editing
820 bool VisuGUI_TableWidget::eventFilter( QObject* o, QEvent* e )
822 if ( e->type() == QEvent::MouseButtonDblClick) {
823 QMouseEvent* me = ( QMouseEvent* )e;
824 if ( me->button() == LeftButton && !myTable->isReadOnly() ) {
825 if ( o == myTable->horizontalHeader() ) {
826 for ( int i = 0; i < myTable->horizontalHeader()->count(); i++ ) {
827 QRect rect = myTable->horizontalHeader()->sectionRect( i );
828 rect.addCoords( 1, 1, -1, -1 );
829 if ( rect.contains( myTable->horizontalHeader()->mapFromGlobal( me->globalPos() ) ) ) {
830 if ( myOrientation == Vertical || i != 0 ) {
832 QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ),
835 myTable->horizontalHeader()->label( i ),
838 if ( bOk && !tlt.isNull() )
839 myTable->horizontalHeader()->setLabel( i, tlt );
845 if ( o == myTable->verticalHeader() ) {
846 for ( int i = 0; i < myTable->verticalHeader()->count(); i++ ) {
847 QRect rect = myTable->verticalHeader()->sectionRect( i );
848 rect.addCoords( 1, 1, -1, -1 );
849 if ( rect.contains( myTable->verticalHeader()->mapFromGlobal( me->globalPos() ) ) ) {
850 if ( myOrientation == Horizontal || i != 0 ) {
852 QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ),
855 myTable->verticalHeader()->label( i ),
858 if ( bOk && !tlt.isNull() )
859 myTable->verticalHeader()->setLabel( i, tlt );
867 else if ( e->type() == QEvent::KeyRelease && o == myTable ) {
868 QKeyEvent* ke = (QKeyEvent*)e;
869 if ( ke->key() == Key_Delete && !myTable->isEditing() ) {
872 else if ( ke->key() == Key_Backspace && !myTable->isEditing() ) {
874 int i = myTable->currentRow();
875 int j = myTable->currentColumn() - 1;
876 if ( j < 0 ) { j = myTable->numCols()-1; i--; }
877 if ( i >= 0 && j >= 0 )
878 myTable->setCurrentCell( i, j );
881 return QWidget::eventFilter( o, e );