##// END OF EJS Templates
Uses Qt::SizeHintRole to set column width and height
Alexandre Leroux -
r258:97758c973a6d
parent child
Show More
@@ -1,57 +1,65
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
25 auto model = ui->tableView->model();
26 const auto count = model->columnCount();
27 for (auto i = 0; i < count; ++i) {
28 ui->tableView->setColumnWidth(
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
30 }
31
24 // Connection to show a menu when right clicking on the tree
32 // Connection to show a menu when right clicking on the tree
25 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
33 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
26 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
34 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
27 &VariableInspectorWidget::onTableMenuRequested);
35 &VariableInspectorWidget::onTableMenuRequested);
28 }
36 }
29
37
30 VariableInspectorWidget::~VariableInspectorWidget()
38 VariableInspectorWidget::~VariableInspectorWidget()
31 {
39 {
32 delete ui;
40 delete ui;
33 }
41 }
34
42
35 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
43 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
36 {
44 {
37 auto selectedIndex = ui->tableView->indexAt(pos);
45 auto selectedIndex = ui->tableView->indexAt(pos);
38 if (selectedIndex.isValid()) {
46 if (selectedIndex.isValid()) {
39 // Gets the model to retrieve the underlying selected variable
47 // Gets the model to retrieve the underlying selected variable
40 auto model = sqpApp->variableController().variableModel();
48 auto model = sqpApp->variableController().variableModel();
41 if (auto selectedVariable = model->variable(selectedIndex.row())) {
49 if (auto selectedVariable = model->variable(selectedIndex.row())) {
42 QMenu tableMenu{};
50 QMenu tableMenu{};
43
51
44 // Emit a signal so that potential receivers can populate the menu before displaying it
52 // Emit a signal so that potential receivers can populate the menu before displaying it
45 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
53 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
46
54
47 if (!tableMenu.isEmpty()) {
55 if (!tableMenu.isEmpty()) {
48 tableMenu.exec(mapToGlobal(pos));
56 tableMenu.exec(mapToGlobal(pos));
49 }
57 }
50 }
58 }
51 }
59 }
52 else {
60 else {
53 qCCritical(LOG_VariableInspectorWidget())
61 qCCritical(LOG_VariableInspectorWidget())
54 << tr("Can't display menu : invalid index (%1;%2)")
62 << tr("Can't display menu : invalid index (%1;%2)")
55 .arg(selectedIndex.row(), selectedIndex.column());
63 .arg(selectedIndex.row(), selectedIndex.column());
56 }
64 }
57 }
65 }
General Comments 0
You need to be logged in to leave comments. Login now