gui: restore search
This commit is contained in:
parent
a117fcdefd
commit
900649ce7a
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user