diff options
author | Sergiusz Bazanski <q3k@q3k.org> | 2018-08-01 03:11:22 +0100 |
---|---|---|
committer | Sergiusz Bazanski <q3k@q3k.org> | 2018-08-01 03:11:22 +0100 |
commit | 900649ce7a337dd7d3dcadf0d323302f09339325 (patch) | |
tree | 466a3a59906476cd0e76e07e962f9e61d1cc0890 /gui | |
parent | a117fcdefd3ce22af04906a447b0f21d403489fa (diff) | |
download | nextpnr-900649ce7a337dd7d3dcadf0d323302f09339325.tar.gz nextpnr-900649ce7a337dd7d3dcadf0d323302f09339325.tar.bz2 nextpnr-900649ce7a337dd7d3dcadf0d323302f09339325.zip |
gui: restore search
Diffstat (limited to 'gui')
-rw-r--r-- | gui/treemodel.cc | 36 | ||||
-rw-r--r-- | gui/treemodel.h | 32 |
2 files changed, 57 insertions, 11 deletions
diff --git a/gui/treemodel.cc b/gui/treemodel.cc index eaf62928..4fc3d4f5 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -124,6 +124,17 @@ void IdStringList::updateElements(Context *ctx, std::vector<IdString> elements) }); } +void IdStringList::search(QList<Item*> &results, QString text, int limit) +{ + for (const auto &child : children_) { + if (limit != -1 && results.size() > limit) + return; + + if (child->name().contains(text)) + results.push_back(child); + } +} + Model::Model(QObject *parent) : QAbstractItemModel(parent), @@ -272,17 +283,20 @@ bool Model::canFetchMore(const QModelIndex &parent) const QList<QModelIndex> Model::search(QString text) { - QList<QModelIndex> list; - //for (int i = 0; i < 6; i++) { - // for (auto key : nameToItem[i].keys()) { - // if (key.contains(text, Qt::CaseInsensitive)) { - // list.append(indexFromNode(nameToItem[i].value(key))); - // if (list.count() > 500) - // break; // limit to 500 results - // } - // } - //} - return list; + const int limit = 500; + + QList<Item*> list; + cell_root_->search(list, text, limit); + net_root_->search(list, text, limit); + bel_root_->search(list, text, limit); + wire_root_->search(list, text, limit); + pip_root_->search(list, text, limit); + + QList<QModelIndex> res; + for (auto i : list) { + res.push_back(indexFromNode(i)); + } + return res; } }; // namespace TreeModel diff --git a/gui/treemodel.h b/gui/treemodel.h index 4f708768..61dc339d 100644 --- a/gui/treemodel.h +++ b/gui/treemodel.h @@ -159,6 +159,9 @@ class IdStringList : public Item // (Re-)create children from a list of IdStrings. void updateElements(Context *ctx, std::vector<IdString> elements); + + // Find children that contain the given text. + void search(QList<Item*> &results, QString text, int limit); }; @@ -243,6 +246,24 @@ class ElementList : public Item } return boost::none; } + + // Find children that contain the given text. + void search(QList<Item*> &results, QString text, int limit) + { + // Last chance to bail out from loading entire tree into memory. + if (limit != -1 && results.size() > limit) + return; + + // Search requires us to load all our elements... + while (canFetchMore()) fetchMore(); + + for (const auto &child : children_) { + if (limit != -1 && results.size() > limit) + return; + if (child->name().contains(text)) + results.push_back(child); + } + } }; // ElementXYRoot is the root of an ElementT multi-level lazy loading list. @@ -320,6 +341,16 @@ class ElementXYRoot : public Item } return boost::none; } + + // Find children that contain the given text. + void search(QList<Item*> &results, QString text, int limit) + { + for (auto &l : managed_lists_) { + if (limit != -1 && results.size() > limit) + return; + l->search(results, text, limit); + } + } }; class Model : public QAbstractItemModel @@ -345,6 +376,7 @@ class Model : public QAbstractItemModel } QList<QModelIndex> search(QString text); + boost::optional<Item*> nodeForIdType(ElementType type, IdString id) const { switch (type) { |