From 9ce4b232ba17493d9064c0a3dd963f26d5405215 Mon Sep 17 00:00:00 2001 From: mgr Date: Sun, 12 Nov 2017 19:26:39 +0100 Subject: [PATCH] New shortcut for Copy with Headers and some self-documented shortcuts Ctrl+H invokes the Copy with Headersers action in the Extended Table Widget as suggested in #1058. The following options in context menu display now their shortcuts: Set to Null, Copy, Copy with Headers and Paste. Some other shortcuts are now displayed in the corresponding tooltips. --- src/EditDialog.ui | 7 +++++-- src/ExtendedTableWidget.cpp | 14 ++++++++++++-- src/MainWindow.ui | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/EditDialog.ui b/src/EditDialog.ui index 63025988..97a1083d 100644 --- a/src/EditDialog.ui +++ b/src/EditDialog.ui @@ -160,8 +160,8 @@ 0 0 - 83 - 40 + 98 + 35 @@ -212,6 +212,9 @@ + + Apply data to cell [Ctrl+Return] + Apply diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index d452cd60..5e38593f 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -95,6 +95,13 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) : m_contextMenu->addAction(pasteAction); setContextMenuPolicy(Qt::CustomContextMenu); + // This is only for displaying the shortcut in the context menu. + // An entry in keyPressEvent is still needed. + nullAction->setShortcut(QKeySequence(tr("Alt+Del"))); + copyAction->setShortcut(QKeySequence::Copy); + copyWithHeadersAction->setShortcut(QKeySequence(tr("Ctrl+H"))); + pasteAction->setShortcut(QKeySequence::Paste); + // Set up context menu actions connect(this, &QTableView::customContextMenuRequested, [=](const QPoint& pos) @@ -389,11 +396,14 @@ void ExtendedTableWidget::keyPressEvent(QKeyEvent* event) // Call a custom copy method when Ctrl-C is pressed if(event->matches(QKeySequence::Copy)) { - copy(); + copy(false); return; } else if(event->matches(QKeySequence::Paste)) { - // Call a custom paste method when Ctrl-P is pressed + // Call a custom paste method when Ctrl-V is pressed paste(); + } else if(event->modifiers().testFlag(Qt::ControlModifier) && (event->key() == Qt::Key_H)) { + // Call copy with headers when Ctrl-H is pressed + copy(true); } else if(event->key() == Qt::Key_Tab && hasFocus() && selectedIndexes().count() == 1 && selectedIndexes().at(0).row() == model()->rowCount()-1 && selectedIndexes().at(0).column() == model()->columnCount()-1) { diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 779ac1ee..894712e3 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -22,7 +22,7 @@ - 0 + 1 @@ -130,7 +130,7 @@ - Refresh the data in the selected table. + Refresh the data in the selected table [F5, Ctrl+R] This button refreshes the data in the currently selected table.