aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/qtime_conversions.h
blob: 080df5f2f53d27a103cd94da15151b2c32084d42 (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
36
37
38
39
40
41
42
43
44
45
namespace Shiboken {

inline bool Converter<QTime>::checkType(PyObject* pyObj)
{
    return ValueTypeConverter<QTime>::checkType(pyObj);
}

inline PyObject* Converter<QTime>::toPython(const ::QTime& cppObj)
{
    return ValueTypeConverter<QTime>::toPython(cppObj);
}

inline bool Converter<QTime>::isConvertible(PyObject* pyObj)
{
    if (ValueTypeConverter<QTime>::isConvertible(pyObj))
        return true;

    if (!PyDateTimeAPI)
        PyDateTime_IMPORT;

    SbkObjectType* shiboType = reinterpret_cast<SbkObjectType*>(SbkType< ::QTime >());
    return PyTime_Check(pyObj) || ObjectType::isExternalConvertible(shiboType, pyObj);
}

inline QTime Converter<QTime>::toCpp(PyObject* pyObj)
{
    if (!PyDateTimeAPI)
        PyDateTime_IMPORT;

    if (pyObj == Py_None) {
        return QTime();
    } else if (PyObject_TypeCheck(pyObj, SbkType<QTime>())) {
        return *Converter<QTime*>::toCpp(pyObj);
    } else  if (PyTime_Check(pyObj)) {
        int hour = PyDateTime_TIME_GET_HOUR(pyObj);
        int min = PyDateTime_TIME_GET_MINUTE(pyObj);
        int sec = PyDateTime_TIME_GET_SECOND(pyObj);
        int msec = PyDateTime_TIME_GET_MICROSECOND(pyObj);
        return QTime(hour, min, sec, msec);
    } else {
        return ValueTypeConverter<QTime>::toCpp(pyObj);
    }
}

}