before new parent check

This commit is contained in:
Hamed Masafi 2018-03-03 18:06:04 +03:30
parent 3bdf6f294d
commit f1e29ba0a4
7 changed files with 77 additions and 57 deletions

View File

@ -57,6 +57,10 @@ DatabaseModel::DatabaseModel(const QJsonObject &json) :
}
}
DatabaseModel::~DatabaseModel()
{
}
TableModel *DatabaseModel::tableByName(QString tableName) const
{
for(int i = 0; i < size(); i++){
@ -223,4 +227,10 @@ DatabaseModel *DatabaseModel::modelByName(const QString &name)
return Q_NULLPTR;
}
void DatabaseModel::deleteAllModels()
{
qDeleteAll(_models.values());
_models.clear();
}
NUT_END_NAMESPACE

View File

@ -43,6 +43,7 @@ public:
DatabaseModel(const QString &name = QString::null);
DatabaseModel(const DatabaseModel &other);
DatabaseModel(const QJsonObject &json);
~DatabaseModel();
TableModel *tableByName(QString tableName) const;
TableModel *tableByClassName(QString className) const;
@ -69,6 +70,7 @@ public:
void fixRelations();
static DatabaseModel *modelByName(const QString &name);
static void deleteAllModels();
};
NUT_END_NAMESPACE

View File

