From c62d29104216ca2f8c502aa8be3dbc990f338d5e Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Thu, 2 Feb 2017 22:07:49 +0100 Subject: [PATCH] Add keyboard shortcuts for switching the currently browsed table 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 #536. --- src/ExtendedTableWidget.cpp | 9 ++++++--- src/ExtendedTableWidget.h | 1 + src/MainWindow.cpp | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index d1c4f24b..7d15efc7 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -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 && @@ -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, diff --git a/src/ExtendedTableWidget.h b/src/ExtendedTableWidget.h index 297527fa..6feadfe0 100644 --- a/src/ExtendedTableWidget.h +++ b/src/ExtendedTableWidget.h @@ -22,6 +22,7 @@ public: 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(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7e18f9ea..9327ae79 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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());