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