aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/qtime_conversions.h
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-05-17 17:36:04 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:54:23 -0300
commit8e221bfb9731589a4a4d4712745252e50b0a97c6 (patch)
tree8218a7ffe61da431312d7003b37547c089aca03f /PySide/QtCore/qtime_conversions.h
parent952f9f0bda958afa36421c6af828f55f643a3deb (diff)
Implemented convertion from Python types for QDate, QTime, QDateTime.
Fixes bug #680 Reviewer: pcacjr <pcacjr@gmail.com> Hugo Parente <hugo.lima@openbossa.org>
Diffstat (limited to 'PySide/QtCore/qtime_conversions.h')
-rw-r--r--PySide/QtCore/qtime_conversions.h65
1 files changed, 37 insertions, 28 deletions
diff --git a/PySide/QtCore/qtime_conversions.h b/PySide/QtCore/qtime_conversions.h
index 5e172fa07..080df5f2f 100644
--- a/PySide/QtCore/qtime_conversions.h
+++ b/PySide/QtCore/qtime_conversions.h
@@ -1,36 +1,45 @@
namespace Shiboken {
-template <>
-struct PythonConverter<QTime>
+
+inline bool Converter<QTime>::checkType(PyObject* pyObj)
{
- static bool isPythonConvertible(PyObject* pyObj)
- {
- if (!PyDateTimeAPI)
- PyDateTime_IMPORT;
+ return ValueTypeConverter<QTime>::checkType(pyObj);
+}
- return pyObj && PyTime_Check(pyObj);
- }
+inline PyObject* Converter<QTime>::toPython(const ::QTime& cppObj)
+{
+ return ValueTypeConverter<QTime>::toPython(cppObj);
+}
- 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;
- }
+inline bool Converter<QTime>::isConvertible(PyObject* pyObj)
+{
+ if (ValueTypeConverter<QTime>::isConvertible(pyObj))
+ return true;
- static PyObject* transformToPython(QTime* d)
- {
- if (d) {
- if (!PyDateTimeAPI)
- PyDateTime_IMPORT;
+ if (!PyDateTimeAPI)
+ PyDateTime_IMPORT;
- return PyTime_FromTime(d->hour(), d->minute(), d->second(), d->msec());
- }
- return 0;
+ 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);
}
-};
+}
+
}