mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Add 'Set to NULL' context menu action
Add a new action 'Set to NULL' to the table browser context menu for setting all selected items to NULL.
This commit is contained in:
@@ -81,8 +81,11 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
|
||||
|
||||
// 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);
|
||||
QAction* nullAction = new QAction(tr("Set to NULL"), m_contextMenu);
|
||||
QAction* copyAction = new QAction(QIcon(":/icons/copy"), tr("Copy"), m_contextMenu);
|
||||
QAction* pasteAction = new QAction(QIcon(":/icons/paste"), tr("Paste"), m_contextMenu);
|
||||
m_contextMenu->addAction(nullAction);
|
||||
m_contextMenu->addSeparator();
|
||||
m_contextMenu->addAction(copyAction);
|
||||
m_contextMenu->addAction(pasteAction);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
@@ -93,11 +96,16 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
|
||||
{
|
||||
// Try to find out whether the current view is editable and (de)activate menu options according to that
|
||||
bool editable = editTriggers() != QAbstractItemView::NoEditTriggers;
|
||||
nullAction->setEnabled(editable);
|
||||
pasteAction->setEnabled(editable);
|
||||
|
||||
// Show menu
|
||||
m_contextMenu->popup(viewport()->mapToGlobal(pos));
|
||||
});
|
||||
connect(nullAction, &QAction::triggered, [&]() {
|
||||
foreach(const QModelIndex& index, selectedIndexes())
|
||||
model()->setData(index, QVariant());
|
||||
});
|
||||
connect(copyAction, &QAction::triggered, [&]() {
|
||||
copy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user