test passed!

This commit is contained in:
Hamed Masafi 2018-02-18 18:28:55 +03:30
parent ace81b6fed
commit 56d8e3e6f7
4 changed files with 58 additions and 51 deletions

View File

@ -34,18 +34,18 @@ PhraseData::PhraseData(const char *className, const char *fieldName) :
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o)
: className(0), fieldName(0),
type(WithoutOperand), operatorCond(o), left(l), right(0), isNot(false)
type(WithoutOperand), operatorCond(o), left(new PhraseData(l)), right(0), isNot(false)
{ }
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o,
const PhraseData *r)
: className(0), fieldName(0),
type(WithOther), operatorCond(o), left(l), right(r), isNot(false)
type(WithOther), operatorCond(o), left(new PhraseData(l)), right(new PhraseData(r)), isNot(false)
{ }
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
: className(0), fieldName(0),
type(WithVariant), operatorCond(o), left(l), operand(r), isNot(false)
type(WithVariant), operatorCond(o), left(new PhraseData(l)), operand(r), isNot(false)
{ }
PhraseData::PhraseData(const PhraseData *other)
@ -57,6 +57,10 @@ PhraseData::PhraseData(const PhraseData *other)
className = other->className;
fieldName = other->fieldName;
type = other->type;
isNot = other->isNot;
if (type != Field) {
qDebug() << "Bug";
}
}
QString PhraseData::toString() const
@ -103,8 +107,9 @@ AbstractFieldPhrase::~AbstractFieldPhrase()
}
}
PhraseList AbstractFieldPhrase::operator |(const AbstractFieldPhrase &other) {
return PhraseList(this, &other);
PhraseList AbstractFieldPhrase::operator |(const AbstractFieldPhrase &other)
{
return PhraseList(this, other);
}
ConditionalPhrase AbstractFieldPhrase::isNull()
@ -164,34 +169,38 @@ PhraseList::PhraseList() : isValid(false)
}
PhraseList::PhraseList(const AbstractFieldPhrase &other) : isValid(true)
PhraseList::PhraseList(const PhraseList &other)
{
data.append(other.data);
data = qMove(other.data);
}
PhraseList::PhraseList(AbstractFieldPhrase *left, const AbstractFieldPhrase *right)
PhraseList::PhraseList(const AbstractFieldPhrase &other) : isValid(true)
{
data.append(new PhraseData(other.data));
}
PhraseList::PhraseList(const AbstractFieldPhrase *left, const AbstractFieldPhrase &right)
: isValid(true)
{
data.append(left->data);
data.append(right->data);
data.append(new PhraseData(left->data));
data.append(new PhraseData(right.data));
}
PhraseList::PhraseList(PhraseList *left, PhraseList *right) : isValid(true)
{
data = left->data;
data.append(right->data);
data = qMove(left->data + right->data);
}
PhraseList::PhraseList(PhraseList *left, const AbstractFieldPhrase *right)
: isValid(true)
{
data = left->data;
data.append(right->data);
data.append(new PhraseData(right->data));
}
PhraseList::~PhraseList()
{
data.clear();
// data.clear();
}
PhraseList PhraseList::operator |(const AbstractFieldPhrase &other) {
@ -247,23 +256,21 @@ AssignmentPhraseList AssignmentPhraseList::operator &(const AssignmentPhrase &ph
return AssignmentPhraseList(this, &ph);
}
ConditionalPhrase::ConditionalPhrase()
{
this->data = 0;
}
ConditionalPhrase::ConditionalPhrase() : data(0)
{ }
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &other)
{
qDebug() << "************* ctor called:";
this->data = new PhraseData(other.data);
// const_cast<ConditionalPhrase&>(other).data = 0;
}
#if __cplusplus >= 201103L
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &&other)
{
this->data = std::move(other.data);
qDebug() << "************* ctor called:";
this->data = qMove(other.data);
}
#endif
ConditionalPhrase::ConditionalPhrase(const PhraseData *data)
{
@ -332,8 +339,8 @@ ConditionalPhrase::~ConditionalPhrase()
ConditionalPhrase ConditionalPhrase::operator =(const ConditionalPhrase &other)
{
return ConditionalPhrase(other.data);
const_cast<ConditionalPhrase&>(other).data = 0;
this->data = new PhraseData(other.data);
return *this;
}
ConditionalPhrase ConditionalPhrase::operator ==(const QVariant &other)

View File

@ -142,8 +142,9 @@ public:
bool isValid;
QList<const PhraseData*> data;
PhraseList();
PhraseList(const PhraseList &other);
PhraseList(const AbstractFieldPhrase &other);
PhraseList(AbstractFieldPhrase *left, const AbstractFieldPhrase *right);
PhraseList(const AbstractFieldPhrase *left, const AbstractFieldPhrase &right);
PhraseList(PhraseList *left, PhraseList *right);
PhraseList(PhraseList *left, const AbstractFieldPhrase *right);
virtual ~PhraseList();
@ -160,9 +161,7 @@ public:
QSharedPointer<PhraseData> rightDataPointer;
ConditionalPhrase();
ConditionalPhrase(const ConditionalPhrase &other);
#if __cplusplus >= 201103L
ConditionalPhrase(const ConditionalPhrase &&other);
#endif
ConditionalPhrase(const PhraseData *data);
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition);
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition, const QVariant &v);

