const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
if ( lineEdit == NULL )
{
// report error
}
QString sRegExp
( "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$" );
if ( uuidValidator == NULL )
{
// report error
}
lineEdit->setInputMask( "HHHHHHHH-HHHH-HHHH-HHHH-HHHHHHHHHHHH" );
lineEdit->setMaxLength( 36 );
lineEdit->setCursorPosition( 0 ); // appears to have no effect
lineEdit->setSelection( 0, 1 ); // appears to have no effect
lineEdit->setValidator( uuidValidator );
connect( lineEdit, SIGNAL( textEdited( const QString& ) ),
this, SLOT( uuidTextEdited( const QString& ) ) );
connect( lineEdit, SIGNAL( editingFinished() ),
this, SLOT( commitAndCloseEditor() ) );
lineEdit->installEventFilter( const_cast<UUIDColumnDelegate*>( this ) );
return lineEdit;
}
void AbstractColumnDelegate::uuidTextEdited( const QString& sValue )
{
if ( sValue.isEmpty() )
return;
qobject_cast<QLineEdit*>( sender() )->setText( sText );
}
QWidget* UUIDColumnDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
QLineEdit* lineEdit = new QLineEdit( parent );
if ( lineEdit == NULL )
{
// report error
return QItemDelegate::createEditor( parent, option, index );
}
QString sRegExp( "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$" );
QRegExp regExp( sRegExp, Qt::CaseInsensitive, QRegExp::RegExp );
QRegExpValidator* uuidValidator = new QRegExpValidator( regExp, lineEdit );
if ( uuidValidator == NULL )
{
// report error
return QItemDelegate::createEditor( parent, option, index );
}
lineEdit->setInputMask( "HHHHHHHH-HHHH-HHHH-HHHH-HHHHHHHHHHHH" );
lineEdit->setMaxLength( 36 );
lineEdit->setCursorPosition( 0 ); // appears to have no effect
lineEdit->setSelection( 0, 1 ); // appears to have no effect
lineEdit->setValidator( uuidValidator );
connect( lineEdit, SIGNAL( textEdited( const QString& ) ),
this, SLOT( uuidTextEdited( const QString& ) ) );
connect( lineEdit, SIGNAL( editingFinished() ),
this, SLOT( commitAndCloseEditor() ) );
lineEdit->installEventFilter( const_cast<UUIDColumnDelegate*>( this ) );
return lineEdit;
}
void AbstractColumnDelegate::uuidTextEdited( const QString& sValue )
{
if ( sValue.isEmpty() )
return;
QString sText = sValue.toUpper();
qobject_cast<QLineEdit*>( sender() )->setText( sText );
}
To copy to clipboard, switch view to plain text mode
Bookmarks