aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/qchar_conversions.h
blob: 1ebcb646b63a41f869ca2ff7cb2b057b6a9ecc11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace Shiboken {

template<>
struct Converter<QChar>
{
    static bool checkType(PyObject* pyObj)
    {
        return PyString_Check(pyObj) && (PyString_Size(pyObj) == 1);
    }

    static bool isConvertible(PyObject* pyObj)
    {
        return (PyString_Check(pyObj) && (PyString_Size(pyObj) == 1))
               || pyObj == Py_None
               || PyInt_Check(pyObj);
    }

    static QChar toCpp(PyObject* pyObj)
    {
        if (PyString_Check(pyObj) && PyString_Size(pyObj) == 1)
            return QChar(Shiboken::Converter<char >::toCpp(pyObj));
        else if (PyInt_Check(pyObj))
            return QChar(Shiboken::Converter<int >::toCpp(pyObj));
        return QChar();
    }

    static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast<QChar*>(cppObj)); }
    static PyObject* toPython(const QChar& cppObj)
    {
        wchar_t c = (wchar_t)cppObj.unicode();
        PyObject* pyObj = PyUnicode_FromWideChar(&c, 1);
        return pyObj;
    }
};
}