@@ -0,0 +1,42 | |||
|
1 | #ifndef SCIQLOP_RESCALEAXEOPERATION_H | |
|
2 | #define SCIQLOP_RESCALEAXEOPERATION_H | |
|
3 | ||
|
4 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
|
5 | #include <Data/SqpDateTime.h> | |
|
6 | ||
|
7 | #include <Common/spimpl.h> | |
|
8 | ||
|
9 | #include <QLoggingCategory> | |
|
10 | ||
|
11 | #include <memory> | |
|
12 | ||
|
13 | class Variable; | |
|
14 | ||
|
15 | Q_DECLARE_LOGGING_CATEGORY(LOG_RescaleAxeOperation) | |
|
16 | ||
|
17 | /** | |
|
18 | * @brief The RescaleAxeOperation class defines an operation that traverses all of visualization | |
|
19 | * widgets to remove a variable if they contain it | |
|
20 | */ | |
|
21 | class RescaleAxeOperation : public IVisualizationWidgetVisitor { | |
|
22 | public: | |
|
23 | /** | |
|
24 | * Ctor | |
|
25 | * @param variable the variable to remove from widgets | |
|
26 | */ | |
|
27 | explicit RescaleAxeOperation(std::shared_ptr<Variable> variable, const SqpDateTime &range); | |
|
28 | ||
|
29 | void visitEnter(VisualizationWidget *widget) override final; | |
|
30 | void visitLeave(VisualizationWidget *widget) override final; | |
|
31 | void visitEnter(VisualizationTabWidget *tabWidget) override final; | |
|
32 | void visitLeave(VisualizationTabWidget *tabWidget) override final; | |
|
33 | void visitEnter(VisualizationZoneWidget *zoneWidget) override final; | |
|
34 | void visitLeave(VisualizationZoneWidget *zoneWidget) override final; | |
|
35 | void visit(VisualizationGraphWidget *graphWidget) override final; | |
|
36 | ||
|
37 | private: | |
|
38 | class RescaleAxeOperationPrivate; | |
|
39 | spimpl::unique_impl_ptr<RescaleAxeOperationPrivate> impl; | |
|
40 | }; | |
|
41 | ||
|
42 | #endif // SCIQLOP_RESCALEAXEOPERATION_H |
@@ -0,0 +1,71 | |||
|
1 | #include "Visualization/operations/RescaleAxeOperation.h" | |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |
|
3 | ||
|
4 | Q_LOGGING_CATEGORY(LOG_RescaleAxeOperation, "RescaleAxeOperation") | |
|
5 | ||
|
6 | struct RescaleAxeOperation::RescaleAxeOperationPrivate { | |
|
7 | explicit RescaleAxeOperationPrivate(std::shared_ptr<Variable> variable, | |
|
8 | const SqpDateTime &range) | |
|
9 | : m_Variable{variable}, m_Range{range} | |
|
10 | { | |
|
11 | } | |
|
12 | ||
|
13 | std::shared_ptr<Variable> m_Variable; | |
|
14 | SqpDateTime m_Range; | |
|
15 | }; | |
|
16 | ||
|
17 | RescaleAxeOperation::RescaleAxeOperation(std::shared_ptr<Variable> variable, | |
|
18 | const SqpDateTime &range) | |
|
19 | : impl{spimpl::make_unique_impl<RescaleAxeOperationPrivate>(variable, range)} | |
|
20 | { | |
|
21 | } | |
|
22 | ||
|
23 | void RescaleAxeOperation::visitEnter(VisualizationWidget *widget) | |
|
24 | { | |
|
25 | // VisualizationWidget is not intended to contain a variable | |
|
26 | Q_UNUSED(widget) | |
|
27 | } | |
|
28 | ||
|
29 | void RescaleAxeOperation::visitLeave(VisualizationWidget *widget) | |
|
30 | { | |
|
31 | // VisualizationWidget is not intended to contain a variable | |
|
32 | Q_UNUSED(widget) | |
|
33 | } | |
|
34 | ||
|
35 | void RescaleAxeOperation::visitEnter(VisualizationTabWidget *tabWidget) | |
|
36 | { | |
|
37 | // VisualizationTabWidget is not intended to contain a variable | |
|
38 | Q_UNUSED(tabWidget) | |
|
39 | } | |
|
40 | ||
|
41 | void RescaleAxeOperation::visitLeave(VisualizationTabWidget *tabWidget) | |
|
42 | { | |
|
43 | // VisualizationTabWidget is not intended to contain a variable | |
|
44 | Q_UNUSED(tabWidget) | |
|
45 | } | |
|
46 | ||
|
47 | void RescaleAxeOperation::visitEnter(VisualizationZoneWidget *zoneWidget) | |
|
48 | { | |
|
49 | // VisualizationZoneWidget is not intended to contain a variable | |
|
50 | Q_UNUSED(zoneWidget) | |
|
51 | } | |
|
52 | ||
|
53 | void RescaleAxeOperation::visitLeave(VisualizationZoneWidget *zoneWidget) | |
|
54 | { | |
|
55 | // VisualizationZoneWidget is not intended to contain a variable | |
|
56 | Q_UNUSED(zoneWidget) | |
|
57 | } | |
|
58 | ||
|
59 | void RescaleAxeOperation::visit(VisualizationGraphWidget *graphWidget) | |
|
60 | { | |
|
61 | if (graphWidget) { | |
|
62 | // If the widget contains the variable, rescale it | |
|
63 | if (impl->m_Variable && graphWidget->contains(*impl->m_Variable)) { | |
|
64 | graphWidget->setRange(impl->m_Variable, impl->m_Range); | |
|
65 | } | |
|
66 | } | |
|
67 | else { | |
|
68 | qCCritical(LOG_RescaleAxeOperation(), | |
|
69 | "Can't visit VisualizationGraphWidget : the widget is null"); | |
|
70 | } | |
|
71 | } |
@@ -0,0 +1,3 | |||
|
1 | Not Found | |
|
2 | ||
|
3 | The requested URL /AMDA/data/WSRESULT/imf(0)-1343153090-1343153092-60.txt was not found on this server. No newline at end of file |
@@ -192,6 +192,10 MainWindow::MainWindow(QWidget *parent) | |||
|
192 | 192 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view, |
|
193 | 193 | SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>))); |
|
194 | 194 | |
|
195 | connect(&sqpApp->visualizationController(), | |
|
196 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view, | |
|
197 | SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &))); | |
|
198 | ||
|
195 | 199 | // Widgets / widgets connections |
|
196 | 200 | |
|
197 | 201 | // For the following connections, we use DirectConnection to allow each widget that can |
@@ -10,6 +10,8 | |||
|
10 | 10 | |
|
11 | 11 | #include <Data/SqpDateTime.h> |
|
12 | 12 | |
|
13 | #include <functional> | |
|
14 | ||
|
13 | 15 | class DataProviderParameters; |
|
14 | 16 | class IDataSeries; |
|
15 | 17 | class QNetworkReply; |
@@ -34,6 +36,11 public: | |||
|
34 | 36 | */ |
|
35 | 37 | virtual void requestDataLoading(QUuid identifier, const DataProviderParameters ¶meters) = 0; |
|
36 | 38 | |
|
39 | /** | |
|
40 | * @brief requestDataAborting stop data loading of the data identified by identifier | |
|
41 | */ | |
|
42 | virtual void requestDataAborting(QUuid identifier) = 0; | |
|
43 | ||
|
37 | 44 | signals: |
|
38 | 45 | /** |
|
39 | 46 | * @brief dataProvided send dataSeries under dateTime and that corresponds of the data |
@@ -42,6 +49,12 signals: | |||
|
42 | 49 | void dataProvided(QUuid identifier, std::shared_ptr<IDataSeries> dateSerie, |
|
43 | 50 | const SqpDateTime &dateTime); |
|
44 | 51 | |
|
52 | /** | |
|
53 | * @brief dataProvided send dataSeries under dateTime and that corresponds of the data | |
|
54 | * identified by identifier | |
|
55 | */ | |
|
56 | void dataProvidedProgress(QUuid identifier, double progress); | |
|
57 | ||
|
45 | 58 | |
|
46 | 59 | /** |
|
47 | 60 | * @brief requestConstructed send a request for the data identified by identifier |
@@ -6,6 +6,8 | |||
|
6 | 6 | #include <QLoggingCategory> |
|
7 | 7 | #include <QObject> |
|
8 | 8 | |
|
9 | #include <functional> | |
|
10 | ||
|
9 | 11 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceItemAction) |
|
10 | 12 | |
|
11 | 13 | class DataSourceItem; |
@@ -50,10 +50,18 public: | |||
|
50 | 50 | */ |
|
51 | 51 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; |
|
52 | 52 | |
|
53 | /** | |
|
54 | * @brief abort the variable retrieve data progression | |
|
55 | */ | |
|
56 | void abortProgress(std::shared_ptr<Variable> variable); | |
|
57 | ||
|
53 | 58 | signals: |
|
54 | 59 | /// Signal emitted when a variable is about to be deleted from the controller |
|
55 | 60 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
56 | 61 | |
|
62 | /// Signal emitted when a data acquisition is requested on a range for a variable | |
|
63 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpDateTime &range); | |
|
64 | ||
|
57 | 65 | public slots: |
|
58 | 66 | /// Request the data loading of the variable whithin dateTime |
|
59 | 67 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
@@ -72,6 +80,8 public slots: | |||
|
72 | 80 | |
|
73 | 81 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); |
|
74 | 82 | |
|
83 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); | |
|
84 | ||
|
75 | 85 | void initialize(); |
|
76 | 86 | void finalize(); |
|
77 | 87 |
@@ -22,6 +22,7 class Variable; | |||
|
22 | 22 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop |
|
23 | 23 | */ |
|
24 | 24 | class VariableModel : public QAbstractTableModel { |
|
25 | Q_OBJECT | |
|
25 | 26 | public: |
|
26 | 27 | explicit VariableModel(QObject *parent = nullptr); |
|
27 | 28 | |
@@ -46,6 +47,7 public: | |||
|
46 | 47 | |
|
47 | 48 | void setDataProgress(std::shared_ptr<Variable> variable, double progress); |
|
48 | 49 | |
|
50 | ||
|
49 | 51 | // /////////////////////////// // |
|
50 | 52 | // QAbstractTableModel methods // |
|
51 | 53 | // /////////////////////////// // |
@@ -56,6 +58,12 public: | |||
|
56 | 58 | virtual QVariant headerData(int section, Qt::Orientation orientation, |
|
57 | 59 | int role = Qt::DisplayRole) const override; |
|
58 | 60 | |
|
61 | ||
|
62 | void abortProgress(const QModelIndex &index); | |
|
63 | ||
|
64 | signals: | |
|
65 | void abortProgessRequested(std::shared_ptr<Variable> variable); | |
|
66 | ||
|
59 | 67 | private: |
|
60 | 68 | class VariableModelPrivate; |
|
61 | 69 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; |
@@ -1,6 +1,8 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONCONTROLLER_H |
|
3 | 3 | |
|
4 | #include <Data/SqpDateTime.h> | |
|
5 | ||
|
4 | 6 | #include <QLoggingCategory> |
|
5 | 7 | #include <QObject> |
|
6 | 8 | #include <QUuid> |
@@ -29,6 +31,9 signals: | |||
|
29 | 31 | /// Signal emitted when a variable is about to be deleted from SciQlop |
|
30 | 32 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
31 | 33 | |
|
34 | /// Signal emitted when a data acquisition is requested on a range for a variable | |
|
35 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpDateTime &range); | |
|
36 | ||
|
32 | 37 | public slots: |
|
33 | 38 | /// Manage init/end of the controller |
|
34 | 39 | void initialize(); |
@@ -4,6 +4,7 | |||
|
4 | 4 | #include <QNetworkAccessManager> |
|
5 | 5 | #include <QNetworkReply> |
|
6 | 6 | #include <QNetworkRequest> |
|
7 | #include <QReadWriteLock> | |
|
7 | 8 | #include <QThread> |
|
8 | 9 | |
|
9 | 10 | #include <unordered_map> |
@@ -14,8 +15,13 struct NetworkController::NetworkControllerPrivate { | |||
|
14 | 15 | explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {} |
|
15 | 16 | QMutex m_WorkingMutex; |
|
16 | 17 | |
|
18 | QReadWriteLock m_Lock; | |
|
17 | 19 | std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId; |
|
18 | 20 | std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr}; |
|
21 | ||
|
22 | void lockRead() { m_Lock.lockForRead(); } | |
|
23 | void lockWrite() { m_Lock.lockForWrite(); } | |
|
24 | void unlock() { m_Lock.unlock(); } | |
|
19 | 25 | }; |
|
20 | 26 | |
|
21 | 27 | NetworkController::NetworkController(QObject *parent) |
@@ -26,35 +32,57 NetworkController::NetworkController(QObject *parent) | |||
|
26 | 32 | void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier, |
|
27 | 33 | std::function<void(QNetworkReply *, QUuid)> callback) |
|
28 | 34 | { |
|
29 |
qC |
|
|
30 | << QThread::currentThread(); | |
|
35 | qCDebug(LOG_NetworkController()) << tr("NetworkController registered") | |
|
36 | << QThread::currentThread()->objectName(); | |
|
31 | 37 | auto reply = impl->m_AccessManager->get(request); |
|
32 | 38 | |
|
33 | 39 | // Store the couple reply id |
|
40 | impl->lockWrite(); | |
|
34 | 41 | impl->m_NetworkReplyToVariableId[reply] = identifier; |
|
42 | impl->unlock(); | |
|
35 | 43 | |
|
36 | 44 | auto onReplyFinished = [reply, this, identifier, callback]() { |
|
37 | 45 | |
|
38 |
qC |
|
|
39 | << QThread::currentThread(); | |
|
46 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") | |
|
47 | << QThread::currentThread() << reply; | |
|
48 | impl->lockRead(); | |
|
40 | 49 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
50 | impl->unlock(); | |
|
41 | 51 | if (it != impl->m_NetworkReplyToVariableId.cend()) { |
|
52 | impl->lockWrite(); | |
|
53 | impl->m_NetworkReplyToVariableId.erase(reply); | |
|
54 | impl->unlock(); | |
|
55 | // Deletes reply | |
|
42 | 56 | callback(reply, identifier); |
|
57 | reply->deleteLater(); | |
|
58 | ||
|
59 | emit this->replyDownloadProgress(identifier, 0); | |
|
43 | 60 | } |
|
61 | ||
|
62 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") | |
|
63 | << QThread::currentThread() << reply; | |
|
44 | 64 | }; |
|
45 | 65 | |
|
46 | 66 | auto onReplyProgress = [reply, this](qint64 bytesRead, qint64 totalBytes) { |
|
47 | 67 | |
|
48 | 68 | double progress = (bytesRead * 100.0) / totalBytes; |
|
69 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress | |
|
70 | << QThread::currentThread() << reply; | |
|
71 | impl->lockRead(); | |
|
49 | 72 | auto it = impl->m_NetworkReplyToVariableId.find(reply); |
|
73 | impl->unlock(); | |
|
50 | 74 | if (it != impl->m_NetworkReplyToVariableId.cend()) { |
|
51 | 75 | emit this->replyDownloadProgress(it->second, progress); |
|
52 | 76 | } |
|
77 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END") | |
|
78 | << QThread::currentThread() << reply; | |
|
53 | 79 | }; |
|
54 | 80 | |
|
55 | 81 | |
|
56 | 82 | connect(reply, &QNetworkReply::finished, this, onReplyFinished); |
|
57 | 83 | connect(reply, &QNetworkReply::downloadProgress, this, onReplyProgress); |
|
84 | qCDebug(LOG_NetworkController()) << tr("NetworkController registered END") | |
|
85 | << QThread::currentThread()->objectName() << reply; | |
|
58 | 86 | } |
|
59 | 87 | |
|
60 | 88 | void NetworkController::initialize() |
@@ -62,6 +90,17 void NetworkController::initialize() | |||
|
62 | 90 | qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread(); |
|
63 | 91 | impl->m_WorkingMutex.lock(); |
|
64 | 92 | impl->m_AccessManager = std::make_unique<QNetworkAccessManager>(); |
|
93 | ||
|
94 | ||
|
95 | auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) { | |
|
96 | ||
|
97 | qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors; | |
|
98 | ||
|
99 | }; | |
|
100 | ||
|
101 | ||
|
102 | connect(impl->m_AccessManager.get(), &QNetworkAccessManager::sslErrors, this, onReplyErrors); | |
|
103 | ||
|
65 | 104 | qCDebug(LOG_NetworkController()) << tr("NetworkController init END"); |
|
66 | 105 | } |
|
67 | 106 | |
@@ -73,12 +112,19 void NetworkController::finalize() | |||
|
73 | 112 | void NetworkController::onReplyCanceled(QUuid identifier) |
|
74 | 113 | { |
|
75 | 114 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; |
|
115 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled") | |
|
116 | << QThread::currentThread(); | |
|
76 | 117 | |
|
118 | ||
|
119 | impl->lockRead(); | |
|
77 | 120 | auto end = impl->m_NetworkReplyToVariableId.cend(); |
|
78 | 121 | auto it = std::find_if(impl->m_NetworkReplyToVariableId.cbegin(), end, findReply); |
|
122 | impl->unlock(); | |
|
79 | 123 | if (it != end) { |
|
80 | 124 | it->first->abort(); |
|
81 | 125 | } |
|
126 | qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END") | |
|
127 | << QThread::currentThread(); | |
|
82 | 128 | } |
|
83 | 129 | |
|
84 | 130 | void NetworkController::waitForFinish() |
@@ -60,7 +60,7 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |||
|
60 | 60 | impl->m_DataSeries->merge(dataSeries.get()); |
|
61 | 61 | impl->m_DataSeries->unlock(); |
|
62 | 62 | dataSeries->unlock(); |
|
63 | emit updated(); | |
|
63 | // emit updated(); | |
|
64 | 64 | } |
|
65 | 65 | } |
|
66 | 66 |
@@ -38,7 +38,7 struct VariableController::VariableControllerPrivate { | |||
|
38 | 38 | |
|
39 | 39 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
40 | 40 | m_VariableToProviderMap; |
|
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifier; | |
|
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; | |
|
42 | 42 | }; |
|
43 | 43 | |
|
44 | 44 | VariableController::VariableController(QObject *parent) |
@@ -46,6 +46,9 VariableController::VariableController(QObject *parent) | |||
|
46 | 46 | { |
|
47 | 47 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
48 | 48 | << QThread::currentThread(); |
|
49 | ||
|
50 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, | |
|
51 | &VariableController::onAbortProgressRequested); | |
|
49 | 52 | } |
|
50 | 53 | |
|
51 | 54 | VariableController::~VariableController() |
@@ -81,6 +84,9 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noex | |||
|
81 | 84 | // make some treatments before the deletion |
|
82 | 85 | emit variableAboutToBeDeleted(variable); |
|
83 | 86 | |
|
87 | // Deletes identifier | |
|
88 | impl->m_VariableToIdentifierMap.erase(variable); | |
|
89 | ||
|
84 | 90 | // Deletes provider |
|
85 | 91 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
86 | 92 | qCDebug(LOG_VariableController()) |
@@ -102,6 +108,10 void VariableController::deleteVariables( | |||
|
102 | 108 | } |
|
103 | 109 | } |
|
104 | 110 | |
|
111 | void VariableController::abortProgress(std::shared_ptr<Variable> variable) | |
|
112 | { | |
|
113 | } | |
|
114 | ||
|
105 | 115 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
106 | 116 | std::shared_ptr<IDataProvider> provider) noexcept |
|
107 | 117 | { |
@@ -119,21 +129,24 void VariableController::createVariable(const QString &name, const QVariantHash | |||
|
119 | 129 | |
|
120 | 130 | // store the provider |
|
121 | 131 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
122 | impl->m_VariableToIdentifier[newVariable] = identifier; | |
|
132 | impl->m_VariableToIdentifierMap[newVariable] = identifier; | |
|
123 | 133 | |
|
124 | 134 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( |
|
125 | 135 | QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) |
|
126 | 136 | { |
|
127 | 137 | if (auto variable = varW.lock()) { |
|
128 | auto varIdentifier = impl->m_VariableToIdentifier.at(variable); | |
|
138 | auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable); | |
|
129 | 139 | if (varIdentifier == identifier) { |
|
130 | 140 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); |
|
131 | 141 | variable->setDataSeries(dataSeriesAcquired); |
|
142 | emit variable->updated(); | |
|
132 | 143 | } |
|
133 | 144 | } |
|
134 | 145 | }; |
|
135 | 146 | |
|
136 | 147 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
148 | connect(provider.get(), &IDataProvider::dataProvidedProgress, this, | |
|
149 | &VariableController::onVariableRetrieveDataInProgress); | |
|
137 | 150 | this->onRequestDataLoading(newVariable, dateTime); |
|
138 | 151 | } |
|
139 | 152 | } |
@@ -148,6 +161,9 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |||
|
148 | 161 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
149 | 162 | selectedVariable->setDateTime(dateTime); |
|
150 | 163 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
164 | ||
|
165 | // notify that rescale operation has to be done | |
|
166 | emit rangeChanged(selectedVariable, dateTime); | |
|
151 | 167 | } |
|
152 | 168 | } |
|
153 | 169 | } |
@@ -156,13 +172,29 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub | |||
|
156 | 172 | { |
|
157 | 173 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; |
|
158 | 174 | |
|
159 | auto end = impl->m_VariableToIdentifier.cend(); | |
|
160 | auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply); | |
|
175 | auto end = impl->m_VariableToIdentifierMap.cend(); | |
|
176 | auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply); | |
|
161 | 177 | if (it != end) { |
|
162 | 178 | impl->m_VariableModel->setDataProgress(it->first, progress); |
|
163 | 179 | } |
|
164 | 180 | } |
|
165 | 181 | |
|
182 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) | |
|
183 | { | |
|
184 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" | |
|
185 | << QThread::currentThread()->objectName(); | |
|
186 | ||
|
187 | auto it = impl->m_VariableToIdentifierMap.find(variable); | |
|
188 | if (it != impl->m_VariableToIdentifierMap.cend()) { | |
|
189 | impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); | |
|
190 | } | |
|
191 | else { | |
|
192 | qCWarning(LOG_VariableController()) | |
|
193 | << tr("Aborting progression of inexistant variable detected !!!") | |
|
194 | << QThread::currentThread()->objectName(); | |
|
195 | } | |
|
196 | } | |
|
197 | ||
|
166 | 198 | |
|
167 | 199 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
168 | 200 | const SqpDateTime &dateTime) |
@@ -179,7 +211,7 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable | |||
|
179 | 211 | |
|
180 | 212 | if (!dateTimeListNotInCache.empty()) { |
|
181 | 213 | // Ask the provider for each data on the dateTimeListNotInCache |
|
182 | auto identifier = impl->m_VariableToIdentifier.at(variable); | |
|
214 | auto identifier = impl->m_VariableToIdentifierMap.at(variable); | |
|
183 | 215 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
184 | 216 | identifier, |
|
185 | 217 | DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()}); |
@@ -49,7 +49,6 struct VariableModel::VariableModelPrivate { | |||
|
49 | 49 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
50 | 50 | std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress; |
|
51 | 51 | |
|
52 | ||
|
53 | 52 | /// Return the row index of the variable. -1 if it's not found |
|
54 | 53 | int indexOfVariable(Variable *variable) const noexcept; |
|
55 | 54 | }; |
@@ -100,6 +99,9 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |||
|
100 | 99 | << tr("Can't delete variable %1 from the model: the variable is not in the model") |
|
101 | 100 | .arg(variable->name()); |
|
102 | 101 | } |
|
102 | ||
|
103 | // Removes variable from progress map | |
|
104 | impl->m_VariableToProgress.erase(variable); | |
|
103 | 105 | } |
|
104 | 106 | |
|
105 | 107 | |
@@ -110,8 +112,12 std::shared_ptr<Variable> VariableModel::variable(int index) const | |||
|
110 | 112 | |
|
111 | 113 | void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress) |
|
112 | 114 | { |
|
113 | ||
|
115 | if (progress > 0.0) { | |
|
114 | 116 | impl->m_VariableToProgress[variable] = progress; |
|
117 | } | |
|
118 | else { | |
|
119 | impl->m_VariableToProgress.erase(variable); | |
|
120 | } | |
|
115 | 121 | auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN); |
|
116 | 122 | |
|
117 | 123 | emit dataChanged(modelIndex, modelIndex); |
@@ -204,6 +210,13 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int | |||
|
204 | 210 | return QVariant{}; |
|
205 | 211 | } |
|
206 | 212 | |
|
213 | void VariableModel::abortProgress(const QModelIndex &index) | |
|
214 | { | |
|
215 | if (auto variable = impl->m_Variables.at(index.row())) { | |
|
216 | emit abortProgessRequested(variable); | |
|
217 | } | |
|
218 | } | |
|
219 | ||
|
207 | 220 | void VariableModel::onVariableUpdated() noexcept |
|
208 | 221 | { |
|
209 | 222 | // Finds variable that has been updated in the model |
@@ -16,6 +16,11 class QCPRange; | |||
|
16 | 16 | class SqpDateTime; |
|
17 | 17 | class Variable; |
|
18 | 18 | |
|
19 | /** | |
|
20 | * Possible types of zoom operation | |
|
21 | */ | |
|
22 | enum class VisualizationGraphWidgetZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; | |
|
23 | ||
|
19 | 24 | namespace Ui { |
|
20 | 25 | class VisualizationGraphWidget; |
|
21 | 26 | } // namespace Ui |
@@ -27,21 +32,28 public: | |||
|
27 | 32 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
28 | 33 | virtual ~VisualizationGraphWidget(); |
|
29 | 34 | |
|
35 | void enableSynchronize(bool enable); | |
|
36 | ||
|
30 | 37 | void addVariable(std::shared_ptr<Variable> variable); |
|
31 | 38 | void addVariableUsingGraph(std::shared_ptr<Variable> variable); |
|
32 | 39 | /// Removes a variable from the graph |
|
33 | 40 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
34 | 41 | |
|
42 | void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range); | |
|
43 | SqpDateTime graphRange() const noexcept; | |
|
44 | void setGraphRange(const SqpDateTime &range); | |
|
45 | ||
|
35 | 46 | // IVisualizationWidget interface |
|
36 | 47 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
37 | 48 | bool canDrop(const Variable &variable) const override; |
|
38 | 49 | bool contains(const Variable &variable) const override; |
|
39 | 50 | QString name() const override; |
|
40 | 51 | |
|
41 | void updateDisplay(std::shared_ptr<Variable> variable); | |
|
42 | 52 | |
|
43 | 53 | signals: |
|
44 | 54 | void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
55 | void synchronize(const SqpDateTime &dateTime, const SqpDateTime &oldDateTime, | |
|
56 | VisualizationGraphWidgetZoomType zoomType); | |
|
45 | 57 | |
|
46 | 58 | |
|
47 | 59 | private: |
@@ -54,10 +66,15 private slots: | |||
|
54 | 66 | /// Slot called when right clicking on the graph (displays a menu) |
|
55 | 67 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
56 | 68 | |
|
57 | void onRangeChanged(const QCPRange &t1); | |
|
69 | /// Rescale the X axe to range parameter | |
|
70 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); | |
|
58 | 71 | |
|
59 | 72 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
60 | 73 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
74 | /// Slot called when a mouse press was made, to activate the calibration of a graph | |
|
75 | void onMousePress(QMouseEvent *event) noexcept; | |
|
76 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph | |
|
77 | void onMouseRelease(QMouseEvent *event) noexcept; | |
|
61 | 78 | |
|
62 | 79 | void onDataCacheVariableUpdated(); |
|
63 | 80 | }; |
@@ -2,6 +2,7 | |||
|
2 | 2 | #define SCIQLOP_VISUALIZATIONWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | #include <Data/SqpDateTime.h> | |
|
5 | 6 | |
|
6 | 7 | #include <QLoggingCategory> |
|
7 | 8 | #include <QWidget> |
@@ -41,6 +42,8 public slots: | |||
|
41 | 42 | /// Slot called when a variable is about to be deleted from SciQlop |
|
42 | 43 | void onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept; |
|
43 | 44 | |
|
45 | void onRangeChanged(std::shared_ptr<Variable> variable, const SqpDateTime &range) noexcept; | |
|
46 | ||
|
44 | 47 | private: |
|
45 | 48 | Ui::VisualizationWidget *ui; |
|
46 | 49 | }; |
@@ -38,11 +38,20 public: | |||
|
38 | 38 | m_VisualizationController.get(), |
|
39 | 39 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
40 | 40 | |
|
41 | connect(m_VariableController.get(), | |
|
42 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), | |
|
43 | m_VisualizationController.get(), | |
|
44 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &))); | |
|
45 | ||
|
41 | 46 | |
|
42 | 47 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
48 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); | |
|
43 | 49 | m_NetworkController->moveToThread(&m_NetworkControllerThread); |
|
50 | m_NetworkControllerThread.setObjectName("NetworkControllerThread"); | |
|
44 | 51 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
52 | m_VariableControllerThread.setObjectName("VariableControllerThread"); | |
|
45 | 53 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
54 | m_VisualizationControllerThread.setObjectName("VsualizationControllerThread"); | |
|
46 | 55 | |
|
47 | 56 | |
|
48 | 57 | // Additionnal init |
@@ -106,11 +115,6 SqpApplication::SqpApplication(int &argc, char **argv) | |||
|
106 | 115 | impl->m_NetworkControllerThread.start(); |
|
107 | 116 | impl->m_VariableControllerThread.start(); |
|
108 | 117 | impl->m_VisualizationControllerThread.start(); |
|
109 | ||
|
110 | // Core connections: | |
|
111 | // NetworkController <-> VariableController | |
|
112 | connect(&sqpApp->networkController(), &NetworkController::replyDownloadProgress, | |
|
113 | &sqpApp->variableController(), &VariableController::onVariableRetrieveDataInProgress); | |
|
114 | 118 | } |
|
115 | 119 | |
|
116 | 120 | SqpApplication::~SqpApplication() |
@@ -5,6 +5,7 | |||
|
5 | 5 | |
|
6 | 6 | #include <ui_VariableInspectorWidget.h> |
|
7 | 7 | |
|
8 | #include <QMouseEvent> | |
|
8 | 9 | #include <QSortFilterProxyModel> |
|
9 | 10 | #include <QStyledItemDelegate> |
|
10 | 11 | #include <QWidgetAction> |
@@ -27,9 +28,12 public: | |||
|
27 | 28 | if (data.isValid() && progressData.isValid()) { |
|
28 | 29 | auto name = data.value<QString>(); |
|
29 | 30 | auto progress = progressData.value<double>(); |
|
30 |
if (progress > |
|
|
31 | if (progress > 0) { | |
|
32 | auto cancelButtonWidth = 20; | |
|
31 | 33 | auto progressBarOption = QStyleOptionProgressBar{}; |
|
32 |
progress |
|
|
34 | auto progressRect = option.rect; | |
|
35 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); | |
|
36 | progressBarOption.rect = progressRect; | |
|
33 | 37 | progressBarOption.minimum = 0; |
|
34 | 38 | progressBarOption.maximum = 100; |
|
35 | 39 | progressBarOption.progress = progress; |
@@ -38,14 +42,69 public: | |||
|
38 | 42 | progressBarOption.textVisible = true; |
|
39 | 43 | progressBarOption.textAlignment = Qt::AlignCenter; |
|
40 | 44 | |
|
45 | ||
|
41 | 46 | QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, |
|
42 | 47 | painter); |
|
48 | ||
|
49 | // Cancel button | |
|
50 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, | |
|
51 | option.rect.height()); | |
|
52 | auto buttonOption = QStyleOptionButton{}; | |
|
53 | buttonOption.rect = buttonRect; | |
|
54 | buttonOption.text = "X"; | |
|
55 | ||
|
56 | QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter); | |
|
57 | } | |
|
58 | else { | |
|
59 | QStyledItemDelegate::paint(painter, option, index); | |
|
43 | 60 | } |
|
44 | 61 | } |
|
45 | 62 | else { |
|
46 | 63 | QStyledItemDelegate::paint(painter, option, index); |
|
47 | 64 | } |
|
48 | 65 | } |
|
66 | ||
|
67 | bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, | |
|
68 | const QModelIndex &index) | |
|
69 | { | |
|
70 | if (event->type() == QEvent::MouseButtonRelease) { | |
|
71 | auto data = index.data(Qt::DisplayRole); | |
|
72 | auto progressData = index.data(VariableRoles::ProgressRole); | |
|
73 | if (data.isValid() && progressData.isValid()) { | |
|
74 | auto cancelButtonWidth = 20; | |
|
75 | auto progressRect = option.rect; | |
|
76 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); | |
|
77 | // Cancel button | |
|
78 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, | |
|
79 | option.rect.height()); | |
|
80 | ||
|
81 | auto e = (QMouseEvent *)event; | |
|
82 | auto clickX = e->x(); | |
|
83 | auto clickY = e->y(); | |
|
84 | ||
|
85 | auto x = buttonRect.left(); // the X coordinate | |
|
86 | auto y = buttonRect.top(); // the Y coordinate | |
|
87 | auto w = buttonRect.width(); // button width | |
|
88 | auto h = buttonRect.height(); // button height | |
|
89 | ||
|
90 | if (clickX > x && clickX < x + w) { | |
|
91 | if (clickY > y && clickY < y + h) { | |
|
92 | auto variableModel = sqpApp->variableController().variableModel(); | |
|
93 | variableModel->abortProgress(index); | |
|
94 | } | |
|
95 | } | |
|
96 | else { | |
|
97 | QStyledItemDelegate::editorEvent(event, model, option, index); | |
|
98 | } | |
|
99 | } | |
|
100 | else { | |
|
101 | QStyledItemDelegate::editorEvent(event, model, option, index); | |
|
102 | } | |
|
103 | } | |
|
104 | else { | |
|
105 | QStyledItemDelegate::editorEvent(event, model, option, index); | |
|
106 | } | |
|
107 | } | |
|
49 | 108 | }; |
|
50 | 109 | |
|
51 | 110 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
@@ -69,7 +69,6 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie | |||
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | // Display all data |
|
72 | component->rescaleAxes(); | |
|
73 | 72 | component->parentPlot()->replot(); |
|
74 | 73 | } |
|
75 | 74 | else { |
@@ -25,8 +25,17 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |||
|
25 | 25 | |
|
26 | 26 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
27 | 27 | |
|
28 | explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize{true}, m_IsCalibration{false} {} | |
|
29 | ||
|
30 | ||
|
31 | // Return the operation when range changed | |
|
32 | VisualizationGraphWidgetZoomType getZoomType(const QCPRange &t1, const QCPRange &t2); | |
|
33 | ||
|
28 | 34 | // 1 variable -> n qcpplot |
|
29 | 35 | std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap; |
|
36 | ||
|
37 | bool m_DoSynchronize; | |
|
38 | bool m_IsCalibration; | |
|
30 | 39 | }; |
|
31 | 40 | |
|
32 | 41 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
@@ -48,10 +57,13 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget | |||
|
48 | 57 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
49 | 58 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
50 | 59 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
60 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
|
61 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
|
62 | &VisualizationGraphWidget::onMouseRelease); | |
|
51 | 63 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
52 | connect(ui->widget->xAxis, | |
|
53 | static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this, | |
|
54 | &VisualizationGraphWidget::onRangeChanged); | |
|
64 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
|
65 | &QCPAxis::rangeChanged), | |
|
66 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
|
55 | 67 | |
|
56 | 68 | // Activates menu when right clicking on the graph |
|
57 | 69 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
@@ -68,6 +80,11 VisualizationGraphWidget::~VisualizationGraphWidget() | |||
|
68 | 80 | delete ui; |
|
69 | 81 | } |
|
70 | 82 | |
|
83 | void VisualizationGraphWidget::enableSynchronize(bool enable) | |
|
84 | { | |
|
85 | impl->m_DoSynchronize = enable; | |
|
86 | } | |
|
87 | ||
|
71 | 88 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
72 | 89 | { |
|
73 | 90 | // Uses delegate to create the qcpplot components according to the variable |
@@ -89,8 +106,8 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> v | |||
|
89 | 106 | |
|
90 | 107 | auto variableDateTimeWithTolerance = dateTime; |
|
91 | 108 | |
|
92 |
// add |
|
|
93 |
auto tolerance = 0. |
|
|
109 | // add 20% tolerance for each side | |
|
110 | auto tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart); | |
|
94 | 111 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
95 | 112 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
96 | 113 | |
@@ -122,6 +139,32 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable | |||
|
122 | 139 | ui->widget->replot(); |
|
123 | 140 | } |
|
124 | 141 | |
|
142 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, | |
|
143 | const SqpDateTime &range) | |
|
144 | { | |
|
145 | // Note: in case of different axes that depends on variable, we could start with a code like | |
|
146 | // that: | |
|
147 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
|
148 | // for (auto it = componentsIt.first; it != componentsIt.second;) { | |
|
149 | // } | |
|
150 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
|
151 | ui->widget->replot(); | |
|
152 | } | |
|
153 | ||
|
154 | SqpDateTime VisualizationGraphWidget::graphRange() const noexcept | |
|
155 | { | |
|
156 | auto grapheRange = ui->widget->xAxis->range(); | |
|
157 | return SqpDateTime{grapheRange.lower, grapheRange.upper}; | |
|
158 | } | |
|
159 | ||
|
160 | void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range) | |
|
161 | { | |
|
162 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
|
163 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
|
164 | ui->widget->replot(); | |
|
165 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
|
166 | } | |
|
167 | ||
|
125 | 168 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
126 | 169 | { |
|
127 | 170 | if (visitor) { |
@@ -175,61 +218,103 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |||
|
175 | 218 | } |
|
176 | 219 | } |
|
177 | 220 | |
|
178 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) | |
|
221 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
|
179 | 222 | { |
|
180 |
qC |
|
|
223 | qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged") | |
|
181 | 224 |
|
|
182 | 225 | |
|
226 | auto dateTimeRange = SqpDateTime{t1.lower, t1.upper}; | |
|
227 | ||
|
228 | auto zoomType = impl->getZoomType(t1, t2); | |
|
183 | 229 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
184 | 230 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
185 | 231 | |
|
186 | 232 | auto variable = it->first; |
|
187 |
auto |
|
|
233 | auto currentDateTime = dateTimeRange; | |
|
188 | 234 | |
|
189 | if (!variable->contains(dateTime)) { | |
|
235 | auto toleranceFactor = 0.2; | |
|
236 | auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
237 | auto variableDateTimeWithTolerance = currentDateTime; | |
|
238 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
|
239 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
|
190 | 240 | |
|
191 | auto variableDateTimeWithTolerance = dateTime; | |
|
192 | if (!variable->isInside(dateTime)) { | |
|
241 | qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime; | |
|
242 | qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance; | |
|
243 | qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime(); | |
|
244 | // If new range with tol is upper than variable datetime parameters. we need to request new | |
|
245 | // data | |
|
246 | if (!variable->contains(variableDateTimeWithTolerance)) { | |
|
247 | ||
|
248 | auto variableDateTimeWithTolerance = currentDateTime; | |
|
249 | if (!variable->isInside(currentDateTime)) { | |
|
193 | 250 | auto variableDateTime = variable->dateTime(); |
|
194 |
if (variable |
|
|
195 |
qCDebug(LOG_VisualizationGraphWidget()) |
|
|
251 | if (variable->contains(variableDateTimeWithTolerance)) { | |
|
252 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
253 | << tr("TORM: Detection zoom in that need request:"); | |
|
254 | // add 10% tolerance for each side | |
|
255 | tolerance | |
|
256 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
257 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
|
258 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
|
259 | } | |
|
260 | else if (variableDateTime.m_TStart < currentDateTime.m_TStart) { | |
|
261 | qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:"); | |
|
196 | 262 | |
|
197 |
auto diffEndToKeepDelta = |
|
|
198 |
|
|
|
263 | auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd; | |
|
264 | currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; | |
|
199 | 265 | // Tolerance have to be added to the right |
|
200 |
// add |
|
|
201 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
|
266 | // add tolerance for right (end) side | |
|
267 | tolerance | |
|
268 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
202 | 269 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
203 | 270 | } |
|
204 |
else if (variableDateTime.m_TEnd > |
|
|
205 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: "); | |
|
206 |
auto diffStartToKeepDelta |
|
|
207 |
|
|
|
271 | else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) { | |
|
272 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: "); | |
|
273 | auto diffStartToKeepDelta | |
|
274 | = variableDateTime.m_TStart - currentDateTime.m_TStart; | |
|
275 | currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; | |
|
208 | 276 | // Tolerance have to be added to the left |
|
209 |
// add |
|
|
210 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
|
277 | // add tolerance for left (start) side | |
|
278 | tolerance | |
|
279 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
211 | 280 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
212 | 281 | } |
|
213 | 282 | else { |
|
214 |
qC |
|
|
283 | qCCritical(LOG_VisualizationGraphWidget()) | |
|
215 | 284 | << tr("Detection anormal zoom detection: "); |
|
216 | 285 | } |
|
217 | 286 | } |
|
218 | 287 | else { |
|
219 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: "); | |
|
288 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: "); | |
|
220 | 289 | // add 10% tolerance for each side |
|
221 |
|
|
|
290 | tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
222 | 291 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
223 | 292 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
293 | zoomType = VisualizationGraphWidgetZoomType::ZoomOut; | |
|
294 | } | |
|
295 | if (!variable->contains(dateTimeRange)) { | |
|
296 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
297 | << "TORM: Modif on variable datetime detected" << currentDateTime; | |
|
298 | variable->setDateTime(currentDateTime); | |
|
224 | 299 | } |
|
225 | variable->setDateTime(dateTime); | |
|
226 | 300 | |
|
301 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: "); | |
|
227 | 302 | // CHangement detected, we need to ask controller to request data loading |
|
228 | 303 | emit requestDataLoading(variable, variableDateTimeWithTolerance); |
|
229 | 304 | } |
|
230 | 305 | else { |
|
231 |
qC |
|
|
306 | qCInfo(LOG_VisualizationGraphWidget()) | |
|
307 | << tr("TORM: Detection zoom in that doesn't need request: "); | |
|
308 | zoomType = VisualizationGraphWidgetZoomType::ZoomIn; | |
|
309 | } | |
|
232 | 310 |
|
|
311 | ||
|
312 | if (impl->m_DoSynchronize && !impl->m_IsCalibration) { | |
|
313 | auto oldDateTime = SqpDateTime{t2.lower, t2.upper}; | |
|
314 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
315 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
|
316 | << QThread::currentThread()->objectName(); | |
|
317 | emit synchronize(dateTimeRange, oldDateTime, zoomType); | |
|
233 | 318 | } |
|
234 | 319 | } |
|
235 | 320 | |
@@ -251,6 +336,16 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |||
|
251 | 336 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
252 | 337 | } |
|
253 | 338 | |
|
339 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
|
340 | { | |
|
341 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); | |
|
342 | } | |
|
343 | ||
|
344 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
|
345 | { | |
|
346 | impl->m_IsCalibration = false; | |
|
347 | } | |
|
348 | ||
|
254 | 349 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
255 | 350 | { |
|
256 | 351 | // NOTE: |
@@ -262,24 +357,45 void VisualizationGraphWidget::onDataCacheVariableUpdated() | |||
|
262 | 357 | // - use an ordered_multimap and the algos of std to group the values by key |
|
263 | 358 | // - use a map (unique keys) and store as values directly the list of components |
|
264 | 359 | |
|
360 | auto grapheRange = ui->widget->xAxis->range(); | |
|
361 | auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper}; | |
|
362 | ||
|
265 | 363 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
266 | 364 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
267 | 365 | auto variable = it->first; |
|
366 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
367 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" | |
|
368 | << variable->dateTime(); | |
|
369 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
370 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
|
371 | if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) { | |
|
372 | ||
|
268 | 373 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, |
|
269 | 374 | variable->dataSeries(), variable->dateTime()); |
|
270 | 375 | } |
|
271 | 376 | } |
|
377 | } | |
|
272 | 378 | |
|
273 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) | |
|
379 | VisualizationGraphWidgetZoomType | |
|
380 | VisualizationGraphWidget::VisualizationGraphWidgetPrivate::getZoomType(const QCPRange &t1, | |
|
381 | const QCPRange &t2) | |
|
274 | 382 | { |
|
275 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
|
276 | ||
|
277 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; | |
|
278 | ||
|
279 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { | |
|
280 | abstractPlotableVect.push_back(it->second); | |
|
383 | // t1.lower <= t2.lower && t2.upper <= t1.upper | |
|
384 | auto zoomType = VisualizationGraphWidgetZoomType::Unknown; | |
|
385 | if (t1.lower <= t2.lower && t2.upper <= t1.upper) { | |
|
386 | zoomType = VisualizationGraphWidgetZoomType::ZoomOut; | |
|
281 | 387 | } |
|
282 | ||
|
283 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), | |
|
284 | variable->dateTime()); | |
|
388 | else if (t1.lower > t2.lower && t1.upper > t2.upper) { | |
|
389 | zoomType = VisualizationGraphWidgetZoomType::PanRight; | |
|
390 | } | |
|
391 | else if (t1.lower < t2.lower && t1.upper < t2.upper) { | |
|
392 | zoomType = VisualizationGraphWidgetZoomType::PanLeft; | |
|
393 | } | |
|
394 | else if (t1.lower > t2.lower && t2.upper > t1.upper) { | |
|
395 | zoomType = VisualizationGraphWidgetZoomType::ZoomIn; | |
|
396 | } | |
|
397 | else { | |
|
398 | qCCritical(LOG_VisualizationGraphWidget()) << "getZoomType: Unknown type detected"; | |
|
399 | } | |
|
400 | return zoomType; | |
|
285 | 401 | } |
@@ -5,6 +5,7 | |||
|
5 | 5 | #include "Visualization/VisualizationZoneWidget.h" |
|
6 | 6 | #include "Visualization/operations/GenerateVariableMenuOperation.h" |
|
7 | 7 | #include "Visualization/operations/RemoveVariableOperation.h" |
|
8 | #include "Visualization/operations/RescaleAxeOperation.h" | |
|
8 | 9 | #include "Visualization/qcustomplot.h" |
|
9 | 10 | |
|
10 | 11 | #include "ui_VisualizationWidget.h" |
@@ -141,3 +142,11 void VisualizationWidget::onVariableAboutToBeDeleted(std::shared_ptr<Variable> v | |||
|
141 | 142 | auto removeVariableOperation = RemoveVariableOperation{variable}; |
|
142 | 143 | accept(&removeVariableOperation); |
|
143 | 144 | } |
|
145 | ||
|
146 | void VisualizationWidget::onRangeChanged(std::shared_ptr<Variable> variable, | |
|
147 | const SqpDateTime &range) noexcept | |
|
148 | { | |
|
149 | // Calls the operation of rescaling all graph that contrains variable in the visualization | |
|
150 | auto rescaleVariableOperation = RescaleAxeOperation{variable, range}; | |
|
151 | accept(&rescaleVariableOperation); | |
|
152 | } |
@@ -1,8 +1,11 | |||
|
1 | 1 | #include "Visualization/VisualizationZoneWidget.h" |
|
2 | ||
|
3 | #include "Data/SqpDateTime.h" | |
|
4 | ||
|
2 | 5 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
6 | #include "Visualization/VisualizationGraphWidget.h" | |
|
3 | 7 | #include "ui_VisualizationZoneWidget.h" |
|
4 | 8 | |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
|
6 | 9 | |
|
7 | 10 | #include <SqpApplication.h> |
|
8 | 11 | |
@@ -57,6 +60,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
57 | 60 | auto graphWidget = new VisualizationGraphWidget{ |
|
58 | 61 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
59 | 62 | |
|
63 | ||
|
60 | 64 | // Set graph properties |
|
61 | 65 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
62 | 66 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
@@ -65,6 +69,91 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
65 | 69 | |
|
66 | 70 | graphWidget->addVariable(variable); |
|
67 | 71 | |
|
72 | // Lambda to synchronize zone widget | |
|
73 | auto synchronizeZoneWidget = [this, graphWidget](const SqpDateTime &dateTime, | |
|
74 | const SqpDateTime &oldDateTime, | |
|
75 | VisualizationGraphWidgetZoomType zoomType) { | |
|
76 | auto frameLayout = ui->visualizationZoneFrame->layout(); | |
|
77 | for (auto i = 0; i < frameLayout->count(); ++i) { | |
|
78 | auto graphChild | |
|
79 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); | |
|
80 | if (graphChild && (graphChild != graphWidget)) { | |
|
81 | ||
|
82 | auto graphChildRange = graphChild->graphRange(); | |
|
83 | switch (zoomType) { | |
|
84 | case VisualizationGraphWidgetZoomType::ZoomIn: { | |
|
85 | auto deltaLeft = dateTime.m_TStart - oldDateTime.m_TStart; | |
|
86 | auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd; | |
|
87 | graphChildRange.m_TStart += deltaLeft; | |
|
88 | graphChildRange.m_TEnd -= deltaRight; | |
|
89 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); | |
|
90 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
|
91 | << deltaLeft; | |
|
92 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
|
93 | << deltaRight; | |
|
94 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
95 | << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart; | |
|
96 | ||
|
97 | break; | |
|
98 | } | |
|
99 | ||
|
100 | case VisualizationGraphWidgetZoomType::ZoomOut: { | |
|
101 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); | |
|
102 | auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart; | |
|
103 | auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd; | |
|
104 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
|
105 | << deltaLeft; | |
|
106 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
|
107 | << deltaRight; | |
|
108 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
109 | << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart; | |
|
110 | graphChildRange.m_TStart -= deltaLeft; | |
|
111 | graphChildRange.m_TEnd += deltaRight; | |
|
112 | break; | |
|
113 | } | |
|
114 | case VisualizationGraphWidgetZoomType::PanRight: { | |
|
115 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); | |
|
116 | auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd; | |
|
117 | graphChildRange.m_TStart += deltaRight; | |
|
118 | graphChildRange.m_TEnd += deltaRight; | |
|
119 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
120 | << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart; | |
|
121 | break; | |
|
122 | } | |
|
123 | case VisualizationGraphWidgetZoomType::PanLeft: { | |
|
124 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); | |
|
125 | auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart; | |
|
126 | graphChildRange.m_TStart -= deltaLeft; | |
|
127 | graphChildRange.m_TEnd -= deltaLeft; | |
|
128 | break; | |
|
129 | } | |
|
130 | case VisualizationGraphWidgetZoomType::Unknown: { | |
|
131 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
132 | << tr("Impossible to synchronize: zoom type unknown"); | |
|
133 | break; | |
|
134 | } | |
|
135 | default: | |
|
136 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
137 | << tr("Impossible to synchronize: zoom type not take into account"); | |
|
138 | // No action | |
|
139 | break; | |
|
140 | } | |
|
141 | graphChild->enableSynchronize(false); | |
|
142 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") | |
|
143 | << graphChild->graphRange(); | |
|
144 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") | |
|
145 | << graphChildRange; | |
|
146 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
147 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; | |
|
148 | graphChild->setGraphRange(graphChildRange); | |
|
149 | graphChild->enableSynchronize(true); | |
|
150 | } | |
|
151 | } | |
|
152 | }; | |
|
153 | ||
|
154 | // connection for synchronization | |
|
155 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); | |
|
156 | ||
|
68 | 157 | return graphWidget; |
|
69 | 158 | } |
|
70 | 159 |
@@ -21,6 +21,8 public: | |||
|
21 | 21 | |
|
22 | 22 | void requestDataLoading(QUuid token, const DataProviderParameters ¶meters) override; |
|
23 | 23 | |
|
24 | void requestDataAborting(QUuid identifier) override; | |
|
25 | ||
|
24 | 26 | private: |
|
25 | 27 | void retrieveData(QUuid token, const SqpDateTime &dateTime, const QVariantHash &data); |
|
26 | 28 | }; |
@@ -26,7 +26,7 const auto AMDA_URL_FORMAT = QStringLiteral( | |||
|
26 | 26 | "timeFormat=ISO8601&gzip=0"); |
|
27 | 27 | |
|
28 | 28 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) |
|
29 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:ss"); | |
|
29 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); | |
|
30 | 30 | |
|
31 | 31 | /// Formats a time to a date that can be passed in URL |
|
32 | 32 | QString dateFormat(double sqpDateTime) noexcept |
@@ -48,6 +48,10 AmdaProvider::AmdaProvider() | |||
|
48 | 48 | &networkController, |
|
49 | 49 | SLOT(onProcessRequested(QNetworkRequest, QUuid, |
|
50 | 50 | std::function<void(QNetworkReply *, QUuid)>))); |
|
51 | ||
|
52 | ||
|
53 | connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this, | |
|
54 | SIGNAL(dataProvidedProgress(QUuid, double))); | |
|
51 | 55 | } |
|
52 | 56 | } |
|
53 | 57 | |
@@ -61,6 +65,14 void AmdaProvider::requestDataLoading(QUuid token, const DataProviderParameters | |||
|
61 | 65 | } |
|
62 | 66 | } |
|
63 | 67 | |
|
68 | void AmdaProvider::requestDataAborting(QUuid identifier) | |
|
69 | { | |
|
70 | if (auto app = sqpApp) { | |
|
71 | auto &networkController = app->networkController(); | |
|
72 | networkController.onReplyCanceled(identifier); | |
|
73 | } | |
|
74 | } | |
|
75 | ||
|
64 | 76 | void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const QVariantHash &data) |
|
65 | 77 | { |
|
66 | 78 | // Retrieves product ID from data: if the value is invalid, no request is made |
@@ -69,6 +81,7 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const | |||
|
69 | 81 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id"); |
|
70 | 82 | return; |
|
71 | 83 | } |
|
84 | qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime; | |
|
72 | 85 | |
|
73 | 86 | // /////////// // |
|
74 | 87 | // Creates URL // |
@@ -78,7 +91,7 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const | |||
|
78 | 91 | auto endDate = dateFormat(dateTime.m_TEnd); |
|
79 | 92 | |
|
80 | 93 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; |
|
81 | ||
|
94 | qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData url:") << url; | |
|
82 | 95 | auto tempFile = std::make_shared<QTemporaryFile>(); |
|
83 | 96 | |
|
84 | 97 | // LAMBDA |
@@ -86,6 +99,9 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const | |||
|
86 | 99 | = [this, dateTime, tempFile, token](QNetworkReply *reply, QUuid dataId) noexcept { |
|
87 | 100 | Q_UNUSED(dataId); |
|
88 | 101 | |
|
102 | // Don't do anything if the reply was abort | |
|
103 | if (reply->error() != QNetworkReply::OperationCanceledError) { | |
|
104 | ||
|
89 | 105 | if (tempFile) { |
|
90 | 106 | auto replyReadAll = reply->readAll(); |
|
91 | 107 | if (!replyReadAll.isEmpty()) { |
@@ -101,24 +117,27 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const | |||
|
101 | 117 | /// @todo ALX : debug |
|
102 | 118 | } |
|
103 | 119 | } |
|
120 | } | |
|
104 | 121 | |
|
105 | // Deletes reply | |
|
106 | reply->deleteLater(); | |
|
107 | reply = nullptr; | |
|
108 | 122 | }; |
|
109 | auto httpFinishedLambda = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, | |
|
110 | QUuid dataId) noexcept { | |
|
123 | auto httpFinishedLambda | |
|
124 | = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { | |
|
111 | 125 | |
|
126 | // Don't do anything if the reply was abort | |
|
127 | if (reply->error() != QNetworkReply::OperationCanceledError) { | |
|
112 | 128 | auto downloadFileUrl = QUrl{QString{reply->readAll()}}; |
|
113 | // Deletes old reply | |
|
114 | reply->deleteLater(); | |
|
115 | 129 | |
|
130 | ||
|
131 | qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData downloadFileUrl:") | |
|
132 | << downloadFileUrl; | |
|
116 | 133 | // Executes request for downloading file // |
|
117 | 134 | |
|
118 | 135 | // Creates destination file |
|
119 | 136 | if (tempFile->open()) { |
|
120 | 137 | // Executes request |
|
121 |
emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId, |
|
|
138 | emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId, | |
|
139 | httpDownloadFinished); | |
|
140 | } | |
|
122 | 141 | } |
|
123 | 142 | }; |
|
124 | 143 |
@@ -12,6 +12,9 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") | |||
|
12 | 12 | |
|
13 | 13 | namespace { |
|
14 | 14 | |
|
15 | /// Message in result file when the file was not found on server | |
|
16 | const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found"); | |
|
17 | ||
|
15 | 18 | /// Format for dates in result files |
|
16 | 19 | const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); |
|
17 | 20 | |
@@ -119,8 +122,16 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) | |||
|
119 | 122 | |
|
120 | 123 | QTextStream stream{&file}; |
|
121 | 124 | |
|
122 | // Ignore first two lines (comments lines) | |
|
123 | stream.readLine(); | |
|
125 | // Checks if the file was found on the server | |
|
126 | auto firstLine = stream.readLine(); | |
|
127 | if (firstLine.compare(FILE_NOT_FOUND_MESSAGE) == 0) { | |
|
128 | qCCritical(LOG_AmdaResultParser()) | |
|
129 | << QObject::tr("Can't retrieve AMDA data from file %1: file was not found on server") | |
|
130 | .arg(filePath); | |
|
131 | return nullptr; | |
|
132 | } | |
|
133 | ||
|
134 | // Ignore comments lines | |
|
124 | 135 | stream.readLine(); |
|
125 | 136 | |
|
126 | 137 | // Reads x-axis unit |
@@ -155,9 +155,12 void TestAmdaResultParser::testReadTxt_data() | |||
|
155 | 155 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, |
|
156 | 156 | QVector<double>{-2.71850, -2.52150}}; |
|
157 | 157 | |
|
158 | // Invalid file | |
|
158 | // Invalid files | |
|
159 | 159 | QTest::newRow("Invalid file (unexisting file)") << QStringLiteral("UnexistingFile.txt") |
|
160 | 160 | << ExpectedResults{}; |
|
161 | ||
|
162 | QTest::newRow("Invalid file (file not found on server)") << QStringLiteral("FileNotFound.txt") | |
|
163 | << ExpectedResults{}; | |
|
161 | 164 | } |
|
162 | 165 | |
|
163 | 166 | void TestAmdaResultParser::testReadTxt() |
@@ -6,7 +6,9 | |||
|
6 | 6 | #include <Data/IDataProvider.h> |
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | #include <QUuid> | |
|
9 | 10 | |
|
11 | #include <QHash> | |
|
10 | 12 | Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) |
|
11 | 13 | |
|
12 | 14 | /** |
@@ -14,12 +16,18 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) | |||
|
14 | 16 | */ |
|
15 | 17 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { |
|
16 | 18 | public: |
|
19 | /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe. | |
|
17 | 20 | void requestDataLoading(QUuid token, const DataProviderParameters ¶meters) override; |
|
18 | 21 | |
|
19 | 22 | |
|
23 | /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe. | |
|
24 | void requestDataAborting(QUuid identifier) override; | |
|
25 | ||
|
26 | ||
|
20 | 27 | private: |
|
21 | /// @sa IDataProvider::retrieveData() | |
|
22 | std::shared_ptr<IDataSeries> retrieveData(const SqpDateTime &dateTime) const; | |
|
28 | std::shared_ptr<IDataSeries> retrieveData(QUuid token, const SqpDateTime &dateTime); | |
|
29 | ||
|
30 | QHash<QUuid, bool> m_VariableToEnableProvider; | |
|
23 | 31 | }; |
|
24 | 32 | |
|
25 | 33 | #endif // SCIQLOP_COSINUSPROVIDER_H |
@@ -6,12 +6,15 | |||
|
6 | 6 | #include <cmath> |
|
7 | 7 | |
|
8 | 8 | #include <QDateTime> |
|
9 | #include <QFuture> | |
|
9 | 10 | #include <QThread> |
|
11 | #include <QtConcurrent/QtConcurrent> | |
|
10 | 12 | |
|
11 | 13 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
12 | 14 | |
|
13 |
std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(const SqpDateTime &dateTime) |
|
|
15 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid token, const SqpDateTime &dateTime) | |
|
14 | 16 | { |
|
17 | // TODO: Add Mutex | |
|
15 | 18 | auto dataIndex = 0; |
|
16 | 19 | |
|
17 | 20 | // Gets the timerange from the parameters |
@@ -28,21 +31,65 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(const SqpDateTime &da | |||
|
28 | 31 | auto scalarSeries |
|
29 | 32 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
30 | 33 | |
|
34 | ||
|
35 | int progress = 0; | |
|
36 | auto progressEnd = end - start; | |
|
31 | 37 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
38 | auto it = m_VariableToEnableProvider.find(token); | |
|
39 | if (it != m_VariableToEnableProvider.end() && it.value()) { | |
|
32 | 40 | const auto timeOnFreq = time / freq; |
|
33 | 41 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); |
|
42 | ||
|
43 | // progression | |
|
44 | int currentProgress = (time - start) * 100.0 / progressEnd; | |
|
45 | if (currentProgress != progress) { | |
|
46 | progress = currentProgress; | |
|
47 | ||
|
48 | emit dataProvidedProgress(token, progress); | |
|
49 | } | |
|
50 | } | |
|
51 | else { | |
|
52 | if (!it.value()) { | |
|
53 | qCDebug(LOG_CosinusProvider()) | |
|
54 | << "CosinusProvider::retrieveData: ARRET De l'acquisition detecté" | |
|
55 | << end - time; | |
|
34 | 56 | } |
|
57 | } | |
|
58 | } | |
|
59 | emit dataProvidedProgress(token, 0.0); | |
|
60 | ||
|
61 | ||
|
35 | 62 | return scalarSeries; |
|
36 | 63 | } |
|
37 | 64 | |
|
38 | 65 | void CosinusProvider::requestDataLoading(QUuid token, const DataProviderParameters ¶meters) |
|
39 | 66 | { |
|
67 | // TODO: Add Mutex | |
|
68 | m_VariableToEnableProvider[token] = true; | |
|
40 | 69 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" |
|
41 | 70 | << QThread::currentThread()->objectName(); |
|
42 | 71 | // NOTE: Try to use multithread if possible |
|
43 | 72 | const auto times = parameters.m_Times; |
|
73 | ||
|
44 | 74 | for (const auto &dateTime : qAsConst(times)) { |
|
45 | auto scalarSeries = this->retrieveData(dateTime); | |
|
75 | if (m_VariableToEnableProvider[token]) { | |
|
76 | auto scalarSeries = this->retrieveData(token, dateTime); | |
|
46 | 77 | emit dataProvided(token, scalarSeries, dateTime); |
|
47 | 78 | } |
|
48 | 79 | } |
|
80 | } | |
|
81 | ||
|
82 | void CosinusProvider::requestDataAborting(QUuid identifier) | |
|
83 | { | |
|
84 | // TODO: Add Mutex | |
|
85 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << identifier | |
|
86 | << QThread::currentThread()->objectName(); | |
|
87 | auto it = m_VariableToEnableProvider.find(identifier); | |
|
88 | if (it != m_VariableToEnableProvider.end()) { | |
|
89 | it.value() = false; | |
|
90 | } | |
|
91 | else { | |
|
92 | qCWarning(LOG_CosinusProvider()) | |
|
93 | << tr("Aborting progression of inexistant identifier detected !!!"); | |
|
94 | } | |
|
95 | } |
General Comments 0
You need to be logged in to leave comments.
Login now