##// END OF EJS Templates
Creates signal to make dynmaic menu for a variable
Alexandre Leroux -
r247:96c4c8973e0c
parent child
Show More
@@ -1,35 +1,46
1 #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H
1 #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H
2 #define SCIQLOP_VARIABLEINSPECTORWIDGET_H
2 #define SCIQLOP_VARIABLEINSPECTORWIDGET_H
3
3
4 #include <QMenu>
4 #include <QMenu>
5 #include <QWidget>
5 #include <QWidget>
6
6
7 #include <memory>
7 #include <memory>
8
8
9 class Variable;
9 class Variable;
10
10
11 namespace Ui {
11 namespace Ui {
12 class VariableInspectorWidget;
12 class VariableInspectorWidget;
13 } // Ui
13 } // Ui
14
14
15 /**
15 /**
16 * @brief The VariableInspectorWidget class representes represents the variable inspector, from
16 * @brief The VariableInspectorWidget class representes represents the variable inspector, from
17 * which it is possible to view the loaded variables, handle them or trigger their display in
17 * which it is possible to view the loaded variables, handle them or trigger their display in
18 * visualization
18 * visualization
19 */
19 */
20 class VariableInspectorWidget : public QWidget {
20 class VariableInspectorWidget : public QWidget {
21 Q_OBJECT
21 Q_OBJECT
22
22
23 public:
23 public:
24 explicit VariableInspectorWidget(QWidget *parent = 0);
24 explicit VariableInspectorWidget(QWidget *parent = 0);
25 virtual ~VariableInspectorWidget();
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 private:
38 private:
28 Ui::VariableInspectorWidget *ui;
39 Ui::VariableInspectorWidget *ui;
29
40
30 private slots:
41 private slots:
31 /// Slot called when right clicking on an variable in the table (displays a menu)
42 /// Slot called when right clicking on an variable in the table (displays a menu)
32 void onTableMenuRequested(const QPoint &pos) noexcept;
43 void onTableMenuRequested(const QPoint &pos) noexcept;
33 };
44 };
34
45
35 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
46 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
@@ -1,49 +1,50
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 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
11 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
12 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
12 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
13 {
13 {
14 ui->setupUi(this);
14 ui->setupUi(this);
15
15
16 // Sets model for table
16 // Sets model for table
17 auto sortFilterModel = new QSortFilterProxyModel{this};
17 auto sortFilterModel = new QSortFilterProxyModel{this};
18 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
18 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
19
19
20 ui->tableView->setModel(sortFilterModel);
20 ui->tableView->setModel(sortFilterModel);
21
21
22 // Connection to show a menu when right clicking on the tree
22 // Connection to show a menu when right clicking on the tree
23 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
23 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
24 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
24 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
25 &VariableInspectorWidget::onTableMenuRequested);
25 &VariableInspectorWidget::onTableMenuRequested);
26 }
26 }
27
27
28 VariableInspectorWidget::~VariableInspectorWidget()
28 VariableInspectorWidget::~VariableInspectorWidget()
29 {
29 {
30 delete ui;
30 delete ui;
31 }
31 }
32
32
33 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
33 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
34 {
34 {
35 auto selectedIndex = ui->tableView->indexAt(pos);
35 auto selectedIndex = ui->tableView->indexAt(pos);
36 if (selectedIndex.isValid()) {
36 if (selectedIndex.isValid()) {
37 // Gets the model to retrieve the underlying selected variable
37 // Gets the model to retrieve the underlying selected variable
38 auto model = sqpApp->variableController().variableModel();
38 auto model = sqpApp->variableController().variableModel();
39 if (auto selectedVariable = model->variable(selectedIndex.row())) {
39 if (auto selectedVariable = model->variable(selectedIndex.row())) {
40 QMenu tableMenu{};
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 if (!tableMenu.isEmpty()) {
45 if (!tableMenu.isEmpty()) {
45 tableMenu.exec(mapToGlobal(pos));
46 tableMenu.exec(mapToGlobal(pos));
46 }
47 }
47 }
48 }
48 }
49 }
49 }
50 }
General Comments 0
You need to be logged in to leave comments. Login now