##// 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 47 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
48 48 {
49 auto selectedIndex = ui->tableView->indexAt(pos);
50 if (selectedIndex.isValid()) {
51 // Gets the model to retrieve the underlying selected variable
52 auto model = sqpApp->variableController().variableModel();
53 if (auto selectedVariable = model->variable(selectedIndex.row())) {
54 QMenu tableMenu{};
55
56 // Emit a signal so that potential receivers can populate the menu before displaying it
57 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
58
59 if (!tableMenu.isEmpty()) {
60 tableMenu.exec(mapToGlobal(pos));
61 }
49 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
50
51 // Gets the model to retrieve the underlying selected variables
52 auto model = sqpApp->variableController().variableModel();
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);
62 57 }
63 58 }
64 else {
65 qCCritical(LOG_VariableInspectorWidget())
66 << tr("Can't display menu : invalid index (%1;%2)")
67 .arg(selectedIndex.row(), selectedIndex.column());
59
60 QMenu tableMenu{};
61
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