gui: make new tree model clickable
This commit is contained in:
parent
6241052e11
commit
c8cf0bbc05
@ -24,7 +24,7 @@ NEXTPNR_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
ContextTreeModel::ContextTreeModel(QObject *parent) :
|
ContextTreeModel::ContextTreeModel(QObject *parent) :
|
||||||
QAbstractItemModel(parent),
|
QAbstractItemModel(parent),
|
||||||
root_(new StaticTreeItem("Elements", nullptr)) {}
|
root_(new StaticTreeItem("Elements", nullptr, ElementType::NONE)) {}
|
||||||
|
|
||||||
ContextTreeModel::~ContextTreeModel() {}
|
ContextTreeModel::~ContextTreeModel() {}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ void ContextTreeModel::loadContext(Context *ctx)
|
|||||||
belMap[std::pair<int, int>(loc.x, loc.y)].push_back(bel);
|
belMap[std::pair<int, int>(loc.x, loc.y)].push_back(bel);
|
||||||
}
|
}
|
||||||
auto belGetter = [](Context *ctx, BelId id) { return ctx->getBelName(id); };
|
auto belGetter = [](Context *ctx, BelId id) { return ctx->getBelName(id); };
|
||||||
bel_root_ = std::unique_ptr<BelXYRoot>(new BelXYRoot(ctx, "Bels", root_.get(), belMap, belGetter));
|
bel_root_ = std::unique_ptr<BelXYRoot>(new BelXYRoot(ctx, "Bels", root_.get(), belMap, belGetter, ElementType::BEL));
|
||||||
|
|
||||||
std::map<std::pair<int, int>, std::vector<WireId>> wireMap;
|
std::map<std::pair<int, int>, std::vector<WireId>> wireMap;
|
||||||
for (int i = 0; i < ctx->chip_info->num_wires; i++) {
|
for (int i = 0; i < ctx->chip_info->num_wires; i++) {
|
||||||
@ -57,7 +57,7 @@ void ContextTreeModel::loadContext(Context *ctx)
|
|||||||
wireMap[std::pair<int, int>(wire->x, wire->y)].push_back(wireid);
|
wireMap[std::pair<int, int>(wire->x, wire->y)].push_back(wireid);
|
||||||
}
|
}
|
||||||
auto wireGetter = [](Context *ctx, WireId id) { return ctx->getWireName(id); };
|
auto wireGetter = [](Context *ctx, WireId id) { return ctx->getWireName(id); };
|
||||||
wire_root_ = std::unique_ptr<WireXYRoot>(new WireXYRoot(ctx, "Wires", root_.get(), wireMap, wireGetter));
|
wire_root_ = std::unique_ptr<WireXYRoot>(new WireXYRoot(ctx, "Wires", root_.get(), wireMap, wireGetter, ElementType::WIRE));
|
||||||
|
|
||||||
std::map<std::pair<int, int>, std::vector<PipId>> pipMap;
|
std::map<std::pair<int, int>, std::vector<PipId>> pipMap;
|
||||||
for (int i = 0; i < ctx->chip_info->num_pips; i++) {
|
for (int i = 0; i < ctx->chip_info->num_pips; i++) {
|
||||||
@ -68,12 +68,12 @@ void ContextTreeModel::loadContext(Context *ctx)
|
|||||||
}
|
}
|
||||||
printf("generating pip static tree...\n");
|
printf("generating pip static tree...\n");
|
||||||
auto pipGetter = [](Context *ctx, PipId id) { return ctx->getPipName(id); };
|
auto pipGetter = [](Context *ctx, PipId id) { return ctx->getPipName(id); };
|
||||||
pip_root_ = std::unique_ptr<PipXYRoot>(new PipXYRoot(ctx, "Pips", root_.get(), pipMap, pipGetter));
|
pip_root_ = std::unique_ptr<PipXYRoot>(new PipXYRoot(ctx, "Pips", root_.get(), pipMap, pipGetter, ElementType::PIP));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cell_root_ = std::unique_ptr<IdStringList>(new IdStringList(QString("Cells"), root_.get()));
|
cell_root_ = std::unique_ptr<IdStringList>(new IdStringList(QString("Cells"), root_.get(), ElementType::CELL));
|
||||||
net_root_ = std::unique_ptr<IdStringList>(new IdStringList(QString("Nets"), root_.get()));
|
net_root_ = std::unique_ptr<IdStringList>(new IdStringList(QString("Nets"), root_.get(), ElementType::NET));
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ class LazyTreeItem
|
|||||||
QString name_;
|
QString name_;
|
||||||
LazyTreeItem *parent_;
|
LazyTreeItem *parent_;
|
||||||
QList<LazyTreeItem *> children_;
|
QList<LazyTreeItem *> children_;
|
||||||
|
ElementType type_;
|
||||||
|
|
||||||
void addChild(LazyTreeItem *child)
|
void addChild(LazyTreeItem *child)
|
||||||
{
|
{
|
||||||
@ -50,8 +51,8 @@ class LazyTreeItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LazyTreeItem(QString name, LazyTreeItem *parent) :
|
LazyTreeItem(QString name, LazyTreeItem *parent, ElementType type) :
|
||||||
name_(name), parent_(parent)
|
name_(name), parent_(parent), type_(type)
|
||||||
{
|
{
|
||||||
// Register in parent if exists.
|
// Register in parent if exists.
|
||||||
if (parent_ != nullptr) {
|
if (parent_ != nullptr) {
|
||||||
@ -84,9 +85,13 @@ class LazyTreeItem
|
|||||||
return parent_;
|
return parent_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElementType type() const
|
||||||
|
{
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool canFetchMore() const = 0;
|
virtual bool canFetchMore() const = 0;
|
||||||
virtual void fetchMore() = 0;
|
virtual void fetchMore() = 0;
|
||||||
virtual ElementType type() const = 0;
|
|
||||||
virtual IdString id() const = 0;
|
virtual IdString id() const = 0;
|
||||||
|
|
||||||
virtual ~LazyTreeItem() {}
|
virtual ~LazyTreeItem() {}
|
||||||
@ -108,11 +113,6 @@ class StaticTreeItem : public LazyTreeItem
|
|||||||
|
|
||||||
virtual ~StaticTreeItem() {}
|
virtual ~StaticTreeItem() {}
|
||||||
|
|
||||||
virtual ElementType type() const override
|
|
||||||
{
|
|
||||||
return ElementType::NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual IdString id() const override
|
virtual IdString id() const override
|
||||||
{
|
{
|
||||||
return IdString();
|
return IdString();
|
||||||
@ -132,6 +132,7 @@ class ElementList : public LazyTreeItem
|
|||||||
int x_, y_;
|
int x_, y_;
|
||||||
ElementGetter getter_;
|
ElementGetter getter_;
|
||||||
std::vector<std::unique_ptr<StaticTreeItem>> managed_;
|
std::vector<std::unique_ptr<StaticTreeItem>> managed_;
|
||||||
|
ElementType child_type_;
|
||||||
|
|
||||||
// scope valid until map gets mutated...
|
// scope valid until map gets mutated...
|
||||||
const std::vector<ElementT> *elements() const
|
const std::vector<ElementT> *elements() const
|
||||||
@ -140,8 +141,8 @@ class ElementList : public LazyTreeItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElementList(Context *ctx, QString name, LazyTreeItem *parent, ElementMap *map, int x, int y, ElementGetter getter) :
|
ElementList(Context *ctx, QString name, LazyTreeItem *parent, ElementMap *map, int x, int y, ElementGetter getter, ElementType type) :
|
||||||
LazyTreeItem(name, parent), ctx_(ctx), map_(map), x_(x), y_(y), getter_(getter)
|
LazyTreeItem(name, parent, ElementType::NONE), ctx_(ctx), map_(map), x_(x), y_(y), getter_(getter), child_type_(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ class ElementList : public LazyTreeItem
|
|||||||
if (name.startsWith(prefix))
|
if (name.startsWith(prefix))
|
||||||
name.remove(0, prefix.size());
|
name.remove(0, prefix.size());
|
||||||
|
|
||||||
auto item = new StaticTreeItem(name, this);
|
auto item = new StaticTreeItem(name, this, child_type_);
|
||||||
managed_.push_back(std::move(std::unique_ptr<StaticTreeItem>(item)));
|
managed_.push_back(std::move(std::unique_ptr<StaticTreeItem>(item)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,11 +173,6 @@ class ElementList : public LazyTreeItem
|
|||||||
fetchMore(100);
|
fetchMore(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ElementType type() const override
|
|
||||||
{
|
|
||||||
return ElementType::NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual IdString id() const override
|
virtual IdString id() const override
|
||||||
{
|
{
|
||||||
return IdString();
|
return IdString();
|
||||||
@ -187,7 +183,10 @@ class IdStringList : public StaticTreeItem
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::unordered_map<IdString, std::unique_ptr<StaticTreeItem>> managed_;
|
std::unordered_map<IdString, std::unique_ptr<StaticTreeItem>> managed_;
|
||||||
|
ElementType child_type_;
|
||||||
public:
|
public:
|
||||||
|
IdStringList(QString name, LazyTreeItem *parent, ElementType type) :
|
||||||
|
StaticTreeItem(name, parent, ElementType::NONE), child_type_(type) {}
|
||||||
using StaticTreeItem::StaticTreeItem;
|
using StaticTreeItem::StaticTreeItem;
|
||||||
|
|
||||||
void updateElements(Context *ctx, std::vector<IdString> elements)
|
void updateElements(Context *ctx, std::vector<IdString> elements)
|
||||||
@ -198,7 +197,7 @@ class IdStringList : public StaticTreeItem
|
|||||||
element_set.insert(elem);
|
element_set.insert(elem);
|
||||||
auto existing = managed_.find(elem);
|
auto existing = managed_.find(elem);
|
||||||
if (existing == managed_.end()) {
|
if (existing == managed_.end()) {
|
||||||
auto item = new StaticTreeItem(elem.c_str(ctx), this);
|
auto item = new StaticTreeItem(elem.c_str(ctx), this, child_type_);
|
||||||
managed_.emplace(elem, std::unique_ptr<StaticTreeItem>(item));
|
managed_.emplace(elem, std::unique_ptr<StaticTreeItem>(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,10 +263,11 @@ class ElementXYRoot : public StaticTreeItem
|
|||||||
std::vector<std::unique_ptr<LazyTreeItem>> managed_;
|
std::vector<std::unique_ptr<LazyTreeItem>> managed_;
|
||||||
ElementMap map_;
|
ElementMap map_;
|
||||||
ElementGetter getter_;
|
ElementGetter getter_;
|
||||||
|
ElementType child_type_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElementXYRoot(Context *ctx, QString name, LazyTreeItem *parent, ElementMap map, ElementGetter getter) :
|
ElementXYRoot(Context *ctx, QString name, LazyTreeItem *parent, ElementMap map, ElementGetter getter, ElementType type) :
|
||||||
StaticTreeItem(name, parent), ctx_(ctx), map_(map), getter_(getter)
|
StaticTreeItem(name, parent, ElementType::NONE), ctx_(ctx), map_(map), getter_(getter), child_type_(type)
|
||||||
{
|
{
|
||||||
std::vector<int> y_present;
|
std::vector<int> y_present;
|
||||||
|
|
||||||
@ -284,10 +284,10 @@ class ElementXYRoot : public StaticTreeItem
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// create X item for tree
|
// create X item for tree
|
||||||
auto item = new StaticTreeItem(QString("X%1").arg(i), this);
|
auto item = new StaticTreeItem(QString("X%1").arg(i), this, child_type_);
|
||||||
managed_.push_back(std::move(std::unique_ptr<LazyTreeItem>(item)));
|
managed_.push_back(std::move(std::unique_ptr<LazyTreeItem>(item)));
|
||||||
for (auto j : y_present) {
|
for (auto j : y_present) {
|
||||||
auto item2 = new ElementList<ElementT>(ctx_, QString("Y%1").arg(j), item, &map_, i, j, getter_);
|
auto item2 = new ElementList<ElementT>(ctx_, QString("Y%1").arg(j), item, &map_, i, j, getter_, child_type_);
|
||||||
item2->fetchMore(1);
|
item2->fetchMore(1);
|
||||||
managed_.push_back(std::move(std::unique_ptr<LazyTreeItem>(item2)));
|
managed_.push_back(std::move(std::unique_ptr<LazyTreeItem>(item2)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user