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