mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Add context menu to all table views
Add a context menu to all table view widgets in the program (Browse Data tab and Execute SQL tab) which opens when right clicking a table item. Currently the menu only allows you to copy and paste the selected item(s). Only activate the paste action when the current view is writable.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QBuffer>
|
||||
#include <QMenu>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -75,7 +76,34 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
|
||||
m_tableHeader = new FilterTableHeader(this);
|
||||
setHorizontalHeader(m_tableHeader);
|
||||
|
||||
// Set up vertical header context menu
|
||||
verticalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
// Set up table view context menu
|
||||
m_contextMenu = new QMenu(this);
|
||||
QAction* copyAction = new QAction(QIcon(":/icons/copy"), "Copy", m_contextMenu);
|
||||
QAction* pasteAction = new QAction(QIcon(":/icons/paste"), "Paste", m_contextMenu);
|
||||
m_contextMenu->addAction(copyAction);
|
||||
m_contextMenu->addAction(pasteAction);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
// Set up context menu actions
|
||||
connect(this, static_cast<void(QTableView::*)(const QPoint&)>(&QTableView::customContextMenuRequested),
|
||||
[=](const QPoint& pos)
|
||||
{
|
||||
// Try to find out whether the current view is editable and (de)activate menu options according to that
|
||||
bool editable = editTriggers() != QAbstractItemView::NoEditTriggers;
|
||||
pasteAction->setEnabled(editable);
|
||||
|
||||
// Show menu
|
||||
m_contextMenu->popup(viewport()->mapToGlobal(pos));
|
||||
});
|
||||
connect(copyAction, &QAction::triggered, [&]() {
|
||||
copy();
|
||||
});
|
||||
connect(pasteAction, &QAction::triggered, [&]() {
|
||||
paste();
|
||||
});
|
||||
}
|
||||
|
||||
void ExtendedTableWidget::reloadSettings()
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QDropEvent>
|
||||
#include <QDragMoveEvent>
|
||||
|
||||
class QMenu;
|
||||
class FilterTableHeader;
|
||||
|
||||
class ExtendedTableWidget : public QTableView
|
||||
@@ -47,6 +48,7 @@ protected:
|
||||
virtual void dropEvent(QDropEvent* event);
|
||||
|
||||
FilterTableHeader* m_tableHeader;
|
||||
QMenu* m_contextMenu;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -54,5 +54,6 @@
|
||||
<file>folder.png</file>
|
||||
<file>database.png</file>
|
||||
<file>cog_go.png</file>
|
||||
<file alias="paste">page_paste.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
src/icons/page_paste.png
Normal file
BIN
src/icons/page_paste.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 703 B |
Reference in New Issue
Block a user