Esempio n. 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;
}
Esempio n. 2
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;
}