1
0
Fork 0

connect data change refresh for component sources

This commit is contained in:
Kevin Matz 2021-09-10 16:05:09 -04:00
parent 7c53a1d9ca
commit 7039696807
1 changed files with 23 additions and 6 deletions

View File

@ -221,22 +221,39 @@ void MultiverseModel::insert(const QModelIndex &parent,
auto index = QPersistentModelIndex(createIndex(item->childCount() - 1, 0,
child));
auto refreshRow = [this] (QPersistentModelIndex index) {
auto begin = index.sibling(index.row(), 0);
auto end = begin.siblingAtColumn(columnCount() - 1);
emit dataChanged(begin, end);
};
connect(universe, &QSacnUniverse::changed,
this, [this, index] () {
auto begin = index.sibling(index.row(), 0);
auto end = begin.siblingAtColumn(columnCount() - 1);
emit dataChanged(begin, end);
});
this, [refreshRow, index](){ refreshRow(index); });
connect(universe, &QSacnUniverse::sourceListChanged,
this, [=]() {
this, [this, universe, child, index, refreshRow]() {
// remove the old children
beginRemoveRows(index, 0, child->childCount() - 1);
child->removeChildren();
endRemoveRows();
// add the new children
beginInsertRows(index, 0, universe->sources().size() - 1);
child->createChildren();
endInsertRows();
// refresh row of new child when data arrives
for (int i = 0; i < child->childCount(); i++)
{
auto grandchild = child->child(i);
auto index = QPersistentModelIndex(createIndex(i, 0, grandchild));
auto data = grandchild->data(Column::Universe, Qt::EditRole);
if (data.metaType().id() != qMetaTypeId<QSacnUniverse*>())
return;
auto universe = data.value<QSacnUniverse*>();
connect(universe, &QSacnUniverse::changed,
this, [refreshRow, index](){ refreshRow(index); });
}
});
}