##// END OF EJS Templates
Creates signal to make dynmaic menu for a variable
Alexandre Leroux -
r230:96c4c8973e0c
parent child
Show More
@@ -1,35 +1,46
1 1 #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H
2 2 #define SCIQLOP_VARIABLEINSPECTORWIDGET_H
3 3
4 4 #include <QMenu>
5 5 #include <QWidget>
6 6
7 7 #include <memory>
8 8
9 9 class Variable;
10 10
11 11 namespace Ui {
12 12 class VariableInspectorWidget;
13 13 } // Ui
14 14
15 15 /**
16 16 * @brief The VariableInspectorWidget class representes represents the variable inspector, from
17 17 * which it is possible to view the loaded variables, handle them or trigger their display in
18 18 * visualization
19 19 */
20 20 class VariableInspectorWidget : public QWidget {
21 21 Q_OBJECT
22 22
23 23 public:
24 24 explicit VariableInspectorWidget(QWidget *parent = 0);
25 25 virtual ~VariableInspectorWidget();
26 26
27 signals:
28 /**
29 * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets
30 * to complete the menu.
31 * @param tableMenu the menu to be completed
32 * @param variable the variable concerned by the menu
33 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
34 * in Qt :: DirectConnection
35 */
36 void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable);
37
27 38 private:
28 39 Ui::VariableInspectorWidget *ui;
29 40
30 41 private slots:
31 42 /// Slot called when right clicking on an variable in the table (displays a menu)
32 43 void onTableMenuRequested(const QPoint &pos) noexcept;
33 44 };
34 45
35 46 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
@@ -1,49 +1,50
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 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
12 12 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
13 13 {
14 14 ui->setupUi(this);
15 15
16 16 // Sets model for table
17 17 auto sortFilterModel = new QSortFilterProxyModel{this};
18 18 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
19 19
20 20 ui->tableView->setModel(sortFilterModel);
21 21
22 22 // Connection to show a menu when right clicking on the tree
23 23 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
24 24 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
25 25 &VariableInspectorWidget::onTableMenuRequested);
26 26 }
27 27
28 28 VariableInspectorWidget::~VariableInspectorWidget()
29 29 {
30 30 delete ui;
31 31 }
32 32
33 33 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
34 34 {
35 35 auto selectedIndex = ui->tableView->indexAt(pos);
36 36 if (selectedIndex.isValid()) {
37 37 // Gets the model to retrieve the underlying selected variable
38 38 auto model = sqpApp->variableController().variableModel();
39 39 if (auto selectedVariable = model->variable(selectedIndex.row())) {
40 40 QMenu tableMenu{};
41 41
42 /// @todo ALX : make menu
42 // Emit a signal so that potential receivers can populate the menu before displaying it
43 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
43 44
44 45 if (!tableMenu.isEmpty()) {
45 46 tableMenu.exec(mapToGlobal(pos));
46 47 }
47 48 }
48 49 }
49 50 }
Unmatched/outdated inline comments below
note

No problem with variable local ?

General Comments 0
You need to be logged in to leave comments. Login now