##// END OF EJS Templates
Merge branch 'feature/VariableMenu2' into develop
Alexandre Leroux -
r250:aa2508ab83a4 merge
parent child
Show More
@@ -182,10 +182,16 MainWindow::MainWindow(QWidget *parent)
182 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
182 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
183 SLOT(onTimeToUpdate(SqpDateTime)));
183 SLOT(onTimeToUpdate(SqpDateTime)));
184
184
185 // Variable
185 // Widgets / widgets connections
186 qRegisterMetaType<std::shared_ptr<Variable> >();
186 qRegisterMetaType<std::shared_ptr<Variable> >();
187 connect(&sqpApp->visualizationController(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
187
188 m_Ui->view, SLOT(displayVariable(std::shared_ptr<Variable>)));
188 // For the following connections, we use DirectConnection to allow each widget that can
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
191 // widget will attach its menu
192 connect(m_Ui->variableInspectorWidget,
193 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, std::shared_ptr<Variable>)), m_Ui->view,
194 SLOT(attachVariableMenu(QMenu *, std::shared_ptr<Variable>)), Qt::DirectConnection);
189
195
190 /* QLopGUI::registerMenuBar(menuBar());
196 /* QLopGUI::registerMenuBar(menuBar());
191 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
197 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
@@ -32,6 +32,8 public:
32 createVariable(const QString &name, const SqpDateTime &dateTime,
32 createVariable(const QString &name, const SqpDateTime &dateTime,
33 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
33 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
34
34
35 std::shared_ptr<Variable> variable(int index) const;
36
35 // /////////////////////////// //
37 // /////////////////////////// //
36 // QAbstractTableModel methods //
38 // QAbstractTableModel methods //
37 // /////////////////////////// //
39 // /////////////////////////// //
@@ -44,6 +44,11 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
44 return variable;
44 return variable;
45 }
45 }
46
46
47 std::shared_ptr<Variable> VariableModel::variable(int index) const
48 {
49 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables.at(index) : nullptr;
50 }
51
47 int VariableModel::columnCount(const QModelIndex &parent) const
52 int VariableModel::columnCount(const QModelIndex &parent) const
48 {
53 {
49 Q_UNUSED(parent);
54 Q_UNUSED(parent);
@@ -1,8 +1,13
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 <QWidget>
5 #include <QWidget>
5
6
7 #include <memory>
8
9 class Variable;
10
6 namespace Ui {
11 namespace Ui {
7 class VariableInspectorWidget;
12 class VariableInspectorWidget;
8 } // Ui
13 } // Ui
@@ -19,8 +24,23 public:
19 explicit VariableInspectorWidget(QWidget *parent = 0);
24 explicit VariableInspectorWidget(QWidget *parent = 0);
20 virtual ~VariableInspectorWidget();
25 virtual ~VariableInspectorWidget();
21
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
22 private:
38 private:
23 Ui::VariableInspectorWidget *ui;
39 Ui::VariableInspectorWidget *ui;
40
41 private slots:
42 /// Slot called when right clicking on an variable in the table (displays a menu)
43 void onTableMenuRequested(const QPoint &pos) noexcept;
24 };
44 };
25
45
26 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
46 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
@@ -8,6 +8,7
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10
10
11 class QMenu;
11 class Variable;
12 class Variable;
12 class VisualizationTabWidget;
13 class VisualizationTabWidget;
13
14
@@ -39,12 +40,11 public:
39
40
40 public slots:
41 public slots:
41 /**
42 /**
42 * Displays a variable in a new graph of a new zone of the current tab
43 * Attaches to a menu the menu relating to the visualization of a variable
43 * @param variable the variable to display
44 * @param menu the parent menu of the generated menu
44 * @todo this is a temporary method that will be replaced by own actions for each type of
45 * @param variable the variable for which to generate the menu
45 * visualization widget
46 */
46 */
47 void displayVariable(std::shared_ptr<Variable> variable) noexcept;
47 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
48
48
49 private:
49 private:
50 Ui::VisualizationWidget *ui;
50 Ui::VisualizationWidget *ui;
@@ -18,9 +18,33 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
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
22 // Connection to show a menu when right clicking on the tree
23 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
24 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
25 &VariableInspectorWidget::onTableMenuRequested);
21 }
26 }
22
27
23 VariableInspectorWidget::~VariableInspectorWidget()
28 VariableInspectorWidget::~VariableInspectorWidget()
24 {
29 {
25 delete ui;
30 delete ui;
26 }
31 }
32
33 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
34 {
35 auto selectedIndex = ui->tableView->indexAt(pos);
36 if (selectedIndex.isValid()) {
37 // Gets the model to retrieve the underlying selected variable
38 auto model = sqpApp->variableController().variableModel();
39 if (auto selectedVariable = model->variable(selectedIndex.row())) {
40 QMenu tableMenu{};
41
42 // Emit a signal so that potential receivers can populate the menu before displaying it
43 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
44
45 if (!tableMenu.isEmpty()) {
46 tableMenu.exec(mapToGlobal(pos));
47 }
48 }
49 }
50 }
@@ -3,6 +3,7
3 #include "Visualization/VisualizationGraphWidget.h"
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
6 #include "Visualization/qcustomplot.h"
7 #include "Visualization/qcustomplot.h"
7
8
8 #include "ui_VisualizationWidget.h"
9 #include "ui_VisualizationWidget.h"
@@ -121,16 +122,10 QString VisualizationWidget::name() const
121 return QStringLiteral("MainView");
122 return QStringLiteral("MainView");
122 }
123 }
123
124
124 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
125 void VisualizationWidget::attachVariableMenu(QMenu *menu,
126 std::shared_ptr<Variable> variable) noexcept
125 {
127 {
126 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
128 // Generates the actions that make it possible to visualize the variable
127 if (!currentTab->createZone(variable)) {
129 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
128 qCCritical(LOG_VisualizationWidget())
130 accept(&generateVariableMenuOperation);
129 << tr("Can't display the variable : can't create a new zone in the current tab");
130 }
131 }
132 else {
133 qCCritical(LOG_VisualizationWidget())
134 << tr("Can't display the variable : there is no current tab");
135 }
136 }
131 }
General Comments 0
You need to be logged in to leave comments. Login now