##// END OF EJS Templates
Pull request fixes
Alexandre Leroux -
r251:f4bacb54bdee
parent child
Show More
@@ -1,125 +1,125
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/IDataSeries.h>
4 #include <Data/IDataSeries.h>
5
5
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
7
7
8 namespace {
8 namespace {
9
9
10 // Column indexes
10 // Column indexes
11 const auto NAME_COLUMN = 0;
11 const auto NAME_COLUMN = 0;
12 const auto UNIT_COLUMN = 1;
12 const auto UNIT_COLUMN = 1;
13 const auto MISSION_COLUMN = 2;
13 const auto MISSION_COLUMN = 2;
14 const auto NB_COLUMNS = 3;
14 const auto NB_COLUMNS = 3;
15
15
16 } // namespace
16 } // namespace
17
17
18 struct VariableModel::VariableModelPrivate {
18 struct VariableModel::VariableModelPrivate {
19 /// Variables created in SciQlop
19 /// Variables created in SciQlop
20 std::vector<std::shared_ptr<Variable> > m_Variables;
20 std::vector<std::shared_ptr<Variable> > m_Variables;
21 };
21 };
22
22
23 VariableModel::VariableModel(QObject *parent)
23 VariableModel::VariableModel(QObject *parent)
24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
25 {
25 {
26 }
26 }
27
27
28 std::shared_ptr<Variable>
28 std::shared_ptr<Variable>
29 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
29 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
31 {
31 {
32 auto insertIndex = rowCount();
32 auto insertIndex = rowCount();
33 beginInsertRows({}, insertIndex, insertIndex);
33 beginInsertRows({}, insertIndex, insertIndex);
34
34
35 /// @todo For the moment, the other data of the variable is initialized with default values
35 /// @todo For the moment, the other data of the variable is initialized with default values
36 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
36 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
37 QStringLiteral("mission"), dateTime);
37 QStringLiteral("mission"), dateTime);
38 variable->setDataSeries(std::move(defaultDataSeries));
38 variable->setDataSeries(std::move(defaultDataSeries));
39
39
40 impl->m_Variables.push_back(variable);
40 impl->m_Variables.push_back(variable);
41
41
42 endInsertRows();
42 endInsertRows();
43
43
44 return variable;
44 return variable;
45 }
45 }
46
46
47 std::shared_ptr<Variable> VariableModel::variable(int index) const
47 std::shared_ptr<Variable> VariableModel::variable(int index) const
48 {
48 {
49 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables.at(index) : nullptr;
49 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
50 }
50 }
51
51
52 int VariableModel::columnCount(const QModelIndex &parent) const
52 int VariableModel::columnCount(const QModelIndex &parent) const
53 {
53 {
54 Q_UNUSED(parent);
54 Q_UNUSED(parent);
55
55
56 return NB_COLUMNS;
56 return NB_COLUMNS;
57 }
57 }
58
58
59 int VariableModel::rowCount(const QModelIndex &parent) const
59 int VariableModel::rowCount(const QModelIndex &parent) const
60 {
60 {
61 Q_UNUSED(parent);
61 Q_UNUSED(parent);
62
62
63 return impl->m_Variables.size();
63 return impl->m_Variables.size();
64 }
64 }
65
65
66 QVariant VariableModel::data(const QModelIndex &index, int role) const
66 QVariant VariableModel::data(const QModelIndex &index, int role) const
67 {
67 {
68 if (!index.isValid()) {
68 if (!index.isValid()) {
69 return QVariant{};
69 return QVariant{};
70 }
70 }
71
71
72 if (index.row() < 0 || index.row() >= rowCount()) {
72 if (index.row() < 0 || index.row() >= rowCount()) {
73 return QVariant{};
73 return QVariant{};
74 }
74 }
75
75
76 if (role == Qt::DisplayRole) {
76 if (role == Qt::DisplayRole) {
77 if (auto variable = impl->m_Variables.at(index.row()).get()) {
77 if (auto variable = impl->m_Variables.at(index.row()).get()) {
78 switch (index.column()) {
78 switch (index.column()) {
79 case NAME_COLUMN:
79 case NAME_COLUMN:
80 return variable->name();
80 return variable->name();
81 case UNIT_COLUMN:
81 case UNIT_COLUMN:
82 return variable->unit();
82 return variable->unit();
83 case MISSION_COLUMN:
83 case MISSION_COLUMN:
84 return variable->mission();
84 return variable->mission();
85 default:
85 default:
86 // No action
86 // No action
87 break;
87 break;
88 }
88 }
89
89
90 qWarning(LOG_VariableModel())
90 qWarning(LOG_VariableModel())
91 << tr("Can't get data (unknown column %1)").arg(index.column());
91 << tr("Can't get data (unknown column %1)").arg(index.column());
92 }
92 }
93 else {
93 else {
94 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
94 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
95 }
95 }
96 }
96 }
97
97
98 return QVariant{};
98 return QVariant{};
99 }
99 }
100
100
101 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
101 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
102 {
102 {
103 if (role != Qt::DisplayRole) {
103 if (role != Qt::DisplayRole) {
104 return QVariant{};
104 return QVariant{};
105 }
105 }
106
106
107 if (orientation == Qt::Horizontal) {
107 if (orientation == Qt::Horizontal) {
108 switch (section) {
108 switch (section) {
109 case NAME_COLUMN:
109 case NAME_COLUMN:
110 return tr("Name");
110 return tr("Name");
111 case UNIT_COLUMN:
111 case UNIT_COLUMN:
112 return tr("Unit");
112 return tr("Unit");
113 case MISSION_COLUMN:
113 case MISSION_COLUMN:
114 return tr("Mission");
114 return tr("Mission");
115 default:
115 default:
116 // No action
116 // No action
117 break;
117 break;
118 }
118 }
119
119
120 qWarning(LOG_VariableModel())
120 qWarning(LOG_VariableModel())
121 << tr("Can't get header data (unknown column %1)").arg(section);
121 << tr("Can't get header data (unknown column %1)").arg(section);
122 }
122 }
123
123
124 return QVariant{};
124 return QVariant{};
125 }
125 }
@@ -1,46 +1,49
1 #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H
1 #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H
2 #define SCIQLOP_VARIABLEINSPECTORWIDGET_H
2 #define SCIQLOP_VARIABLEINSPECTORWIDGET_H
3
3
4 #include <QLoggingCategory>
4 #include <QMenu>
5 #include <QMenu>
5 #include <QWidget>
6 #include <QWidget>
6
7
7 #include <memory>
8 #include <memory>
8
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget)
11
9 class Variable;
12 class Variable;
10
13
11 namespace Ui {
14 namespace Ui {
12 class VariableInspectorWidget;
15 class VariableInspectorWidget;
13 } // Ui
16 } // Ui
14
17
15 /**
18 /**
16 * @brief The VariableInspectorWidget class representes represents the variable inspector, from
19 * @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
20 * which it is possible to view the loaded variables, handle them or trigger their display in
18 * visualization
21 * visualization
19 */
22 */
20 class VariableInspectorWidget : public QWidget {
23 class VariableInspectorWidget : public QWidget {
21 Q_OBJECT
24 Q_OBJECT
22
25
23 public:
26 public:
24 explicit VariableInspectorWidget(QWidget *parent = 0);
27 explicit VariableInspectorWidget(QWidget *parent = 0);
25 virtual ~VariableInspectorWidget();
28 virtual ~VariableInspectorWidget();
26
29
27 signals:
30 signals:
28 /**
31 /**
29 * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets
32 * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets
30 * to complete the menu.
33 * to complete the menu.
31 * @param tableMenu the menu to be completed
34 * @param tableMenu the menu to be completed
32 * @param variable the variable concerned by the menu
35 * @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
36 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
34 * in Qt :: DirectConnection
37 * in Qt :: DirectConnection
35 */
38 */
36 void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable);
39 void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable);
37
40
38 private:
41 private:
39 Ui::VariableInspectorWidget *ui;
42 Ui::VariableInspectorWidget *ui;
40
43
41 private slots:
44 private slots:
42 /// Slot called when right clicking on an variable in the table (displays a menu)
45 /// Slot called when right clicking on an variable in the table (displays a menu)
43 void onTableMenuRequested(const QPoint &pos) noexcept;
46 void onTableMenuRequested(const QPoint &pos) noexcept;
44 };
47 };
45
48
46 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
49 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
@@ -1,50 +1,57
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 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
12
11 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
13 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
12 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
14 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
13 {
15 {
14 ui->setupUi(this);
16 ui->setupUi(this);
15
17
16 // Sets model for table
18 // Sets model for table
17 auto sortFilterModel = new QSortFilterProxyModel{this};
19 auto sortFilterModel = new QSortFilterProxyModel{this};
18 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
20 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
19
21
20 ui->tableView->setModel(sortFilterModel);
22 ui->tableView->setModel(sortFilterModel);
21
23
22 // Connection to show a menu when right clicking on the tree
24 // Connection to show a menu when right clicking on the tree
23 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
25 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
24 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
26 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
25 &VariableInspectorWidget::onTableMenuRequested);
27 &VariableInspectorWidget::onTableMenuRequested);
26 }
28 }
27
29
28 VariableInspectorWidget::~VariableInspectorWidget()
30 VariableInspectorWidget::~VariableInspectorWidget()
29 {
31 {
30 delete ui;
32 delete ui;
31 }
33 }
32
34
33 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
35 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
34 {
36 {
35 auto selectedIndex = ui->tableView->indexAt(pos);
37 auto selectedIndex = ui->tableView->indexAt(pos);
36 if (selectedIndex.isValid()) {
38 if (selectedIndex.isValid()) {
37 // Gets the model to retrieve the underlying selected variable
39 // Gets the model to retrieve the underlying selected variable
38 auto model = sqpApp->variableController().variableModel();
40 auto model = sqpApp->variableController().variableModel();
39 if (auto selectedVariable = model->variable(selectedIndex.row())) {
41 if (auto selectedVariable = model->variable(selectedIndex.row())) {
40 QMenu tableMenu{};
42 QMenu tableMenu{};
41
43
42 // Emit a signal so that potential receivers can populate the menu before displaying it
44 // Emit a signal so that potential receivers can populate the menu before displaying it
43 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
45 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
44
46
45 if (!tableMenu.isEmpty()) {
47 if (!tableMenu.isEmpty()) {
46 tableMenu.exec(mapToGlobal(pos));
48 tableMenu.exec(mapToGlobal(pos));
47 }
49 }
48 }
50 }
49 }
51 }
52 else {
53 qCCritical(LOG_VariableInspectorWidget())
54 << tr("Can't display menu : invalid index (%1;%2)")
55 .arg(selectedIndex.row(), selectedIndex.column());
56 }
50 }
57 }
General Comments 0
You need to be logged in to leave comments. Login now