QDjango
 All Classes Functions Typedefs Enumerations Enumerator Properties Groups Pages
QDjangoMetaModel.h
1 /*
2  * Copyright (C) 2010-2012 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 isValid() const;
44  QString name() const;
45  QVariant toDatabase(const QVariant &value) const;
46 
47 private:
48  QSharedDataPointer<QDjangoMetaFieldPrivate> d;
49  friend class QDjangoMetaModel;
50 };
51 
59 class QDJANGO_EXPORT QDjangoMetaModel
60 {
61 public:
62  QDjangoMetaModel(const QObject *model = 0);
63  QDjangoMetaModel(const QDjangoMetaModel &other);
65  QDjangoMetaModel& operator=(const QDjangoMetaModel &other);
66 
67  bool createTable() const;
68  bool dropTable() const;
69 
70  void load(QObject *model, const QVariantList &props, int &pos) const;
71  bool remove(QObject *model) const;
72  bool save(QObject *model) const;
73 
74  QObject *foreignKey(const QObject *model, const char *name) const;
75  void setForeignKey(QObject *model, const char *name, QObject *value) const;
76 
77  QDjangoMetaField localField(const QString &name) const;
78  QList<QDjangoMetaField> localFields() const;
79  QMap<QByteArray, QString> foreignFields() const;
80  QByteArray primaryKey() const;
81  QString table() const;
82 
83 private:
84  QSharedDataPointer<QDjangoMetaModelPrivate> d;
85 };
86 
87 #endif