View File

@ -139,7 +139,7 @@ Q_OUTOFLINE_TEMPLATE QList<T *> Query<T>::toList(int count)
d->sql = d->database->sqlGenertor()->selectCommand(
d->tableName, d->fieldPhrase, d->wherePhrase, d->orderPhrase,
d->relations, d->skip, d->take);
qDebug() <<d->sql;
QSqlQuery q = d->database->exec(d->sql);
if (q.lastError().isValid()) {
qDebug() << q.lastError().text();
@ -151,7 +151,6 @@ Q_OUTOFLINE_TEMPLATE QList<T *> Query<T>::toList(int count)
foreach (RelationModel *rel, d->relations)
relatedTables << rel->slaveTable << rel->masterTable;
struct LevelData{
QList<int> masters;
QList<int> slaves;
@ -441,7 +440,10 @@ template <class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph)
{
Q_D(Query);
d->wherePhrase = d->wherePhrase && ph;
if (d->wherePhrase.data)
d->wherePhrase = d->wherePhrase && ph;
else
d->wherePhrase = ph;
return this;
}
@ -541,32 +543,31 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::remove()
template <class T>
Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query<T>::toModal()
{
// Q_D(Query);
Q_D(Query);
d->sql = d->database->sqlGenertor()->selectCommand(
d->tableName,
d->fieldPhrase,
d->wherePhrase, d->orderPhrase, d->relations,
d->skip, d->take);
// QString fff = "";
DatabaseModel dbModel = d->database->model();
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery(d->sql, d->database->database());
// foreach (WherePhrase p, d->fields) {
// if (fff != "")
// fff.append(", ");
// fff.append(d->database->sqlGenertor()->phraseOrder(p.data()));
// }
int fieldIndex = 0;
foreach (const PhraseData *pd, d->fieldPhrase.data) {
QString displayName = dbModel.tableByClassName(pd->className)
->field(pd->fieldName)->displayName;
// d->sql = d->database->sqlGenertor()->selectCommand(
// SqlGeneratorBase::SelectAll, "",
// d->tableName,
// d->wheres, d->orderPhrases, d->relations,
// d->skip, d->take);
// qDebug()<<"Model to" << fff;
// QSqlQueryModel *model = new QSqlQueryModel;
// TableModel *tableModel = d->database->model().tableByName(d->tableName);
// model->setQuery(d->sql, d->database->database());
qDebug() << "Display name for"<<pd->className<<pd->fieldName
<<"="<<displayName;
model->setHeaderData(fieldIndex++,
Qt::Horizontal,
displayName);
}
// int fieldIndex = 0;
// foreach (FieldModel *f, tableModel->fields()) {
// model->setHeaderData(fieldIndex++, Qt::Horizontal, f->displayName);
// }
// return model;
return model;
}
template <class T>

View File

@ -264,7 +264,7 @@ TableModel::TableModel(int typeId, QString tableName)
else if(type == __nut_UNIQUE)
f->isUnique = true;
else if(type == __nut_DISPLAY)
f->displayName = value;
f->displayName = value.mid(1, value.length() - 2);
}
if(!findByTypeId(typeId) && !tableName.isNull())