From 37254eb43d9f7760abbb4630df9875485ef79e0b 2017-06-28 07:35:22 From: Alexandre Leroux Date: 2017-06-28 07:35:22 Subject: [PATCH] Retrieves the current selected variable when clicking on the variable widget --- diff --git a/core/include/Variable/VariableModel.h b/core/include/Variable/VariableModel.h index 490f43b..07f60fc 100644 --- a/core/include/Variable/VariableModel.h +++ b/core/include/Variable/VariableModel.h @@ -32,6 +32,8 @@ public: createVariable(const QString &name, const SqpDateTime &dateTime, std::unique_ptr defaultDataSeries) noexcept; + std::shared_ptr variable(int index) const; + // /////////////////////////// // // QAbstractTableModel methods // // /////////////////////////// // diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 601f3cb..af16df1 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -44,6 +44,11 @@ VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, return variable; } +std::shared_ptr VariableModel::variable(int index) const +{ + return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables.at(index) : nullptr; +} + int VariableModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); diff --git a/gui/src/Variable/VariableInspectorWidget.cpp b/gui/src/Variable/VariableInspectorWidget.cpp index 9cfd7e3..8b49751 100644 --- a/gui/src/Variable/VariableInspectorWidget.cpp +++ b/gui/src/Variable/VariableInspectorWidget.cpp @@ -32,4 +32,18 @@ VariableInspectorWidget::~VariableInspectorWidget() void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept { + auto selectedIndex = ui->tableView->indexAt(pos); + if (selectedIndex.isValid()) { + // Gets the model to retrieve the underlying selected variable + auto model = sqpApp->variableController().variableModel(); + if (auto selectedVariable = model->variable(selectedIndex.row())) { + QMenu tableMenu{}; + + /// @todo ALX : make menu + + if (!tableMenu.isEmpty()) { + tableMenu.exec(mapToGlobal(pos)); + } + } + } }