wip: shared pointer childs for tableset

This commit is contained in:
Hamed Masafi 2019-07-08 19:23:02 +04:30
parent 1c196fe3ef
commit 1975ff0027
3 changed files with 29 additions and 5 deletions

View File

@ -289,11 +289,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
//create table row
Table *table;
Row<T> shp;
if (data.table->className() == d->className) {
table = new T();
#ifdef NUT_SHARED_POINTER
auto shp = QSharedPointer<T>(qobject_cast<T*>(table));
shp = QSharedPointer<T>(qobject_cast<T*>(table));
returnList.append(shp);
d->tableSet->add(shp);
#else
returnList.append(dynamic_cast<T*>(table));
#endif
@ -331,9 +333,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
if (!ok)
qWarning("Unable to set property %s::%s",
table->metaObject()->className(), data.masterFields[i].toLocal8Bit().data());
table->setParentTableSet(
levels[master].lastRow->childTableSet(
data.table->className()));
auto tableset = levels[master].lastRow->childTableSet(
data.table->className());
table->setParentTableSet(tableset);
#ifdef NUT_SHARED_POINTER
tableset->add(qSharedPointerCast<Table>(shp));
#endif
}
table->setStatus(Table::FeatchedFromDB);

View File

@ -42,6 +42,9 @@ TableSetBase::~TableSetBase()
{
foreach (Table *t, data->tables)
t->setParentTableSet(nullptr);
foreach (Row<Table> t, data->childs)
t->setParentTableSet(nullptr);
}
int TableSetBase::save(Database *db, bool cleanUp)
@ -101,6 +104,18 @@ void TableSetBase::remove(Table *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
{
return data->childClassName;

View File

@ -57,10 +57,13 @@ protected:
// QString _childClassName;
QExplicitlySharedDataPointer<TableSetBaseData> data;
private:
public://TODO: change this to private
void add(Table* t);
void remove(Table *t);
void add(Row<Table> t);
void remove(Row<Table> t);
friend class Table;
friend class QueryBase;
};