##// END OF EJS Templates
Merge pull request 184 from SCIQLOP-Initialisation develop...
leroux -
r403:756d172725c6 merge
parent child
Show More
@@ -25,13 +25,16 public:
25 void finalize();
25 void finalize();
26
26
27 public slots:
27 public slots:
28 /// Execute request and call callback when the reply is finished. Identifier is attached to the
29 /// callback
28 void onProcessRequested(const QNetworkRequest &request, QUuid identifier,
30 void onProcessRequested(const QNetworkRequest &request, QUuid identifier,
29 std::function<void(QNetworkReply *, QUuid)> callback);
31 std::function<void(QNetworkReply *, QUuid)> callback);
32 /// Cancel the request of identifier
30 void onReplyCanceled(QUuid identifier);
33 void onReplyCanceled(QUuid identifier);
31
34
32 signals:
35 signals:
33 void replyFinished(QNetworkReply *reply, QUuid identifier);
36 void replyFinished(QNetworkReply *reply, QUuid identifier);
34 void replyDownloadProgress(QUuid identifier);
37 void replyDownloadProgress(QUuid identifier, double progress);
35
38
36 private:
39 private:
37 void waitForFinish();
40 void waitForFinish();
@@ -67,6 +67,9 public slots:
67 /// Update the temporal parameters of every selected variable to dateTime
67 /// Update the temporal parameters of every selected variable to dateTime
68 void onDateTimeOnSelection(const SqpDateTime &dateTime);
68 void onDateTimeOnSelection(const SqpDateTime &dateTime);
69
69
70
71 void onVariableRetrieveDataInProgress(QUuid identifier, double progress);
72
70 void initialize();
73 void initialize();
71 void finalize();
74 void finalize();
72
75
@@ -12,6 +12,9
12
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
14
14
15 enum VariableRoles { ProgressRole = Qt::UserRole };
16
17
15 class IDataSeries;
18 class IDataSeries;
16 class Variable;
19 class Variable;
17
20
@@ -37,11 +40,15 public:
37 */
40 */
38 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
41 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
39
42
43
40 std::shared_ptr<Variable> variable(int index) const;
44 std::shared_ptr<Variable> variable(int index) const;
41
45
46 void setDataProgress(std::shared_ptr<Variable> variable, double progress);
47
42 // /////////////////////////// //
48 // /////////////////////////// //
43 // QAbstractTableModel methods //
49 // QAbstractTableModel methods //
44 // /////////////////////////// //
50 // /////////////////////////// //
51
45 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
52 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
46 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
53 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
47 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
54 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
@@ -26,7 +26,7 NetworkController::NetworkController(QObject *parent)
26 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier,
26 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier,
27 std::function<void(QNetworkReply *, QUuid)> callback)
27 std::function<void(QNetworkReply *, QUuid)> callback)
28 {
28 {
29 qCDebug(LOG_NetworkController()) << tr("NetworkController registered")
29 qCInfo(LOG_NetworkController()) << tr("NetworkController registered")
30 << QThread::currentThread();
30 << QThread::currentThread();
31 auto reply = impl->m_AccessManager->get(request);
31 auto reply = impl->m_AccessManager->get(request);
32
32
@@ -35,7 +35,7 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid
35
35
36 auto onReplyFinished = [reply, this, identifier, callback]() {
36 auto onReplyFinished = [reply, this, identifier, callback]() {
37
37
38 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
38 qCInfo(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
39 << QThread::currentThread();
39 << QThread::currentThread();
40 auto it = impl->m_NetworkReplyToVariableId.find(reply);
40 auto it = impl->m_NetworkReplyToVariableId.find(reply);
41 if (it != impl->m_NetworkReplyToVariableId.cend()) {
41 if (it != impl->m_NetworkReplyToVariableId.cend()) {
@@ -43,19 +43,18 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid
43 }
43 }
44 };
44 };
45
45
46 auto onReplyDownloadProgress = [reply, this]() {
46 auto onReplyProgress = [reply, this](qint64 bytesRead, qint64 totalBytes) {
47
47
48 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyDownloadProgress")
48 double progress = (bytesRead * 100.0) / totalBytes;
49 << QThread::currentThread();
50 auto it = impl->m_NetworkReplyToVariableId.find(reply);
49 auto it = impl->m_NetworkReplyToVariableId.find(reply);
51 if (it != impl->m_NetworkReplyToVariableId.cend()) {
50 if (it != impl->m_NetworkReplyToVariableId.cend()) {
52 emit this->replyDownloadProgress(it->second);
51 emit this->replyDownloadProgress(it->second, progress);
53 }
52 }
54 };
53 };
55
54
56
55
57 connect(reply, &QNetworkReply::finished, this, onReplyFinished);
56 connect(reply, &QNetworkReply::finished, this, onReplyFinished);
58 connect(reply, &QNetworkReply::downloadProgress, this, onReplyDownloadProgress);
57 connect(reply, &QNetworkReply::downloadProgress, this, onReplyProgress);
59 }
58 }
60
59
61 void NetworkController::initialize()
60 void NetworkController::initialize()
@@ -157,6 +157,17 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
157 }
157 }
158 }
158 }
159
159
160 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
161 {
162 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
163
164 auto end = impl->m_VariableToIdentifier.cend();
165 auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply);
166 if (it != end) {
167 impl->m_VariableModel->setDataProgress(it->first, progress);
168 }
169 }
170
160
171
161 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
172 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
162 const SqpDateTime &dateTime)
173 const SqpDateTime &dateTime)
@@ -5,6 +5,7
5
5
6 #include <QDateTime>
6 #include <QDateTime>
7 #include <QSize>
7 #include <QSize>
8 #include <unordered_map>
8
9
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
10 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
10
11
@@ -40,11 +41,17 const auto COLUMN_PROPERTIES
40 /// Format for datetimes
41 /// Format for datetimes
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
42 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
42
43
44
43 } // namespace
45 } // namespace
44
46
45 struct VariableModel::VariableModelPrivate {
47 struct VariableModel::VariableModelPrivate {
46 /// Variables created in SciQlop
48 /// Variables created in SciQlop
47 std::vector<std::shared_ptr<Variable> > m_Variables;
49 std::vector<std::shared_ptr<Variable> > m_Variables;
50 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
51
52
53 /// Return the row index of the variable. -1 if it's not found
54 int indexOfVariable(Variable *variable) const noexcept;
48 };
55 };
49
56
50 VariableModel::VariableModel(QObject *parent)
57 VariableModel::VariableModel(QObject *parent)
@@ -96,11 +103,21 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
96 }
103 }
97 }
104 }
98
105
106
99 std::shared_ptr<Variable> VariableModel::variable(int index) const
107 std::shared_ptr<Variable> VariableModel::variable(int index) const
100 {
108 {
101 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
109 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
102 }
110 }
103
111
112 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
113 {
114
115 impl->m_VariableToProgress[variable] = progress;
116 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
117
118 emit dataChanged(modelIndex, modelIndex);
119 }
120
104 int VariableModel::columnCount(const QModelIndex &parent) const
121 int VariableModel::columnCount(const QModelIndex &parent) const
105 {
122 {
106 Q_UNUSED(parent);
123 Q_UNUSED(parent);
@@ -152,6 +169,15 QVariant VariableModel::data(const QModelIndex &index, int role) const
152 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
169 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
153 }
170 }
154 }
171 }
172 else if (role == VariableRoles::ProgressRole) {
173 if (auto variable = impl->m_Variables.at(index.row())) {
174
175 auto it = impl->m_VariableToProgress.find(variable);
176 if (it != impl->m_VariableToProgress.cend()) {
177 return it->second;
178 }
179 }
180 }
155
181
156 return QVariant{};
182 return QVariant{};
157 }
183 }
@@ -183,18 +209,28 void VariableModel::onVariableUpdated() noexcept
183 {
209 {
184 // Finds variable that has been updated in the model
210 // Finds variable that has been updated in the model
185 if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
211 if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
186 auto begin = std::cbegin(impl->m_Variables);
212 auto updatedVariableIndex = impl->indexOfVariable(updatedVariable);
187 auto end = std::cend(impl->m_Variables);
213
188 auto it = std::find_if(begin, end, [updatedVariable](const auto &variable) {
214 if (updatedVariableIndex > -1) {
189 return variable.get() == updatedVariable;
215 emit dataChanged(createIndex(updatedVariableIndex, 0),
190 });
216 createIndex(updatedVariableIndex, columnCount() - 1));
217 }
218 }
219 }
220
221 int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept
222 {
223 auto begin = std::cbegin(m_Variables);
224 auto end = std::cend(m_Variables);
225 auto it
226 = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; });
191
227
192 if (it != end) {
228 if (it != end) {
193 // Gets the index of the variable in the model: we assume here that views have the same
229 // Gets the index of the variable in the model: we assume here that views have the same
194 // order as the model
230 // order as the model
195 auto updateVariableIndex = std::distance(begin, it);
231 return std::distance(begin, it);
196 emit dataChanged(createIndex(updateVariableIndex, 0),
197 createIndex(updateVariableIndex, columnCount() - 1));
198 }
232 }
233 else {
234 return -1;
199 }
235 }
200 }
236 }
@@ -11,6 +11,8 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget)
11
11
12 class Variable;
12 class Variable;
13
13
14 class QProgressBarItemDelegate;
15
14 namespace Ui {
16 namespace Ui {
15 class VariableInspectorWidget;
17 class VariableInspectorWidget;
16 } // Ui
18 } // Ui
@@ -42,6 +44,8 signals:
42 private:
44 private:
43 Ui::VariableInspectorWidget *ui;
45 Ui::VariableInspectorWidget *ui;
44
46
47 QProgressBarItemDelegate *m_ProgressBarItemDelegate;
48
45 private slots:
49 private slots:
46 /// Slot called when right clicking on an variable in the table (displays a menu)
50 /// Slot called when right clicking on an variable in the table (displays a menu)
47 void onTableMenuRequested(const QPoint &pos) noexcept;
51 void onTableMenuRequested(const QPoint &pos) noexcept;
@@ -104,6 +104,11 SqpApplication::SqpApplication(int &argc, char **argv)
104 impl->m_NetworkControllerThread.start();
104 impl->m_NetworkControllerThread.start();
105 impl->m_VariableControllerThread.start();
105 impl->m_VariableControllerThread.start();
106 impl->m_VisualizationControllerThread.start();
106 impl->m_VisualizationControllerThread.start();
107
108 // Core connections:
109 // NetworkController <-> VariableController
110 connect(&sqpApp->networkController(), &NetworkController::replyDownloadProgress,
111 &sqpApp->variableController(), &VariableController::onVariableRetrieveDataInProgress);
107 }
112 }
108
113
109 SqpApplication::~SqpApplication()
114 SqpApplication::~SqpApplication()
@@ -6,14 +6,52
6 #include <ui_VariableInspectorWidget.h>
6 #include <ui_VariableInspectorWidget.h>
7
7
8 #include <QSortFilterProxyModel>
8 #include <QSortFilterProxyModel>
9 #include <QStyledItemDelegate>
9 #include <QWidgetAction>
10 #include <QWidgetAction>
10
11
11 #include <SqpApplication.h>
12 #include <SqpApplication.h>
12
13
13 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
14 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
14
15
16
17 class QProgressBarItemDelegate : public QStyledItemDelegate {
18
19 public:
20 QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {}
21
22 void paint(QPainter *painter, const QStyleOptionViewItem &option,
23 const QModelIndex &index) const
24 {
25 auto data = index.data(Qt::DisplayRole);
26 auto progressData = index.data(VariableRoles::ProgressRole);
27 if (data.isValid() && progressData.isValid()) {
28 auto name = data.value<QString>();
29 auto progress = progressData.value<double>();
30 if (progress >= 0) {
31 auto progressBarOption = QStyleOptionProgressBar{};
32 progressBarOption.rect = option.rect;
33 progressBarOption.minimum = 0;
34 progressBarOption.maximum = 100;
35 progressBarOption.progress = progress;
36 progressBarOption.text
37 = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%");
38 progressBarOption.textVisible = true;
39 progressBarOption.textAlignment = Qt::AlignCenter;
40
41 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption,
42 painter);
43 }
44 }
45 else {
46 QStyledItemDelegate::paint(painter, option, index);
47 }
48 }
49 };
50
15 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
51 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
16 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
52 : QWidget{parent},
53 ui{new Ui::VariableInspectorWidget},
54 m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}}
17 {
55 {
18 ui->setupUi(this);
56 ui->setupUi(this);
19
57
@@ -30,6 +68,7 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
30 SLOT(refresh()));
68 SLOT(refresh()));
31
69
32 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
70 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
71 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
33
72
34 // Fixes column sizes
73 // Fixes column sizes
35 auto model = ui->tableView->model();
74 auto model = ui->tableView->model();
@@ -6,6 +6,8
6 #include <QFile>
6 #include <QFile>
7 #include <QRegularExpression>
7 #include <QRegularExpression>
8
8
9 #include <cmath>
10
9 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser")
11 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser")
10
12
11 namespace {
13 namespace {
@@ -156,8 +156,8 void TestAmdaResultParser::testReadTxt_data()
156 QVector<double>{-2.71850, -2.52150}};
156 QVector<double>{-2.71850, -2.52150}};
157
157
158 // Invalid file
158 // Invalid file
159 QTest::newRow("Invalid file (unexisting file)")
159 QTest::newRow("Invalid file (unexisting file)") << QStringLiteral("UnexistingFile.txt")
160 << QStringLiteral("UnexistingFile.txt") << ExpectedResults{};
160 << ExpectedResults{};
161 }
161 }
162
162
163 void TestAmdaResultParser::testReadTxt()
163 void TestAmdaResultParser::testReadTxt()
General Comments 0
You need to be logged in to leave comments. Login now