wip: shared pointer childs for tableset
This commit is contained in:
parent
1c196fe3ef
commit
1975ff0027
14
src/query.h
14
src/query.h
|
|
@ -289,11 +289,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
|
|
||||||
//create table row
|
//create table row
|
||||||
Table *table;
|
Table *table;
|
||||||
|
Row<T> shp;
|
||||||
if (data.table->className() == d->className) {
|
if (data.table->className() == d->className) {
|
||||||
table = new T();
|
table = new T();
|
||||||
#ifdef NUT_SHARED_POINTER
|
#ifdef NUT_SHARED_POINTER
|
||||||
auto shp = QSharedPointer<T>(qobject_cast<T*>(table));
|
shp = QSharedPointer<T>(qobject_cast<T*>(table));
|
||||||
returnList.append(shp);
|
returnList.append(shp);
|
||||||
|
d->tableSet->add(shp);
|
||||||
#else
|
#else
|
||||||
returnList.append(dynamic_cast<T*>(table));
|
returnList.append(dynamic_cast<T*>(table));
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -331,9 +333,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
if (!ok)
|
if (!ok)
|
||||||
qWarning("Unable to set property %s::%s",
|
qWarning("Unable to set property %s::%s",
|
||||||
table->metaObject()->className(), data.masterFields[i].toLocal8Bit().data());
|
table->metaObject()->className(), data.masterFields[i].toLocal8Bit().data());
|
||||||
table->setParentTableSet(
|
|
||||||
levels[master].lastRow->childTableSet(
|
auto tableset = levels[master].lastRow->childTableSet(
|
||||||
data.table->className()));
|
data.table->className());
|
||||||
|
table->setParentTableSet(tableset);
|
||||||
|
#ifdef NUT_SHARED_POINTER
|
||||||
|
tableset->add(qSharedPointerCast<Table>(shp));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
table->setStatus(Table::FeatchedFromDB);
|
table->setStatus(Table::FeatchedFromDB);
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ TableSetBase::~TableSetBase()
|
||||||
{
|
{
|
||||||
foreach (Table *t, data->tables)
|
foreach (Table *t, data->tables)
|
||||||
t->setParentTableSet(nullptr);
|
t->setParentTableSet(nullptr);
|
||||||
|
|
||||||
|
foreach (Row<Table> t, data->childs)
|
||||||
|
t->setParentTableSet(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TableSetBase::save(Database *db, bool cleanUp)
|
int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
|
|
@ -101,6 +104,18 @@ void TableSetBase::remove(Table *t)
|
||||||
data->childRows.removeOne(get(t));
|
data->childRows.removeOne(get(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TableSetBase::add(Row<Table> t)
|
||||||
|
{
|
||||||
|
data.detach();
|
||||||
|
data->childs.append(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableSetBase::remove(Row<Table> t)
|
||||||
|
{
|
||||||
|
data.detach();
|
||||||
|
data->childs.removeOne(t);
|
||||||
|
}
|
||||||
|
|
||||||
QString TableSetBase::childClassName() const
|
QString TableSetBase::childClassName() const
|
||||||
{
|
{
|
||||||
return data->childClassName;
|
return data->childClassName;
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,13 @@ protected:
|
||||||
// QString _childClassName;
|
// QString _childClassName;
|
||||||
QExplicitlySharedDataPointer<TableSetBaseData> data;
|
QExplicitlySharedDataPointer<TableSetBaseData> data;
|
||||||
|
|
||||||
private:
|
public://TODO: change this to private
|
||||||
void add(Table* t);
|
void add(Table* t);
|
||||||
void remove(Table *t);
|
void remove(Table *t);
|
||||||
|
|
||||||
|
void add(Row<Table> t);
|
||||||
|
void remove(Row<Table> t);
|
||||||
|
|
||||||
friend class Table;
|
friend class Table;
|
||||||
friend class QueryBase;
|
friend class QueryBase;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue