Fix possible crashes when using context menu in Browse Data tab

Deactivate all menu actions in the context menu in the Browse Data tab
if no database file is opened. Without a database the read-only actions
were still enabled and would lead to a crash.

See issue #1228.
This commit is contained in:
Martin Kleusberg
2017-11-17 13:20:08 +01:00
parent 011f7edd1f
commit d0771cb4bd

View File

@@ -106,10 +106,16 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
connect(this, &QTableView::customContextMenuRequested,
[=](const QPoint& pos)
{
// Deactivate context menu options if there is no model set
bool enabled = model();
filterAction->setEnabled(enabled);
copyAction->setEnabled(enabled);
copyWithHeadersAction->setEnabled(enabled);
// 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);
nullAction->setEnabled(enabled && editable);
pasteAction->setEnabled(enabled && editable);
// Show menu
m_contextMenu->popup(viewport()->mapToGlobal(pos));