Merge pull request #1570 from KLayout/issue-1569

Implemented solution for issue #1569
This commit is contained in:
Matthias Köfferlein 2023-12-16 20:29:16 +01:00 committed by GitHub
commit 2c59d4190f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 172 additions and 3 deletions

View File

@ -43,6 +43,7 @@ public:
lay::ColorConverter cc;
options.push_back (std::pair<std::string, std::string> (cfg_default_lyp_file, ""));
options.push_back (std::pair<std::string, std::string> (cfg_default_add_other_layers, "false"));
options.push_back (std::pair<std::string, std::string> (cfg_layer_visibility_follows_selection, "false"));
options.push_back (std::pair<std::string, std::string> (cfg_layers_always_show_source, "false"));
options.push_back (std::pair<std::string, std::string> (cfg_layers_always_show_ld, "true"));
options.push_back (std::pair<std::string, std::string> (cfg_layers_always_show_layout_index, "false"));

View File

@ -117,6 +117,7 @@ static const std::string cfg_drop_small_cells_value ("drop-small-cells-value");
static const std::string cfg_array_border_instances ("draw-array-border-instances");
static const std::string cfg_default_lyp_file ("default-layer-properties");
static const std::string cfg_default_add_other_layers ("default-add-other-layers");
static const std::string cfg_layer_visibility_follows_selection ("layer-visibility-follows-selection");
static const std::string cfg_layers_always_show_source ("layers-always-show-source");
static const std::string cfg_layers_always_show_ld ("layers-always-show-ld");
static const std::string cfg_layers_always_show_layout_index ("layers-always-show-layout-index");

View File

