##// END OF EJS Templates
Activates multi-selection on variable widget
Alexandre Leroux -
r264:437da76793e4
parent child
Show More
@@ -1,65 +1,69
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableInspectorWidget.h>
2 #include <Variable/VariableInspectorWidget.h>
3 #include <Variable/VariableModel.h>
3 #include <Variable/VariableModel.h>
4
4
5 #include <ui_VariableInspectorWidget.h>
5 #include <ui_VariableInspectorWidget.h>
6
6
7 #include <QSortFilterProxyModel>
7 #include <QSortFilterProxyModel>
8
8
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10
10
11 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
11 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
12
12
13 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
13 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
14 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
14 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
15 {
15 {
16 ui->setupUi(this);
16 ui->setupUi(this);
17
17
18 // Sets model for table
18 // Sets model for table
19 auto sortFilterModel = new QSortFilterProxyModel{this};
19 auto sortFilterModel = new QSortFilterProxyModel{this};
20 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
20 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
21
21
22 ui->tableView->setModel(sortFilterModel);
22 ui->tableView->setModel(sortFilterModel);
23
23
24 // Fixes column sizes
24 // Fixes column sizes
25 auto model = ui->tableView->model();
25 auto model = ui->tableView->model();
26 const auto count = model->columnCount();
26 const auto count = model->columnCount();
27 for (auto i = 0; i < count; ++i) {
27 for (auto i = 0; i < count; ++i) {
28 ui->tableView->setColumnWidth(
28 ui->tableView->setColumnWidth(
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
30 }
30 }
31
31
32 // Sets selection options
33 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
34 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
35
32 // Connection to show a menu when right clicking on the tree
36 // Connection to show a menu when right clicking on the tree
33 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
37 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
34 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
38 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
35 &VariableInspectorWidget::onTableMenuRequested);
39 &VariableInspectorWidget::onTableMenuRequested);
36 }
40 }
37
41
38 VariableInspectorWidget::~VariableInspectorWidget()
42 VariableInspectorWidget::~VariableInspectorWidget()
39 {
43 {
40 delete ui;
44 delete ui;
41 }
45 }
42
46
43 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
47 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
44 {
48 {
45 auto selectedIndex = ui->tableView->indexAt(pos);
49 auto selectedIndex = ui->tableView->indexAt(pos);
46 if (selectedIndex.isValid()) {
50 if (selectedIndex.isValid()) {
47 // Gets the model to retrieve the underlying selected variable
51 // Gets the model to retrieve the underlying selected variable
48 auto model = sqpApp->variableController().variableModel();
52 auto model = sqpApp->variableController().variableModel();
49 if (auto selectedVariable = model->variable(selectedIndex.row())) {
53 if (auto selectedVariable = model->variable(selectedIndex.row())) {
50 QMenu tableMenu{};
54 QMenu tableMenu{};
51
55
52 // Emit a signal so that potential receivers can populate the menu before displaying it
56 // Emit a signal so that potential receivers can populate the menu before displaying it
53 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
57 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
54
58
55 if (!tableMenu.isEmpty()) {
59 if (!tableMenu.isEmpty()) {
56 tableMenu.exec(mapToGlobal(pos));
60 tableMenu.exec(mapToGlobal(pos));
57 }
61 }
58 }
62 }
59 }
63 }
60 else {
64 else {
61 qCCritical(LOG_VariableInspectorWidget())
65 qCCritical(LOG_VariableInspectorWidget())
62 << tr("Can't display menu : invalid index (%1;%2)")
66 << tr("Can't display menu : invalid index (%1;%2)")
63 .arg(selectedIndex.row(), selectedIndex.column());
67 .arg(selectedIndex.row(), selectedIndex.column());
64 }
68 }
65 }
69 }
General Comments 0
You need to be logged in to leave comments. Login now