VariableInspectorWidget.cpp
70 lines
| 2.3 KiB
| text/x-c
|
CppLexer
|
r152 | #include <Variable/VariableController.h> | ||
|
r110 | #include <Variable/VariableInspectorWidget.h> | ||
|
r152 | #include <Variable/VariableModel.h> | ||
|
r110 | |||
#include <ui_VariableInspectorWidget.h> | ||||
|
r152 | #include <QSortFilterProxyModel> | ||
#include <SqpApplication.h> | ||||
|
r251 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") | ||
|
r110 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) | ||
: QWidget{parent}, ui{new Ui::VariableInspectorWidget} | ||||
{ | ||||
ui->setupUi(this); | ||||
|
r152 | |||
// Sets model for table | ||||
auto sortFilterModel = new QSortFilterProxyModel{this}; | ||||
sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); | ||||
ui->tableView->setModel(sortFilterModel); | ||||
|
r245 | |||
|
r278 | // Fixes column sizes | ||
auto model = ui->tableView->model(); | ||||
const auto count = model->columnCount(); | ||||
for (auto i = 0; i < count; ++i) { | ||||
ui->tableView->setColumnWidth( | ||||
i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); | ||||
} | ||||
|
r286 | // Sets selection options | ||
ui->tableView->setSelectionBehavior(QTableView::SelectRows); | ||||
ui->tableView->setSelectionMode(QTableView::ExtendedSelection); | ||||
|
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); | ||||
|
r110 | } | ||
VariableInspectorWidget::~VariableInspectorWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
|
r245 | |||
void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | ||||
{ | ||||
|
r287 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); | ||
// Gets the model to retrieve the underlying selected variables | ||||
auto model = sqpApp->variableController().variableModel(); | ||||
auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; | ||||
for (const auto &selectedRow : qAsConst(selectedRows)) { | ||||
if (auto selectedVariable = model->variable(selectedRow.row())) { | ||||
selectedVariables.push_back(selectedVariable); | ||||
|
r246 | } | ||
} | ||||
|
r287 | |||
QMenu tableMenu{}; | ||||
// Emits a signal so that potential receivers can populate the menu before displaying it | ||||
/// @todo ALX : handles list of variables in the signal | ||||
emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); | ||||
if (!tableMenu.isEmpty()) { | ||||
// Displays menu | ||||
tableMenu.exec(mapToGlobal(pos)); | ||||
|
r251 | } | ||
|
r245 | } | ||