QDjango
QDjangoMetaModel.h
00001 /*
00002  * Copyright (C) 2010-2012 Jeremy Lainé
00003  * Contact: http://code.google.com/p/qdjango/
00004  *
00005  * This file is part of the QDjango Library.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  */
00017 
00018 #ifndef QDJANGOMETAMODEL_H
00019 #define QDJANGOMETAMODEL_H
00020 
00021 #include <QMap>
00022 #include <QSharedDataPointer>
00023 #include <QVariant>
00024 
00025 #include "QDjango_p.h"
00026 
00027 class QDjangoMetaFieldPrivate;
00028 class QDjangoMetaModelPrivate;
00029 
00034 class QDJANGO_EXPORT QDjangoMetaField
00035 {
00036 public:
00037     QDjangoMetaField();
00038     QDjangoMetaField(const QDjangoMetaField &other);
00039     ~QDjangoMetaField();
00040     QDjangoMetaField& operator=(const QDjangoMetaField &other);
00041 
00042     QString column() const;
00043     bool isValid() const;
00044     QString name() const;
00045     QVariant toDatabase(const QVariant &value) const;
00046 
00047 private:
00048     QSharedDataPointer<QDjangoMetaFieldPrivate> d;
00049     friend class QDjangoMetaModel;
00050 };
00051 
00059 class QDJANGO_EXPORT QDjangoMetaModel
00060 {
00061 public:
00062     QDjangoMetaModel(const QObject *model = 0);
00063     QDjangoMetaModel(const QDjangoMetaModel &other);
00064     ~QDjangoMetaModel();
00065     QDjangoMetaModel& operator=(const QDjangoMetaModel &other);
00066 
00067     bool createTable() const;
00068     bool dropTable() const;
00069 
00070     void load(QObject *model, const QVariantList &props, int &pos) const;
00071     bool remove(QObject *model) const;
00072     bool save(QObject *model) const;
00073 
00074     QObject *foreignKey(const QObject *model, const char *name) const;
00075     void setForeignKey(QObject *model, const char *name, QObject *value) const;
00076 
00077     QDjangoMetaField localField(const QString &name) const;
00078     QList<QDjangoMetaField> localFields() const;
00079     QMap<QByteArray, QString> foreignFields() const;
00080     QByteArray primaryKey() const;
00081     QString table() const;
00082 
00083 private:
00084     QSharedDataPointer<QDjangoMetaModelPrivate> d;
00085 };
00086 
00087 #endif
 All Classes Functions Typedefs Enumerations Enumerator Properties