Skip to content

Commit

Permalink
Add keyboard shortcuts for switching the currently browsed table
Browse files Browse the repository at this point in the history
Add two new keyboard shortcuts for switching the currently selected
table in the Browse Data tab. These work as long as the table widget is
active. For now I have set them to Ctrl+PageUp and Ctrl+PageDown.

See issue sqlitebrowser#536.
  • Loading branch information
MKleusberg committed Feb 2, 2017
1 parent bf5ab01 commit c62d291
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ExtendedTableWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,8 @@ void ExtendedTableWidget::keyPressEvent(QKeyEvent* event)
{
copy();
return;
// Call a custom paste method when Ctrl-P is pressed
} else if(event->matches(QKeySequence::Paste))
{
} else if(event->matches(QKeySequence::Paste)) {
// Call a custom paste method when Ctrl-P is pressed
paste();
} else if(event->key() == Qt::Key_Tab && hasFocus() &&
selectedIndexes().count() == 1 &&
Expand All @@ -320,6 +319,10 @@ void ExtendedTableWidget::keyPressEvent(QKeyEvent* event)
foreach(const QModelIndex& index, selectedIndexes())
model()->setData(index, "");
}
} else if(event->modifiers().testFlag(Qt::ControlModifier) && (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_PageDown)) {
// When pressing Ctrl + Page up/down send a signal indicating the user wants to change the current table
emit switchTable(event->key() == Qt::Key_PageDown);
return;
}

// This prevents the current selection from being changed when pressing tab to move to the next filter. Note that this is in an 'if' condition,
Expand Down
1 change: 1 addition & 0 deletions src/ExtendedTableWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ExtendedTableWidget : public QTableView

signals:
void foreignKeyClicked(const QString& table, const QString& column, const QByteArray& value);
void switchTable(bool next); // 'next' parameter is set to true if next table should be selected and to false if previous table should be selected

private:
void copy();
Expand Down
16 changes: 16 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ void MainWindow::init()
connect(ui->dockEdit, SIGNAL(visibilityChanged(bool)), this, SLOT(toggleEditDock(bool)));
connect(&m_remoteDb, SIGNAL(openFile(QString)), this, SLOT(fileOpen(QString)));

// Lambda function for keyboard shortcuts for selecting next/previous table in Browse Data tab
connect(ui->dataTable, &ExtendedTableWidget::switchTable, [this](bool next) {
int index = ui->comboBrowseTable->currentIndex();
int num_items = ui->comboBrowseTable->count();
if(next)
{
if(++index >= num_items)
index = 0;
} else {
if(--index < 0)
index = num_items - 1;
}
ui->comboBrowseTable->setCurrentIndex(index);
populateTable();
});

// Set other window settings
setAcceptDrops(true);
setWindowTitle(QApplication::applicationName());
Expand Down

0 comments on commit c62d291

Please sign in to comment.