@ -213,7 +213,9 @@ LayerControlPanel::LayerControlPanel (lay::LayoutViewBase *view, db::Manager *ma
m_oversampling (1),
m_hrm (false),
m_do_update_content_dm (this, &LayerControlPanel::do_update_content),
m_no_stipples (false)
m_do_update_visibility_dm (this, &LayerControlPanel::do_update_visibility),
m_no_stipples (false),
m_layer_visibility_follows_selection (false)
{
setObjectName (QString::fromUtf8 (name));
@ -315,6 +317,7 @@ LayerControlPanel::LayerControlPanel (lay::LayoutViewBase *view, db::Manager *ma
connect (mp_layer_list, SIGNAL (expanded (const QModelIndex &)), this, SLOT (group_expanded (const QModelIndex &)));
connect (mp_layer_list, SIGNAL (search_triggered (const QString &)), this, SLOT (search_triggered (const QString &)));
connect (mp_layer_list->selectionModel (), SIGNAL (currentChanged (const QModelIndex &, const QModelIndex &)), this, SLOT (current_index_changed (const QModelIndex &)));
connect (mp_layer_list->selectionModel (), SIGNAL (selectionChanged (const QItemSelection &, const QItemSelection &)), this, SLOT (selection_changed (const QItemSelection &, const QItemSelection &)));
mp_layer_list->setContextMenuPolicy (Qt::CustomContextMenu);
connect (mp_layer_list, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT (context_menu (const QPoint &)));
mp_layer_list->header ()->hide ();
@ -885,7 +888,27 @@ LayerControlPanel::cm_show ()
END_PROTECTED_CLEANUP { recover (); }
}
void
void
LayerControlPanel::cm_toggle_visibility ()
{
BEGIN_PROTECTED_CLEANUP
transaction (tl::to_string (QObject::tr ("Toggle visibility")));
std::vector<lay::LayerPropertiesConstIterator> sel = mp_view->selected_layers ();
for (std::vector<lay::LayerPropertiesConstIterator>::const_iterator l = sel.begin (); l != sel.end (); ++l) {
lay::LayerProperties props (**l);
props.set_visible (! props.visible (false));
mp_view->set_properties (*l, props);
}
commit ();
END_PROTECTED_CLEANUP { recover (); }
}
void
LayerControlPanel::cm_show_all ()
{
BEGIN_PROTECTED_CLEANUP
@ -1061,7 +1084,44 @@ LayerControlPanel::cm_select_all ()
END_PROTECTED_CLEANUP { recover (); }
}
void
void
LayerControlPanel::cm_invert_selection ()
{
BEGIN_PROTECTED_CLEANUP
std::vector<lay::LayerPropertiesConstIterator> sel = mp_view->selected_layers ();
std::set<size_t> ids;
for (auto s = sel.begin (); s != sel.end (); ++s) {
ids.insert (s->uint ());
}
std::vector<lay::LayerPropertiesConstIterator> new_sel;
for (lay::LayerPropertiesConstIterator l = mp_view->begin_layers (); ! l.at_end (); ) {
if (ids.find (l.uint ()) == ids.end ()) {
new_sel.push_back (l);
++l;
} else if (l->has_children ()) {
while (! l.at_end ()) {
l.next_sibling ();
if (l.at_end () && ! l.at_top ()) {
l.up ();
} else {
break;
}
}
} else {
++l;
}
}
mp_layer_list->set_selection (new_sel);
END_PROTECTED_CLEANUP { recover (); }
}
void
LayerControlPanel::set_selection (const std::vector<lay::LayerPropertiesConstIterator> &new_sel)
{
// If the tree has changed we need to delay the selection update until the model has been updated.
@ -1642,6 +1702,21 @@ LayerControlPanel::update_hidden_flags ()
m_do_update_content_dm ();
}
void
LayerControlPanel::set_layer_visibility_follows_selection (bool f)
{
if (f != m_layer_visibility_follows_selection) {
m_layer_visibility_follows_selection = f;
m_do_update_visibility_dm ();
}
}
bool
LayerControlPanel::layer_visibility_follows_selection ()
{
return m_layer_visibility_follows_selection;
}
void
LayerControlPanel::set_hide_empty_layers (bool f)
{
@ -1790,6 +1865,29 @@ LayerControlPanel::do_update_hidden_flags ()
}
}
void
LayerControlPanel::do_update_visibility ()
{
if (! m_layer_visibility_follows_selection) {
return;
}
std::set<size_t> sel_uints;
QModelIndexList selected = mp_layer_list->selectionModel ()->selectedIndexes ();
for (QModelIndexList::const_iterator i = selected.begin (); i != selected.end (); ++i) {
if (i->column () == 0) {
sel_uints.insert (mp_model->iterator (*i).uint ());
}
}
for (lay::LayerPropertiesConstIterator l = mp_view->begin_layers (); ! l.at_end (); ++l) {
lay::LayerProperties props (*l);
props.set_visible (sel_uints.find (l.uint ()) != sel_uints.end () || l->has_children ());
mp_view->set_properties (l, props);
}
}
void
LayerControlPanel::do_update_content ()
{
@ -2051,6 +2149,14 @@ LayerControlPanel::current_index_changed (const QModelIndex &index)
}
}
void
LayerControlPanel::selection_changed (const QItemSelection &, const QItemSelection &)
{
if (m_layer_visibility_follows_selection) {
m_do_update_visibility_dm ();
}
}
void
LayerControlPanel::group_collapsed (const QModelIndex &index)
{
@ -2291,6 +2397,7 @@ public:
at = "@lcp_context_menu.end";
menu_entries.push_back (lay::menu_item ("cm_lv_select_all", "select_all", at, tl::to_string (QObject::tr ("Select All"))));
menu_entries.push_back (lay::menu_item ("cm_lv_invert_selection", "invert_selection", at, tl::to_string (QObject::tr ("Invert Selection"))));
// It is not sure, whether "expandAll" destabilizes the tree widget:
// menu_entries.push_back (lay::menu_item ("cm_lv_expand_all", "expand_all", at, tl::to_string (QObject::tr ("Expand All"))));
menu_entries.push_back (lay::separator ("tab_group", at));
@ -2304,11 +2411,13 @@ public:
}
menu_entries.push_back (lay::separator ("visibility_group", at));
menu_entries.push_back (lay::config_menu_item ("visibility_follows_selection", at, tl::to_string (QObject::tr ("Visibility Follows Selection")), cfg_layer_visibility_follows_selection, "?"));
menu_entries.push_back (lay::menu_item ("cm_lv_hide", "hide", at, tl::to_string (QObject::tr ("Hide"))));
menu_entries.push_back (lay::menu_item ("cm_lv_hide_all", "hide_all", at, tl::to_string (QObject::tr ("Hide All"))));
menu_entries.push_back (lay::menu_item ("cm_lv_show", "show", at, tl::to_string (QObject::tr ("Show"))));
menu_entries.push_back (lay::menu_item ("cm_lv_show_all", "show_all", at, tl::to_string (QObject::tr ("Show All"))));
menu_entries.push_back (lay::menu_item ("cm_lv_show_only", "show_only", at, tl::to_string (QObject::tr ("Show Only Selected"))));
menu_entries.push_back (lay::menu_item ("cm_lv_toggle_visibility", "toggle_visibility", at, tl::to_string (QObject::tr ("Toggle Visibility"))));
menu_entries.push_back (lay::menu_item ("cm_lv_make_valid", "valid", at, tl::to_string (QObject::tr ("Make Valid"))));
menu_entries.push_back (lay::menu_item ("cm_lv_make_invalid", "invvalid", at, tl::to_string (QObject::tr ("Make Invalid"))));
menu_entries.push_back (lay::menu_item ("cm_lv_rename", "rename", at, tl::to_string (QObject::tr ("Rename"))));

