LVSDB browser: filter based on status ('show all')

This commit is contained in:
Matthias Koefferlein 2019-05-25 10:12:35 +02:00
parent f8646412ca
commit 01f7939918
3 changed files with 47 additions and 4 deletions

View File

@ -29,6 +29,7 @@
#include <QPainter>
#include <QIcon>
#include <QWidget>
#include <QTreeView>
namespace lay
{
@ -1771,6 +1772,8 @@ NetlistBrowserModel::headerData (int section, Qt::Orientation /*orientation*/, i
}
}
} else if (role == Qt::DecorationRole && section == m_status_column) {
return QIcon (":/info_16.png");
}
return QVariant ();
@ -2242,5 +2245,31 @@ NetlistBrowserModel::subcircuits_from_id (void *id) const
}
}
void
NetlistBrowserModel::show_or_hide_items (QTreeView *view, const QModelIndex &parent, bool show_all, bool with_warnings, bool with_children)
{
int n = rowCount (parent);
for (int i = 0; i < n; ++i) {
QModelIndex idx = index (i, 0, parent);
IndexedNetlistModel::Status st = status (idx);
bool visible = (show_all || (st != db::NetlistCrossReference::Match && (with_warnings || st != db::NetlistCrossReference::MatchWithWarning)));
view->setRowHidden (int (i), parent, ! visible);
if (visible && with_children) {
show_or_hide_items (view, idx, show_all, with_warnings, false /*just two levels of recursion*/);
}
}
}
void
NetlistBrowserModel::set_item_visibility (QTreeView *view, bool show_all, bool with_warnings)
{
// TODO: this implementation is based on the model but is fairly inefficient
show_or_hide_items (view, QModelIndex (), show_all, with_warnings, true);
}
}

View File

@ -36,6 +36,8 @@
#include <map>
#include <memory>
class QTreeView;
namespace lay
{
@ -138,6 +140,8 @@ public:
std::pair<const db::Device *, const db::Device *> device_from_index (const QModelIndex &index) const;
void set_item_visibility (QTreeView *view, bool show_all, bool with_warnings);
private slots:
void colors_changed ();
@ -209,6 +213,8 @@ private:
QIcon icon_for_nets (const std::pair<const db::Net *, const db::Net *> &net) const;
QIcon icon_for_connection (const std::pair<const db::Net *, const db::Net *> &net) const;
void show_or_hide_items (QTreeView *view, const QModelIndex &parent, bool show_all, bool with_warnings, bool with_children);
db::LayoutToNetlist *mp_l2ndb;
db::LayoutVsSchematic *mp_lvsdb;
NetColorizer *mp_colorizer;

View File

@ -114,7 +114,6 @@ NetlistBrowserPage::NetlistBrowserPage (QWidget * /*parent*/)
{
Ui::NetlistBrowserPage::setupUi (this);
// TODO: insert into menu
m_show_all_action = new QAction (QObject::tr ("Show All"), this);
m_show_all_action->setCheckable (true);
m_show_all_action->setChecked (m_show_all);
@ -125,6 +124,7 @@ NetlistBrowserPage::NetlistBrowserPage (QWidget * /*parent*/)
color_action->setMenu (menu);
QAction *sep;
directory_tree->addAction (m_show_all_action);
directory_tree->addAction (actionCollapseAll);
directory_tree->addAction (actionExpandAll);
sep = new QAction (directory_tree);
@ -496,7 +496,7 @@ NetlistBrowserPage::info_button_pressed ()
mp_info_dialog->show ();
}
static QModelIndex find_next (QAbstractItemModel *model, const QRegExp &to_find, const QModelIndex &from)
static QModelIndex find_next (QTreeView *view, QAbstractItemModel *model, const QRegExp &to_find, const QModelIndex &from)
{
QModelIndex index = from;
@ -571,7 +571,7 @@ static QModelIndex find_next (QAbstractItemModel *model, const QRegExp &to_find,
if (has_next) {
QString text = model->data (current, Qt::UserRole).toString ();
if (text.indexOf (to_find) >= 0) {
if (text.indexOf (to_find) >= 0 && ! view->isRowHidden (rows_stack.back ().first, parent_stack.back ())) {
return current;
}
@ -589,7 +589,7 @@ NetlistBrowserPage::find_button_pressed ()
actionCaseSensitive->isChecked () ? Qt::CaseSensitive : Qt::CaseInsensitive,
actionUseRegularExpressions->isChecked () ? QRegExp::RegExp : QRegExp::FixedString);
QModelIndex next = find_next (directory_tree->model (), re, directory_tree->currentIndex ());
QModelIndex next = find_next (directory_tree, directory_tree->model (), re, directory_tree->currentIndex ());
if (next.isValid ()) {
navigate_to (next.internalPointer ());
}
@ -611,6 +611,11 @@ NetlistBrowserPage::show_all (bool f)
m_show_all = f;
m_show_all_action->setChecked (f);
NetlistBrowserModel *model = dynamic_cast<NetlistBrowserModel *> (directory_tree->model ());
if (model) {
model->set_item_visibility (directory_tree, m_show_all, false /*show warnings only with 'show all'*/);
}
}
}
@ -666,6 +671,9 @@ NetlistBrowserPage::set_db (db::LayoutToNetlist *l2ndb)
// hide the status column if not needed
directory_tree->header ()->setSectionHidden (1, new_model->status_column () < 0);
// establish visibility according to "show all"
new_model->set_item_visibility (directory_tree, m_show_all, false /*show warnings only with 'show all'*/);
find_text->setText (QString ());
}