diff options
author | renatofilho <renato.filho@openbossa.org> | 2010-10-01 19:00:36 -0300 |
---|---|---|
committer | renatofilho <renato.filho@openbossa.org> | 2010-10-01 19:45:30 -0300 |
commit | 940b90e80a7ec21e513ac16ff73d8fa8cf23d489 (patch) | |
tree | e75a0dd76faab2379d23f72a1e8ac6ab82e98b75 /PySide/QtCore/qdate_conversions.h | |
parent | 288a53369fa8df74a92c7517e8744c5139797c78 (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/qdate_conversions.h')
-rw-r--r-- | PySide/QtCore/qdate_conversions.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/PySide/QtCore/qdate_conversions.h b/PySide/QtCore/qdate_conversions.h new file mode 100644 index 000000000..e0f1dd953 --- /dev/null +++ b/PySide/QtCore/qdate_conversions.h @@ -0,0 +1,35 @@ +namespace Shiboken { +template <> +struct PythonConverter<QDate> +{ + static bool isPythonConvertible(PyObject* pyObj) + { + if (!PyDateTimeAPI) + PyDateTime_IMPORT; + + return pyObj && PyDate_Check(pyObj); + } + + 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; + } + + static PyObject* transformToPython(QDate* d) + { + if (d) { + if (!PyDateTimeAPI) + PyDateTime_IMPORT; + + return PyDate_FromDate(d->year(), d->month(), d->day()); + } + return 0; + } +}; +} |