##// 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 QMenu tableMenu{};
54 for (const auto &selectedRow : qAsConst(selectedRows)) {
55
55 if (auto selectedVariable = model->variable(selectedRow.row())) {
56 // Emit a signal so that potential receivers can populate the menu before displaying it
56 selectedVariables.push_back(selectedVariable);
57 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
58
59 if (!tableMenu.isEmpty()) {
60 tableMenu.exec(mapToGlobal(pos));
61 }
62 }
57 }
63 }
58 }
64 else {
59
65 qCCritical(LOG_VariableInspectorWidget())
60 QMenu tableMenu{};
66 << tr("Can't display menu : invalid index (%1;%2)")
61
67 .arg(selectedIndex.row(), selectedIndex.column());
62 // Emits a signal so that potential receivers can populate the menu before displaying it
63 /// @todo ALX : handles list of variables in the signal
64 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
65
66 if (!tableMenu.isEmpty()) {
67 // Displays menu
68 tableMenu.exec(mapToGlobal(pos));
68 }
69 }
69 }
70 }
General Comments 1
Approved

Status change > Approved

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