# HG changeset patch # User Torsten # Date 1444244485 -7200 # Node ID 734d446560a836afa1b275391427dbc520030e30 # Parent f61c67865d9fe1d09b3d46766c8c962e8d00c352 possibility to hide filters in history and workspace view (bug#45428) * history_dock_widget.cc(construct): use settings file for show/hide the filter; (~history_dock_widget): save current filter state to settings file; (ctxMenu): add menu entry for showing/hiding the filter; (handle_contextmenu_filter): slot for the new menu entry * history-dock-widget.h: new slot for new menu entry, new class variables for filter and show/hide-state * workspace-view.cc(workspace_view): use settings file for show/hide the filter; (~workspace_view): save current filter state to settings file; (contextmenu_requested): add menu entry for showing/hiding the filter; (handle_contextmenu_filter): slot for the new menu entry * workspace-view.h: new slot for new menu entry, new class variables for filter and show/hide-state diff -r f61c67865d9f -r 734d446560a8 libgui/src/history-dock-widget.cc --- a/libgui/src/history-dock-widget.cc Wed Oct 07 07:41:44 2015 -0700 +++ b/libgui/src/history-dock-widget.cc Wed Oct 07 21:01:25 2015 +0200 @@ -94,21 +94,29 @@ set_title (tr ("Command History")); setWidget (new QWidget ()); - QVBoxLayout *vbox_layout = new QVBoxLayout (); - QHBoxLayout *hbox_layout = new QHBoxLayout (); - hbox_layout->addWidget (filter_label); - hbox_layout->addWidget (_filter_checkbox); - hbox_layout->addWidget (_filter); - vbox_layout->addLayout (hbox_layout); - vbox_layout->addWidget (_history_list_view); - vbox_layout->setMargin (2); + _filter_widget = new QWidget (this); + QHBoxLayout *filter_layout = new QHBoxLayout (); + filter_layout->addWidget (filter_label); + filter_layout->addWidget (_filter_checkbox); + filter_layout->addWidget (_filter); + filter_layout->setMargin(0); + _filter_widget->setLayout (filter_layout); - widget ()->setLayout (vbox_layout); + QVBoxLayout *hist_layout = new QVBoxLayout (); + hist_layout->addWidget (_filter_widget); + hist_layout->addWidget (_history_list_view); + + hist_layout->setMargin (2); + widget ()->setLayout (hist_layout); setFocusProxy (_filter->lineEdit ()); // Init state of the filter QSettings *settings = resource_manager::get_settings (); + + _filter_shown = settings->value ("history_dock_widget/filter_shown",true).toBool(); + _filter_widget->setVisible (_filter_shown); + _filter->addItems (settings->value ("history_dock_widget/mru_list").toStringList ()); bool filter_state = @@ -142,6 +150,7 @@ settings->setValue ("history_dock_widget/filter_active", _filter_checkbox->isChecked ()); + settings->setValue ("history_dock_widget/filter_shown", _filter_shown); QStringList mru; for (int i = 0; i < _filter->count (); i++) @@ -191,8 +200,15 @@ menu.addAction (resource_manager::icon ("document-new"), tr ("Create script"), this, SLOT (handle_contextmenu_create_script (bool))); - menu.exec (_history_list_view->mapToGlobal (xpos)); } + if (_filter_shown) + menu.addAction (tr ("Hide filter"), this, + SLOT (handle_contextmenu_filter ())); + else + menu.addAction (tr ("Show filter"), this, + SLOT (handle_contextmenu_filter ())); + + menu.exec (_history_list_view->mapToGlobal (xpos)); } void history_dock_widget::handle_contextmenu_copy (bool) @@ -250,6 +266,12 @@ emit command_create_script (text); } +void +history_dock_widget::handle_contextmenu_filter (void) +{ + _filter_shown = not _filter_shown; + _filter_widget->setVisible (_filter_shown); +} void history_dock_widget::handle_double_click (QModelIndex modelIndex) diff -r f61c67865d9f -r 734d446560a8 libgui/src/history-dock-widget.h --- a/libgui/src/history-dock-widget.h Wed Oct 07 07:41:44 2015 -0700 +++ b/libgui/src/history-dock-widget.h Wed Oct 07 21:01:25 2015 +0200 @@ -67,6 +67,7 @@ void handle_contextmenu_copy (bool flag); void handle_contextmenu_evaluate (bool flag); void handle_contextmenu_create_script (bool flag); + void handle_contextmenu_filter (void); void ctxMenu (const QPoint &pos); void copyClipboard (); @@ -84,6 +85,8 @@ QCheckBox *_filter_checkbox; QComboBox *_filter; + QWidget *_filter_widget; + bool _filter_shown; enum { MaxFilterHistory = 10 }; }; diff -r f61c67865d9f -r 734d446560a8 libgui/src/workspace-view.cc --- a/libgui/src/workspace-view.cc Wed Oct 07 07:41:44 2015 -0700 +++ b/libgui/src/workspace-view.cc Wed Oct 07 21:01:25 2015 +0200 @@ -75,23 +75,32 @@ // Set an empty widget, so we can assign a layout to it. setWidget (new QWidget (this)); - // Create a new layout and add widgets to it. - QVBoxLayout *vbox_layout = new QVBoxLayout (); - QHBoxLayout *hbox_layout = new QHBoxLayout (); - hbox_layout->addWidget (filter_label); - hbox_layout->addWidget (_filter_checkbox); - hbox_layout->addWidget (_filter); - vbox_layout->addLayout (hbox_layout); - vbox_layout->addWidget (view); - vbox_layout->setMargin (2); + // Create the layouts + _filter_widget = new QWidget (this); + QHBoxLayout *filter_layout = new QHBoxLayout (); + + filter_layout->addWidget (filter_label); + filter_layout->addWidget (_filter_checkbox); + filter_layout->addWidget (_filter); + filter_layout->setMargin(0); + _filter_widget->setLayout (filter_layout); + + QVBoxLayout *ws_layout = new QVBoxLayout (); + ws_layout->addWidget (_filter_widget); + ws_layout->addWidget (view); + + QSettings *settings = resource_manager::get_settings (); + + _filter_shown = settings->value ("workspaceview/filter_shown",true).toBool(); + _filter_widget->setVisible (_filter_shown); + + ws_layout->setMargin (2); // Set the empty widget to have our layout. - widget ()->setLayout (vbox_layout); + widget ()->setLayout (ws_layout); // Initialize collapse/expand state of the workspace subcategories. - QSettings *settings = resource_manager::get_settings (); - //enable sorting (setting column and order after model was set) view->setSortingEnabled (true); // Initialize column order and width of the workspace @@ -129,7 +138,6 @@ connect (this, SIGNAL (command_requested (const QString&)), p, SLOT (execute_command_in_terminal (const QString&))); - } workspace_view::~workspace_view (void) @@ -146,6 +154,7 @@ settings->setValue ("workspaceview/filter_active", _filter_checkbox->isChecked ()); + settings->setValue ("workspaceview/filter_shown", _filter_shown); QStringList mru; for (int i = 0; i < _filter->count (); i++) @@ -263,8 +272,18 @@ menu.addAction ("stem (" + var_name + ")", this, SLOT (handle_contextmenu_stem ())); - menu.exec (view->mapToGlobal (qpos)); + menu.addSeparator (); + } + + if (_filter_shown) + menu.addAction (tr ("Hide filter"), this, + SLOT (handle_contextmenu_filter ())); + else + menu.addAction (tr ("Show filter"), this, + SLOT (handle_contextmenu_filter ())); + + menu.exec (view->mapToGlobal (qpos)); } void @@ -359,6 +378,13 @@ } void +workspace_view::handle_contextmenu_filter (void) +{ + _filter_shown = not _filter_shown; + _filter_widget->setVisible (_filter_shown); +} + +void workspace_view::handle_model_changed (void) { // view->resizeRowsToContents (); diff -r f61c67865d9f -r 734d446560a8 libgui/src/workspace-view.h --- a/libgui/src/workspace-view.h Wed Oct 07 07:41:44 2015 -0700 +++ b/libgui/src/workspace-view.h Wed Oct 07 21:01:25 2015 +0200 @@ -70,6 +70,7 @@ void handle_contextmenu_disp (void); void handle_contextmenu_plot (void); void handle_contextmenu_stem (void); + void handle_contextmenu_filter (void); void handle_model_changed (void); @@ -92,6 +93,9 @@ QSortFilterProxyModel _filter_model; QCheckBox *_filter_checkbox; QComboBox *_filter; + QWidget *_filter_widget; + bool _filter_shown; + enum { MaxFilterHistory = 10 }; };