@ -32,73 +32,77 @@
# define NUT_EXPORT Q_DECL_EXPORT
#endif
#define NUT_INFO(type, name, value) \
Q_CLASSINFO(__nut_NAME_PERFIX type #name #value, type "\n" #name "\n" #value)
#define NUT_INFO(type, name, value) \
Q_CLASSINFO(__nut_NAME_PERFIX type #name #value, \
type "\n" #name "\n" #value)
// Database
#define NUT_DB_VERSION(version) \
NUT_INFO(__nut_DB_VERSION, version, 0)
#define NUT_DECLARE_TABLE(type, name) \
#define NUT_DECLARE_TABLE(type, name) \
NUT_INFO(__nut_TABLE, type, name) \
Q_PROPERTY(type* name READ name) \
Q_PROPERTY(NUT_WRAP_NAMESPACE(TableSet<type>) name##Table READ name##Table) \
type* m_##name; \
NUT_WRAP_NAMESPACE(TableSet<type>) *m_##name##Table; \
public: \
static const type _##name; \
type* name() const{ return m_##name; } \
NUT_WRAP_NAMESPACE(TableSet<type>) *name##Table() const { return m_##name##Table; }
Q_PROPERTY(type* name READ name) \
Q_PROPERTY(NUT_WRAP_NAMESPACE(TableSet<type>) name##Table READ name##Table)\
type* m_##name; \
NUT_WRAP_NAMESPACE(TableSet<type>) *m_##name##Table; \
public: \
static const type _##name; \
type* name() const{ return m_##name; } \
NUT_WRAP_NAMESPACE(TableSet<type>) *name##Table() const \
{ return m_##name##Table; }
//Table
#define NUT_DECLARE_FIELD(type, name, read, write) \
Q_PROPERTY(type name READ read WRITE write) \
NUT_INFO(__nut_FIELD, name, 0) \
type m_##name; \
public: \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>) name ## Field(){ \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>) f = NUT_WRAP_NAMESPACE(FieldPhrase<type>)(staticMetaObject.className(), #name); \
return f; \
} \
type read() const{ \
return m_##name; \
} \
void write(type name){ \
m_##name = name; \
propertyChanged(#name); \
#define NUT_DECLARE_FIELD(type, name, read, write) \
Q_PROPERTY(type name READ read WRITE write) \
NUT_INFO(__nut_FIELD, name, 0) \
type m_##name; \
public: \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>) name ## Field(){ \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>) f = \
NUT_WRAP_NAMESPACE(FieldPhrase<type>) \
(staticMetaObject.className(), #name); \
return f; \
} \
type read() const{ \
return m_##name; \
} \
void write(type name){ \
m_##name = name; \
propertyChanged(#name); \
}
#define NUT_FOREGION_KEY(type, keytype, name, read, write) \
Q_PROPERTY(type* name READ read WRITE write) \
NUT_DECLARE_FIELD(keytype, name##Id, read##Id, write##Id) \
#define NUT_FOREGION_KEY(type, keytype, name, read, write) \
Q_PROPERTY(type* name READ read WRITE write) \
NUT_DECLARE_FIELD(keytype, name##Id, read##Id, write##Id) \
NUT_INFO(__nut_FOREGION_KEY, name, type) \
type *m_##name; \
public: \
type *read() const { return m_##name ; } \
void write(type *name){ \
m_##name = name; \
type *m_##name; \
public: \
type *read() const { return m_##name ; } \
void write(type *name){ \
m_##name = name; \
}
#define NUT_DECLARE_CHILD_TABLE(type, n) \
private: \
NUT_WRAP_NAMESPACE(TableSet)<type> *m_##n; \
public: \
static type *n##Table(); \
#define NUT_DECLARE_CHILD_TABLE(type, n) \
private: \
NUT_WRAP_NAMESPACE(TableSet)<type> *m_##n; \
public: \
static type *n##Table(); \
NUT_WRAP_NAMESPACE(TableSet)<type> *n();
#define NUT_IMPLEMENT_CHILD_TABLE(class, type, n) \
type *class::n##Table(){ \
static type *f = new type(); \
return f; \
} \
NUT_WRAP_NAMESPACE(TableSet)<type> *class::n(){ \
return m_##n; \
#define NUT_IMPLEMENT_CHILD_TABLE(class, type, n) \
type *class::n##Table(){ \
static type *f = new type(); \
return f; \
} \
NUT_WRAP_NAMESPACE(TableSet)<type> *class::n(){ \
return m_##n; \
}
#define NUT_PRIMARY_KEY(x) NUT_INFO(__nut_PRIMARY_KEY, x, 0)
#define NUT_AUTO_INCREMENT(x) NUT_INFO(__nut_AUTO_INCREMENT, x, 0)
#define NUT_PRIMARY_AUTO_INCREMENT(x) NUT_PRIMARY_KEY(x) \
#define NUT_PRIMARY_AUTO_INCREMENT(x) NUT_PRIMARY_KEY(x) \
NUT_AUTO_INCREMENT(x)
#define NUT_DISPLAY_NAME(field, name) NUT_INFO(__nut_DISPLAY, field, name)
#define NUT_UNIQUE(x) NUT_INFO(__nut_UNIQUE, x, 0)

View File

@ -21,10 +21,10 @@
#ifndef DEFINES_P_H
#define DEFINES_P_H
#define __NAME "name"
#define __TYPE "type"
#define __FIELDS "fields"
#define __FOREIGN_KEYS "foreign_keys"
#define __NAME "name"
#define __TYPE "type"
#define __FIELDS "fields"
#define __FOREIGN_KEYS "foreign_keys"
#define __nut_FIELD "field"
#define __nut_DB_VERSION "database_version"

View File

@ -157,11 +157,11 @@ AbstractFieldPhraseOperatorField(<=, PhraseData::LessEqual)
AbstractFieldPhraseOperatorField(> , PhraseData::Greater)
AbstractFieldPhraseOperatorField(>=, PhraseData::GreaterEqual)
AbstractFieldPhrase &AbstractFieldPhrase::operator !()
AbstractFieldPhrase AbstractFieldPhrase::operator !()
{
AbstractFieldPhrase *f = new AbstractFieldPhrase(new PhraseData(data));
f->data->isNot = !data->isNot;
return *f;
AbstractFieldPhrase f(new PhraseData(data));
f.data->isNot = !data->isNot;
return f;
}
AssignmentPhrase AbstractFieldPhrase::operator =(const QVariant &other)
@ -182,6 +182,7 @@ PhraseList::PhraseList() : isValid(false)
PhraseList::PhraseList(const PhraseList &other) : isValid(true)
{
data = qMove(other.data);
const_cast<PhraseList&>(other).data.clear();
}
PhraseList::PhraseList(const AbstractFieldPhrase &other) : isValid(true)
@ -199,6 +200,8 @@ PhraseList::PhraseList(const AbstractFieldPhrase *left, const AbstractFieldPhras
PhraseList::PhraseList(PhraseList *left, PhraseList *right) : isValid(true)
{
data = qMove(left->data + right->data);
left->data.clear();
right->data.clear();
}
PhraseList::PhraseList(PhraseList *left, const AbstractFieldPhrase *right)
@ -210,6 +213,7 @@ PhraseList::PhraseList(PhraseList *left, const AbstractFieldPhrase *right)
PhraseList::~PhraseList()
{
qDeleteAll(data);
// data.clear();
}

View File

@ -253,7 +253,7 @@ public:
ConditionalPhrase operator <=(const AbstractFieldPhrase &other);
ConditionalPhrase operator >=(const AbstractFieldPhrase &other);
AbstractFieldPhrase &operator !();
AbstractFieldPhrase operator !();
AssignmentPhrase operator =(const QVariant &other);
AssignmentPhrase operator <<(const QVariant &other);
};

View File

@ -89,7 +89,7 @@ struct RelationModel{
};
bool operator ==(const RelationModel &l, const RelationModel &r);
bool operator !=(const RelationModel &l, const RelationModel &r);
class TableModel
class TableModel
{
public:
explicit TableModel(int typeId, QString tableName = QString::null);