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 | |
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')
-rw-r--r-- | gui/designwidget.cc | 18 | ||||
-rw-r--r-- | gui/treemodel.cc | 17 |
2 files changed, 27 insertions, 8 deletions
diff --git a/gui/designwidget.cc b/gui/designwidget.cc index 106c3146..0f01b3c5 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -160,6 +160,10 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), sel connect(treeView, &QTreeWidget::customContextMenuRequested, this, &DesignWidget::prepareMenuTree);
+ selectionModel = treeView->selectionModel();
+ connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+ SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
+
history_index = -1;
history_ignore = false;
@@ -210,7 +214,6 @@ void DesignWidget::newContext(Context *ctx) highlightSelected.clear();
this->ctx = ctx;
- treeView->setModel(nullptr);
treeModel->loadData(ctx);
updateTree();
}
@@ -232,10 +235,6 @@ void DesignWidget::updateTree() }
treeModel->updateData(ctx);
- treeView->setModel(treeModel);
- selectionModel = treeView->selectionModel();
- connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
- SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
}
QtProperty *DesignWidget::addTopLevelProperty(const QString &id)
{
@@ -310,21 +309,24 @@ QtProperty *DesignWidget::addSubGroup(QtProperty *topItem, const QString &name) void DesignWidget::onClickedBel(BelId bel, bool keep)
{
ContextTreeItem *item = treeModel->nodeForIdType(ElementType::BEL, ctx->getBelName(bel).c_str(ctx));
- selectionModel->setCurrentIndex(treeModel->indexFromNode(item), keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
+ selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
+ keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
Q_EMIT selected(getDecals(ElementType::BEL, ctx->getBelName(bel)), keep);
}
void DesignWidget::onClickedWire(WireId wire, bool keep)
{
ContextTreeItem *item = treeModel->nodeForIdType(ElementType::WIRE, ctx->getWireName(wire).c_str(ctx));
- selectionModel->setCurrentIndex(treeModel->indexFromNode(item), keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
+ selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
+ keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
Q_EMIT selected(getDecals(ElementType::WIRE, ctx->getWireName(wire)), keep);
}
void DesignWidget::onClickedPip(PipId pip, bool keep)
{
ContextTreeItem *item = treeModel->nodeForIdType(ElementType::PIP, ctx->getPipName(pip).c_str(ctx));
- selectionModel->setCurrentIndex(treeModel->indexFromNode(item), keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
+ selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
+ keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
Q_EMIT selected(getDecals(ElementType::PIP, ctx->getPipName(pip)), keep);
}
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(); } } } |