Mercurial > hg > octave-lojdl
changeset 13545:ffc2e1d1ad5f
History can be filtered with an input search box while typing.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Tue, 26 Jul 2011 23:56:03 +0200 |
parents | 81eef7babeb5 |
children | 5ef33f99a078 |
files | gui/src/HistoryDockWidget.cpp gui/src/HistoryDockWidget.h |
diffstat | 2 files changed, 22 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/HistoryDockWidget.cpp +++ b/gui/src/HistoryDockWidget.cpp @@ -17,7 +17,7 @@ */ #include "HistoryDockWidget.h" -#include <QHBoxLayout> +#include <QVBoxLayout> HistoryDockWidget::HistoryDockWidget (QWidget * parent):QDockWidget (parent) { @@ -28,19 +28,24 @@ void HistoryDockWidget::construct () { + m_sortFilterProxyModel.setSourceModel(OctaveLink::instance ()->historyModel()); m_historyListView = new QListView (this); - m_historyListView->setModel (OctaveLink::instance ()->historyModel()); + m_historyListView->setModel (&m_sortFilterProxyModel); m_historyListView->setAlternatingRowColors (true); m_historyListView->setEditTriggers (QAbstractItemView::NoEditTriggers); - QHBoxLayout *layout = new QHBoxLayout (); + m_filterLineEdit = new QLineEdit (this); + QVBoxLayout *layout = new QVBoxLayout (); setWindowTitle (tr ("Command History")); setWidget (new QWidget ()); layout->addWidget (m_historyListView); + layout->addWidget (m_filterLineEdit); layout->setMargin (2); widget ()->setLayout (layout); + + connect (m_filterLineEdit, SIGNAL (textEdited (QString)), this, SLOT (setFilter (QString))); } void @@ -48,3 +53,11 @@ { } + +void +HistoryDockWidget::setFilter(QString filter) +{ + m_historyListView->setEnabled (false); + m_sortFilterProxyModel.setFilterWildcard ( QString ("*%1*").arg (filter)); + m_historyListView->setEnabled (true); +}
--- a/gui/src/HistoryDockWidget.h +++ b/gui/src/HistoryDockWidget.h @@ -20,8 +20,11 @@ #define HISTORYDOCKWIDGET_H #include <QDockWidget> +#include <QLineEdit> #include <QListView> +#include <QSortFilterProxyModel> #include "OctaveLink.h" +#include <QThread> class HistoryDockWidget:public QDockWidget { @@ -33,13 +36,15 @@ public slots: /** Tells the widget to notice settings that are probably new. */ void noticeSettings (); - + void setFilter (QString filter); signals: void information (QString message); private: void construct (); QListView *m_historyListView; + QLineEdit *m_filterLineEdit; + QSortFilterProxyModel m_sortFilterProxyModel; }; #endif // HISTORYDOCKWIDGET_H