-// VISU VISUGUI : GUI of VISU component
+// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003 CEA/DEN, EDF R&D
+// 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 "SUIT_MessageBox.h"
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+
+#include "LightApp_Application.h"
+
+#include "CAM_Module.h"
#include "SALOMEDSClient_Study.hxx"
#include "SALOMEDSClient_GenericAttribute.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
#define MIN_TABLE_WIDTH 200
#define MIN_TABLE_HEIGHT 200
+NumDelegateItem::NumDelegateItem( QObject* parent, NumValidator mode )
+ : QItemDelegate( parent ),
+ myMode( mode )
+{
+}
-class VisuGUI_Table : public QTable {
+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 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(); }
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 );
protected:
QValidator* myValidator;
Orientation myOrientation;
-};
+ };*/
/*!
Constructor
_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;
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
}
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 );
}
btnLayout->setMargin( 0 ); btnLayout->setSpacing( SPACING_SIZE );
myOKBtn = new QPushButton( tr( "BUT_OK" ), this );
+ myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this );
if ( edit ) {
myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
btnLayout->addWidget( myOKBtn );
btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
btnLayout->addWidget( myCancelBtn );
+ btnLayout->addWidget( myHelpBtn );
connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( onOK() ) );
connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
}
else {
- btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
btnLayout->addWidget( myOKBtn );
btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
+ btnLayout->addWidget( myHelpBtn );
connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
}
+ connect( myHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
mainLayout->addWidget( top );
mainLayout->addLayout( btnLayout );
}
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" );
}
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!
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") );
}
}
}
accept();
}
+/*!
+ <Help> button slot, shows corresponding help page
+*/
+void VisuGUI_TableDlg::onHelp()
+{
+ QString aHelpFileName = "/files/displaying_tables.htm";
+ LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+ if (app)
+ app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
+ else {
+ 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) );
+ }
+}
+
/*!
Populates table with data
*/
}
}
+/*!
+ 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 );
}
}
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 );
*/
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
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
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
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() : "" );
}
}
}
*/
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" ) );
}
/*!
{
// !!! 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() : "" );
}
}
}
*/
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] ) );
+ }
}
}
/*!
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() );
+ }
}
}
/*!
*/
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] ) );
+
}
}
}
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() );
+ }
}
}
}
*/
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++) {
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 );
*/
void VisuGUI_TableWidget::addRow()
{
- myTable->insertRows( myTable->numRows(), 1 );
+ myTable->insertRow( myTable->rowCount() );
updateButtonsState();
}
/*!
*/
void VisuGUI_TableWidget::addCol()
{
- myTable->insertColumns( myTable->numCols(), 1 );
+ myTable->insertColumn( myTable->columnCount() );
updateButtonsState();
}
/*!
*/
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 ) {
for ( i = 0; i < il.count(); i++ )
ildel[ i ] = il[ i ];
myTable->removeRows( ildel );
- }
+ }*/
+
updateButtonsState();
}
/*!
*/
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++ )
for ( i = 0; i < il.count(); i++ )
ildel[ i ] = il[ i ];
myTable->removeColumns( ildel );
- }
+ }*/
updateButtonsState();
}
/*!
*/
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();
}
/*!
*/
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 );
}
if ( nbSel == 0 )
myTable->clearCell( myTable->currentRow(), myTable->currentColumn() );
- myTable->clearSelection();
+ myTable->clearSelection();*/
+ myTable->clearContents();
updateButtonsState();
}
/*!
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" ),
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" ),
}
}
}
- }
- }
+ }*/
+ }
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 );
}
-
-
-