~ubuntu-branches/ubuntu/vivid/kdesdk/vivid

« back to all changes in this revision

Viewing changes to okteta/kasten/controllers/view/structures/datatypes/primitive/uintdatainformation.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-06 11:49:54 UTC
  • mfrom: (0.4.21)
  • Revision ID: package-import@ubuntu.com-20120606114954-rdls73fzlpzxglbx
Tags: 4:4.8.80-0ubuntu1
* New uptream beta release
* Update dont_export_private_classes.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 */
22
22
#include "uintdatainformation.h"
23
23
 
24
 
#include <QtScript/QScriptEngine>
25
 
 
26
 
 
27
 
template<typename T, PrimitiveDataType typeValue>
28
 
QScriptValue UIntDataInformation<T, typeValue>::asScriptValue(T value, QScriptEngine* engine,
 
24
#include <QtScript/QScriptValue>
 
25
 
 
26
#include <KGlobal>
 
27
 
 
28
 
 
29
template<typename T>
 
30
QScriptValue UIntDataInformation<T>::asScriptValue(T value, QScriptEngine* engine,
29
31
        ScriptHandlerInfo* handlerInfo)
30
32
{
31
33
    Q_UNUSED(engine);
34
36
}
35
37
 
36
38
template<>
37
 
QScriptValue UIntDataInformation<quint64, Type_UInt64>::asScriptValue(quint64 value, QScriptEngine* engine,
 
39
QScriptValue UIntDataInformation<quint64>::asScriptValue(quint64 value, QScriptEngine* engine,
38
40
        ScriptHandlerInfo* handlerInfo)
39
41
{
40
42
    Q_UNUSED(engine);
42
44
    return QScriptValue(QString::number(value, 10));
43
45
}
44
46
 
45
 
template<typename T, PrimitiveDataType typeValue>
46
 
QScriptValue UIntDataInformation<T, typeValue>::valueAsQScriptValue() const
 
47
template<typename T>
 
48
QScriptValue UIntDataInformation<T>::valueAsQScriptValue() const
47
49
{
48
 
    return UIntDataInformation<T, typeValue>::asScriptValue(UnsignedDataInformation<T>::mValue, 0, 0);
 
50
    return UIntDataInformation<T>::asScriptValue(UnsignedDataInformation<T>::mValue, 0, 0);
49
51
}
50
52
 
51
 
template<typename T, PrimitiveDataType typeValue>
52
 
QString UIntDataInformation<T, typeValue>::valueString() const
 
53
template<typename T>
 
54
QString UIntDataInformation<T>::valueString() const
53
55
{
54
 
    if (!UIntDataInformation::mWasAbleToRead)
 
56
    if (!this->mWasAbleToRead)
55
57
        return i18nc("invalid value (out of range)", "&lt;invalid&gt;");
56
 
    return UIntDataInformation<T, typeValue>::valueString(UnsignedDataInformation<T>::mValue);
 
58
    return UIntDataInformation<T>::valueString(UnsignedDataInformation<T>::mValue);
57
59
}
58
60
 
59
 
template<typename T, PrimitiveDataType typeValue>
60
 
QString UIntDataInformation<T, typeValue>::valueString(T value)
 
61
template<typename T>
 
62
QString UIntDataInformation<T>::valueString(T value, int base)
61
63
{
62
 
    int base = UnsignedDataInformation<T>::displayBase();
63
64
    QString num = QString::number(value, base);
64
 
    if (base == 16)
65
 
        num.prepend(QLatin1String("0x"));
66
 
    else if (base == 2)
67
 
        num.prepend(QLatin1String("0b"));
68
 
    else if (base == 8)
69
 
        num.prepend(QLatin1String("0o"));
70
 
    else if (base == 10 && Kasten1::StructViewPreferences::localeAwareDecimalFormatting())
71
 
        num = KGlobal::locale()->formatNumber(num, false, 0);
 
65
    if (base == 10)
 
66
    {
 
67
        if (Kasten2::StructViewPreferences::localeAwareDecimalFormatting())
 
68
            num = KGlobal::locale()->formatNumber(num, false, 0);
 
69
    }
 
70
    else
 
71
    {
 
72
        //add one space every 8 chars
 
73
        for (int i = 8; i < num.length(); i += 9) {
 
74
            num.insert(num.length() - i, QLatin1Char(' '));
 
75
        }
 
76
        if (base == 16)
 
77
            num.prepend(QLatin1String("0x"));
 
78
        else if (base == 2)
 
79
            num.prepend(QLatin1String("0b"));
 
80
        else if (base == 8)
 
81
            num.prepend(QLatin1String("0o"));
 
82
        else
 
83
            kDebug() << "unsupported number base" << base;
 
84
    }
72
85
    return num;
73
86
}
74
87
 
75
88
//explicitly instantiate all valid classes (c++-faq-lite 35.12)
76
 
template class UIntDataInformation<quint8, Type_UInt8>;
77
 
template class UIntDataInformation<quint16, Type_UInt16>;
78
 
template class UIntDataInformation<quint32, Type_UInt32>;
79
 
template class UIntDataInformation<quint64, Type_UInt64>;
 
89
template class UIntDataInformation<quint8>;
 
90
template class UIntDataInformation<quint16>;
 
91
template class UIntDataInformation<quint32>;
 
92
template class UIntDataInformation<quint64>;