Skip to content

Commit 5064638

Browse files
committed
Improve focusing the filter line with keyboard shortcut
See issue #3439
1 parent 3f73143 commit 5064638

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/FilterTableHeader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ QString FilterTableHeader::filterValue(size_t column) const
137137
{
138138
return filterWidgets[column]->text();
139139
}
140+
141+
void FilterTableHeader::setFocusColumn(size_t column)
142+
{
143+
if(column < filterWidgets.size())
144+
filterWidgets.at(column)->setFocus();
145+
}

src/FilterTableHeader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class FilterTableHeader : public QHeaderView
1616
QSize sizeHint() const override;
1717
bool hasFilters() const {return (filterWidgets.size() > 0);}
1818
QString filterValue(size_t column) const;
19-
19+
void setFocusColumn(size_t column);
20+
2021
public slots:
2122
void generateFilters(size_t number, size_t number_of_hidden_filters = 1);
2223
void adjustPositions();

src/TableBrowser.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,22 @@ TableBrowser::TableBrowser(DBBrowserDB* _db, QWidget* parent) :
363363
// Restore cursor because in the ExtendedTableWidget it is changed to a hand when Ctrl+Shift
364364
// is pressed.
365365
QApplication::restoreOverrideCursor();
366-
ui->dataTable->horizontalHeader()->setFocus();
366+
FilterTableHeader* header = qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader());
367+
// Set the focus to the current column if valid, otherwise, set focus to the first visible
368+
// column.
369+
if(!header) {
370+
ui->dataTable->horizontalHeader()->setFocus();
371+
} else if(currentIndex().isValid()) {
372+
header->setFocusColumn(static_cast<size_t>(currentIndex().column()));
373+
} else {
374+
for(int col = 0; col < ui->dataTable->model()->columnCount(); col++)
375+
{
376+
if(!ui->dataTable->isColumnHidden(col)) {
377+
header->setFocusColumn(static_cast<size_t>(col));
378+
break;
379+
}
380+
}
381+
}
367382
});
368383

369384
QShortcut* shortcutActionGlobalFilter = new QShortcut(QKeySequence("Ctrl+Alt+F"), this, nullptr, nullptr, Qt::WidgetWithChildrenShortcut);

0 commit comments

Comments
 (0)