##// END OF EJS Templates
Activates multi-selection on variable widget
Activates multi-selection on variable widget

File last commit:

r264:437da76793e4
r264:437da76793e4
Show More
VariableInspectorWidget.cpp
69 lines | 2.3 KiB | text/x-c | CppLexer
/ gui / src / Variable / VariableInspectorWidget.cpp
Alexandre Leroux
Affects model to the Variable Widget
r143 #include <Variable/VariableController.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105 #include <Variable/VariableInspectorWidget.h>
Alexandre Leroux
Affects model to the Variable Widget
r143 #include <Variable/VariableModel.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105
#include <ui_VariableInspectorWidget.h>
Alexandre Leroux
Affects model to the Variable Widget
r143 #include <QSortFilterProxyModel>
#include <SqpApplication.h>
Alexandre Leroux
Pull request fixes
r234 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
: QWidget{parent}, ui{new Ui::VariableInspectorWidget}
{
ui->setupUi(this);
Alexandre Leroux
Affects model to the Variable Widget
r143
// Sets model for table
auto sortFilterModel = new QSortFilterProxyModel{this};
sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
ui->tableView->setModel(sortFilterModel);
Alexandre Leroux
Activates menu on variable widget
r228
Alexandre Leroux
Uses Qt::SizeHintRole to set column width and height
r258 // 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());
}
Alexandre Leroux
Activates multi-selection on variable widget
r264 // Sets selection options
ui->tableView->setSelectionBehavior(QTableView::SelectRows);
ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
Alexandre Leroux
Activates menu on variable widget
r228 // 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
Initializes the variable inspector and adds it to the MainWindow
r105 }
VariableInspectorWidget::~VariableInspectorWidget()
{
delete ui;
}
Alexandre Leroux
Activates menu on variable widget
r228
void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
{
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r229 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{};
Alexandre Leroux
Creates signal to make dynmaic menu for a variable
r230 // Emit a signal so that potential receivers can populate the menu before displaying it
emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r229
if (!tableMenu.isEmpty()) {
tableMenu.exec(mapToGlobal(pos));
}
}
}
Alexandre Leroux
Pull request fixes
r234 else {
qCCritical(LOG_VariableInspectorWidget())
<< tr("Can't display menu : invalid index (%1;%2)")
.arg(selectedIndex.row(), selectedIndex.column());
}
Alexandre Leroux
Activates menu on variable widget
r228 }