m_pTableCellKeyHandler = new TableCellKeyHandler( this );
setItemDelegate( new DMXTableCellDelegate( this ) );
m_pTableCellKeyHandler = new TableCellKeyHandler( this );
setItemDelegate( new DMXTableCellDelegate( this ) );
connect( this, SIGNAL( itemChanged( QTableWidgetItem* ) ),
this, SLOT( SLOT_itemChanged( QTableWidgetItem* ) ) );
To copy to clipboard, switch view to plain text mode
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
lineEdit->setMaxLength( DEVICE_NAME_MAX );
connect( lineEdit, SIGNAL( editingFinished() ),
this, SLOT( commitAndCloseEditor() ) );
return lineEdit;
}
else if ( index.column() == COL_Next )
{
...
}
else
}
void DMXTableCellDelegate::commitAndCloseEditor( void )
{
QLineEdit* editor
= qobject_cast<QLineEdit
*>
( sender
() );
emit commitData( editor );
emit closeEditor( editor );
}
{
int nRow = pItem->row();
int nCol = pItem->column();
CDMXGateway* pDevice = static_cast<CDMXGateway*>( GetDeviceData( nRow ) );
if ( pDevice == NULL )
return;
// Turn off sorting
m_pDMXCfgTable->setSortingEnabled( false );
// Process device-specific cells
bool bValueChanged = false;
bool bNameChanged = false;
switch ( nCol )
{
case COL_Name:
{
sNewName = pItem->text();
if ( (bNameChanged = updateNameItem( pItem, sNewName, static_cast<CNode*>( pDevice ) )) )
bValueChanged = true;
break;
}
...
}
m_pDMXCfgTable->setSortingEnabled( true );
}
QString& sNewName, CNode* pNode )
{
bool bNameChanged = false;
QString sOldName
= pNode
->GetDeviceName
();
// Compare new name to old name
if ( sOldName.compare( sNewName, Qt::CaseSensitive ) != 0 )
{
if ( !m_parent->ValidateDeviceName( sNewName ) )
{
// Restrict length
if ( sNewName.length() > DEVICE_NAME_MAX )
sNewName.truncate( DEVICE_NAME_MAX );
if ( !m_parent->ShowRestrictedCharMsg( sTypedName, sOldName, sNewName ) )
{
pItem->setText( sOldName );
return false;
}
pItem->setText( sNewName );
}
pNode->SetDeviceName( sNewName );
bNameChanged = true;
if ( !m_bIsCfgTable && pNode->IsOnline() ) // update and save now
m_parent->m_pController->UpdateDeviceName( pNode->GetDevType(), sNewName, pNode, true );
}
return bNameChanged;
}
bool MainWin::ValidateDeviceName( QString& sName )
{
bool bCharIsValid = true;
// Substitute for illegal Discovery characters
for ( int i = 0; i < sName.length(); i++ )
{
c = sName.at( i );
if ( c == '(' )
{
sName.replace( i, 1, "[" );
bCharIsValid = false;
}
...
}
return bCharIsValid;
}
bool TableCellKeyHandler
::eventFilter( QObject* obj,
QEvent* pEvent
) {
if ( pEvent
->type
() == QEvent::KeyPress ) {
QKeyEvent* pKeyEvent
= static_cast<QKeyEvent
*>
( pEvent
);
int nKey = pKeyEvent->key();
// Check for enter keys: 0x01000004 || 0x01000005
if ( (nKey == Qt::Key_Return) || (nKey == Qt::Key_Enter) )
{
int nRow = m_pParent->currentRow();
int nCol = m_pParent->currentColumn();
qDebug( "eventFilter(): ( %u, %u )", nRow, nCol );
...
}
}
}
QWidget* DMXTableCellDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
QLineEdit* lineEdit = new QLineEdit( parent );
lineEdit->setMaxLength( DEVICE_NAME_MAX );
connect( lineEdit, SIGNAL( editingFinished() ),
this, SLOT( commitAndCloseEditor() ) );
return lineEdit;
}
else if ( index.column() == COL_Next )
{
...
}
else
return QItemDelegate::createEditor( parent, option, index );
}
void DMXTableCellDelegate::commitAndCloseEditor( void )
{
QLineEdit* editor = qobject_cast<QLineEdit*>( sender() );
emit commitData( editor );
emit closeEditor( editor );
}
void DMXTable::SLOT_itemChanged( QTableWidgetItem* pItem )
{
int nRow = pItem->row();
int nCol = pItem->column();
CDMXGateway* pDevice = static_cast<CDMXGateway*>( GetDeviceData( nRow ) );
if ( pDevice == NULL )
return;
// Turn off sorting
m_pDMXCfgTable->setSortingEnabled( false );
// Process device-specific cells
bool bValueChanged = false;
QString sNewName;
bool bNameChanged = false;
switch ( nCol )
{
case COL_Name:
{
sNewName = pItem->text();
if ( (bNameChanged = updateNameItem( pItem, sNewName, static_cast<CNode*>( pDevice ) )) )
bValueChanged = true;
break;
}
...
}
m_pDMXCfgTable->setSortingEnabled( true );
}
bool Table::updateNameItem( QTableWidgetItem* pItem,
QString& sNewName, CNode* pNode )
{
bool bNameChanged = false;
QString sOldName = pNode->GetDeviceName();
// Compare new name to old name
if ( sOldName.compare( sNewName, Qt::CaseSensitive ) != 0 )
{
QString sTypedName( sNewName );
if ( !m_parent->ValidateDeviceName( sNewName ) )
{
// Restrict length
if ( sNewName.length() > DEVICE_NAME_MAX )
sNewName.truncate( DEVICE_NAME_MAX );
if ( !m_parent->ShowRestrictedCharMsg( sTypedName, sOldName, sNewName ) )
{
pItem->setText( sOldName );
return false;
}
pItem->setText( sNewName );
}
pNode->SetDeviceName( sNewName );
bNameChanged = true;
if ( !m_bIsCfgTable && pNode->IsOnline() ) // update and save now
m_parent->m_pController->UpdateDeviceName( pNode->GetDevType(), sNewName, pNode, true );
}
return bNameChanged;
}
bool MainWin::ValidateDeviceName( QString& sName )
{
bool bCharIsValid = true;
QChar c;
// Substitute for illegal Discovery characters
for ( int i = 0; i < sName.length(); i++ )
{
c = sName.at( i );
if ( c == '(' )
{
sName.replace( i, 1, "[" );
bCharIsValid = false;
}
...
}
return bCharIsValid;
}
bool TableCellKeyHandler::eventFilter( QObject* obj, QEvent* pEvent )
{
if ( pEvent->type() == QEvent::KeyPress )
{
QKeyEvent* pKeyEvent = static_cast<QKeyEvent*>( pEvent );
int nKey = pKeyEvent->key();
// Check for enter keys: 0x01000004 || 0x01000005
if ( (nKey == Qt::Key_Return) || (nKey == Qt::Key_Enter) )
{
int nRow = m_pParent->currentRow();
int nCol = m_pParent->currentColumn();
qDebug( "eventFilter(): ( %u, %u )", nRow, nCol );
...
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks