~ubuntu-branches/ubuntu/oneiric/pyside/oneiric

« back to all changes in this revision

Viewing changes to PySide/QtCore/qdate_conversions.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2010-10-19 22:52:14 UTC
  • mfrom: (1.1.4 upstream)
  • mto: (13.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101019225214-0s9fbpz12x3962qa
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace Shiboken {
 
2
template <>
 
3
struct PythonConverter<QDate>
 
4
{
 
5
    static bool isPythonConvertible(PyObject* pyObj)
 
6
    {
 
7
        if (!PyDateTimeAPI)
 
8
            PyDateTime_IMPORT;
 
9
 
 
10
        return pyObj && PyDate_Check(pyObj);
 
11
    }
 
12
 
 
13
    static QDate* transformFromPython(PyObject* obj)
 
14
    {
 
15
        if (isPythonConvertible(obj)) {
 
16
            int day = PyDateTime_GET_DAY(obj);
 
17
            int month = PyDateTime_GET_MONTH(obj);
 
18
            int year = PyDateTime_GET_YEAR(obj);
 
19
            return new QDate(year, month, day);
 
20
        }
 
21
        return 0;
 
22
    }
 
23
 
 
24
    static PyObject* transformToPython(QDate* d)
 
25
    {
 
26
        if (d) {
 
27
            if (!PyDateTimeAPI) 
 
28
                PyDateTime_IMPORT;
 
29
 
 
30
            return PyDate_FromDate(d->year(), d->month(), d->day());
 
31
        }
 
32
        return 0;
 
33
    }
 
34
};
 
35
}