QDjango: QDjangoMetaModel.h Source File

QDjango

QDjangoMetaModel.h
1 /*
2 * Copyright (C) 2010-2015 Jeremy Lainé
3 * Contact: https://github.com/jlaine/qdjango
4 *
5 * This file is part of the QDjango Library.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 */
17
18 #ifndef QDJANGOMETAMODEL_H
19 #define QDJANGOMETAMODEL_H
20
21 #include <QMap>
22 #include <QSharedDataPointer>
23 #include <QVariant>
24 #include <QStringList>
25
26 #include "QDjango_p.h"
27
28 class QDjangoMetaFieldPrivate;
29 class QDjangoMetaModelPrivate;
30
35 class QDJANGO_DB_EXPORT QDjangoMetaField
36 {
37 public:
38 QDjangoMetaField();
39 QDjangoMetaField(const QDjangoMetaField &other);
40 ~QDjangoMetaField();
41 QDjangoMetaField& operator=(const QDjangoMetaField &other);
42
43 QString column() const;
44 bool isAutoIncrement() const;
45 bool isBlank() const;
46 bool isNullable() const;
47 bool isUnique() const;
48 bool isValid() const;
49 QString name() const;
50 int maxLength() const;
51 QVariant toDatabase(const QVariant &value) const;
52
53 private:
54 QSharedDataPointer<QDjangoMetaFieldPrivate> d;
55 friend class QDjangoMetaModel;
56 };
57
65 class QDJANGO_DB_EXPORT QDjangoMetaModel
66 {
67 public:
68 QDjangoMetaModel(const QMetaObject *model = 0);
69 QDjangoMetaModel(const QDjangoMetaModel &other);
70 ~QDjangoMetaModel();
71 QDjangoMetaModel& operator=(const QDjangoMetaModel &other);
72
73 bool isValid() const;
74
75 bool createTable() const;
76 QStringList createTableSql() const;
77 bool dropTable() const;
78
79 void load(QObject *model, const QVariantList &props, int &pos, const QStringList &relatedFields = QStringList()) const;
80 bool remove(QObject *model) const;
81 bool save(QObject *model) const;
82
83 QObject *foreignKey(const QObject *model, const char *name) const;
84 void setForeignKey(QObject *model, const char *name, QObject *value) const;
85
86 QString className() const;
87 QDjangoMetaField localField(const char *name) const;
88 QList<QDjangoMetaField> localFields() const;
89 QMap<QByteArray, QByteArray> foreignFields() const;
90 QByteArray primaryKey() const;
91 QString table() const;
92
93 private:
94 QSharedDataPointer<QDjangoMetaModelPrivate> d;
95 };
96
97 #endif
QDjangoMetaField
The QDjangoMetaField class holds the database schema for a field.
Definition: QDjangoMetaModel.h:36
QDjangoMetaModel
The QDjangoMetaModel class holds the database schema for a model.
Definition: QDjangoMetaModel.h:66