QDjango
 All Classes Functions Typedefs Enumerations Enumerator Properties Groups Pages
QDjangoMetaModel.h
1 /*
2  * Copyright (C) 2010-2013 Jeremy LainĂ©
3  * Contact: http://code.google.com/p/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_EXPORT QDjangoMetaField
35 {
36 public:
38  QDjangoMetaField(const QDjangoMetaField &other);
40  QDjangoMetaField& operator=(const QDjangoMetaField &other);
41 
42  QString column() const;
43  bool isNullable() const;
44  bool isValid() const;
45  QString name() const;
46  QVariant toDatabase(const QVariant &value) const;
47 
48 private:
49  QSharedDataPointer<QDjangoMetaFieldPrivate> d;
50  friend class QDjangoMetaModel;
51 };
52 
60 class QDJANGO_EXPORT QDjangoMetaModel
61 {
62 public:
63  QDjangoMetaModel(const QMetaObject *model = 0);
64  QDjangoMetaModel(const QDjangoMetaModel &other);
66  QDjangoMetaModel& operator=(const QDjangoMetaModel &other);
67 
68  bool createTable() const;
69  QStringList createTableSql() const;
70  bool dropTable() const;
71 
72  void load(QObject *model, const QVariantList &props, int &pos) const;
73  bool remove(QObject *model) const;
74  bool save(QObject *model) const;
75 
76  QObject *foreignKey(const QObject *model, const char *name) const;
77  void setForeignKey(QObject *model, const char *name, QObject *value) const;
78 
79  QDjangoMetaField localField(const char *name) const;
80  QList<QDjangoMetaField> localFields() const;
81  QMap<QByteArray, QByteArray> foreignFields() const;
82  QByteArray primaryKey() const;
83  QString table() const;
84 
85 private:
86  QSharedDataPointer<QDjangoMetaModelPrivate> d;
87 };
88 
89 #endif