##// END OF EJS Templates
Merge branch 'feature/VariableSelection' into develop
Alexandre Leroux -
r292:7f62a644886e merge
parent child
Show More
@@ -0,0 +1,37
1 #ifndef SCIQLOP_VARIABLEMENUHEADERWIDGET_H
2 #define SCIQLOP_VARIABLEMENUHEADERWIDGET_H
3
4 #include <QLoggingCategory>
5 #include <QWidget>
6
7 #include <memory>
8
9 namespace Ui {
10 class VariableMenuHeaderWidget;
11 } // Ui
12
13 class Variable;
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget)
16
17 /**
18 * @brief The VariableMenuHeaderWidget class represents the widget used as a header of a menu in the
19 * variable inspector
20 * @sa VariableInspectorWidget
21 */
22 class VariableMenuHeaderWidget : public QWidget {
23 public:
24 /**
25 * Ctor
26 * @param variables the list of variables used to generate the header
27 * @param parent the parent widget
28 */
29 explicit VariableMenuHeaderWidget(const QVector<std::shared_ptr<Variable> > &variables,
30 QWidget *parent = 0);
31 virtual ~VariableMenuHeaderWidget() noexcept;
32
33 private:
34 Ui::VariableMenuHeaderWidget *ui;
35 };
36
37 #endif // SCIQLOP_VARIABLEMENUHEADERWIDGET_H
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,38
1 #include "Variable/VariableMenuHeaderWidget.h"
2 #include "Variable/Variable.h"
3
4 #include <ui_VariableMenuHeaderWidget.h>
5
6 Q_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget, "VariableMenuHeaderWidget")
7
8 VariableMenuHeaderWidget::VariableMenuHeaderWidget(
9 const QVector<std::shared_ptr<Variable> > &variables, QWidget *parent)
10 : QWidget{parent}, ui{new Ui::VariableMenuHeaderWidget}
11 {
12 ui->setupUi(this);
13
14 // Generates label according to the state of the variables. The label contains :
15 // - the variable name if there is only one variable in the list
16 // - 'x variables' where x is the number of variables otherwise
17 const auto nbVariables = variables.size();
18 if (nbVariables == 1) {
19 if (auto variable = variables.first()) {
20 ui->label->setText(variable->name());
21 }
22 else {
23 qCCritical(LOG_VariableMenuHeaderWidget())
24 << tr("Can't get the name of the variable : variable is null");
25 }
26 }
27 else if (nbVariables > 1) {
28 ui->label->setText(tr("%1 variables").arg(nbVariables));
29 }
30 else {
31 ui->label->setText(tr("No variable"));
32 }
33 }
34
35 VariableMenuHeaderWidget::~VariableMenuHeaderWidget() noexcept
36 {
37 delete ui;
38 }
@@ -0,0 +1,31
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>VariableMenuHeaderWidget</class>
4 <widget class="QWidget" name="VariableMenuHeaderWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>110</width>
10 <height>34</height>
11 </rect>
12 </property>
13 <layout class="QGridLayout" name="gridLayout">
14 <item row="0" column="0">
15 <widget class="QLabel" name="label">
16 <property name="styleSheet">
17 <string notr="true">background-color: rgba(127, 127, 127, 127);</string>
18 </property>
19 <property name="text">
20 <string>TextLabel</string>
21 </property>
22 <property name="alignment">
23 <set>Qt::AlignCenter</set>
24 </property>
25 </widget>
26 </item>
27 </layout>
28 </widget>
29 <resources/>
30 <connections/>
31 </ui>
@@ -189,9 +189,11 MainWindow::MainWindow(QWidget *parent)
189 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
189 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
190 // The order of connections is also important, since it determines the order in which each
190 // The order of connections is also important, since it determines the order in which each
191 // widget will attach its menu
191 // widget will attach its menu
192 connect(m_Ui->variableInspectorWidget,
192 connect(
193 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, std::shared_ptr<Variable>)), m_Ui->view,
193 m_Ui->variableInspectorWidget,
194 SLOT(attachVariableMenu(QMenu *, std::shared_ptr<Variable>)), Qt::DirectConnection);
194 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
195 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
196 Qt::DirectConnection);
195
197
196 /* QLopGUI::registerMenuBar(menuBar());
198 /* QLopGUI::registerMenuBar(menuBar());
197 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
199 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
@@ -29,14 +29,15 public:
29
29
30 signals:
30 signals:
31 /**
31 /**
32 * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets
32 * Signal emitted before a menu concerning variables is displayed. It is used for other widgets
33 * to complete the menu.
33 * to complete the menu.
34 * @param tableMenu the menu to be completed
34 * @param tableMenu the menu to be completed
35 * @param variable the variable concerned by the menu
35 * @param variables the variables concerned by the menu
36 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
36 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
37 * in Qt :: DirectConnection
37 * in Qt :: DirectConnection
38 */
38 */
39 void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable);
39 void tableMenuAboutToBeDisplayed(QMenu *tableMenu,
40 const QVector<std::shared_ptr<Variable> > &variables);
40
41
41 private:
42 private:
42 Ui::VariableInspectorWidget *ui;
43 Ui::VariableInspectorWidget *ui;
@@ -30,11 +30,12 public:
30
30
31 public slots:
31 public slots:
32 /**
32 /**
33 * Attaches to a menu the menu relating to the visualization of a variable
33 * Attaches to a menu the menu relative to the visualization of variables
34 * @param menu the parent menu of the generated menu
34 * @param menu the parent menu of the generated menu
35 * @param variable the variable for which to generate the menu
35 * @param variables the variables for which to generate the menu
36 */
36 */
37 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
37 void attachVariableMenu(QMenu *menu,
38 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
38
39
39 private:
40 private:
40 Ui::VisualizationWidget *ui;
41 Ui::VisualizationWidget *ui;
@@ -1,5 +1,6
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>
@@ -1,10 +1,12
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/VariableModel.h>
4 #include <Variable/VariableModel.h>
4
5
5 #include <ui_VariableInspectorWidget.h>
6 #include <ui_VariableInspectorWidget.h>
6
7
7 #include <QSortFilterProxyModel>
8 #include <QSortFilterProxyModel>
9 #include <QWidgetAction>
8
10
9 #include <SqpApplication.h>
11 #include <SqpApplication.h>
10
12
@@ -29,6 +31,10 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
31 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
30 }
32 }
31
33
34 // Sets selection options
35 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
36 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
37
32 // Connection to show a menu when right clicking on the tree
38 // Connection to show a menu when right clicking on the tree
33 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
39 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
34 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
40 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
@@ -42,24 +48,41 VariableInspectorWidget::~VariableInspectorWidget()
42
48
43 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
49 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
44 {
50 {
45 auto selectedIndex = ui->tableView->indexAt(pos);
51 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
46 if (selectedIndex.isValid()) {
52
47 // Gets the model to retrieve the underlying selected variable
53 // Gets the model to retrieve the underlying selected variables
48 auto model = sqpApp->variableController().variableModel();
54 auto model = sqpApp->variableController().variableModel();
49 if (auto selectedVariable = model->variable(selectedIndex.row())) {
55 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
50 QMenu tableMenu{};
56 for (const auto &selectedRow : qAsConst(selectedRows)) {
51
57 if (auto selectedVariable = model->variable(selectedRow.row())) {
52 // Emit a signal so that potential receivers can populate the menu before displaying it
58 selectedVariables.push_back(selectedVariable);
53 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
54
55 if (!tableMenu.isEmpty()) {
56 tableMenu.exec(mapToGlobal(pos));
57 }
58 }
59 }
59 }
60 }
60 else {
61
61 qCCritical(LOG_VariableInspectorWidget())
62 QMenu tableMenu{};
62 << tr("Can't display menu : invalid index (%1;%2)")
63
63 .arg(selectedIndex.row(), selectedIndex.column());
64 // Emits a signal so that potential receivers can populate the menu before displaying it
65 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
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
78 if (!tableMenu.isEmpty()) {
79 // Generates menu header (inserted before first action)
80 auto firstAction = tableMenu.actions().first();
81 auto headerAction = new QWidgetAction{&tableMenu};
82 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
83 tableMenu.insertAction(firstAction, headerAction);
84
85 // Displays menu
86 tableMenu.exec(mapToGlobal(pos));
64 }
87 }
65 }
88 }
@@ -106,10 +106,24 QString VisualizationWidget::name() const
106 return QStringLiteral("MainView");
106 return QStringLiteral("MainView");
107 }
107 }
108
108
109 void VisualizationWidget::attachVariableMenu(QMenu *menu,
109 void VisualizationWidget::attachVariableMenu(
110 std::shared_ptr<Variable> variable) noexcept
110 QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept
111 {
111 {
112 // Generates the actions that make it possible to visualize the variable
112 // Menu is generated only if there is a single variable
113 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
113 if (variables.size() == 1) {
114 accept(&generateVariableMenuOperation);
114 if (auto variable = variables.first()) {
115 // Generates the actions that make it possible to visualize the variable
116 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
117 accept(&generateVariableMenuOperation);
118 }
119 else {
120 qCCritical(LOG_VisualizationWidget()) << tr(
121 "Can't generate the menu relative to the visualization: the variable is null");
122 }
123 }
124 else {
125 qCDebug(LOG_VisualizationWidget())
126 << tr("No generation of the menu related to the visualization: several variables are "
127 "selected");
128 }
115 }
129 }
General Comments 0
You need to be logged in to leave comments. Login now