diff --git a/src/layui/layui/layLayerControlPanel.cc b/src/layui/layui/layLayerControlPanel.cc index 8f9eb165c..05d53b135 100644 --- a/src/layui/layui/layLayerControlPanel.cc +++ b/src/layui/layui/layLayerControlPanel.cc @@ -885,7 +885,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 sel = mp_view->selected_layers (); + + for (std::vector::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 +1081,44 @@ LayerControlPanel::cm_select_all () END_PROTECTED_CLEANUP { recover (); } } -void +void +LayerControlPanel::cm_invert_selection () +{ + BEGIN_PROTECTED_CLEANUP + + std::vector sel = mp_view->selected_layers (); + + std::set ids; + for (auto s = sel.begin (); s != sel.end (); ++s) { + ids.insert (s->uint ()); + } + + std::vector 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 &new_sel) { // If the tree has changed we need to delay the selection update until the model has been updated. @@ -2291,6 +2348,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)); @@ -2309,6 +2367,7 @@ public: 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")))); diff --git a/src/layui/layui/layLayerControlPanel.h b/src/layui/layui/layLayerControlPanel.h index 40134c9e5..f115b6bf0 100644 --- a/src/layui/layui/layLayerControlPanel.h +++ b/src/layui/layui/layLayerControlPanel.h @@ -300,12 +300,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 (); diff --git a/src/layui/layui/layLayoutViewFunctions.cc b/src/layui/layui/layLayoutViewFunctions.cc index ac988ae0e..ed6a600c5 100644 --- a/src/layui/layui/layLayoutViewFunctions.cc +++ b/src/layui/layui/layLayoutViewFunctions.cc @@ -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 () { diff --git a/src/layui/layui/layLayoutViewFunctions.h b/src/layui/layui/layLayoutViewFunctions.h index 724bd3a89..075b62395 100644 --- a/src/layui/layui/layLayoutViewFunctions.h +++ b/src/layui/layui/layLayoutViewFunctions.h @@ -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 ();