Skip to content

Commit eb8e801

Browse files
committed
Make it possible to jump between filters by pressing the tab key
Allow jumping between the filter input fields by pressing Tab and Shift+Tab. See issue sqlitebrowser#106.
1 parent 0177155 commit eb8e801

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/ExtendedTableWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ void ExtendedTableWidget::keyPressEvent(QKeyEvent* event)
6767
// Call a custom copy method when Ctrl-C is pressed
6868
if(event->matches(QKeySequence::Copy))
6969
copy();
70-
else
71-
QTableView::keyPressEvent(event);
70+
else if((event->key() != Qt::Key_Tab && event->key() != Qt::Key_Backtab) || hasFocus()) // This prevents the current selection from being changed when pressing
71+
QTableView::keyPressEvent(event); // tab to move to the next filter
7272
}
7373

7474
void ExtendedTableWidget::updateGeometries()

src/FilterTableHeader.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@
33
#include <QLineEdit>
44
#include <QTableView>
55
#include <QScrollBar>
6+
#include <QKeyEvent>
7+
#include <QDebug>
8+
9+
class FilterLineEdit : public QLineEdit
10+
{
11+
public:
12+
explicit FilterLineEdit(QWidget* parent, QList<FilterLineEdit*>* filters, int columnnum) : QLineEdit(parent), filterList(filters), columnNumber(columnnum)
13+
{
14+
setPlaceholderText(tr("Filter"));
15+
setProperty("column", columnnum); // Store the column number for later use
16+
}
17+
18+
protected:
19+
void keyReleaseEvent(QKeyEvent* event)
20+
{
21+
if(event->key() == Qt::Key_Tab)
22+
{
23+
if(columnNumber < filterList->size() - 1)
24+
{
25+
filterList->at(columnNumber + 1)->setFocus();
26+
event->accept();
27+
}
28+
} else if(event->key() == Qt::Key_Backtab) {
29+
if(columnNumber > 0)
30+
{
31+
filterList->at(columnNumber - 1)->setFocus();
32+
event->accept();
33+
}
34+
}
35+
}
36+
37+
private:
38+
QList<FilterLineEdit*>* filterList;
39+
int columnNumber;
40+
};
641

742
FilterTableHeader::FilterTableHeader(QTableView* parent) :
843
QHeaderView(Qt::Horizontal, parent)
@@ -37,9 +72,7 @@ void FilterTableHeader::generateFilters(int number, bool bKeepValues)
3772
// And generate a bunch of new ones
3873
for(int i=0;i < number; ++i)
3974
{
40-
QLineEdit* l = new QLineEdit(this);
41-
l->setPlaceholderText(tr("Filter"));
42-
l->setProperty("column", i); // Store the column number for later use
75+
FilterLineEdit* l = new FilterLineEdit(this, &filterWidgets, i);
4376
l->setVisible(i>0); // This hides the first input widget which belongs to the hidden rowid column
4477
connect(l, SIGNAL(textChanged(QString)), this, SLOT(inputChanged(QString)));
4578
if(bKeepValues && !oldvalues[i].isEmpty()) // restore old values

src/FilterTableHeader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class QLineEdit;
88
class QTableView;
9+
class FilterLineEdit;
910

1011
class FilterTableHeader : public QHeaderView
1112
{
@@ -29,7 +30,7 @@ private slots:
2930
void inputChanged(const QString& new_value);
3031

3132
private:
32-
QList<QLineEdit*> filterWidgets;
33+
QList<FilterLineEdit*> filterWidgets;
3334
};
3435

3536
#endif

0 commit comments

Comments
 (0)