View File

@ -188,6 +188,18 @@ public:
*/
bool hide_empty_layers ();
/**
* @brief Set the "layer visibility follows selection" flag
*
* If this flag is set, only the selected layers are made visible.
*/
void set_layer_visibility_follows_selection (bool f);
/**
* @brief Get the "layer visibility follows selection" flag
*/
bool layer_visibility_follows_selection ();
/**
* @brief Set the "test_shapes_in_view" flag
*
@ -300,12 +312,14 @@ public slots:
void cm_remove_tab ();
void cm_rename_tab ();
void cm_select_all ();
void cm_invert_selection ();
void cm_make_valid ();
void cm_make_invalid ();
void cm_hide ();
void cm_hide_all ();
void cm_show ();
void cm_show_all ();
void cm_toggle_visibility ();
void cm_show_only ();
void cm_rename ();
void cm_delete ();
@ -332,6 +346,7 @@ public slots:
void group_collapsed (const QModelIndex &index);
void group_expanded (const QModelIndex &index);
void current_index_changed (const QModelIndex &index);
void selection_changed (const QItemSelection &, const QItemSelection &);
void up_clicked ();
void upup_clicked ();
void down_clicked ();
@ -361,7 +376,9 @@ private:
int m_oversampling;
bool m_hrm;
tl::DeferredMethod<LayerControlPanel> m_do_update_content_dm;
tl::DeferredMethod<LayerControlPanel> m_do_update_visibility_dm;
bool m_no_stipples;
bool m_layer_visibility_follows_selection;
QLabel *m_no_stipples_label;
lay::DecoratedLineEdit *mp_search_edit_box;
QAction *mp_case_sensitive;
@ -382,6 +399,7 @@ private:
void signal_vp_changed ();
void do_update_content ();
void do_update_visibility ();
void do_update_hidden_flags ();
void do_delete ();
void do_copy ();

View File

@ -367,6 +367,8 @@ LayoutViewFunctions::menu_activated (const std::string &symbol)
}
} else if (symbol == "cm_lv_select_all") {
cm_select_all ();
} else if (symbol == "cm_lv_invert_selection") {
cm_invert_selection ();
} else if (symbol == "cm_lv_new_tab") {
cm_new_tab ();
} else if (symbol == "cm_lv_rename_tab") {
@ -387,6 +389,8 @@ LayoutViewFunctions::menu_activated (const std::string &symbol)
cm_show_all ();
} else if (symbol == "cm_lv_show") {
cm_show ();
} else if (symbol == "cm_lv_toggle_visibility") {
cm_toggle_visibility ();
} else if (symbol == "cm_lv_rename") {
cm_rename ();
} else if (symbol == "cm_lv_delete") {
@ -946,6 +950,14 @@ LayoutViewFunctions::cm_select_all ()
}
}
void
LayoutViewFunctions::cm_invert_selection ()
{
if (view ()->control_panel ()) {
view ()->control_panel ()->cm_invert_selection ();
}
}
void
LayoutViewFunctions::cm_new_tab ()
{
@ -1026,6 +1038,14 @@ LayoutViewFunctions::cm_show ()
}
}
void
LayoutViewFunctions::cm_toggle_visibility ()
{
if (view ()->control_panel ()) {
view ()->control_panel ()->cm_toggle_visibility ();
}
}
void
LayoutViewFunctions::cm_rename ()
{

View File

@ -87,12 +87,14 @@ public:
void cm_rename_tab ();
void cm_remove_tab ();
void cm_select_all ();
void cm_invert_selection ();
void cm_make_valid ();
void cm_make_invalid ();
void cm_hide ();
void cm_hide_all ();
void cm_show ();
void cm_show_all ();
void cm_toggle_visibility ();
void cm_show_only ();
void cm_rename ();
void cm_delete ();

View File

@ -960,6 +960,24 @@ LayoutView::configure (const std::string &name, const std::string &value)
}
return true;
} else if (name == cfg_layer_visibility_follows_selection) {
bool f;
tl::from_string (value, f);
if (mp_control_panel) {
mp_control_panel->set_layer_visibility_follows_selection (f);
}
return true;
} else if (name == cfg_test_shapes_in_view) {
bool f;
tl::from_string (value, f);
if (mp_control_panel) {
mp_control_panel->set_test_shapes_in_view (f);
}
return true;
} else if (name == cfg_test_shapes_in_view) {
bool f;