working for now && compiler in success form

This commit is contained in:
Hamed Masafi 2019-07-19 17:22:52 +04:30
parent 7871092a81
commit 8af5f06727
5 changed files with 64 additions and 27 deletions

View File

@ -259,6 +259,10 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
int n = -1;
while (p) {
// Q_ASSERT(p != lastP);
// if (p == lastP)
// qFatal("NULL Loop detected");
++n;
n = n % levels.count();
if (checked[n])
@ -268,14 +272,14 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
// check if key value is changed
if (data.lastKeyValue == q.value(data.keyFiledname)) {
--p;
qDebug() << "key os not changed for" << data.keyFiledname;
// qDebug() << "key os not changed for" << data.keyFiledname;
continue;
}
// check if master if current table has processed
foreach (int m, data.masters)
if (!checked[m]) {
qDebug() << "row is checked";
// qDebug() << "row is checked";
continue;
}
@ -285,13 +289,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
//create table row
Table *table;
Row<T> tablePointer;
Row<Table> shp;
if (data.table->className() == d->className) {
table = new T();
#ifdef NUT_SHARED_POINTER
tablePointer = QSharedPointer<T>(qobject_cast<T*>(table));
returnList.append(tablePointer);
d->tableSet->add(tablePointer);
shp = QSharedPointer<Table>(table);
returnList.append(shp.objectCast<T>());
d->tableSet->add(shp);
#else
returnList.append(dynamic_cast<T*>(table));
#endif
@ -303,9 +307,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
if (!table)
qFatal("Could not create instance of %s",
qPrintable(data.table->name()));
shp = QSharedPointer<Table>(table);
}
connect(table, &QObject::destroyed, [](QObject *){
qDebug() << "Destroyed";
});
QList<FieldModel*> childFields = data.table->fields();
foreach (FieldModel *field, childFields)
table->setProperty(field->name.toLatin1().data(),
@ -321,6 +329,9 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
bool ok = table->metaObject()->invokeMethod(table,
mName.toLocal8Bit().data(),
QGenericArgument(type.toLatin1().data(), levels[master].lastRow));
// bool ok = table->setProperty(data.masterFields[i].toLocal8Bit().data(),
// QVariant::fromValue(shp.data()));
#else
bool ok = table->setProperty(data.masterFields[i].toLocal8Bit().data(),
QVariant::fromValue(levels[master].lastRow));
@ -334,7 +345,9 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
data.table->className());
table->setParentTableSet(tableset);
#ifdef NUT_SHARED_POINTER
tableset->add(qSharedPointerCast<Table>(tablePointer));
tableset->add(shp);
#else
tableset->add(table);
#endif
}
@ -352,6 +365,7 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
deleteLater();
#endif
return returnList;
}
template <typename T>

View File

@ -58,8 +58,8 @@ public:
void remove(RowList<T> t);
int length() const;
T *at(int i) const;
const T &operator[](int i) const;
Row<T> at(int i) const;
const Row<T> operator[](int i) const;
Query<T> *query(bool autoDelete = true);
BulkInserter *bulkInserter();
@ -95,20 +95,27 @@ Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet<T>::bulkInserter()
template<class T>
Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
{
return data->tables.count();
return data->childs.count();
}
template<class T>
Q_OUTOFLINE_TEMPLATE T *TableSet<T >::at(int i) const
Q_OUTOFLINE_TEMPLATE Row<T> TableSet<T >::at(int i) const
{
//TODO: check
return reinterpret_cast<T*>(data->childRows.at(i));
#ifdef NUT_SHARED_POINTER
return data->childs.at(i).objectCast<T>();
#else
return reinterpret_cast<T*>(data->childs.at(i));
#endif
}
template<class T>
Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
Q_OUTOFLINE_TEMPLATE const Row<T> TableSet<T>::operator[](int i) const
{
return data->childRows[i];
#ifdef NUT_SHARED_POINTER
return data->childs.at(i).objectCast<T>();
#else
return reinterpret_cast<T*>(data->childs.at(i));
#endif
}
template<class T>
@ -116,8 +123,8 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(Row<T> t)
{
data.detach();
data->childs.append(t);
data->tables.insert(t.data());
data->childRows.append(t.data());
// data->tables.insert(t.data());
// data->childRows.append(t.data());
// if (_database)
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
@ -138,8 +145,8 @@ template<class T>
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(Row<T> t)
{
data.detach();
data->childs.removeOne(t.data());
data->tables.remove(t.data());
// data->childs.removeOne(t.data());
// data->tables.remove(t.data());
data->childs.removeOne(t);
t->setStatus(Table::Deleted);
}

View File

@ -40,8 +40,8 @@ TableSetBase::TableSetBase(Table *parent) : QObject(parent),
TableSetBase::~TableSetBase()
{
foreach (Table *t, data->tables)
t->setParentTableSet(nullptr);
// foreach (Table *t, data->tables)
// t->setParentTableSet(nullptr);
foreach (Row<Table> t, data->childs)
if (t)
@ -75,7 +75,7 @@ int TableSetBase::save(Database *db, bool cleanUp)
}
if (cleanUp)
data->childRows.clear();
data->childs.clear();
return rowsAffected;
}
@ -83,10 +83,10 @@ int TableSetBase::save(Database *db, bool cleanUp)
void TableSetBase::clearChilds()
{
#ifndef NUT_SHARED_POINTER
foreach (Table *t, data->childRows)
foreach (Table *t, data->childs)
t->deleteLater();
#endif
data->childRows.clear();
data->childs.clear();
}
//void TableSetBase::add(Table *t)

View File

@ -39,8 +39,8 @@ public:
database(nullptr), table(parent)
{ }
QSet<Table*> tables;
QList<Table*> childRows;
// QSet<Table*> tables;
// QList<Table*> childRows;
RowList<Table> childs;
Database *database;

View File

@ -2,6 +2,7 @@
#define CONSTS_H
#include <qsystemdetection.h>
#include <qcompilerdetection.h>
#define REGISTER(x) qDebug() << (#x) << "type id:" << qMetaTypeId<x*>()
#define PRINT(x)
@ -27,6 +28,20 @@
# define OS "Unknown"
#endif
#ifdef Q_CC_GNU
# ifdef Q_CC_MINGW
# define CC "MinGW"
# else
# define CC "GNU"
# endif
#elif defined (Q_CC_MSVC)
# define CC "msvc"
#elif defined (Q_CC_CLANG)
# define CC "clang"
#else
# define CC "Unknown"
#endif
#define PRINT_FORM(db) \
qDebug() << "\n\n****************************" \
<< "\nAll tests passed," \
@ -34,6 +49,7 @@
<< "hamed.masafi@gmail.com" \
<< "\n\tDriver:" << db.driver() \
<< "\n\tOS: " OS " (version: ________)" \
<< "\n\tCompiler: " CC " (version: ________)" \
<< "\n\tQt version: " QT_VERSION_STR \
<< "\n\tTest:" << metaObject()->className() \
<< "\n****************************\n";