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