Some first filtering code.

This commit is contained in:
Martin Rotter 2014-04-07 14:24:28 +02:00
parent 6acf273bcf
commit 746962c557
5 changed files with 31 additions and 1 deletions

View File

@ -194,6 +194,10 @@ void FeedMessageViewer::switchFeedComponentVisibility() {
void FeedMessageViewer::createConnections() {
FormMain *form_main = FormMain::instance();
// Filtering.
connect(m_toolBarMessages, SIGNAL(messageSearchPatternChanged(QString)),
m_messagesView, SLOT(filterMessages(QString)));
// Message changers.
connect(m_messagesView, SIGNAL(currentMessagesRemoved()),
m_messagesBrowser, SLOT(clear()));

View File

@ -14,7 +14,7 @@ MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
m_txtSearchMessages(new BaseLineEdit(this)) {
m_txtSearchMessages->setFixedWidth(FILTER_WIDTH);
m_txtSearchMessages->setPlaceholderText(tr("Filter messages"));
m_txtSearchMessages->setPlaceholderText(tr("Search messages"));
// Setup wrapping action for search box.
m_actionSearchMessages = new QWidgetAction(this);
@ -27,6 +27,9 @@ MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
QMargins margins = contentsMargins();
margins.setRight(margins.right() + FILTER_RIGHT_MARGIN);
setContentsMargins(margins);
connect(m_txtSearchMessages, SIGNAL(textChanged(QString)),
this, SIGNAL(messageSearchPatternChanged(QString)));
}
MessagesToolBar::~MessagesToolBar() {
@ -45,6 +48,11 @@ QList<QAction*> MessagesToolBar::changeableActions() const {
void MessagesToolBar::saveChangeableActions(const QStringList& actions) {
Settings::instance()->setValue(APP_CFG_GUI, "messages_toolbar", actions.join(","));
loadChangeableActions(actions);
// If user hidden search messages box, then remove the filter.
if (!changeableActions().contains(m_actionSearchMessages)) {
m_txtSearchMessages->clear();
}
}
void MessagesToolBar::loadChangeableActions(const QStringList& actions) {

View File

@ -15,6 +15,10 @@ class MessagesToolBar : public BaseToolBar {
explicit MessagesToolBar(const QString &title, QWidget *parent = 0);
virtual ~MessagesToolBar();
inline BaseLineEdit *searchLineEdit() {
return m_txtSearchMessages;
}
// Implementation of BaseToolBar interface.
QHash<QString, QAction*> availableActions() const;
QList<QAction*> changeableActions() const;
@ -27,6 +31,9 @@ class MessagesToolBar : public BaseToolBar {
void loadChangeableActions(const QStringList &actions);
signals:
// TODO: sem pridat este mozna mode: wildcard, regexp, fixed text.
// na tuto udalost se navaze filtrovani
void messageSearchPatternChanged(const QString &pattern);
public slots:

View File

@ -398,6 +398,14 @@ void MessagesView::selectPreviousItem() {
}
}
void MessagesView::filterMessages(const QString &pattern) {
m_proxyModel->setFilterWildcard(pattern);
if (selectionModel()->selectedRows().size() == 0) {
emit currentMessagesRemoved();
}
}
void MessagesView::adjustColumns() {
if (header()->count() > 0 && !m_columnsAdjusted) {
m_columnsAdjusted = true;

View File

@ -76,6 +76,9 @@ class MessagesView : public QTreeView {
void selectNextItem();
void selectPreviousItem();
// Filters the visible message according to given pattern.
void filterMessages(const QString &pattern);
protected slots:
// Marks given indexes as selected.
void reselectIndexes(const QModelIndexList &indexes);