Loading...
Searching...
No Matches
QDjangoMetaModel.h
/*
* Copyright (C) 2010-2015 Jeremy Lainé
* Contact: https://github.com/jlaine/qdjango
*
* This file is part of the QDjango Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#ifndef QDJANGOMETAMODEL_H
#define QDJANGOMETAMODEL_H
#include <QMap>
#include <QSharedDataPointer>
#include <QVariant>
#include "QDjango_p.h"
class QDjangoMetaFieldPrivate;
class QDjangoMetaModelPrivate;
class QDJANGO_DB_EXPORT QDjangoMetaField
{
public:
QDjangoMetaField();
QDjangoMetaField(const QDjangoMetaField &other);
~QDjangoMetaField();
QDjangoMetaField& operator=(const QDjangoMetaField &other);
QString column() const;
bool isAutoIncrement() const;
bool isBlank() const;
bool isNullable() const;
bool isUnique() const;
bool isValid() const;
QString name() const;
int maxLength() const;
QVariant toDatabase(const QVariant &value) const;
private:
QSharedDataPointer<QDjangoMetaFieldPrivate> d;
friend class QDjangoMetaModel;
};
class QDJANGO_DB_EXPORT QDjangoMetaModel
{
public:
QDjangoMetaModel(const QMetaObject *model = 0);
QDjangoMetaModel(const QDjangoMetaModel &other);
~QDjangoMetaModel();
QDjangoMetaModel& operator=(const QDjangoMetaModel &other);
bool isValid() const;
bool createTable() const;
QStringList createTableSql() const;
bool dropTable() const;
void load(QObject *model, const QVariantList &props, int &pos) const;
bool remove(QObject *model) const;
bool save(QObject *model) const;
QObject *foreignKey(const QObject *model, const char *name) const;
void setForeignKey(QObject *model, const char *name, QObject *value) const;
QString className() const;
QDjangoMetaField localField(const char *name) const;
QList<QDjangoMetaField> localFields() const;
QMap<QByteArray, QByteArray> foreignFields() const;
QByteArray primaryKey() const;
QString table() const;
private:
QSharedDataPointer<QDjangoMetaModelPrivate> d;
};
#endif
QDjangoMetaField
The QDjangoMetaField class holds the database schema for a field.
Definition QDjangoMetaModel.h:35
QDjangoMetaField::column
QString column() const
Returns the database column for this meta field.
Definition QDjangoMetaModel.cpp:136
QDjangoMetaField::isNullable
bool isNullable() const
Returns true if this field is nullable.
Definition QDjangoMetaModel.cpp:144
QDjangoMetaField::isBlank
bool isBlank() const
Returns true if this field can be empty.
Definition QDjangoMetaModel.cpp:176
QDjangoMetaField::toDatabase
QVariant toDatabase(const QVariant &value) const
Transforms the given field value for database storage.
Definition QDjangoMetaModel.cpp:200
QDjangoMetaField::maxLength
int maxLength() const
Returns the max length of this field.
Definition QDjangoMetaModel.cpp:192
QDjangoMetaField::name
QString name() const
Returns name of this meta field.
Definition QDjangoMetaModel.cpp:184
QDjangoMetaField::isUnique
bool isUnique() const
Returns true if this field is unique.
Definition QDjangoMetaModel.cpp:168
QDjangoMetaField::QDjangoMetaField
QDjangoMetaField()
Constructs a new QDjangoMetaField.
Definition QDjangoMetaModel.cpp:104
QDjangoMetaField::isAutoIncrement
bool isAutoIncrement() const
Returns true if this field is auto incremented.
Definition QDjangoMetaModel.cpp:160
QDjangoMetaField::operator=
QDjangoMetaField & operator=(const QDjangoMetaField &other)
Assigns other to this meta field.
Definition QDjangoMetaModel.cpp:127
QDjangoMetaField::isValid
bool isValid() const
Returns true if this is a valid field.
Definition QDjangoMetaModel.cpp:152
QDjangoMetaModel::localFields
QList< QDjangoMetaField > localFields() const
Returns the list of local fields.
Definition QDjangoMetaModel.cpp:772
QDjangoMetaModel::QDjangoMetaModel
QDjangoMetaModel(const QMetaObject *model=0)
Constructs a new QDjangoMetaModel by inspecting the given meta model.
Definition QDjangoMetaModel.cpp:245
QDjangoMetaModel::foreignKey
QObject * foreignKey(const QObject *model, const char *name) const
Retrieves the QDjangoModel pointed to by the given foreign-key.
Definition QDjangoMetaModel.cpp:667
QDjangoMetaModel::remove
bool remove(QObject *model) const
Removes the given model instance from the database.
Definition QDjangoMetaModel.cpp:796
QDjangoMetaModel::setForeignKey
void setForeignKey(QObject *model, const char *name, QObject *value) const
Sets the QDjangoModel pointed to by the given foreign-key.
Definition QDjangoMetaModel.cpp:702
QDjangoMetaModel::localField
QDjangoMetaField localField(const char *name) const
Return the local field with the specified name.
Definition QDjangoMetaModel.cpp:759
QDjangoMetaModel::table
QString table() const
Returns the name of the database table.
Definition QDjangoMetaModel.cpp:788
QDjangoMetaModel::dropTable
bool dropTable() const
Drops the database table for this QDjangoMetaModel.
Definition QDjangoMetaModel.cpp:650
QDjangoMetaModel::primaryKey
QByteArray primaryKey() const
Returns the name of the primary key for the current QDjangoMetaModel.
Definition QDjangoMetaModel.cpp:780
QDjangoMetaModel::operator=
QDjangoMetaModel & operator=(const QDjangoMetaModel &other)
Assigns other to this meta model.
Definition QDjangoMetaModel.cpp:414
QDjangoMetaModel::createTable
bool createTable() const
Creates the database table for this QDjangoMetaModel.
Definition QDjangoMetaModel.cpp:425
QDjangoMetaModel::isValid
bool isValid() const
Determine whether this is a valid model, or just default constructed.
Definition QDjangoMetaModel.cpp:406
QDjangoMetaModel::createTableSql
QStringList createTableSql() const
Returns the SQL queries to create the database table for this QDjangoMetaModel.
Definition QDjangoMetaModel.cpp:439
QDjangoMetaModel::save
bool save(QObject *model) const
Saves the given model instance to the database.
Definition QDjangoMetaModel.cpp:809
QDjangoMetaModel::foreignFields
QMap< QByteArray, QByteArray > foreignFields() const
Returns the foreign field mapping.
Definition QDjangoMetaModel.cpp:751
QDjangoMetaModel::load
void load(QObject *model, const QVariantList &props, int &pos) const
Loads the given properties into a model instance.
Definition QDjangoMetaModel.cpp:728