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) :
|
Model::Model(QObject *parent) :
|
||||||
QAbstractItemModel(parent),
|
QAbstractItemModel(parent),
|
||||||
@ -272,17 +283,20 @@ bool Model::canFetchMore(const QModelIndex &parent) const
|
|||||||
|
|
||||||
QList<QModelIndex> Model::search(QString text)
|
QList<QModelIndex> Model::search(QString text)
|
||||||
{
|
{
|
||||||
QList<QModelIndex> list;
|
const int limit = 500;
|
||||||
//for (int i = 0; i < 6; i++) {
|
|
||||||
// for (auto key : nameToItem[i].keys()) {
|
QList<Item*> list;
|
||||||
// if (key.contains(text, Qt::CaseInsensitive)) {
|
cell_root_->search(list, text, limit);
|
||||||
// list.append(indexFromNode(nameToItem[i].value(key)));
|
net_root_->search(list, text, limit);
|
||||||
// if (list.count() > 500)
|
bel_root_->search(list, text, limit);
|
||||||
// break; // limit to 500 results
|
wire_root_->search(list, text, limit);
|
||||||
// }
|
pip_root_->search(list, text, limit);
|
||||||
// }
|
|
||||||
//}
|
QList<QModelIndex> res;
|
||||||
return list;
|
for (auto i : list) {
|
||||||
|
res.push_back(indexFromNode(i));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace TreeModel
|
}; // namespace TreeModel
|
||||||
|
@ -159,6 +159,9 @@ class IdStringList : public Item
|
|||||||
|
|
||||||
// (Re-)create children from a list of IdStrings.
|
// (Re-)create children from a list of IdStrings.
|
||||||
void updateElements(Context *ctx, std::vector<IdString> elements);
|
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;
|
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.
|
// ElementXYRoot is the root of an ElementT multi-level lazy loading list.
|
||||||
@ -320,6 +341,16 @@ class ElementXYRoot : public Item
|
|||||||
}
|
}
|
||||||
return boost::none;
|
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
|
class Model : public QAbstractItemModel
|
||||||
@ -345,6 +376,7 @@ class Model : public QAbstractItemModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<QModelIndex> search(QString text);
|
QList<QModelIndex> search(QString text);
|
||||||
|
|
||||||
boost::optional<Item*> nodeForIdType(ElementType type, IdString id) const
|
boost::optional<Item*> nodeForIdType(ElementType type, IdString id) const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user