summaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/qtime_conversions.h
blob: 5e172fa076a3797ec439331edd6a0e992aa049b3 (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
namespace Shiboken {
template <>
struct PythonConverter<QTime>
{
    static bool isPythonConvertible(PyObject* pyObj)
    {
        if (!PyDateTimeAPI)
            PyDateTime_IMPORT;

        return pyObj && PyTime_Check(pyObj);
    }

    static QTime* transformFromPython(PyObject* obj)
    {
        if (isPythonConvertible(obj)) {
            int hour = PyDateTime_TIME_GET_HOUR(obj);
            int min = PyDateTime_TIME_GET_MINUTE(obj);
            int sec = PyDateTime_TIME_GET_SECOND(obj);
            int msec = PyDateTime_TIME_GET_MICROSECOND(obj);
            return new QTime(hour, min, sec, msec);
        }
        return 0;
    }

    static PyObject* transformToPython(QTime* d)
    {
        if (d) {
            if (!PyDateTimeAPI) 
                PyDateTime_IMPORT;

            return PyTime_FromTime(d->hour(), d->minute(), d->second(), d->msec());
        }
        return 0;
    }
};
}