##// END OF EJS Templates
Centralization of qregistermetatype management
Centralization of qregistermetatype management

File last commit:

r304:08349e12a7ef
r308:d6942e8f24d6
Show More
VariableInspectorWidget.cpp
89 lines | 3.1 KiB | text/x-c | CppLexer
/ gui / src / Variable / VariableInspectorWidget.cpp
Alexandre Leroux
Affects model to the Variable Widget
r152 #include <Variable/VariableController.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r110 #include <Variable/VariableInspectorWidget.h>
Alexandre Leroux
Adds header in the menu
r290 #include <Variable/VariableMenuHeaderWidget.h>
Alexandre Leroux
Affects model to the Variable Widget
r152 #include <Variable/VariableModel.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r110
#include <ui_VariableInspectorWidget.h>
Alexandre Leroux
Affects model to the Variable Widget
r152 #include <QSortFilterProxyModel>
Alexandre Leroux
Adds header in the menu
r290 #include <QWidgetAction>
Alexandre Leroux
Affects model to the Variable Widget
r152
#include <SqpApplication.h>
Alexandre Leroux
Pull request fixes
r251 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r110 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
: QWidget{parent}, ui{new Ui::VariableInspectorWidget}
{
ui->setupUi(this);
Alexandre Leroux
Affects model to the Variable Widget
r152
// Sets model for table
Temporal parameters of the selected variables can be updated using the...
r304 // auto sortFilterModel = new QSortFilterProxyModel{this};
// sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
Alexandre Leroux
Affects model to the Variable Widget
r152
Temporal parameters of the selected variables can be updated using the...
r304 ui->tableView->setModel(sqpApp->variableController().variableModel());
ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
Alexandre Leroux
Activates menu on variable widget
r245
Alexandre Leroux
Uses Qt::SizeHintRole to set column width and height
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());
}
Alexandre Leroux
Activates multi-selection on variable widget
r286 // Sets selection options
ui->tableView->setSelectionBehavior(QTableView::SelectRows);
ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
Alexandre Leroux
Activates menu on variable widget
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
Initializes the variable inspector and adds it to the MainWindow
r110 }
VariableInspectorWidget::~VariableInspectorWidget()
{
delete ui;
}
Alexandre Leroux
Activates menu on variable widget
r245
void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
{
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
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);
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r246 }
}
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287
QMenu tableMenu{};
// Emits a signal so that potential receivers can populate the menu before displaying it
emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
Alexandre Leroux
Adds an entry to the menu for deleting a variable...
r291 // Adds menu-specific actions
if (!selectedVariables.isEmpty()) {
// 'Delete' action
auto deleteFun = []() {
/// @todo ALX : call variable deletion
};
tableMenu.addSeparator();
tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
}
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287 if (!tableMenu.isEmpty()) {
Alexandre Leroux
Adds header in the menu
r290 // Generates menu header (inserted before first action)
auto firstAction = tableMenu.actions().first();
auto headerAction = new QWidgetAction{&tableMenu};
headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
tableMenu.insertAction(firstAction, headerAction);
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287 // Displays menu
tableMenu.exec(mapToGlobal(pos));
Alexandre Leroux
Pull request fixes
r251 }
Alexandre Leroux
Activates menu on variable widget
r245 }