aboutsummaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-07-29 10:56:36 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2018-07-29 10:56:36 +0200
commit7c8865d2fc9c2d6b19185627d650448df858fe75 (patch)
tree61f82ba6898260ab8ef88670b464ec15b2cf1fbc /gui
parentba2531edc04a9e57b69fe6a289444db2f69c44d2 (diff)
downloadnextpnr-7c8865d2fc9c2d6b19185627d650448df858fe75.tar.gz
nextpnr-7c8865d2fc9c2d6b19185627d650448df858fe75.tar.bz2
nextpnr-7c8865d2fc9c2d6b19185627d650448df858fe75.zip
Added sorting
Diffstat (limited to 'gui')
-rw-r--r--gui/treemodel.cc51
-rw-r--r--gui/treemodel.h1
2 files changed, 38 insertions, 14 deletions
diff --git a/gui/treemodel.cc b/gui/treemodel.cc
index 86b272bb..59391f02 100644
--- a/gui/treemodel.cc
+++ b/gui/treemodel.cc
@@ -21,6 +21,11 @@
NEXTPNR_NAMESPACE_BEGIN
+static bool contextTreeItemLessThan(const ContextTreeItem *v1, const ContextTreeItem *v2)
+ {
+ return v1->name() < v2->name();
+ }
+
ContextTreeItem::ContextTreeItem() { parentNode = nullptr; }
ContextTreeItem::ContextTreeItem(QString name)
@@ -45,6 +50,13 @@ void ContextTreeItem::addChild(ContextTreeItem *item)
children.append(item);
}
+void ContextTreeItem::sort()
+{
+ for (auto item : children)
+ if (item->count()>1) item->sort();
+ qSort(children.begin(), children.end(), contextTreeItemLessThan);
+}
+
ContextTreeModel::ContextTreeModel(QObject *parent) : QAbstractItemModel(parent) { root = new ContextTreeItem(); }
ContextTreeModel::~ContextTreeModel() { delete root; }
@@ -91,8 +103,9 @@ void ContextTreeModel::loadData(Context *ctx)
}
parent = bel_items[name];
}
- }
-
+ }
+ bels_root->sort();
+
ContextTreeItem *wire_root = new ContextTreeItem("Wires");
root->addChild(wire_root);
QMap<QString, ContextTreeItem *> wire_items;
@@ -121,6 +134,7 @@ void ContextTreeModel::loadData(Context *ctx)
parent = wire_items[name];
}
}
+ wire_root->sort();
ContextTreeItem *pip_root = new ContextTreeItem("Pips");
root->addChild(pip_root);
@@ -150,6 +164,7 @@ void ContextTreeModel::loadData(Context *ctx)
parent = pip_items[name];
}
}
+ pip_root->sort();
nets_root = new ContextTreeItem("Nets");
root->addChild(nets_root);
@@ -165,18 +180,20 @@ void ContextTreeModel::updateData(Context *ctx)
if (!ctx)
return;
- QModelIndex nets_index = indexFromNode(nets_root);
+ beginResetModel();
+
+ //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);
+ //int pos = prev.value()->parent()->indexOf(prev.value());
+ //beginRemoveRows(nets_index, pos, pos);
delete prev.value();
nameToItem[3].erase(prev);
- endRemoveRows();
+ //endRemoveRows();
}
}
// Add nets to tree
@@ -184,26 +201,28 @@ 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);
+ //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();
+ //endInsertRows();
}
}
- QModelIndex cell_index = indexFromNode(cells_root);
+ nets_root->sort();
+
+ //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);
+ //int pos = prev.value()->parent()->indexOf(prev.value());
+ //beginRemoveRows(cell_index, pos, pos);
delete prev.value();
nameToItem[4].erase(prev);
- endRemoveRows();
+ //endRemoveRows();
}
}
// Add cells to tree
@@ -211,13 +230,17 @@ 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);
+ //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();
+ //endInsertRows();
}
}
+
+ cells_root->sort();
+
+ endResetModel();
}
int ContextTreeModel::rowCount(const QModelIndex &parent) const { return nodeFromIndex(parent)->count(); }
diff --git a/gui/treemodel.h b/gui/treemodel.h
index a976c5bc..a85c290a 100644
--- a/gui/treemodel.h
+++ b/gui/treemodel.h
@@ -52,6 +52,7 @@ class ContextTreeItem
IdString id() const { return itemId; }
ElementType type() const { return itemType; }
QString name() const { return itemName; }
+ void sort();
private:
ContextTreeItem *parentNode;
QList<ContextTreeItem *> children;