aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/qtime_conversions.h
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-01 19:00:36 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-10-01 19:45:30 -0300
commit940b90e80a7ec21e513ac16ff73d8fa8cf23d489 (patch)
treee75a0dd76faab2379d23f72a1e8ac6ab82e98b75 /PySide/QtCore/qtime_conversions.h
parent288a53369fa8df74a92c7517e8744c5139797c78 (diff)
Implement python conversion to QTime, QDate, QDateTime
Fixes bug #371. Reviewer: Hugo Parente Lima <hugo.pl@gmail.com> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide/QtCore/qtime_conversions.h')
-rw-r--r--PySide/QtCore/qtime_conversions.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/PySide/QtCore/qtime_conversions.h b/PySide/QtCore/qtime_conversions.h
new file mode 100644
index 000000000..5e172fa07
--- /dev/null
+++ b/PySide/QtCore/qtime_conversions.h
@@ -0,0 +1,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;
+ }
+};
+}