Exemple #1
0
QVariant ByteTableModel::data( const QModelIndex &index, int role ) const
{
    QVariant result;
    if( role == Qt::DisplayRole )
    {
        QString content;

        const unsigned char byte = index.row();
        const int column = index.column();
        if( column == CharacterId )
        {
            const Okteta::Character decodedChar = mCharCodec->decode( byte );
            content =
                decodedChar.isUndefined() ?
                    i18nc( "@item:intable character is not defined", "undef." ) :
                (decodedChar.unicode() == 0x09) ? // tab only creates a wider column
                    QString() :
                    QString( static_cast<QChar>(decodedChar) );
             // TODO: show proper descriptions for all control values, incl. space and delete
             // cmp. KCharSelect
        }
        else if( column < CharacterId )
            mValueCodec[column]->encode( content, 0, byte );

        result = content;
    }
    else if( role == Qt::TextAlignmentRole )
        result = Qt::AlignRight;

    return result;
}
Exemple #2
0
QByteArray Char8Codec::valueToBytes( const QVariant& value ) const
{
    const Okteta::Character character = value.value<Char8>().character;

    bool success = ( ! character.isUndefined() );
    Okteta::Byte byte;

    if( success )
        success = mCharCodec->encode( &byte, character );

    return success ? QByteArray( 1, byte ) : QByteArray();
}
Exemple #3
0
QVariant StatisticTableModel::data( const QModelIndex &index, int role ) const
{
    QVariant result;
    if( role == Qt::DisplayRole )
    {
        const unsigned char byte = index.row();
        const int column = index.column();
        switch( column )
        {
            case CharacterId:
            {
                const Okteta::Character decodedChar = mCharCodec->decode( byte );
                result =
                    decodedChar.isUndefined() ?
                        i18nc( "@item:intable character is not defined", "undef." ) :
                    (decodedChar.unicode() == 0x09) ? // tab only creates a wider column
                        QString() :
                        QString( static_cast<QChar>(decodedChar) );
                // TODO: show proper descriptions for all control values, incl. space and delete
                // cmp. KCharSelect
                break;
            }
            case ValueId:
            {
                QString value;
                mValueCodec->encode( value, 0, byte );
                result = value;
                break;
            }
            case CountId:
                result =  ( mSize == -1 ) ?
                    QVariant( QStringLiteral("-") ) :
                    QVariant( mByteCount[byte] );
                break;
            case PercentId:
                result = ( mSize > 0 ) ?
                          // TODO: before we printed only a string (which killed sorting) with QString::number( x, 'f', 6 )
                          // Qt now cuts trailing 0s, results in unaligned numbers, not so beautiful.
                          QVariant( 100.0*(double)mByteCount[byte]/mSize ) :
                          QVariant( QStringLiteral("-") );
                break;
            default:
                ;
        }
    }
    else if( role == Qt::TextAlignmentRole )
        result = Qt::AlignRight;
    else if( role == Qt::ForegroundRole )
    {
        const int column = index.column();
        bool isInactive = false;
        switch( column )
        {
        case CountId:
            isInactive = ( mSize == -1 );
            break;
        case PercentId:
            isInactive = ( mSize <= 0 );
            break;
        default:
            ;
        }
        if( isInactive )
        {
            const QPalette& palette = QApplication::palette();
            const KColorScheme colorScheme( palette.currentColorGroup(), KColorScheme::View );
            result = colorScheme.foreground( KColorScheme::InactiveText );
        }
    }

    return result;
}