Add Quick Filter to StringsWidget #162

This commit is contained in:
Florian Märkl 2017-12-19 19:56:18 +01:00
parent f694daac88
commit 15a1a6bd9c
3 changed files with 36 additions and 2 deletions

View File

@ -333,12 +333,12 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
//ui->filterLineEdit->setVisible(false); //ui->filterLineEdit->setVisible(false);
// Ctrl-F to show/hide the filter entry // Ctrl-F to show/hide the filter entry
QShortcut *search_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), this); QShortcut *search_shortcut = new QShortcut(QKeySequence::Find, this);
connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter); connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter);
search_shortcut->setContext(Qt::WidgetWithChildrenShortcut); search_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
// Esc to clear the filter entry // Esc to clear the filter entry
QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this); QShortcut *clear_shortcut = new QShortcut(QKeySequence::Cancel, this);
connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter); connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut); clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);

View File

@ -126,11 +126,24 @@ StringsWidget::StringsWidget(QWidget *parent) :
qhelpers::setVerticalScrollMode(ui->stringsTreeView); qhelpers::setVerticalScrollMode(ui->stringsTreeView);
// Ctrl-F to show/hide the filter entry
QShortcut *search_shortcut = new QShortcut(QKeySequence::Find, this);
connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter);
search_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
// Esc to clear the filter entry
QShortcut *clear_shortcut = new QShortcut(QKeySequence::Cancel, this);
connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
model = new StringsModel(&strings, this); model = new StringsModel(&strings, this);
proxy_model = new StringsSortFilterProxyModel(model, this); proxy_model = new StringsSortFilterProxyModel(model, this);
ui->stringsTreeView->setModel(proxy_model); ui->stringsTreeView->setModel(proxy_model);
ui->stringsTreeView->sortByColumn(StringsModel::OFFSET, Qt::AscendingOrder); ui->stringsTreeView->sortByColumn(StringsModel::OFFSET, Qt::AscendingOrder);
connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)), proxy_model, SLOT(setFilterWildcard(const QString &)));
connect(ui->quickFilterView, SIGNAL(filterClosed()), ui->stringsTreeView, SLOT(setFocus()));
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshStrings())); connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshStrings()));
} }

View File

@ -15,6 +15,9 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -56,9 +59,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QuickFilterView" name="quickFilterView" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QuickFilterView</class>
<extends>QWidget</extends>
<header>widgets/QuickFilterView.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>