diff options
author | Renato Filho <renato.filho@openbossa.org> | 2011-05-17 17:36:04 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:54:23 -0300 |
commit | 8e221bfb9731589a4a4d4712745252e50b0a97c6 (patch) | |
tree | 8218a7ffe61da431312d7003b37547c089aca03f /PySide/QtCore/qdate_conversions.h | |
parent | 952f9f0bda958afa36421c6af828f55f643a3deb (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/qdate_conversions.h')
-rw-r--r-- | PySide/QtCore/qdate_conversions.h | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/PySide/QtCore/qdate_conversions.h b/PySide/QtCore/qdate_conversions.h index e0f1dd953..7c45eece9 100644 --- a/PySide/QtCore/qdate_conversions.h +++ b/PySide/QtCore/qdate_conversions.h @@ -1,35 +1,45 @@ namespace Shiboken { -template <> -struct PythonConverter<QDate> + +inline bool Converter<QDate>::checkType(PyObject* pyObj) { - static bool isPythonConvertible(PyObject* pyObj) - { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; + return ValueTypeConverter<QDate>::checkType(pyObj); +} - return pyObj && PyDate_Check(pyObj); - } +inline PyObject* Converter<QDate>::toPython(const ::QDate& cppObj) +{ + return ValueTypeConverter<QDate>::toPython(cppObj); +} - static QDate* transformFromPython(PyObject* obj) - { - if (isPythonConvertible(obj)) { - int day = PyDateTime_GET_DAY(obj); - int month = PyDateTime_GET_MONTH(obj); - int year = PyDateTime_GET_YEAR(obj); - return new QDate(year, month, day); - } - return 0; - } +inline bool Converter<QDate>::isConvertible(PyObject* pyObj) +{ + if (ValueTypeConverter<QDate>::isConvertible(pyObj)) + return true; - static PyObject* transformToPython(QDate* d) - { - if (d) { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; + if (!PyDateTimeAPI) + PyDateTime_IMPORT; - return PyDate_FromDate(d->year(), d->month(), d->day()); - } - return 0; + SbkObjectType* shiboType = reinterpret_cast<SbkObjectType*>(SbkType< ::QDate >()); + return PyDate_Check(pyObj) || ObjectType::isExternalConvertible(shiboType, pyObj); +} + +inline QDate Converter<QDate>::toCpp(PyObject* pyObj) +{ + if (!PyDateTimeAPI) + PyDateTime_IMPORT; + + if (pyObj == Py_None) { + return QDate(); + } else if (PyObject_TypeCheck(pyObj, SbkType<QDate>())) { + return *Converter<QDate*>::toCpp(pyObj); + } else if (PyDate_Check(pyObj)) { + int day = PyDateTime_GET_DAY(pyObj); + int month = PyDateTime_GET_MONTH(pyObj); + int year = PyDateTime_GET_YEAR(pyObj); + return QDate(year, month, day); + } else { + return ValueTypeConverter<QDate>::toCpp(pyObj); } -}; +} + + } |