From 423dddae62040917ebbd0eb7f5264da7b7d4b0f2 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 12 Feb 2021 00:44:31 +0100 Subject: [PATCH] Bug fixes on cell name search feature. --- src/laybasic/laybasic/layCellTreeModel.cc | 55 ++++++++++++++----- src/laybasic/laybasic/layCellTreeModel.h | 4 -- .../laybasic/layHierarchyControlPanel.cc | 11 ++++ .../laybasic/layHierarchyControlPanel.h | 1 + 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/laybasic/laybasic/layCellTreeModel.cc b/src/laybasic/laybasic/layCellTreeModel.cc index 9dc6ff0c7..503328a42 100644 --- a/src/laybasic/laybasic/layCellTreeModel.cc +++ b/src/laybasic/laybasic/layCellTreeModel.cc @@ -450,6 +450,8 @@ CellTreeModel::do_configure (db::Layout *layout, db::Library *library, lay::Layo } else { + emit layoutAboutToBeChanged (); + // Translate persistent indexes: translation happens according to the path given by // a sequence of cell indexes. @@ -511,9 +513,9 @@ CellTreeModel::do_configure (db::Layout *layout, db::Library *library, lay::Layo changePersistentIndexList (indexes, new_indexes); - } + emit layoutChanged (); - signal_data_changed (); + } // TODO: harden against exceptions for (std::vector::iterator t = old_toplevel_items.begin (); t != old_toplevel_items.end (); ++t) { @@ -541,6 +543,7 @@ CellTreeModel::set_sorting (Sorting s) void CellTreeModel::signal_data_changed () { + emit layoutAboutToBeChanged (); emit layoutChanged (); } @@ -1043,7 +1046,22 @@ CellTreeModel::clear_locate () m_current_index = m_selected_indexes.begin (); 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 @@ -1141,20 +1159,21 @@ CellTreeModel::search_children (const tl::GlobPattern &pattern, CellTreeItem *it bool visible = false; + c->set_tree_index (std::numeric_limits::max ()); if (c->name_matches (pattern)) { + c->set_tree_index (ti); m_selected_indexes.push_back (model_index (c)); visible = true; } if (search_children (pattern, c)) { + c->set_tree_index (ti); visible = true; } if (visible) { - c->set_tree_index (ti++); + ++ti; m_visible_cell_set.insert (c); any = true; - } else { - c->set_tree_index (std::numeric_limits::max ()); } } @@ -1171,7 +1190,15 @@ CellTreeModel::locate (const char *name, bool glob_pattern, bool case_sensitive, return QModelIndex (); } + emit layoutAboutToBeChanged (); + QModelIndexList indexes = persistentIndexList (); + std::vector 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_visible_cell_set.clear (); @@ -1187,19 +1214,20 @@ CellTreeModel::locate (const char *name, bool glob_pattern, bool case_sensitive, bool visible = false; + (*lc)->set_tree_index (std::numeric_limits::max ()); if ((*lc)->name_matches (p)) { + (*lc)->set_tree_index (ti); m_selected_indexes.push_back (model_index (*lc)); visible = true; } if (! top_only && search_children (p, *lc)) { + (*lc)->set_tree_index (ti); visible = true; } if (visible) { - (*lc)->set_tree_index (ti++); + ++ti; m_visible_cell_set.insert (*lc); - } else { - (*lc)->set_tree_index (std::numeric_limits::max ()); } } @@ -1215,10 +1243,9 @@ CellTreeModel::locate (const char *name, bool glob_pattern, bool case_sensitive, QModelIndexList new_indexes; - for (QModelIndexList::iterator i = indexes.begin (); i != indexes.end (); ++i) { - CellTreeItem *item = (CellTreeItem *) i->internalPointer (); - if (m_visible_cell_set.find (item) != m_visible_cell_set.end ()) { - new_indexes.push_back (model_index (item)); + for (std::vector::const_iterator item = persistent_index_cells.begin (); item != persistent_index_cells.end (); ++item) { + if (m_visible_cell_set.find (*item) != m_visible_cell_set.end ()) { + new_indexes.push_back (model_index (*item)); } else { 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 diff --git a/src/laybasic/laybasic/layCellTreeModel.h b/src/laybasic/laybasic/layCellTreeModel.h index 1c667f6c2..65abc1f73 100644 --- a/src/laybasic/laybasic/layCellTreeModel.h +++ b/src/laybasic/laybasic/layCellTreeModel.h @@ -240,10 +240,6 @@ public: /** * @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 (); diff --git a/src/laybasic/laybasic/layHierarchyControlPanel.cc b/src/laybasic/laybasic/layHierarchyControlPanel.cc index 37727e855..30c6f62b2 100644 --- a/src/laybasic/laybasic/layHierarchyControlPanel.cc +++ b/src/laybasic/laybasic/layHierarchyControlPanel.cc @@ -79,6 +79,17 @@ HCPCellTreeWidget::HCPCellTreeWidget (QWidget *parent, const char *name, QWidget 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 HCPCellTreeWidget::event (QEvent *event) diff --git a/src/laybasic/laybasic/layHierarchyControlPanel.h b/src/laybasic/laybasic/layHierarchyControlPanel.h index 31def9efe..58d2a8688 100644 --- a/src/laybasic/laybasic/layHierarchyControlPanel.h +++ b/src/laybasic/laybasic/layHierarchyControlPanel.h @@ -66,6 +66,7 @@ Q_OBJECT public: HCPCellTreeWidget (QWidget *parent, const char *name, QWidget *key_event_receiver); + ~HCPCellTreeWidget (); signals: void cell_clicked (const QModelIndex &);