From 01378367a63b28e5e1b1ea484db2a1a496f85ea8 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 27 Oct 2019 23:35:48 +0100 Subject: [PATCH] Easy way of selecting columns (and rows) Add shortcuts for selection of entire columns ("Ctrl+Space") or rows ("Shift+Space") from the current cell selection. A new menu entry in the column header is also added, including the shortcut legend for selecting the column. This addresses #1717 and complements #1976 for quick formatting of entire columns or rows. --- src/ExtendedTableWidget.cpp | 11 +++++++++++ src/TableBrowser.cpp | 5 +++++ src/TableBrowser.ui | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index cb0179dc..88501e56 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -380,6 +381,16 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) : openPrintDialog(); }); + // Add spreadsheet shortcuts for selecting entire columns or entire rows. + QShortcut* selectColumnShortcut = new QShortcut(QKeySequence("Ctrl+Space"), this); + connect(selectColumnShortcut, &QShortcut::activated, [this]() { + selectionModel()->select(QItemSelection(selectionModel()->selectedIndexes().constFirst(), selectionModel()->selectedIndexes().constLast()), QItemSelectionModel::Select | QItemSelectionModel::Columns); + }); + QShortcut* selectRowShortcut = new QShortcut(QKeySequence("Shift+Space"), this); + connect(selectRowShortcut, &QShortcut::activated, [this]() { + selectionModel()->select(QItemSelection(selectionModel()->selectedIndexes().constFirst(), selectionModel()->selectedIndexes().constLast()), QItemSelectionModel::Select | QItemSelectionModel::Rows); + }); + #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) && QT_VERSION < QT_VERSION_CHECK(5, 12, 3) // This work arounds QTBUG-73721 and it is applied only for the affected version range. setWordWrap(false); diff --git a/src/TableBrowser.cpp b/src/TableBrowser.cpp index 45dad07c..21fdfabe 100644 --- a/src/TableBrowser.cpp +++ b/src/TableBrowser.cpp @@ -56,6 +56,7 @@ TableBrowser::TableBrowser(QWidget* parent) : popupHeaderMenu->addAction(ui->actionShowRowidColumn); popupHeaderMenu->addAction(ui->actionHideColumns); popupHeaderMenu->addAction(ui->actionShowAllColumns); + popupHeaderMenu->addAction(ui->actionSelectColumn); popupHeaderMenu->addSeparator(); popupHeaderMenu->addAction(ui->actionUnlockViewEditing); popupHeaderMenu->addAction(ui->actionBrowseTableEditDisplayFormat); @@ -63,6 +64,10 @@ TableBrowser::TableBrowser(QWidget* parent) : popupHeaderMenu->addAction(ui->actionSetTableEncoding); popupHeaderMenu->addAction(ui->actionSetAllTablesEncoding); + connect(ui->actionSelectColumn, &QAction::triggered, [this]() { + ui->dataTable->selectColumn(ui->actionBrowseTableEditDisplayFormat->property("clicked_column").toInt()); + }); + // Set up shortcuts QShortcut* dittoRecordShortcut = new QShortcut(QKeySequence("Ctrl+\""), this); connect(dittoRecordShortcut, &QShortcut::activated, [this]() { diff --git a/src/TableBrowser.ui b/src/TableBrowser.ui index 2be465d1..a93ccd96 100644 --- a/src/TableBrowser.ui +++ b/src/TableBrowser.ui @@ -942,6 +942,14 @@ This button shows or hides the formatting toolbar of the Data Browser + + + Select column + + + Ctrl+Space + +