##// END OF EJS Templates
Handles multi-selection when displaying the menu of the variable widget...
Alexandre Leroux -
r265:3a544b0581a5
parent child
Show More
@@ -46,24 +46,25 VariableInspectorWidget::~VariableInspectorWidget()
46
46
47 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
47 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
48 {
48 {
49 auto selectedIndex = ui->tableView->indexAt(pos);
49 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
50 if (selectedIndex.isValid()) {
50
51 // Gets the model to retrieve the underlying selected variable
51 // Gets the model to retrieve the underlying selected variables
52 auto model = sqpApp->variableController().variableModel();
52 auto model = sqpApp->variableController().variableModel();
53 if (auto selectedVariable = model->variable(selectedIndex.row())) {
53 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
54 for (const auto &selectedRow : qAsConst(selectedRows)) {
55 if (auto selectedVariable = model->variable(selectedRow.row())) {
56 selectedVariables.push_back(selectedVariable);
57 }
58 }
59
54 QMenu tableMenu{};
60 QMenu tableMenu{};
55
61
56 // Emit a signal so that potential receivers can populate the menu before displaying it
62 // Emits a signal so that potential receivers can populate the menu before displaying it
57 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
63 /// @todo ALX : handles list of variables in the signal
64 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
58
65
59 if (!tableMenu.isEmpty()) {
66 if (!tableMenu.isEmpty()) {
67 // Displays menu
60 tableMenu.exec(mapToGlobal(pos));
68 tableMenu.exec(mapToGlobal(pos));
61 }
69 }
62 }
70 }
63 }
64 else {
65 qCCritical(LOG_VariableInspectorWidget())
66 << tr("Can't display menu : invalid index (%1;%2)")
67 .arg(selectedIndex.row(), selectedIndex.column());
68 }
69 }
General Comments 1
Approved

Status change > Approved

You need to be logged in to leave comments. Login now