VariableInspectorWidget.cpp
49 lines
| 1.5 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r152 | #include <Variable/VariableController.h> | ||
Alexandre Leroux
|
r110 | #include <Variable/VariableInspectorWidget.h> | ||
Alexandre Leroux
|
r152 | #include <Variable/VariableModel.h> | ||
Alexandre Leroux
|
r110 | |||
#include <ui_VariableInspectorWidget.h> | ||||
Alexandre Leroux
|
r152 | #include <QSortFilterProxyModel> | ||
#include <SqpApplication.h> | ||||
Alexandre Leroux
|
r110 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) | ||
: QWidget{parent}, ui{new Ui::VariableInspectorWidget} | ||||
{ | ||||
ui->setupUi(this); | ||||
Alexandre Leroux
|
r152 | |||
// Sets model for table | ||||
auto sortFilterModel = new QSortFilterProxyModel{this}; | ||||
sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); | ||||
ui->tableView->setModel(sortFilterModel); | ||||
Alexandre Leroux
|
r245 | |||
// Connection to show a menu when right clicking on the tree | ||||
ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); | ||||
connect(ui->tableView, &QTableView::customContextMenuRequested, this, | ||||
&VariableInspectorWidget::onTableMenuRequested); | ||||
Alexandre Leroux
|
r110 | } | ||
VariableInspectorWidget::~VariableInspectorWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
Alexandre Leroux
|
r245 | |||
void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | ||||
{ | ||||
Alexandre Leroux
|
r246 | 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)); | ||||
} | ||||
} | ||||
} | ||||
Alexandre Leroux
|
r245 | } | ||