##// END OF EJS Templates
Adds an entry to the menu for deleting a variable...
Alexandre Leroux -
r269:b01ed1a46678
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -1,7 +1,8
1 <RCC>
1 <RCC>
2 <qresource prefix="/">
2 <qresource prefix="/">
3 <file>icones/delete.png</file>
3 <file>icones/openInspector.png</file>
4 <file>icones/openInspector.png</file>
4 <file>icones/next.png</file>
5 <file>icones/next.png</file>
5 <file>icones/previous.png</file>
6 <file>icones/previous.png</file>
6 </qresource>
7 </qresource>
7 </RCC>
8 </RCC>
@@ -1,77 +1,88
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableInspectorWidget.h>
2 #include <Variable/VariableInspectorWidget.h>
3 #include <Variable/VariableMenuHeaderWidget.h>
3 #include <Variable/VariableMenuHeaderWidget.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <ui_VariableInspectorWidget.h>
6 #include <ui_VariableInspectorWidget.h>
7
7
8 #include <QSortFilterProxyModel>
8 #include <QSortFilterProxyModel>
9 #include <QWidgetAction>
9 #include <QWidgetAction>
10
10
11 #include <SqpApplication.h>
11 #include <SqpApplication.h>
12
12
13 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
13 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
14
14
15 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
15 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
16 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
16 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
17 {
17 {
18 ui->setupUi(this);
18 ui->setupUi(this);
19
19
20 // Sets model for table
20 // Sets model for table
21 auto sortFilterModel = new QSortFilterProxyModel{this};
21 auto sortFilterModel = new QSortFilterProxyModel{this};
22 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
22 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
23
23
24 ui->tableView->setModel(sortFilterModel);
24 ui->tableView->setModel(sortFilterModel);
25
25
26 // Fixes column sizes
26 // Fixes column sizes
27 auto model = ui->tableView->model();
27 auto model = ui->tableView->model();
28 const auto count = model->columnCount();
28 const auto count = model->columnCount();
29 for (auto i = 0; i < count; ++i) {
29 for (auto i = 0; i < count; ++i) {
30 ui->tableView->setColumnWidth(
30 ui->tableView->setColumnWidth(
31 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
31 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
32 }
32 }
33
33
34 // Sets selection options
34 // Sets selection options
35 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
35 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
36 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
36 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
37
37
38 // Connection to show a menu when right clicking on the tree
38 // Connection to show a menu when right clicking on the tree
39 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
39 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
40 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
40 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
41 &VariableInspectorWidget::onTableMenuRequested);
41 &VariableInspectorWidget::onTableMenuRequested);
42 }
42 }
43
43
44 VariableInspectorWidget::~VariableInspectorWidget()
44 VariableInspectorWidget::~VariableInspectorWidget()
45 {
45 {
46 delete ui;
46 delete ui;
47 }
47 }
48
48
49 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
49 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
50 {
50 {
51 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
51 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
52
52
53 // Gets the model to retrieve the underlying selected variables
53 // Gets the model to retrieve the underlying selected variables
54 auto model = sqpApp->variableController().variableModel();
54 auto model = sqpApp->variableController().variableModel();
55 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
55 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
56 for (const auto &selectedRow : qAsConst(selectedRows)) {
56 for (const auto &selectedRow : qAsConst(selectedRows)) {
57 if (auto selectedVariable = model->variable(selectedRow.row())) {
57 if (auto selectedVariable = model->variable(selectedRow.row())) {
58 selectedVariables.push_back(selectedVariable);
58 selectedVariables.push_back(selectedVariable);
59 }
59 }
60 }
60 }
61
61
62 QMenu tableMenu{};
62 QMenu tableMenu{};
63
63
64 // Emits a signal so that potential receivers can populate the menu before displaying it
64 // Emits a signal so that potential receivers can populate the menu before displaying it
65 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
65 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
66
66
67 // Adds menu-specific actions
68 if (!selectedVariables.isEmpty()) {
69 // 'Delete' action
70 auto deleteFun = []() {
71 /// @todo ALX : call variable deletion
72 };
73
74 tableMenu.addSeparator();
75 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
76 }
77
67 if (!tableMenu.isEmpty()) {
78 if (!tableMenu.isEmpty()) {
68 // Generates menu header (inserted before first action)
79 // Generates menu header (inserted before first action)
69 auto firstAction = tableMenu.actions().first();
80 auto firstAction = tableMenu.actions().first();
70 auto headerAction = new QWidgetAction{&tableMenu};
81 auto headerAction = new QWidgetAction{&tableMenu};
71 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
82 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
72 tableMenu.insertAction(firstAction, headerAction);
83 tableMenu.insertAction(firstAction, headerAction);
73
84
74 // Displays menu
85 // Displays menu
75 tableMenu.exec(mapToGlobal(pos));
86 tableMenu.exec(mapToGlobal(pos));
76 }
87 }
77 }
88 }
General Comments 0
You need to be logged in to leave comments. Login now