summaryrefslogtreecommitdiffstats
path: root/PySide
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
parent288a53369fa8df74a92c7517e8744c5139797c78 (diff)
downloadpyside-940b90e80a7ec21e513ac16ff73d8fa8cf23d489.tar.gz
pyside-940b90e80a7ec21e513ac16ff73d8fa8cf23d489.tar.xz
pyside-940b90e80a7ec21e513ac16ff73d8fa8cf23d489.zip
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')
-rw-r--r--PySide/QtCore/qdate_conversions.h35
-rw-r--r--PySide/QtCore/qdatetime_conversions.h41
-rw-r--r--PySide/QtCore/qtime_conversions.h36
-rw-r--r--PySide/QtCore/typesystem_core.xml20
4 files changed, 130 insertions, 2 deletions
diff --git a/PySide/QtCore/qdate_conversions.h b/PySide/QtCore/qdate_conversions.h
new file mode 100644
index 0000000..e0f1dd9
--- /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;
+ }
+};
+}
diff --git a/PySide/QtCore/qdatetime_conversions.h b/PySide/QtCore/qdatetime_conversions.h
new file mode 100644
index 0000000..a3cdf09
--- /dev/null
+++ b/PySide/QtCore/qdatetime_conversions.h
@@ -0,0 +1,41 @@
+namespace Shiboken {
+template <>
+struct PythonConverter<QDateTime>
+{
+ static bool isPythonConvertible(PyObject* pyObj)
+ {
+ if (!PyDateTimeAPI)
+ PyDateTime_IMPORT;
+
+ return pyObj && PyDateTime_Check(pyObj);
+ }
+
+ static QDateTime* transformFromPython(PyObject* obj)
+ {
+ if (isPythonConvertible(obj)) {
+ int day = PyDateTime_GET_DAY(obj);
+ int month = PyDateTime_GET_MONTH(obj);
+ int year = PyDateTime_GET_YEAR(obj);
+ int hour = PyDateTime_DATE_GET_HOUR(obj);
+ int min = PyDateTime_DATE_GET_MINUTE(obj);
+ int sec = PyDateTime_DATE_GET_SECOND(obj);
+ int msec = PyDateTime_DATE_GET_MICROSECOND(obj);
+ return new QDateTime(QDate(year, month, day), QTime(hour, min, sec, msec));
+ }
+ return 0;
+ }
+
+ static PyObject* transformToPython(QDateTime* d)
+ {
+ if (d) {
+ if (!PyDateTimeAPI)
+ PyDateTime_IMPORT;
+
+ QDate date = d->date();
+ QTime time = d->time();
+ return PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec());
+ }
+ return 0;
+ }
+};
+}
diff --git a/PySide/QtCore/qtime_conversions.h b/PySide/QtCore/qtime_conversions.h
new file mode 100644
index 0000000..5e172fa
--- /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;
+ }
+};
+}
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 68bd04c..704e8d4 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -721,6 +721,10 @@
<value-type name="QBasicTimer"/>
<value-type name="QByteArrayMatcher"/>
<value-type name="QDate" hash-function="PySide::hash" >
+ <conversion-rule class="target" file="qdate_conversions.h"/>
+ <extra-includes>
+ <include file-name="datetime.h" location="global"/>
+ </extra-includes>
<enum-type name="MonthNameType"/>
<modify-function signature="julianToGregorian(uint,int&amp;,int&amp;,int&amp;)" remove="all"/>
<modify-function signature="getDate(int*,int*,int*)" >
@@ -756,7 +760,14 @@
</inject-code>
</modify-function>
</value-type>
- <value-type name="QDateTime" hash-function="PySide::hash"/>
+
+ <value-type name="QDateTime" hash-function="PySide::hash">
+ <conversion-rule class="target" file="qdatetime_conversions.h"/>
+ <extra-includes>
+ <include file-name="datetime.h" location="global"/>
+ </extra-includes>
+ </value-type>
+
<value-type name="QDir">
<enum-type name="Filter" flags="QDir::Filters"/>
<enum-type name="SortFlag" flags="QDir::SortFlags" />
@@ -818,7 +829,12 @@
<modify-function signature="rwidth()" remove="all" />
</value-type>
- <value-type name="QTime" hash-function="PySide::hash"/>
+ <value-type name="QTime" hash-function="PySide::hash">
+ <conversion-rule class="target" file="qtime_conversions.h"/>
+ <extra-includes>
+ <include file-name="datetime.h" location="global"/>
+ </extra-includes>
+ </value-type>
<value-type name="QPersistentModelIndex">
<modify-function signature="internalPointer()const" remove="all"/>
<modify-function signature="operator const QModelIndex&amp;()const" remove="all" /> <!-- FIXME Removed due to a shiboken bug-->