remove -=gui from tests

This commit is contained in:
Hamed Masafi 2019-02-28 11:40:41 +03:30
parent 5ac713dd23
commit d906bd81fd
39 changed files with 463 additions and 180 deletions

View File

@ -3,7 +3,7 @@
# Nut
## Build result
| Brancc name | Icon |
| Branch | Status |
| ------------- |:-------------:|
| master | [![Build Status](https://travis-ci.org/HamedMasafi/Nut.svg?branch=master)](https://travis-ci.org/HamedMasafi/Nut) |
| dev | [![Build Status](https://travis-ci.org/HamedMasafi/Nut.svg?branch=dev)](https://travis-ci.org/HamedMasafi/Nut) |

View File

@ -4,3 +4,4 @@ SUBDIRS += \
src \
test

View File

@ -117,6 +117,8 @@ inline bool nutClassInfoInt(const QMetaClassInfo &classInfo,
}
}
#define NUT_FIELD_PERFIX
#define NUT_FIELD_POSTFIX Field
// Database
#define NUT_DB_VERSION(version) \

View File

@ -724,14 +724,14 @@ QString SqlGeneratorBase::insertCommand(const QString &tableName, const Assignme
void SqlGeneratorBase::replaceTableNames(QString &command)
{
foreach (TableModel *m, TableModel::allModels())
foreach (TableModel *m, _database->model())
command = command
.replace("[" + m->className() + "]", m->name());
}
void SqlGeneratorBase::removeTableNames(QString &command)
{
foreach (TableModel *m, TableModel::allModels())
foreach (TableModel *m, _database->model())
command = command.replace("[" + m->className() + "].", "");
}

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "abstractfieldphrase.h"
NUT_BEGIN_NAMESPACE

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef ABSTRACTFIELDPHRASE_H
#define ABSTRACTFIELDPHRASE_H

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "abstractfieldphrase.h"
#include "assignmentphrase.h"
#include "phrasedata.h"

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef ASSIGNMENTPHRASE_H
#define ASSIGNMENTPHRASE_H

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "assignmentphraselist.h"
#include "phrasedata.h"
#include <phrase.h>

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef ASSIGNMENTPHRASELIST_H
#define ASSIGNMENTPHRASELIST_H

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "abstractfieldphrase.h"
#include "conditionalphrase.h"
#include "phrasedata.h"

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef CONDITIONALPHRASE_H
#define CONDITIONALPHRASE_H

View File

@ -1,2 +1,22 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "datephrase.h"

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef DATEPHRASE_H
#define DATEPHRASE_H

View File

@ -1 +1,21 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "fieldphrase.h"

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef FIELDPHRASE_H
#define FIELDPHRASE_H
@ -43,57 +63,6 @@ public:
}
};
//#define SPECIALIZATION_NUMERIC(type) \
//template<> \
//class FieldPhrase<type> : public AbstractFieldPhrase \
//{ \
// public: \
// FieldPhrase(const char *className, const char *s) : \
// AbstractFieldPhrase(className, s) \
// {} \
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less) \
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual) \
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater) \
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual) \
// SPECIALIZATION_NUMERIC_MEMBER(type, %, PhraseData::Mod) \
// \
// SPECIALIZATION_NUMERIC_MEMBER(type, +, PhraseData::Add) \
// SPECIALIZATION_NUMERIC_MEMBER(type, -, PhraseData::Minus) \
// SPECIALIZATION_NUMERIC_MEMBER(type, *, PhraseData::Multiple) \
// SPECIALIZATION_NUMERIC_MEMBER(type, /, PhraseData::Divide) \
// AssignmentPhrase operator =(const QVariant &other) { \
// return AssignmentPhrase(this, other); \
// } \
// AssignmentPhrase operator =(const ConditionalPhrase &other) { \
// return AssignmentPhrase(new PhraseData(data, PhraseData::Equal, other.data)); \
// } \
// ConditionalPhrase between(const QVariant &min, const QVariant &max) \
// { \
// return ConditionalPhrase(this, PhraseData::Between, \
// QVariantList() << min << max); \
// } \
// ConditionalPhrase operator ++() \
// {return ConditionalPhrase(this, PhraseData::Add, 1);} \
// ConditionalPhrase operator --() \
// {return ConditionalPhrase(this, PhraseData::Minus, 1);} \
// ConditionalPhrase operator ++(int) \
// {return ConditionalPhrase(this, PhraseData::Add, 1);} \
// ConditionalPhrase operator --(int) \
// {return ConditionalPhrase(this, PhraseData::Minus, 1);} \
//};
//SPECIALIZATION_NUMERIC(qint8)
//SPECIALIZATION_NUMERIC(qint16)
//SPECIALIZATION_NUMERIC(qint32)
//SPECIALIZATION_NUMERIC(qint64)
//SPECIALIZATION_NUMERIC(quint8)
//SPECIALIZATION_NUMERIC(quint16)
//SPECIALIZATION_NUMERIC(quint32)
//SPECIALIZATION_NUMERIC(quint64)
//SPECIALIZATION_NUMERIC(qreal)
//Date and time
#define CONDITIONAL_VARIANT_METHOD(name, cond) \
ConditionalPhrase name(int val) \
@ -127,83 +96,6 @@ public:
}
};
//template<>
//class FieldPhrase<QDate> : public AbstractFieldPhrase
//{
//public:
// FieldPhrase(const char *className, const char *s) :
// AbstractFieldPhrase(className, s)
// {}
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
// AssignmentPhrase operator =(const QDate &other) {
// return AssignmentPhrase(this, other);
// }
// ConditionalPhrase between(const QDate &min, const QDate &max)
// {
// return ConditionalPhrase(this, PhraseData::Between,
// QVariantList() << min << max);
// }
// CONDITIONAL_VARIANT_METHOD(addYears, PhraseData::AddYears)
// CONDITIONAL_VARIANT_METHOD(addMonths, PhraseData::AddMonths)
// CONDITIONAL_VARIANT_METHOD(addDays, PhraseData::AddDays)
//};
//template<>
//class FieldPhrase<QTime> : public AbstractFieldPhrase
//{
//public:
// FieldPhrase(const char *className, const char *s) :
// AbstractFieldPhrase(className, s)
// {}
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
// AssignmentPhrase operator =(const QTime &other) {
// return AssignmentPhrase(this, other);
// }
// ConditionalPhrase between(const QTime &min, const QTime &max)
// {
// return ConditionalPhrase(this, PhraseData::Between,
// QVariantList() << min << max);
// }
// CONDITIONAL_VARIANT_METHOD(addHours, PhraseData::AddHours)
// CONDITIONAL_VARIANT_METHOD(addMinutes, PhraseData::AddMinutes)
// CONDITIONAL_VARIANT_METHOD(addSeconds, PhraseData::AddSeconds)
//};
//template<>
//class FieldPhrase<QDateTime> : public AbstractFieldPhrase
//{
//public:
// FieldPhrase(const char *className, const char *s) :
// AbstractFieldPhrase(className, s)
// {}
// SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
// SPECIALIZATION_NUMERIC_MEMBER(type, <=, PhraseData::LessEqual)
// SPECIALIZATION_NUMERIC_MEMBER(type, >, PhraseData::Greater)
// SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
// AssignmentPhrase operator =(const QDateTime &other) {
// return AssignmentPhrase(this, other);
// }
// ConditionalPhrase between(const QDateTime &min, const QDateTime &max)
// {
// return ConditionalPhrase(this, PhraseData::Between,
// QVariantList() << min << max);
// }
// CONDITIONAL_VARIANT_METHOD(addYears, PhraseData::AddYears)
// CONDITIONAL_VARIANT_METHOD(addMonths, PhraseData::AddMonths)
// CONDITIONAL_VARIANT_METHOD(addDays, PhraseData::AddDays)
// CONDITIONAL_VARIANT_METHOD(addHours, PhraseData::AddHours)
// CONDITIONAL_VARIANT_METHOD(addMinutes, PhraseData::AddMinutes)
// CONDITIONAL_VARIANT_METHOD(addSeconds, PhraseData::AddSeconds)
//};
NUT_END_NAMESPACE
#endif // FIELDPHRASE_H

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "phrasedata.h"
NUT_BEGIN_NAMESPACE

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef PHRASEDATA_H
#define PHRASEDATA_H

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "phrasedatalist.h"
NUT_BEGIN_NAMESPACE

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef PHRASEDATALIST_H
#define PHRASEDATALIST_H

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "abstractfieldphrase.h"
#include "phraselist.h"

