File: tst_qdjangometamodel.h

package info (click to toggle)
qdjango 0.6.2-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 908 kB
  • sloc: cpp: 7,818; sh: 32; makefile: 12; javascript: 1
file content (249 lines) | stat: -rw-r--r-- 6,487 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * Copyright (C) 2010-2015 Jeremy Lainé
 * Contact: https://github.com/jlaine/qdjango
 *
 * This file is part of the QDjango Library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

#include <QDate>

#include "QDjangoModel.h"

#include "auth-models.h"

class tst_QDjangoMetaModel : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase();
    void testBool();
    void testByteArray();
    void testDate();
    void testDateTime();
    void testDouble();
    void testInteger();
    void testLongLong();
    void testString();
    void testTime();
    void testOptions();
    void testConstraints();
    void testIsValid();
};

class tst_Bool : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(bool value READ value WRITE setValue)

public:
    bool value() const { return m_value; }
    void setValue(bool value) { m_value = value; }

private:
    bool m_value;
};

class tst_ByteArray : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(QByteArray value READ value WRITE setValue)

public:
    QByteArray value() const { return m_value; }
    void setValue(const QByteArray &value) { m_value = value; }

private:
    QByteArray m_value;
};

class tst_Date : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(QDate value READ value WRITE setValue)

public:
    QDate value() const { return m_value; }
    void setValue(const QDate &value) { m_value = value; }

private:
    QDate m_value;
};

class tst_DateTime : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(QDateTime value READ value WRITE setValue)

public:
    QDateTime value() const { return m_value; }
    void setValue(const QDateTime &value) { m_value = value; }

private:
    QDateTime m_value;
};

class tst_Double : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(double value READ value WRITE setValue)

public:
    double value() const { return m_value; }
    void setValue(double value) { m_value = value; }

private:
    double m_value;
};

class tst_Integer : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(int value READ value WRITE setValue)

public:
    int value() const { return m_value; }
    void setValue(int value) { m_value = value; }

private:
    int m_value;
};

class tst_LongLong : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(qlonglong value READ value WRITE setValue)

public:
    qlonglong value() const { return m_value; }
    void setValue(qlonglong value) { m_value = value; }

private:
    qlonglong m_value;
};

class tst_String : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(QString value READ value WRITE setValue)
    Q_CLASSINFO("value", "max_length=255")

public:
    QString value() const { return m_value; }
    void setValue(const QString &value) { m_value = value; }

private:
    QString m_value;
};

class tst_Time : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(QTime value READ value WRITE setValue)

public:
    QTime value() const { return m_value; }
    void setValue(const QTime &value) { m_value = value; }

private:
    QTime m_value;
};

class tst_Options : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(int aField READ aField WRITE setAField)
    Q_PROPERTY(int bField READ bField WRITE setBField)
    Q_PROPERTY(int blankField READ blankField WRITE setBlankField)
    Q_PROPERTY(int ignoredField READ ignoredField WRITE setIgnoredField)
    Q_PROPERTY(int indexField READ indexField WRITE setIndexField)
    Q_PROPERTY(int nullField READ nullField WRITE setNullField)
    Q_PROPERTY(int uniqueField READ uniqueField WRITE setUniqueField)

    Q_CLASSINFO("__meta__", "db_table=some_table unique_together=aField,bField")
    Q_CLASSINFO("bField", "db_column=b_field")
    Q_CLASSINFO("blankField", "blank=true")
    Q_CLASSINFO("ignoredField", "ignore_field=true")
    Q_CLASSINFO("indexField", "db_index=true")
    Q_CLASSINFO("nullField", "null=true")
    Q_CLASSINFO("uniqueField", "unique=true")

public:
    int aField() const { return m_aField; }
    void setAField(int value) { m_aField = value; }

    int bField() const { return m_bField; }
    void setBField(int value) { m_bField = value; }

    int blankField() const { return m_blankField; }
    void setBlankField(int value) { m_blankField = value; }

    int ignoredField() const { return m_ignoredField; }
    void setIgnoredField(int value) { m_ignoredField = value; }

    int indexField() const { return m_indexField; }
    void setIndexField(int value) { m_indexField = value; }

    int nullField() const { return m_nullField; }
    void setNullField(int value) { m_nullField = value; }

    int uniqueField() const { return m_uniqueField; }
    void setUniqueField(int value) { m_uniqueField = value; }

private:
    int m_aField;
    int m_bField;
    int m_blankField;
    int m_ignoredField;
    int m_indexField;
    int m_nullField;
    int m_uniqueField;
};

class tst_FkConstraint : public QDjangoModel
{
    Q_OBJECT
    Q_PROPERTY(User *noConstraint READ noConstraint WRITE setNoConstraint)
    Q_PROPERTY(User *cascadeConstraint READ cascadeConstraint WRITE setCascadeConstraint)
    Q_PROPERTY(Group *nullConstraint READ nullConstraint WRITE setNullConstraint)

    Q_CLASSINFO("cascadeConstraint", "on_delete=cascade")
    Q_CLASSINFO("restrictConstraint", "on_delete=restrict")
    Q_CLASSINFO("nullConstraint", "null=true on_delete=set_null")

public:
    tst_FkConstraint(QObject *parent = 0);

    User *noConstraint() const;
    void setNoConstraint(User *user);

    User *cascadeConstraint() const;
    void setCascadeConstraint(User *user);

    Group *nullConstraint() const;
    void setNullConstraint(Group *group);
};

class tst_FkConstraintWithRestrict : public tst_FkConstraint
{
    Q_OBJECT
    Q_PROPERTY(User *restrictConstraint READ restrictConstraint WRITE setRestrictConstraint)

    Q_CLASSINFO("__meta__", "db_table=tst_fkconstraint")
    Q_CLASSINFO("restrictConstraint", "on_delete=restrict")
public:
    tst_FkConstraintWithRestrict(QObject *parent = 0);

    User *restrictConstraint() const;
    void setRestrictConstraint(User *user);
};