##// END OF EJS Templates
Fixes refresh problem in Variable widget
Alexandre Leroux -
r368:fc12ad933c3b
parent child
Show More
@@ -7,6 +7,7
7 #include <QAbstractTableModel>
7 #include <QAbstractTableModel>
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9
9
10 #include <Common/MetaTypes.h>
10 #include <Common/spimpl.h>
11 #include <Common/spimpl.h>
11
12
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
@@ -50,6 +51,13 public:
50 private:
51 private:
51 class VariableModelPrivate;
52 class VariableModelPrivate;
52 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
53 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
54
55 private slots:
56 /// Slot called when data of a variable has been updated
57 void onVariableUpdated() noexcept;
53 };
58 };
54
59
60 // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal
61 SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>)
62
55 #endif // SCIQLOP_VARIABLEMODEL_H
63 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -63,6 +63,7 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
63 QStringLiteral("mission"), dateTime);
63 QStringLiteral("mission"), dateTime);
64
64
65 impl->m_Variables.push_back(variable);
65 impl->m_Variables.push_back(variable);
66 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
66
67
67 endInsertRows();
68 endInsertRows();
68
69
@@ -177,3 +178,21 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int
177
178
178 return QVariant{};
179 return QVariant{};
179 }
180 }
181
182 void VariableModel::onVariableUpdated() noexcept
183 {
184 // Finds variable that has been updated in the model
185 if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
186 auto begin = std::cbegin(impl->m_Variables);
187 auto end = std::cend(impl->m_Variables);
188 auto it = std::find_if(begin, end, [updatedVariable](const auto &variable) {
189 return variable.get() == updatedVariable;
190 });
191
192 if (it != end) {
193 auto updateVariableIndex = std::distance(begin, it);
194 emit dataChanged(createIndex(updateVariableIndex, 0),
195 createIndex(updateVariableIndex, columnCount() - 1));
196 }
197 }
198 }
@@ -45,6 +45,8 private:
45 private slots:
45 private slots:
46 /// Slot called when right clicking on an variable in the table (displays a menu)
46 /// Slot called when right clicking on an variable in the table (displays a menu)
47 void onTableMenuRequested(const QPoint &pos) noexcept;
47 void onTableMenuRequested(const QPoint &pos) noexcept;
48 /// Refreshes instantly the variable view
49 void refresh() noexcept;
48 };
50 };
49
51
50 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
52 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
@@ -21,7 +21,14 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
21 // auto sortFilterModel = new QSortFilterProxyModel{this};
21 // auto sortFilterModel = new QSortFilterProxyModel{this};
22 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
22 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
23
23
24 ui->tableView->setModel(sqpApp->variableController().variableModel());
24 auto variableModel = sqpApp->variableController().variableModel();
25 ui->tableView->setModel(variableModel);
26
27 // Adds extra signal/slot between view and model, so the view can be updated instantly when
28 // there is a change of data in the model
29 connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
30 SLOT(refresh()));
31
25 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
32 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
26
33
27 // Fixes column sizes
34 // Fixes column sizes
@@ -87,3 +94,8 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
87 tableMenu.exec(mapToGlobal(pos));
94 tableMenu.exec(mapToGlobal(pos));
88 }
95 }
89 }
96 }
97
98 void VariableInspectorWidget::refresh() noexcept
99 {
100 ui->tableView->viewport()->update();
101 }
General Comments 0
You need to be logged in to leave comments. Login now