Bug fixes on cell name search feature.

This commit is contained in:
Matthias Koefferlein 2021-02-12 00:44:31 +01:00
parent 71a7326fe9
commit 423dddae62
4 changed files with 53 additions and 18 deletions

View File

@ -450,6 +450,8 @@ CellTreeModel::do_configure (db::Layout *layout, db::Library *library, lay::Layo
} else { } else {
emit layoutAboutToBeChanged ();
// Translate persistent indexes: translation happens according to the path given by // Translate persistent indexes: translation happens according to the path given by
// a sequence of cell indexes. // a sequence of cell indexes.
@ -511,9 +513,9 @@ CellTreeModel::do_configure (db::Layout *layout, db::Library *library, lay::Layo
changePersistentIndexList (indexes, new_indexes); changePersistentIndexList (indexes, new_indexes);
} emit layoutChanged ();
signal_data_changed (); }
// TODO: harden against exceptions // TODO: harden against exceptions
for (std::vector<lay::CellTreeItem *>::iterator t = old_toplevel_items.begin (); t != old_toplevel_items.end (); ++t) { for (std::vector<lay::CellTreeItem *>::iterator t = old_toplevel_items.begin (); t != old_toplevel_items.end (); ++t) {
@ -541,6 +543,7 @@ CellTreeModel::set_sorting (Sorting s)
void void
CellTreeModel::signal_data_changed () CellTreeModel::signal_data_changed ()
{ {
emit layoutAboutToBeChanged ();
emit layoutChanged (); emit layoutChanged ();
} }
@ -1043,7 +1046,22 @@ CellTreeModel::clear_locate ()
m_current_index = m_selected_indexes.begin (); m_current_index = m_selected_indexes.begin ();
m_selected_indexes_set.clear (); m_selected_indexes_set.clear ();
signal_data_changed (); emit layoutAboutToBeChanged ();
if (m_filter_mode) {
QModelIndexList indexes = persistentIndexList ();
QModelIndexList new_indexes;
for (QModelIndexList::iterator i = indexes.begin (); i != indexes.end (); ++i) {
new_indexes.push_back (model_index ((CellTreeItem *) i->internalPointer ()));
}
changePersistentIndexList (indexes, new_indexes);
}
emit layoutChanged ();
} }
QModelIndex QModelIndex
@ -1141,20 +1159,21 @@ CellTreeModel::search_children (const tl::GlobPattern &pattern, CellTreeItem *it
bool visible = false; bool visible = false;
c->set_tree_index (std::numeric_limits<size_t>::max ());
if (c->name_matches (pattern)) { if (c->name_matches (pattern)) {
c->set_tree_index (ti);
m_selected_indexes.push_back (model_index (c)); m_selected_indexes.push_back (model_index (c));
visible = true; visible = true;
} }
if (search_children (pattern, c)) { if (search_children (pattern, c)) {
c->set_tree_index (ti);
visible = true; visible = true;
} }
if (visible) { if (visible) {
c->set_tree_index (ti++); ++ti;
m_visible_cell_set.insert (c); m_visible_cell_set.insert (c);
any = true; any = true;
} else {
c->set_tree_index (std::numeric_limits<size_t>::max ());
} }
} }
@ -1171,7 +1190,15 @@ CellTreeModel::locate (const char *name, bool glob_pattern, bool case_sensitive,
return QModelIndex (); return QModelIndex ();
} }
emit layoutAboutToBeChanged ();
QModelIndexList indexes = persistentIndexList (); QModelIndexList indexes = persistentIndexList ();
std::vector<CellTreeItem *> persistent_index_cells;
persistent_index_cells.reserve (indexes.size ());
for (QModelIndexList::iterator i = indexes.begin (); i != indexes.end (); ++i) {
persistent_index_cells.push_back ((CellTreeItem *) i->internalPointer ());
}
m_selected_indexes.clear (); m_selected_indexes.clear ();
m_visible_cell_set.clear (); m_visible_cell_set.clear ();
@ -1187,19 +1214,20 @@ CellTreeModel::locate (const char *name, bool glob_pattern, bool case_sensitive,
bool visible = false; bool visible = false;
(*lc)->set_tree_index (std::numeric_limits<size_t>::max ());
if ((*lc)->name_matches (p)) { if ((*lc)->name_matches (p)) {
(*lc)->set_tree_index (ti);
m_selected_indexes.push_back (model_index (*lc)); m_selected_indexes.push_back (model_index (*lc));
visible = true; visible = true;
} }
if (! top_only && search_children (p, *lc)) { if (! top_only && search_children (p, *lc)) {
(*lc)->set_tree_index (ti);
visible = true; visible = true;
} }
if (visible) { if (visible) {
(*lc)->set_tree_index (ti++); ++ti;
m_visible_cell_set.insert (*lc); m_visible_cell_set.insert (*lc);
} else {
(*lc)->set_tree_index (std::numeric_limits<size_t>::max ());
} }
} }
@ -1215,10 +1243,9 @@ CellTreeModel::locate (const char *name, bool glob_pattern, bool case_sensitive,
QModelIndexList new_indexes; QModelIndexList new_indexes;
for (QModelIndexList::iterator i = indexes.begin (); i != indexes.end (); ++i) { for (std::vector<CellTreeItem *>::const_iterator item = persistent_index_cells.begin (); item != persistent_index_cells.end (); ++item) {
CellTreeItem *item = (CellTreeItem *) i->internalPointer (); if (m_visible_cell_set.find (*item) != m_visible_cell_set.end ()) {
if (m_visible_cell_set.find (item) != m_visible_cell_set.end ()) { new_indexes.push_back (model_index (*item));
new_indexes.push_back (model_index (item));
} else { } else {
new_indexes.push_back (QModelIndex ()); new_indexes.push_back (QModelIndex ());
} }
@ -1228,7 +1255,7 @@ CellTreeModel::locate (const char *name, bool glob_pattern, bool case_sensitive,
} }
signal_data_changed (); emit layoutChanged ();
// make the first selected one current // make the first selected one current

View File

@ -240,10 +240,6 @@ public:
/** /**
* @brief Signal to the owner of the model that the data has changed * @brief Signal to the owner of the model that the data has changed
*
* Basically, this signal should be emitted by the model, if it knew that
* something changed. However, in our current architecture, it does not. So we
* need to tell the model that something has changed.
*/ */
void signal_data_changed (); void signal_data_changed ();

View File

@ -79,6 +79,17 @@ HCPCellTreeWidget::HCPCellTreeWidget (QWidget *parent, const char *name, QWidget
setObjectName (QString::fromUtf8 (name)); setObjectName (QString::fromUtf8 (name));
} }
HCPCellTreeWidget::~HCPCellTreeWidget ()
{
// NOTE: this should not be required, but I got a strange crash on closing the app with Qt 5.12.8
// after using changePersistentIndex inside the model when ~QTreeWidget tried to clean up it's
// persistent indexes and only found a model which was deleted already.
QAbstractItemModel *m = model ();
if (m) {
setModel (0);
delete m;
}
}
bool bool
HCPCellTreeWidget::event (QEvent *event) HCPCellTreeWidget::event (QEvent *event)

View File

@ -66,6 +66,7 @@ Q_OBJECT
public: public:
HCPCellTreeWidget (QWidget *parent, const char *name, QWidget *key_event_receiver); HCPCellTreeWidget (QWidget *parent, const char *name, QWidget *key_event_receiver);
~HCPCellTreeWidget ();
signals: signals:
void cell_clicked (const QModelIndex &); void cell_clicked (const QModelIndex &);