Mercurial > hg > octave-nkf
changeset 19759:010cef260698 gui-release
improve filter of workspace view
* workspace-view.cc (constructor): fix tooltip, filter model is not a pointer,
do not set filter column here;
(setModel): filter model is not a pointer, set filter column here;
(filter_update): use wildcard instead of reg. exp., filter model no pointer;
(filter_activate): filter model no pointer;
(update_filter_history): remove an existing item of current one,
insert current to first position and amke sure it stays the current item;
(handle_model_changed): filter model is no pointer
* workspace-view.h: filter model is no pointer
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 10 Jan 2015 13:31:24 +0100 |
parents | 77e58a7945b3 |
children | a402493c0605 |
files | libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 2 files changed, 17 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -51,7 +51,7 @@ setStatusTip (tr ("View the variables in the active workspace.")); _filter = new QComboBox (this); - _filter->setToolTip (tr ("Enter the path or filename")); + _filter->setToolTip (tr ("Enter text to filter the workspace")); _filter->setEditable (true); _filter->setMaxCount (MaxFilterHistory); _filter->setInsertPolicy (QComboBox::NoInsert); @@ -88,10 +88,6 @@ // Set the empty widget to have our layout. widget ()->setLayout (vbox_layout); - // Filter model - _filter_model = new QSortFilterProxyModel (); - _filter_model->setFilterKeyColumn(0); - // Initialize collapse/expand state of the workspace subcategories. QSettings *settings = resource_manager::get_settings (); @@ -144,8 +140,10 @@ void workspace_view::setModel (workspace_model *model) { - _filter_model->setSourceModel (model); - view->setModel (_filter_model); + _filter_model.setSourceModel (model); + _filter_model.setFilterKeyColumn(0); + + view->setModel (&_filter_model); _model = model; } @@ -159,7 +157,7 @@ void workspace_view::filter_update (const QString& expression) { - _filter_model->setFilterRegExp (QRegExp (expression, Qt::CaseSensitive)); + _filter_model.setFilterWildcard (expression); handle_model_changed (); } @@ -167,7 +165,7 @@ workspace_view::filter_activate (bool state) { _filter->setEnabled (state); - _filter_model->setDynamicSortFilter (state); + _filter_model.setDynamicSortFilter (state); if (state) filter_update (_filter->currentText ()); @@ -178,9 +176,14 @@ void workspace_view::update_filter_history () { - QString text = _filter->currentText (); - if (! text.isEmpty () && _filter->findText (text) == -1) - _filter->insertItem (0, _filter->currentText ()); + QString text = _filter->currentText (); // get current text + int index = _filter->findText (text); // and its actual index + + if (index > -1) + _filter->removeItem (index); // remove if already existing + + _filter->insertItem (0, text); // (re)insert at beginning + _filter->setCurrentIndex (0); } QString @@ -337,7 +340,7 @@ // the whole list. For-loop test will handle when number of rows reduced. QFontMetrics fm = view->fontMetrics (); int row_height = fm.height (); - int new_row_count = _filter_model->rowCount (); + int new_row_count = _filter_model.rowCount (); for (int i = view_previous_row_count; i < new_row_count; i++) view->setRowHeight (i, row_height); view_previous_row_count = new_row_count;