diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-07-28 18:48:32 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-07-28 18:48:32 +0200 |
commit | ba2531edc04a9e57b69fe6a289444db2f69c44d2 (patch) | |
tree | 9f20f1218338e3033c3579f577650a7bf73b97d2 /gui/treemodel.cc | |
parent | 9a30b6330b1997d07a8f18b87e2b413faf95094a (diff) | |
download | nextpnr-ba2531edc04a9e57b69fe6a289444db2f69c44d2.tar.gz nextpnr-ba2531edc04a9e57b69fe6a289444db2f69c44d2.tar.bz2 nextpnr-ba2531edc04a9e57b69fe6a289444db2f69c44d2.zip |
add proper info on model changes
Diffstat (limited to 'gui/treemodel.cc')
-rw-r--r-- | gui/treemodel.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gui/treemodel.cc b/gui/treemodel.cc index 5a064f57..86b272bb 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -53,6 +53,9 @@ void ContextTreeModel::loadData(Context *ctx) { if (!ctx) return; + + beginResetModel(); + delete root; root = new ContextTreeItem(); @@ -153,6 +156,8 @@ void ContextTreeModel::loadData(Context *ctx) cells_root = new ContextTreeItem("Cells"); root->addChild(cells_root); + + endResetModel(); } void ContextTreeModel::updateData(Context *ctx) @@ -160,14 +165,18 @@ void ContextTreeModel::updateData(Context *ctx) if (!ctx) return; + QModelIndex nets_index = indexFromNode(nets_root); // Remove nets not existing any more QMap<QString, ContextTreeItem *>::iterator i = nameToItem[3].begin(); while (i != nameToItem[3].end()) { QMap<QString, ContextTreeItem *>::iterator prev = i; ++i; if (ctx->nets.find(ctx->id(prev.key().toStdString())) == ctx->nets.end()) { + int pos = prev.value()->parent()->indexOf(prev.value()); + beginRemoveRows(nets_index, pos, pos); delete prev.value(); nameToItem[3].erase(prev); + endRemoveRows(); } } // Add nets to tree @@ -175,20 +184,26 @@ void ContextTreeModel::updateData(Context *ctx) auto id = item.first; QString name = QString(id.c_str(ctx)); if (!nameToItem[3].contains(name)) { + beginInsertRows(nets_index, nets_root->count() + 1, nets_root->count() + 1); ContextTreeItem *newItem = new ContextTreeItem(id, ElementType::NET, name); nets_root->addChild(newItem); nameToItem[3].insert(name, newItem); + endInsertRows(); } } + QModelIndex cell_index = indexFromNode(cells_root); // Remove cells not existing any more i = nameToItem[4].begin(); while (i != nameToItem[4].end()) { QMap<QString, ContextTreeItem *>::iterator prev = i; ++i; if (ctx->cells.find(ctx->id(prev.key().toStdString())) == ctx->cells.end()) { + int pos = prev.value()->parent()->indexOf(prev.value()); + beginRemoveRows(cell_index, pos, pos); delete prev.value(); nameToItem[4].erase(prev); + endRemoveRows(); } } // Add cells to tree @@ -196,9 +211,11 @@ void ContextTreeModel::updateData(Context *ctx) auto id = item.first; QString name = QString(id.c_str(ctx)); if (!nameToItem[4].contains(name)) { + beginInsertRows(cell_index, cells_root->count() + 1, cells_root->count() + 1); ContextTreeItem *newItem = new ContextTreeItem(id, ElementType::CELL, name); cells_root->addChild(newItem); nameToItem[4].insert(name, newItem); + endInsertRows(); } } } |