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 
25 #include "QDjango_p.h"
26 
27 class QDjangoMetaFieldPrivate;
28 class QDjangoMetaModelPrivate;
29 
34 class QDJANGO_DB_EXPORT QDjangoMetaField
35 {
36 public:
38  QDjangoMetaField(const QDjangoMetaField &other);
40  QDjangoMetaField& operator=(const QDjangoMetaField &other);
41 
42  QString column() const;
43  bool isAutoIncrement() const;
44  bool isBlank() const;
45  bool isNullable() const;
46  bool isUnique() const;
47  bool isValid() const;
48  QString name() const;
49  int maxLength() const;
50  QVariant toDatabase(const QVariant &value) const;
51 
52 private:
53  QSharedDataPointer<QDjangoMetaFieldPrivate> d;
54  friend class QDjangoMetaModel;
55 };
56 
64 class QDJANGO_DB_EXPORT QDjangoMetaModel
65 {
66 public:
67  QDjangoMetaModel(const QMetaObject *model = 0);
68  QDjangoMetaModel(const QDjangoMetaModel &other);
70  QDjangoMetaModel& operator=(const QDjangoMetaModel &other);
71 
72  bool isValid() const;
73 
74  bool createTable() const;
75  QStringList createTableSql() const;
76  bool dropTable() const;
77 
78  void load(QObject *model, const QVariantList &props, int &pos) const;
79  bool remove(QObject *model) const;
80  bool save(QObject *model) const;
81 
82  QObject *foreignKey(const QObject *model, const char *name) const;
83  void setForeignKey(QObject *model, const char *name, QObject *value) const;
84 
85  QString className() const;
86  QDjangoMetaField localField(const char *name) const;
87  QList<QDjangoMetaField> localFields() const;
88  QMap<QByteArray, QByteArray> foreignFields() const;
89  QByteArray primaryKey() const;
90  QString table() const;
91 
92 private:
93  QSharedDataPointer<QDjangoMetaModelPrivate> d;
94 };
95 
96 #endif
The QDjangoMetaField class holds the database schema for a field.
Definition: QDjangoMetaModel.h:34
The QDjangoMetaModel class holds the database schema for a model.
Definition: QDjangoMetaModel.h:64