View File

@ -1,3 +1,23 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut 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 3 of the License, or
** (at your option) any later version.
**
** Nut 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.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef PHRASELIST_H
#define PHRASELIST_H

View File

@ -1,5 +1,4 @@
QT += sql
QT -= gui
QT += sql gui
TARGET = nut
TEMPLATE = lib
@ -40,7 +39,8 @@ HEADERS += \
$$PWD/phrases/phrasedata.h \
$$PWD/phrases/phrasedatalist.h \
$$PWD/phrases/phraselist.h \
$$PWD/phrases/datephrase.h
$$PWD/phrases/datephrase.h \
$$PWD/table_p.h
SOURCES += \
$$PWD/generators/sqlgeneratorbase.cpp \

View File

@ -21,6 +21,7 @@
#include <QMetaMethod>
#include <QVariant>
#include "table.h"
#include "table_p.h"
#include "database.h"
#include "databasemodel.h"
#include "generators/sqlgeneratorbase_p.h"
@ -40,25 +41,28 @@ NUT_BEGIN_NAMESPACE
*/
Table::Table(QObject *parent) : QObject(parent),
_status(NewCreated), _parentTableSet(nullptr)
d_ptr(new TablePrivate(this))
{
myModel = TableModel::findByClassName(metaObject()->className());
Q_D(Table);
d->model = TableModel::findByClassName(metaObject()->className());
}
void Table::add(TableSetBase *t)
{
this->childTableSets.insert(t);
Q_D(Table);
d->childTableSets.insert(t);
}
QString Table::primaryKey() const
{
return myModel->primaryKey();
Q_D(const Table);
return d->model->primaryKey();
}
bool Table::isPrimaryKeyAutoIncrement() const
{
FieldModel *pk = myModel->field(myModel->primaryKey());
Q_D(const Table);
FieldModel *pk = d->model->field(d->model->primaryKey());
if (!pk)
return false;
return pk->isAutoIncrement;
@ -72,44 +76,49 @@ QVariant Table::primaryValue() const
void Table::propertyChanged(const QString &propName)
{
if (!myModel)
myModel = TableModel::findByClassName(metaObject()->className());
Q_D(Table);
if (!d->model)
d->model = TableModel::findByClassName(metaObject()->className());
if (!myModel)
if (!d->model)
qFatal ("model for class '%s' not found", qPrintable(metaObject()->className()));
foreach (FieldModel *f, myModel->fields())
foreach (FieldModel *f, d->model->fields())
if(f->isPrimaryKey && propName == f->name && f->isAutoIncrement)
return;
_changedProperties.insert(propName);
if (_status == FeatchedFromDB)
_status = Modified;
d->changedProperties.insert(propName);
if (d->status == FeatchedFromDB)
d->status = Modified;
if (_status == NewCreated)
_status = Added;
if (d->status == NewCreated)
d->status = Added;
}
void Table::clear()
{
_changedProperties.clear();
Q_D(Table);
d->changedProperties.clear();
}
QSet<QString> Table::changedProperties() const
{
return _changedProperties;
Q_D(const Table);
return d->changedProperties;
}
bool Table::setParentTable(Table *master)
{
Q_D(Table);
QString masterClassName = master->metaObject()->className();
foreach (RelationModel *r, myModel->foregionKeys())
foreach (RelationModel *r, d->model->foregionKeys())
if(r->masterClassName == masterClassName)
{
setProperty(QString(r->localColumn).toLatin1().data(),
master->primaryValue());
_changedProperties.insert(r->localColumn);
d->changedProperties.insert(r->localColumn);
return true;
}
@ -118,18 +127,21 @@ bool Table::setParentTable(Table *master)
TableSetBase *Table::parentTableSet() const
{
return _parentTableSet;
Q_D(const Table);
return d->parentTableSet;
}
void Table::setParentTableSet(TableSetBase *parent)
{
_parentTableSet = parent;
_parentTableSet->add(this);
Q_D(Table);
d->parentTableSet = parent;
d->parentTableSet->add(this);
}
TableSetBase *Table::childTableSet(const QString &name) const
{
foreach (TableSetBase *t, childTableSets)
Q_D(const Table);
foreach (TableSetBase *t, d->childTableSets)
if (t->childClassName() == name)
return t;
return Q_NULLPTR;
@ -137,12 +149,14 @@ TableSetBase *Table::childTableSet(const QString &name) const
int Table::save(Database *db)
{
Q_D(Table);
QSqlQuery q = db->exec(db->sqlGenertor()->saveRecord(this, db->tableName(metaObject()->className())));
if(status() == Added && isPrimaryKeyAutoIncrement())
setProperty(primaryKey().toLatin1().data(), q.lastInsertId());
foreach(TableSetBase *ts, childTableSets)
foreach(TableSetBase *ts, d->childTableSets)
ts->save(db);
setStatus(FeatchedFromDB);
@ -151,12 +165,22 @@ int Table::save(Database *db)
Table::Status Table::status() const
{
return _status;
Q_D(const Table);
return static_cast<Status>(d->status);
}
void Table::setStatus(const Status &status)
{
_status = status;
Q_D(Table);
d->status = status;
}
TablePrivate::TablePrivate(Table *parent) : q_ptr(parent),
status(Table::NewCreated), parentTableSet(nullptr)
{
}
NUT_END_NAMESPACE

View File

@ -34,9 +34,12 @@ NUT_BEGIN_NAMESPACE
class Database;
class TableSetBase;
class TableModel;
class TablePrivate;
class NUT_EXPORT Table : public QObject
{
Q_OBJECT
TablePrivate *d_ptr;
Q_DECLARE_PRIVATE(Table)
public:
explicit Table(QObject *parentTableSet = nullptr);
@ -73,13 +76,13 @@ protected:
void propertyChanged(const QString &propName);
private:
TableModel *myModel;
Status _status;
QSet<QString> _changedProperties;
// TableModel *myModel;
// Status _status;
// QSet<QString> _changedProperties;
//TODO: is this removable?
TableSetBase *_parentTableSet;
// TableSetBase *_parentTableSet;
QSet<TableSetBase*> childTableSets;
// QSet<TableSetBase*> childTableSets;
void clear();
void add(TableSetBase *);

30
src/table_p.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef TABLEPRIVATE_H
#define TABLEPRIVATE_H
#include "defines.h"
#include <QtCore/QSet>
NUT_BEGIN_NAMESPACE
class TableModel;
class Table;
class TableSetBase;
class TablePrivate {
Table *q_ptr;
Q_DECLARE_PUBLIC(Table)
public:
TablePrivate(Table *parent);
TableModel *model;
int status;
QSet<QString> changedProperties;
TableSetBase *parentTableSet;
QSet<TableSetBase*> childTableSets;
};
NUT_END_NAMESPACE
#endif // TABLEPRIVATE_H

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 NUT_EXPORT TableModel
{
public:
explicit TableModel(int typeId, const QString &tableName = QString());

View File

@ -278,7 +278,7 @@ void BasicTest::cleanupTestCase()
user->deleteLater();
//release models before exiting
qDeleteAll(TableModel::allModels());
// qDeleteAll(TableModel::allModels());
if (QFile::remove("nut_tst_basic"))
qDebug() << "database removed";

View File

@ -1,5 +1,4 @@
QT += testlib sql
QT -= gui
TARGET = tst_nut
TEMPLATE = app

View File

@ -1,5 +1,4 @@
QT += testlib sql
QT -= gui
TARGET = tst_benchmark
TEMPLATE = app

View File

@ -1,7 +1,5 @@
QT += qml quick testlib sql
QT -= gui
TARGET = tst_nut
CONFIG += warn_on qmltestcase c++11
INCLUDEPATH += $$PWD/../../src $$PWD/../common

View File

@ -1,4 +1,4 @@
QT += testlib sql
QT += testlib sql gui
TARGET = tst_datatypes
TEMPLATE = app

View File

@ -1,5 +1,4 @@
QT += testlib sql
QT -= gui
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle

View File

@ -1,5 +1,4 @@
QT += qml quick testlib sql
QT -= gui
TARGET = tst_nut
TEMPLATE = app

View File

@ -123,7 +123,7 @@ void MainTest::mix()
insert(id = 0);
insert((id = 4) & (name = "john"));
order_by(id);
order_by(id | ~name);
order_by(id | !name);
}
void MainTest::select(const PhraseList &ph)
@ -148,7 +148,7 @@ void MainTest::insert(const AssignmentPhraseList &p)
void MainTest::order_by(const PhraseList &ph)
{
QTEST_ASSERT(ph.data.count());
}
QTEST_MAIN(MainTest)

View File

@ -1,5 +1,4 @@
QT += testlib sql
QT -= gui
TARGET = tst_phrases
TEMPLATE = app

View File

@ -1,5 +1,4 @@
QT += testlib sql
QT -= gui
TARGET = tst_uuid
TEMPLATE = app

View File

@ -63,7 +63,7 @@ void UuidTest::restore()
void UuidTest::cleanupTestCase()
{
qDeleteAll(Nut::TableModel::allModels());
// qDeleteAll(Nut::TableModel::allModels());
// Nut::DatabaseModel::deleteAllModels();
}

View File

@ -1,5 +1,4 @@
QT += testlib sql
QT -= gui
TARGET = tst_upgrades
TEMPLATE = app