##// END OF EJS Templates
Merge pull request 292 from SCIQLOP-Initialisation develop...
leroux -
r765:a6dacc853f4a merge
parent child
Show More
@@ -1,108 +1,112
1 #ifndef SCIQLOP_SQPITERATOR_H
1 #ifndef SCIQLOP_SQPITERATOR_H
2 #define SCIQLOP_SQPITERATOR_H
2 #define SCIQLOP_SQPITERATOR_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 /**
6 /**
7 * @brief The SqpIterator class represents an iterator used in SciQlop. It defines all operators
7 * @brief The SqpIterator class represents an iterator used in SciQlop. It defines all operators
8 * needed for a standard forward iterator
8 * needed for a standard forward iterator
9 * @tparam T the type of object handled in iterator
9 * @tparam T the type of object handled in iterator
10 * @sa http://www.cplusplus.com/reference/iterator/
10 * @sa http://www.cplusplus.com/reference/iterator/
11 */
11 */
12 template <typename T>
12 template <typename T>
13 class SCIQLOP_CORE_EXPORT SqpIterator {
13 class SCIQLOP_CORE_EXPORT SqpIterator {
14 public:
14 public:
15 using iterator_category = std::random_access_iterator_tag;
15 using iterator_category = std::random_access_iterator_tag;
16 using value_type = const T;
16 using value_type = const T;
17 using difference_type = std::ptrdiff_t;
17 using difference_type = std::ptrdiff_t;
18 using pointer = value_type *;
18 using pointer = value_type *;
19 using reference = value_type &;
19 using reference = value_type &;
20
20
21 explicit SqpIterator(T value) : m_CurrentValue{std::move(value)} {}
21 explicit SqpIterator(T value) : m_CurrentValue{std::move(value)} {}
22
22
23 virtual ~SqpIterator() noexcept = default;
23 virtual ~SqpIterator() noexcept = default;
24 SqpIterator(const SqpIterator &) = default;
24 SqpIterator(const SqpIterator &) = default;
25 SqpIterator &operator=(SqpIterator other) { swap(m_CurrentValue, other.m_CurrentValue); }
25 SqpIterator &operator=(SqpIterator other)
26 {
27 swap(m_CurrentValue, other.m_CurrentValue);
28 return *this;
29 }
26
30
27 SqpIterator &operator++()
31 SqpIterator &operator++()
28 {
32 {
29 m_CurrentValue.next();
33 m_CurrentValue.next();
30 return *this;
34 return *this;
31 }
35 }
32
36
33 SqpIterator &operator--()
37 SqpIterator &operator--()
34 {
38 {
35 m_CurrentValue.prev();
39 m_CurrentValue.prev();
36 return *this;
40 return *this;
37 }
41 }
38
42
39 SqpIterator operator++(int)const
43 SqpIterator operator++(int)const
40 {
44 {
41 auto result = *this;
45 auto result = *this;
42 this->operator++();
46 this->operator++();
43 return result;
47 return result;
44 }
48 }
45 SqpIterator operator--(int)const
49 SqpIterator operator--(int)const
46 {
50 {
47 auto result = *this;
51 auto result = *this;
48 this->operator--();
52 this->operator--();
49 return result;
53 return result;
50 }
54 }
51
55
52 SqpIterator &operator+=(int offset)
56 SqpIterator &operator+=(int offset)
53 {
57 {
54 if (offset >= 0) {
58 if (offset >= 0) {
55 m_CurrentValue.next(offset);
59 m_CurrentValue.next(offset);
56 }
60 }
57 else {
61 else {
58 while (offset++) {
62 while (offset++) {
59 m_CurrentValue.prev();
63 m_CurrentValue.prev();
60 }
64 }
61 }
65 }
62
66
63 return *this;
67 return *this;
64 }
68 }
65 SqpIterator &operator-=(int offset) { return *this += -offset; }
69 SqpIterator &operator-=(int offset) { return *this += -offset; }
66
70
67 SqpIterator operator+(int offset) const
71 SqpIterator operator+(int offset) const
68 {
72 {
69 auto result = *this;
73 auto result = *this;
70 result += offset;
74 result += offset;
71 return result;
75 return result;
72 }
76 }
73 SqpIterator operator-(int offset) const
77 SqpIterator operator-(int offset) const
74 {
78 {
75 auto result = *this;
79 auto result = *this;
76 result -= offset;
80 result -= offset;
77 return result;
81 return result;
78 }
82 }
79
83
80 int operator-(const SqpIterator &other) const
84 int operator-(const SqpIterator &other) const
81 {
85 {
82 return m_CurrentValue.distance(other.m_CurrentValue);
86 return m_CurrentValue.distance(other.m_CurrentValue);
83 }
87 }
84
88
85 const T *operator->() const { return &m_CurrentValue; }
89 const T *operator->() const { return &m_CurrentValue; }
86 const T &operator*() const { return m_CurrentValue; }
90 const T &operator*() const { return m_CurrentValue; }
87 T *operator->() { return &m_CurrentValue; }
91 T *operator->() { return &m_CurrentValue; }
88 T &operator*() { return m_CurrentValue; }
92 T &operator*() { return m_CurrentValue; }
89 T &operator[](int offset) const { return m_CurrentValue.advance(offset); }
93 T &operator[](int offset) const { return m_CurrentValue.advance(offset); }
90
94
91 bool operator==(const SqpIterator &other) const
95 bool operator==(const SqpIterator &other) const
92 {
96 {
93 return m_CurrentValue.equals(other.m_CurrentValue);
97 return m_CurrentValue.equals(other.m_CurrentValue);
94 }
98 }
95 bool operator!=(const SqpIterator &other) const { return !(*this == other); }
99 bool operator!=(const SqpIterator &other) const { return !(*this == other); }
96 bool operator>(const SqpIterator &other) const { return other.m_CurrentValue.lowerThan(*this); }
100 bool operator>(const SqpIterator &other) const { return other.m_CurrentValue.lowerThan(*this); }
97 bool operator<(const SqpIterator &other) const
101 bool operator<(const SqpIterator &other) const
98 {
102 {
99 return m_CurrentValue.lowerThan(other.m_CurrentValue);
103 return m_CurrentValue.lowerThan(other.m_CurrentValue);
100 }
104 }
101 bool operator>=(const SqpIterator &other) const { return !(*this < other); }
105 bool operator>=(const SqpIterator &other) const { return !(*this < other); }
102 bool operator<=(const SqpIterator &other) const { return !(*this > other); }
106 bool operator<=(const SqpIterator &other) const { return !(*this > other); }
103
107
104 private:
108 private:
105 T m_CurrentValue;
109 T m_CurrentValue;
106 };
110 };
107
111
108 #endif // SCIQLOP_SQPITERATOR_H
112 #endif // SCIQLOP_SQPITERATOR_H
@@ -1,84 +1,83
1 #include "Data/DataSeriesIterator.h"
1 #include "Data/DataSeriesIterator.h"
2
2
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
5 : m_Impl{std::move(impl)}
5 : m_Impl{std::move(impl)}
6 {
6 {
7 }
7 }
8
8
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
10 : m_Impl{other.m_Impl->clone()}
10 : m_Impl{other.m_Impl->clone()}
11 {
11 {
12 }
12 }
13
13
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
15 {
15 {
16 m_Impl->swap(*other.m_Impl);
16 m_Impl->swap(*other.m_Impl);
17 return *this;
17 return *this;
18 }
18 }
19
19
20 int DataSeriesIteratorValue::distance(const DataSeriesIteratorValue &other) const
20 int DataSeriesIteratorValue::distance(const DataSeriesIteratorValue &other) const
21 {
21 {
22 auto dist = m_Impl->distance(*other.m_Impl);
23 return m_Impl->distance(*other.m_Impl);
22 return m_Impl->distance(*other.m_Impl);
24 }
23 }
25
24
26 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
25 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
27 {
26 {
28 return m_Impl->equals(*other.m_Impl);
27 return m_Impl->equals(*other.m_Impl);
29 }
28 }
30
29
31 bool DataSeriesIteratorValue::lowerThan(const DataSeriesIteratorValue &other) const
30 bool DataSeriesIteratorValue::lowerThan(const DataSeriesIteratorValue &other) const
32 {
31 {
33 return m_Impl->lowerThan(*other.m_Impl);
32 return m_Impl->lowerThan(*other.m_Impl);
34 }
33 }
35
34
36 DataSeriesIteratorValue DataSeriesIteratorValue::advance(int offset) const
35 DataSeriesIteratorValue DataSeriesIteratorValue::advance(int offset) const
37 {
36 {
38 return DataSeriesIteratorValue{m_Impl->advance(offset)};
37 return DataSeriesIteratorValue{m_Impl->advance(offset)};
39 }
38 }
40
39
41 void DataSeriesIteratorValue::next(int offset)
40 void DataSeriesIteratorValue::next(int offset)
42 {
41 {
43 m_Impl->next(offset);
42 m_Impl->next(offset);
44 }
43 }
45
44
46 void DataSeriesIteratorValue::prev()
45 void DataSeriesIteratorValue::prev()
47 {
46 {
48 m_Impl->prev();
47 m_Impl->prev();
49 }
48 }
50
49
51 double DataSeriesIteratorValue::x() const
50 double DataSeriesIteratorValue::x() const
52 {
51 {
53 return m_Impl->x();
52 return m_Impl->x();
54 }
53 }
55
54
56 double DataSeriesIteratorValue::value() const
55 double DataSeriesIteratorValue::value() const
57 {
56 {
58 return m_Impl->value();
57 return m_Impl->value();
59 }
58 }
60
59
61 double DataSeriesIteratorValue::value(int componentIndex) const
60 double DataSeriesIteratorValue::value(int componentIndex) const
62 {
61 {
63 return m_Impl->value(componentIndex);
62 return m_Impl->value(componentIndex);
64 }
63 }
65
64
66 double DataSeriesIteratorValue::minValue() const
65 double DataSeriesIteratorValue::minValue() const
67 {
66 {
68 return m_Impl->minValue();
67 return m_Impl->minValue();
69 }
68 }
70
69
71 double DataSeriesIteratorValue::maxValue() const
70 double DataSeriesIteratorValue::maxValue() const
72 {
71 {
73 return m_Impl->maxValue();
72 return m_Impl->maxValue();
74 }
73 }
75
74
76 QVector<double> DataSeriesIteratorValue::values() const
75 QVector<double> DataSeriesIteratorValue::values() const
77 {
76 {
78 return m_Impl->values();
77 return m_Impl->values();
79 }
78 }
80
79
81 DataSeriesIteratorValue::Impl *DataSeriesIteratorValue::impl()
80 DataSeriesIteratorValue::Impl *DataSeriesIteratorValue::impl()
82 {
81 {
83 return m_Impl.get();
82 return m_Impl.get();
84 }
83 }
@@ -1,834 +1,839
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableAcquisitionWorker.h>
2 #include <Variable/VariableAcquisitionWorker.h>
3 #include <Variable/VariableCacheStrategy.h>
3 #include <Variable/VariableCacheStrategy.h>
4 #include <Variable/VariableController.h>
4 #include <Variable/VariableController.h>
5 #include <Variable/VariableModel.h>
5 #include <Variable/VariableModel.h>
6 #include <Variable/VariableSynchronizationGroup.h>
6 #include <Variable/VariableSynchronizationGroup.h>
7
7
8 #include <Data/DataProviderParameters.h>
8 #include <Data/DataProviderParameters.h>
9 #include <Data/IDataProvider.h>
9 #include <Data/IDataProvider.h>
10 #include <Data/IDataSeries.h>
10 #include <Data/IDataSeries.h>
11 #include <Data/VariableRequest.h>
11 #include <Data/VariableRequest.h>
12 #include <Time/TimeController.h>
12 #include <Time/TimeController.h>
13
13
14 #include <QMutex>
14 #include <QMutex>
15 #include <QThread>
15 #include <QThread>
16 #include <QUuid>
16 #include <QUuid>
17 #include <QtCore/QItemSelectionModel>
17 #include <QtCore/QItemSelectionModel>
18
18
19 #include <deque>
19 #include <deque>
20 #include <set>
20 #include <set>
21 #include <unordered_map>
21 #include <unordered_map>
22
22
23 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
23 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
24
24
25 namespace {
25 namespace {
26
26
27 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
27 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
28 const SqpRange &oldGraphRange)
28 const SqpRange &oldGraphRange)
29 {
29 {
30 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
30 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
31
31
32 auto varRangeRequested = varRange;
32 auto varRangeRequested = varRange;
33 switch (zoomType) {
33 switch (zoomType) {
34 case AcquisitionZoomType::ZoomIn: {
34 case AcquisitionZoomType::ZoomIn: {
35 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
35 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
36 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
36 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
37 varRangeRequested.m_TStart += deltaLeft;
37 varRangeRequested.m_TStart += deltaLeft;
38 varRangeRequested.m_TEnd -= deltaRight;
38 varRangeRequested.m_TEnd -= deltaRight;
39 break;
39 break;
40 }
40 }
41
41
42 case AcquisitionZoomType::ZoomOut: {
42 case AcquisitionZoomType::ZoomOut: {
43 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
43 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
44 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
44 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
45 varRangeRequested.m_TStart -= deltaLeft;
45 varRangeRequested.m_TStart -= deltaLeft;
46 varRangeRequested.m_TEnd += deltaRight;
46 varRangeRequested.m_TEnd += deltaRight;
47 break;
47 break;
48 }
48 }
49 case AcquisitionZoomType::PanRight: {
49 case AcquisitionZoomType::PanRight: {
50 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
50 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
51 varRangeRequested.m_TStart += deltaRight;
51 varRangeRequested.m_TStart += deltaRight;
52 varRangeRequested.m_TEnd += deltaRight;
52 varRangeRequested.m_TEnd += deltaRight;
53 break;
53 break;
54 }
54 }
55 case AcquisitionZoomType::PanLeft: {
55 case AcquisitionZoomType::PanLeft: {
56 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
56 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
57 varRangeRequested.m_TStart -= deltaLeft;
57 varRangeRequested.m_TStart -= deltaLeft;
58 varRangeRequested.m_TEnd -= deltaLeft;
58 varRangeRequested.m_TEnd -= deltaLeft;
59 break;
59 break;
60 }
60 }
61 case AcquisitionZoomType::Unknown: {
61 case AcquisitionZoomType::Unknown: {
62 qCCritical(LOG_VariableController())
62 qCCritical(LOG_VariableController())
63 << VariableController::tr("Impossible to synchronize: zoom type unknown");
63 << VariableController::tr("Impossible to synchronize: zoom type unknown");
64 break;
64 break;
65 }
65 }
66 default:
66 default:
67 qCCritical(LOG_VariableController()) << VariableController::tr(
67 qCCritical(LOG_VariableController()) << VariableController::tr(
68 "Impossible to synchronize: zoom type not take into account");
68 "Impossible to synchronize: zoom type not take into account");
69 // No action
69 // No action
70 break;
70 break;
71 }
71 }
72
72
73 return varRangeRequested;
73 return varRangeRequested;
74 }
74 }
75 }
75 }
76
76
77 struct VariableController::VariableControllerPrivate {
77 struct VariableController::VariableControllerPrivate {
78 explicit VariableControllerPrivate(VariableController *parent)
78 explicit VariableControllerPrivate(VariableController *parent)
79 : m_WorkingMutex{},
79 : m_WorkingMutex{},
80 m_VariableModel{new VariableModel{parent}},
80 m_VariableModel{new VariableModel{parent}},
81 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
81 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
84 q{parent}
84 q{parent}
85 {
85 {
86
86
87 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
87 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
88 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
88 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
89 }
89 }
90
90
91
91
92 virtual ~VariableControllerPrivate()
92 virtual ~VariableControllerPrivate()
93 {
93 {
94 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
94 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
95 m_VariableAcquisitionWorkerThread.quit();
95 m_VariableAcquisitionWorkerThread.quit();
96 m_VariableAcquisitionWorkerThread.wait();
96 m_VariableAcquisitionWorkerThread.wait();
97 }
97 }
98
98
99
99
100 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
100 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
101 QUuid varRequestId);
101 QUuid varRequestId);
102
102
103 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
103 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
104 const SqpRange &dateTime);
104 const SqpRange &dateTime);
105
105
106 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
106 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
107 std::shared_ptr<IDataSeries>
107 std::shared_ptr<IDataSeries>
108 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
108 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
109
109
110 void registerProvider(std::shared_ptr<IDataProvider> provider);
110 void registerProvider(std::shared_ptr<IDataProvider> provider);
111
111
112 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
112 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
113 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
113 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
114 void updateVariableRequest(QUuid varRequestId);
114 void updateVariableRequest(QUuid varRequestId);
115 void cancelVariableRequest(QUuid varRequestId);
115 void cancelVariableRequest(QUuid varRequestId);
116
116
117 QMutex m_WorkingMutex;
117 QMutex m_WorkingMutex;
118 /// Variable model. The VariableController has the ownership
118 /// Variable model. The VariableController has the ownership
119 VariableModel *m_VariableModel;
119 VariableModel *m_VariableModel;
120 QItemSelectionModel *m_VariableSelectionModel;
120 QItemSelectionModel *m_VariableSelectionModel;
121
121
122
122
123 TimeController *m_TimeController{nullptr};
123 TimeController *m_TimeController{nullptr};
124 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
124 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
125 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
125 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
126 QThread m_VariableAcquisitionWorkerThread;
126 QThread m_VariableAcquisitionWorkerThread;
127
127
128 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
128 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
129 m_VariableToProviderMap;
129 m_VariableToProviderMap;
130 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
130 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
131 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
131 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
132 m_GroupIdToVariableSynchronizationGroupMap;
132 m_GroupIdToVariableSynchronizationGroupMap;
133 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
133 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
134 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
134 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
135
135
136 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
136 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
137
137
138 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
138 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
139
139
140
140
141 VariableController *q;
141 VariableController *q;
142 };
142 };
143
143
144
144
145 VariableController::VariableController(QObject *parent)
145 VariableController::VariableController(QObject *parent)
146 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
146 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
147 {
147 {
148 qCDebug(LOG_VariableController()) << tr("VariableController construction")
148 qCDebug(LOG_VariableController()) << tr("VariableController construction")
149 << QThread::currentThread();
149 << QThread::currentThread();
150
150
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
152 &VariableController::onAbortProgressRequested);
152 &VariableController::onAbortProgressRequested);
153
153
154 connect(impl->m_VariableAcquisitionWorker.get(),
154 connect(impl->m_VariableAcquisitionWorker.get(),
155 &VariableAcquisitionWorker::variableCanceledRequested, this,
155 &VariableAcquisitionWorker::variableCanceledRequested, this,
156 &VariableController::onAbortAcquisitionRequested);
156 &VariableController::onAbortAcquisitionRequested);
157
157
158 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
158 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
159 &VariableController::onDataProvided);
159 &VariableController::onDataProvided);
160 connect(impl->m_VariableAcquisitionWorker.get(),
160 connect(impl->m_VariableAcquisitionWorker.get(),
161 &VariableAcquisitionWorker::variableRequestInProgress, this,
161 &VariableAcquisitionWorker::variableRequestInProgress, this,
162 &VariableController::onVariableRetrieveDataInProgress);
162 &VariableController::onVariableRetrieveDataInProgress);
163
163
164
164
165 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
165 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
166 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
166 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
167 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
167 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
168 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
168 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
169
169
170
170
171 impl->m_VariableAcquisitionWorkerThread.start();
171 impl->m_VariableAcquisitionWorkerThread.start();
172 }
172 }
173
173
174 VariableController::~VariableController()
174 VariableController::~VariableController()
175 {
175 {
176 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
176 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
177 << QThread::currentThread();
177 << QThread::currentThread();
178 this->waitForFinish();
178 this->waitForFinish();
179 }
179 }
180
180
181 VariableModel *VariableController::variableModel() noexcept
181 VariableModel *VariableController::variableModel() noexcept
182 {
182 {
183 return impl->m_VariableModel;
183 return impl->m_VariableModel;
184 }
184 }
185
185
186 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
186 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
187 {
187 {
188 return impl->m_VariableSelectionModel;
188 return impl->m_VariableSelectionModel;
189 }
189 }
190
190
191 void VariableController::setTimeController(TimeController *timeController) noexcept
191 void VariableController::setTimeController(TimeController *timeController) noexcept
192 {
192 {
193 impl->m_TimeController = timeController;
193 impl->m_TimeController = timeController;
194 }
194 }
195
195
196 std::shared_ptr<Variable>
196 std::shared_ptr<Variable>
197 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
197 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
198 {
198 {
199 if (impl->m_VariableModel->containsVariable(variable)) {
199 if (impl->m_VariableModel->containsVariable(variable)) {
200 // Clones variable
200 // Clones variable
201 auto duplicate = variable->clone();
201 auto duplicate = variable->clone();
202
202
203 // Adds clone to model
203 // Adds clone to model
204 impl->m_VariableModel->addVariable(duplicate);
204 impl->m_VariableModel->addVariable(duplicate);
205
205
206 // Generates clone identifier
206 // Generates clone identifier
207 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
207 impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid();
208
208
209 // Registers provider
209 // Registers provider
210 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
210 auto variableProvider = impl->m_VariableToProviderMap.at(variable);
211 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
211 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
212
212
213 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
213 impl->m_VariableToProviderMap[duplicate] = duplicateProvider;
214 if (duplicateProvider) {
214 if (duplicateProvider) {
215 impl->registerProvider(duplicateProvider);
215 impl->registerProvider(duplicateProvider);
216 }
216 }
217
217
218 return duplicate;
218 return duplicate;
219 }
219 }
220 else {
220 else {
221 qCCritical(LOG_VariableController())
221 qCCritical(LOG_VariableController())
222 << tr("Can't create duplicate of variable %1: variable not registered in the model")
222 << tr("Can't create duplicate of variable %1: variable not registered in the model")
223 .arg(variable->name());
223 .arg(variable->name());
224 return nullptr;
224 return nullptr;
225 }
225 }
226 }
226 }
227
227
228 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
228 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
229 {
229 {
230 if (!variable) {
230 if (!variable) {
231 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
231 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
232 return;
232 return;
233 }
233 }
234
234
235 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
235 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
236 // make some treatments before the deletion
236 // make some treatments before the deletion
237 emit variableAboutToBeDeleted(variable);
237 emit variableAboutToBeDeleted(variable);
238
238
239 // Deletes identifier
239 // Deletes identifier
240 impl->m_VariableToIdentifierMap.erase(variable);
240 impl->m_VariableToIdentifierMap.erase(variable);
241
241
242 // Deletes provider
242 // Deletes provider
243 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
243 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
244 qCDebug(LOG_VariableController())
244 qCDebug(LOG_VariableController())
245 << tr("Number of providers deleted for variable %1: %2")
245 << tr("Number of providers deleted for variable %1: %2")
246 .arg(variable->name(), QString::number(nbProvidersDeleted));
246 .arg(variable->name(), QString::number(nbProvidersDeleted));
247
247
248
248
249 // Deletes from model
249 // Deletes from model
250 impl->m_VariableModel->deleteVariable(variable);
250 impl->m_VariableModel->deleteVariable(variable);
251 }
251 }
252
252
253 void VariableController::deleteVariables(
253 void VariableController::deleteVariables(
254 const QVector<std::shared_ptr<Variable> > &variables) noexcept
254 const QVector<std::shared_ptr<Variable> > &variables) noexcept
255 {
255 {
256 for (auto variable : qAsConst(variables)) {
256 for (auto variable : qAsConst(variables)) {
257 deleteVariable(variable);
257 deleteVariable(variable);
258 }
258 }
259 }
259 }
260
260
261 std::shared_ptr<Variable>
261 std::shared_ptr<Variable>
262 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
262 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
263 std::shared_ptr<IDataProvider> provider) noexcept
263 std::shared_ptr<IDataProvider> provider) noexcept
264 {
264 {
265 if (!impl->m_TimeController) {
265 if (!impl->m_TimeController) {
266 qCCritical(LOG_VariableController())
266 qCCritical(LOG_VariableController())
267 << tr("Impossible to create variable: The time controller is null");
267 << tr("Impossible to create variable: The time controller is null");
268 return nullptr;
268 return nullptr;
269 }
269 }
270
270
271 auto range = impl->m_TimeController->dateTime();
271 auto range = impl->m_TimeController->dateTime();
272
272
273 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
273 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
274 auto identifier = QUuid::createUuid();
274 auto identifier = QUuid::createUuid();
275
275
276 // store the provider
276 // store the provider
277 impl->registerProvider(provider);
277 impl->registerProvider(provider);
278
278
279 // Associate the provider
279 // Associate the provider
280 impl->m_VariableToProviderMap[newVariable] = provider;
280 impl->m_VariableToProviderMap[newVariable] = provider;
281 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
281 qCInfo(LOG_VariableController()) << "createVariable: " << identifier;
282 impl->m_VariableToIdentifierMap[newVariable] = identifier;
282 impl->m_VariableToIdentifierMap[newVariable] = identifier;
283
283
284
284
285 auto varRequestId = QUuid::createUuid();
285 auto varRequestId = QUuid::createUuid();
286 impl->processRequest(newVariable, range, varRequestId);
286 impl->processRequest(newVariable, range, varRequestId);
287 impl->updateVariableRequest(varRequestId);
287 impl->updateVariableRequest(varRequestId);
288
288
289 return newVariable;
289 return newVariable;
290 }
290 }
291 }
291 }
292
292
293 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
293 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
294 {
294 {
295 // TODO check synchronisation and Rescale
295 // TODO check synchronisation and Rescale
296 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
296 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
297 << QThread::currentThread()->objectName();
297 << QThread::currentThread()->objectName();
298 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
298 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
299 auto varRequestId = QUuid::createUuid();
299 auto varRequestId = QUuid::createUuid();
300
300
301 for (const auto &selectedRow : qAsConst(selectedRows)) {
301 for (const auto &selectedRow : qAsConst(selectedRows)) {
302 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
302 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
303 selectedVariable->setRange(dateTime);
303 selectedVariable->setRange(dateTime);
304 impl->processRequest(selectedVariable, dateTime, varRequestId);
304 impl->processRequest(selectedVariable, dateTime, varRequestId);
305
305
306 // notify that rescale operation has to be done
306 // notify that rescale operation has to be done
307 emit rangeChanged(selectedVariable, dateTime);
307 emit rangeChanged(selectedVariable, dateTime);
308 }
308 }
309 }
309 }
310 impl->updateVariableRequest(varRequestId);
310 impl->updateVariableRequest(varRequestId);
311 }
311 }
312
312
313 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
313 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
314 const SqpRange &cacheRangeRequested,
314 const SqpRange &cacheRangeRequested,
315 QVector<AcquisitionDataPacket> dataAcquired)
315 QVector<AcquisitionDataPacket> dataAcquired)
316 {
316 {
317 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
317 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
318 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
318 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
319 if (!varRequestId.isNull()) {
319 if (!varRequestId.isNull()) {
320 impl->updateVariableRequest(varRequestId);
320 impl->updateVariableRequest(varRequestId);
321 }
321 }
322 }
322 }
323
323
324 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
324 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
325 {
325 {
326 qCDebug(LOG_VariableController())
326 qCDebug(LOG_VariableController())
327 << "TORM: variableController::onVariableRetrieveDataInProgress"
327 << "TORM: variableController::onVariableRetrieveDataInProgress"
328 << QThread::currentThread()->objectName() << progress;
328 << QThread::currentThread()->objectName() << progress;
329 if (auto var = impl->findVariable(identifier)) {
329 if (auto var = impl->findVariable(identifier)) {
330 impl->m_VariableModel->setDataProgress(var, progress);
330 impl->m_VariableModel->setDataProgress(var, progress);
331 }
331 }
332 else {
332 else {
333 qCCritical(LOG_VariableController())
333 qCCritical(LOG_VariableController())
334 << tr("Impossible to notify progression of a null variable");
334 << tr("Impossible to notify progression of a null variable");
335 }
335 }
336 }
336 }
337
337
338 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
338 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
339 {
339 {
340 auto it = impl->m_VariableToIdentifierMap.find(variable);
340 auto it = impl->m_VariableToIdentifierMap.find(variable);
341 if (it != impl->m_VariableToIdentifierMap.cend()) {
341 if (it != impl->m_VariableToIdentifierMap.cend()) {
342 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
342 impl->m_VariableAcquisitionWorker->abortProgressRequested(it->second);
343
343
344 QUuid varRequestId;
344 QUuid varRequestId;
345 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
345 auto varIdToVarRequestIdQueueMapIt = impl->m_VarIdToVarRequestIdQueueMap.find(it->second);
346 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
346 if (varIdToVarRequestIdQueueMapIt != impl->m_VarIdToVarRequestIdQueueMap.cend()) {
347 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
347 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
348 varRequestId = varRequestIdQueue.front();
348 varRequestId = varRequestIdQueue.front();
349 impl->cancelVariableRequest(varRequestId);
349 impl->cancelVariableRequest(varRequestId);
350
350
351 // Finish the progression for the request
351 // Finish the progression for the request
352 impl->m_VariableModel->setDataProgress(variable, 0.0);
352 impl->m_VariableModel->setDataProgress(variable, 0.0);
353 }
353 }
354 else {
354 else {
355 qCWarning(LOG_VariableController())
355 qCWarning(LOG_VariableController())
356 << tr("Aborting progression of inexistant variable request detected !!!")
356 << tr("Aborting progression of inexistant variable request detected !!!")
357 << QThread::currentThread()->objectName();
357 << QThread::currentThread()->objectName();
358 }
358 }
359 }
359 }
360 else {
360 else {
361 qCWarning(LOG_VariableController())
361 qCWarning(LOG_VariableController())
362 << tr("Aborting progression of inexistant variable detected !!!")
362 << tr("Aborting progression of inexistant variable detected !!!")
363 << QThread::currentThread()->objectName();
363 << QThread::currentThread()->objectName();
364 }
364 }
365 }
365 }
366
366
367 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
367 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
368 {
368 {
369 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
369 qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested"
370 << QThread::currentThread()->objectName() << vIdentifier;
370 << QThread::currentThread()->objectName() << vIdentifier;
371
371
372 if (auto var = impl->findVariable(vIdentifier)) {
372 if (auto var = impl->findVariable(vIdentifier)) {
373 this->onAbortProgressRequested(var);
373 this->onAbortProgressRequested(var);
374 }
374 }
375 else {
375 else {
376 qCCritical(LOG_VariableController())
376 qCCritical(LOG_VariableController())
377 << tr("Impossible to abort Acquisition Requestof a null variable");
377 << tr("Impossible to abort Acquisition Requestof a null variable");
378 }
378 }
379 }
379 }
380
380
381 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
381 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
382 {
382 {
383 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
383 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
384 << QThread::currentThread()->objectName()
384 << QThread::currentThread()->objectName()
385 << synchronizationGroupId;
385 << synchronizationGroupId;
386 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
386 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
387 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
387 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
388 std::make_pair(synchronizationGroupId, vSynchroGroup));
388 std::make_pair(synchronizationGroupId, vSynchroGroup));
389 }
389 }
390
390
391 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
391 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
392 {
392 {
393 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
393 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
394 }
394 }
395
395
396 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
396 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
397 QUuid synchronizationGroupId)
397 QUuid synchronizationGroupId)
398
398
399 {
399 {
400 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
400 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
401 << synchronizationGroupId;
401 << synchronizationGroupId;
402 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
402 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
403 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
403 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
404 auto groupIdToVSGIt
404 auto groupIdToVSGIt
405 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
405 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
406 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
406 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
407 impl->m_VariableIdGroupIdMap.insert(
407 impl->m_VariableIdGroupIdMap.insert(
408 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
408 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
409 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
409 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
410 }
410 }
411 else {
411 else {
412 qCCritical(LOG_VariableController())
412 qCCritical(LOG_VariableController())
413 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
413 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
414 << variable->name();
414 << variable->name();
415 }
415 }
416 }
416 }
417 else {
417 else {
418 qCCritical(LOG_VariableController())
418 qCCritical(LOG_VariableController())
419 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
419 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
420 }
420 }
421 }
421 }
422
422
423 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
423 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
424 QUuid synchronizationGroupId)
424 QUuid synchronizationGroupId)
425 {
425 {
426 // Gets variable id
426 // Gets variable id
427 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
427 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
428 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
428 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
429 qCCritical(LOG_VariableController())
429 qCCritical(LOG_VariableController())
430 << tr("Can't desynchronize variable %1: variable identifier not found")
430 << tr("Can't desynchronize variable %1: variable identifier not found")
431 .arg(variable->name());
431 .arg(variable->name());
432 return;
432 return;
433 }
433 }
434
434
435 // Gets synchronization group
435 // Gets synchronization group
436 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
436 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
437 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
437 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
438 qCCritical(LOG_VariableController())
438 qCCritical(LOG_VariableController())
439 << tr("Can't desynchronize variable %1: unknown synchronization group")
439 << tr("Can't desynchronize variable %1: unknown synchronization group")
440 .arg(variable->name());
440 .arg(variable->name());
441 return;
441 return;
442 }
442 }
443
443
444 auto variableId = variableIt->second;
444 auto variableId = variableIt->second;
445
445
446 // Removes variable from synchronization group
446 // Removes variable from synchronization group
447 auto synchronizationGroup = groupIt->second;
447 auto synchronizationGroup = groupIt->second;
448 synchronizationGroup->removeVariableId(variableId);
448 synchronizationGroup->removeVariableId(variableId);
449
449
450 // Removes link between variable and synchronization group
450 // Removes link between variable and synchronization group
451 impl->m_VariableIdGroupIdMap.erase(variableId);
451 impl->m_VariableIdGroupIdMap.erase(variableId);
452 }
452 }
453
453
454 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
454 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
455 const SqpRange &range, const SqpRange &oldRange,
455 const SqpRange &range, const SqpRange &oldRange,
456 bool synchronise)
456 bool synchronise)
457 {
457 {
458 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
458 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
459
459
460 // we want to load data of the variable for the dateTime.
460 // we want to load data of the variable for the dateTime.
461 // First we check if the cache contains some of them.
461 // First we check if the cache contains some of them.
462 // For the other, we ask the provider to give them.
462 // For the other, we ask the provider to give them.
463
463
464 auto varRequestId = QUuid::createUuid();
464 auto varRequestId = QUuid::createUuid();
465 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
465 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
466 << QThread::currentThread()->objectName() << varRequestId;
466 << QThread::currentThread()->objectName() << varRequestId;
467
467
468 for (const auto &var : variables) {
468 for (const auto &var : variables) {
469 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
469 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
470 impl->processRequest(var, range, varRequestId);
470 impl->processRequest(var, range, varRequestId);
471 }
471 }
472
472
473 if (synchronise) {
473 if (synchronise) {
474 // Get the group ids
474 // Get the group ids
475 qCDebug(LOG_VariableController())
475 qCDebug(LOG_VariableController())
476 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
476 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
477 auto groupIds = std::set<QUuid>{};
477 auto groupIds = std::set<QUuid>{};
478 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
478 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
479 for (const auto &var : variables) {
479 for (const auto &var : variables) {
480 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
480 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
481 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
481 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
482 auto vId = varToVarIdIt->second;
482 auto vId = varToVarIdIt->second;
483 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
483 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
484 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
484 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
485 auto gId = varIdToGroupIdIt->second;
485 auto gId = varIdToGroupIdIt->second;
486 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
486 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
487 if (groupIds.find(gId) == groupIds.cend()) {
487 if (groupIds.find(gId) == groupIds.cend()) {
488 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
488 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
489 groupIds.insert(gId);
489 groupIds.insert(gId);
490 }
490 }
491 }
491 }
492 }
492 }
493 }
493 }
494
494
495 // We assume here all group ids exist
495 // We assume here all group ids exist
496 for (const auto &gId : groupIds) {
496 for (const auto &gId : groupIds) {
497 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
497 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
498 auto vSyncIds = vSynchronizationGroup->getIds();
498 auto vSyncIds = vSynchronizationGroup->getIds();
499 qCDebug(LOG_VariableController()) << "Var in synchro group ";
499 qCDebug(LOG_VariableController()) << "Var in synchro group ";
500 for (auto vId : vSyncIds) {
500 for (auto vId : vSyncIds) {
501 auto var = impl->findVariable(vId);
501 auto var = impl->findVariable(vId);
502
502
503 // Don't process already processed var
503 // Don't process already processed var
504 if (!variables.contains(var)) {
504 if (!variables.contains(var)) {
505 if (var != nullptr) {
505 if (var != nullptr) {
506 qCDebug(LOG_VariableController()) << "processRequest synchro for"
506 qCDebug(LOG_VariableController()) << "processRequest synchro for"
507 << var->name();
507 << var->name();
508 auto vSyncRangeRequested = computeSynchroRangeRequested(
508 auto vSyncRangeRequested = computeSynchroRangeRequested(
509 var->range(), range, groupIdToOldRangeMap.at(gId));
509 var->range(), range, groupIdToOldRangeMap.at(gId));
510 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
510 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
511 impl->processRequest(var, vSyncRangeRequested, varRequestId);
511 impl->processRequest(var, vSyncRangeRequested, varRequestId);
512 }
512 }
513 else {
513 else {
514 qCCritical(LOG_VariableController())
514 qCCritical(LOG_VariableController())
515
515
516 << tr("Impossible to synchronize a null variable");
516 << tr("Impossible to synchronize a null variable");
517 }
517 }
518 }
518 }
519 }
519 }
520 }
520 }
521 }
521 }
522
522
523 impl->updateVariableRequest(varRequestId);
523 impl->updateVariableRequest(varRequestId);
524 }
524 }
525
525
526
526
527 void VariableController::initialize()
527 void VariableController::initialize()
528 {
528 {
529 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
529 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
530 impl->m_WorkingMutex.lock();
530 impl->m_WorkingMutex.lock();
531 qCDebug(LOG_VariableController()) << tr("VariableController init END");
531 qCDebug(LOG_VariableController()) << tr("VariableController init END");
532 }
532 }
533
533
534 void VariableController::finalize()
534 void VariableController::finalize()
535 {
535 {
536 impl->m_WorkingMutex.unlock();
536 impl->m_WorkingMutex.unlock();
537 }
537 }
538
538
539 void VariableController::waitForFinish()
539 void VariableController::waitForFinish()
540 {
540 {
541 QMutexLocker locker{&impl->m_WorkingMutex};
541 QMutexLocker locker{&impl->m_WorkingMutex};
542 }
542 }
543
543
544 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
544 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
545 {
545 {
546 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
546 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
547 auto zoomType = AcquisitionZoomType::Unknown;
547 auto zoomType = AcquisitionZoomType::Unknown;
548 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
548 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
549 zoomType = AcquisitionZoomType::ZoomOut;
549 zoomType = AcquisitionZoomType::ZoomOut;
550 }
550 }
551 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
551 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
552 zoomType = AcquisitionZoomType::PanRight;
552 zoomType = AcquisitionZoomType::PanRight;
553 }
553 }
554 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
554 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
555 zoomType = AcquisitionZoomType::PanLeft;
555 zoomType = AcquisitionZoomType::PanLeft;
556 }
556 }
557 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
557 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
558 zoomType = AcquisitionZoomType::ZoomIn;
558 zoomType = AcquisitionZoomType::ZoomIn;
559 }
559 }
560 else {
560 else {
561 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
561 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
562 }
562 }
563 return zoomType;
563 return zoomType;
564 }
564 }
565
565
566 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
566 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
567 const SqpRange &rangeRequested,
567 const SqpRange &rangeRequested,
568 QUuid varRequestId)
568 QUuid varRequestId)
569 {
569 {
570
570
571 // TODO: protect at
571 // TODO: protect at
572 auto varRequest = VariableRequest{};
572 auto varRequest = VariableRequest{};
573 auto varId = m_VariableToIdentifierMap.at(var);
573 auto varId = m_VariableToIdentifierMap.at(var);
574
574
575 auto varStrategyRangesRequested
575 auto varStrategyRangesRequested
576 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
576 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
577 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
577
578 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
578 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
579 auto inCacheRangeList = QVector<SqpRange>{};
580 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
581 notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
582 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
583 }
579
584
580 if (!notInCacheRangeList.empty()) {
585 if (!notInCacheRangeList.empty()) {
581 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
586 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
582 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
587 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
583
588
584 // store VarRequest
589 // store VarRequest
585 storeVariableRequest(varId, varRequestId, varRequest);
590 storeVariableRequest(varId, varRequestId, varRequest);
586
591
587 auto varProvider = m_VariableToProviderMap.at(var);
592 auto varProvider = m_VariableToProviderMap.at(var);
588 if (varProvider != nullptr) {
593 if (varProvider != nullptr) {
589 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
594 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
590 varRequestId, varId, varStrategyRangesRequested.first,
595 varRequestId, varId, varStrategyRangesRequested.first,
591 varStrategyRangesRequested.second,
596 varStrategyRangesRequested.second,
592 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
597 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
593 varProvider);
598 varProvider);
594
599
595 if (!varRequestIdCanceled.isNull()) {
600 if (!varRequestIdCanceled.isNull()) {
596 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
601 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
597 << varRequestIdCanceled;
602 << varRequestIdCanceled;
598 cancelVariableRequest(varRequestIdCanceled);
603 cancelVariableRequest(varRequestIdCanceled);
599 }
604 }
600 }
605 }
601 else {
606 else {
602 qCCritical(LOG_VariableController())
607 qCCritical(LOG_VariableController())
603 << "Impossible to provide data with a null provider";
608 << "Impossible to provide data with a null provider";
604 }
609 }
605
610
606 if (!inCacheRangeList.empty()) {
611 if (!inCacheRangeList.empty()) {
607 emit q->updateVarDisplaying(var, inCacheRangeList.first());
612 emit q->updateVarDisplaying(var, inCacheRangeList.first());
608 }
613 }
609 }
614 }
610 else {
615 else {
611 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
616 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
612 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
617 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
613 // store VarRequest
618 // store VarRequest
614 storeVariableRequest(varId, varRequestId, varRequest);
619 storeVariableRequest(varId, varRequestId, varRequest);
615 acceptVariableRequest(varId,
620 acceptVariableRequest(varId,
616 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
621 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
617 }
622 }
618 }
623 }
619
624
620 std::shared_ptr<Variable>
625 std::shared_ptr<Variable>
621 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
626 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
622 {
627 {
623 std::shared_ptr<Variable> var;
628 std::shared_ptr<Variable> var;
624 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
629 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
625
630
626 auto end = m_VariableToIdentifierMap.cend();
631 auto end = m_VariableToIdentifierMap.cend();
627 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
632 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
628 if (it != end) {
633 if (it != end) {
629 var = it->first;
634 var = it->first;
630 }
635 }
631 else {
636 else {
632 qCCritical(LOG_VariableController())
637 qCCritical(LOG_VariableController())
633 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
638 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
634 }
639 }
635
640
636 return var;
641 return var;
637 }
642 }
638
643
639 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
644 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
640 const QVector<AcquisitionDataPacket> acqDataPacketVector)
645 const QVector<AcquisitionDataPacket> acqDataPacketVector)
641 {
646 {
642 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
647 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
643 << acqDataPacketVector.size();
648 << acqDataPacketVector.size();
644 std::shared_ptr<IDataSeries> dataSeries;
649 std::shared_ptr<IDataSeries> dataSeries;
645 if (!acqDataPacketVector.isEmpty()) {
650 if (!acqDataPacketVector.isEmpty()) {
646 dataSeries = acqDataPacketVector[0].m_DateSeries;
651 dataSeries = acqDataPacketVector[0].m_DateSeries;
647 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
652 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
648 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
653 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
649 }
654 }
650 }
655 }
651 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
656 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
652 << acqDataPacketVector.size();
657 << acqDataPacketVector.size();
653 return dataSeries;
658 return dataSeries;
654 }
659 }
655
660
656 void VariableController::VariableControllerPrivate::registerProvider(
661 void VariableController::VariableControllerPrivate::registerProvider(
657 std::shared_ptr<IDataProvider> provider)
662 std::shared_ptr<IDataProvider> provider)
658 {
663 {
659 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
664 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
660 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
665 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
661 << provider->objectName();
666 << provider->objectName();
662 m_ProviderSet.insert(provider);
667 m_ProviderSet.insert(provider);
663 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
668 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
664 &VariableAcquisitionWorker::onVariableDataAcquired);
669 &VariableAcquisitionWorker::onVariableDataAcquired);
665 connect(provider.get(), &IDataProvider::dataProvidedProgress,
670 connect(provider.get(), &IDataProvider::dataProvidedProgress,
666 m_VariableAcquisitionWorker.get(),
671 m_VariableAcquisitionWorker.get(),
667 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
672 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
668 connect(provider.get(), &IDataProvider::dataProvidedFailed,
673 connect(provider.get(), &IDataProvider::dataProvidedFailed,
669 m_VariableAcquisitionWorker.get(),
674 m_VariableAcquisitionWorker.get(),
670 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
675 &VariableAcquisitionWorker::onVariableAcquisitionFailed);
671 }
676 }
672 else {
677 else {
673 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
678 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
674 }
679 }
675 }
680 }
676
681
677 void VariableController::VariableControllerPrivate::storeVariableRequest(
682 void VariableController::VariableControllerPrivate::storeVariableRequest(
678 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
683 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
679 {
684 {
680 // First request for the variable. we can create an entry for it
685 // First request for the variable. we can create an entry for it
681 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
686 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
682 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
687 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
683 auto varRequestIdQueue = std::deque<QUuid>{};
688 auto varRequestIdQueue = std::deque<QUuid>{};
684 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
689 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
685 varRequestIdQueue.push_back(varRequestId);
690 varRequestIdQueue.push_back(varRequestId);
686 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
691 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
687 }
692 }
688 else {
693 else {
689 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
694 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
690 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
695 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
691 varRequestIdQueue.push_back(varRequestId);
696 varRequestIdQueue.push_back(varRequestId);
692 }
697 }
693
698
694 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
699 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
695 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
700 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
696 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
701 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
697 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
702 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
698 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
703 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
699 m_VarRequestIdToVarIdVarRequestMap.insert(
704 m_VarRequestIdToVarIdVarRequestMap.insert(
700 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
705 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
701 }
706 }
702 else {
707 else {
703 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
708 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
704 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
709 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
705 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
710 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
706 }
711 }
707 }
712 }
708
713
709 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
714 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
710 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
715 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
711 {
716 {
712 QUuid varRequestId;
717 QUuid varRequestId;
713 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
718 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
714 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
719 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
715 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
720 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
716 varRequestId = varRequestIdQueue.front();
721 varRequestId = varRequestIdQueue.front();
717 auto varRequestIdToVarIdVarRequestMapIt
722 auto varRequestIdToVarIdVarRequestMapIt
718 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
723 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
719 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
724 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
720 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
725 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
721 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
726 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
722 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
727 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
723 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
728 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
724 auto &varRequest = varIdToVarRequestMapIt->second;
729 auto &varRequest = varIdToVarRequestMapIt->second;
725 varRequest.m_DataSeries = dataSeries;
730 varRequest.m_DataSeries = dataSeries;
726 varRequest.m_CanUpdate = true;
731 varRequest.m_CanUpdate = true;
727 }
732 }
728 else {
733 else {
729 qCDebug(LOG_VariableController())
734 qCDebug(LOG_VariableController())
730 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
735 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
731 "to a variableRequestId")
736 "to a variableRequestId")
732 << varRequestId << varId;
737 << varRequestId << varId;
733 }
738 }
734 }
739 }
735 else {
740 else {
736 qCCritical(LOG_VariableController())
741 qCCritical(LOG_VariableController())
737 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
742 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
738 << varRequestId;
743 << varRequestId;
739 }
744 }
740
745
741 varRequestIdQueue.pop_front();
746 varRequestIdQueue.pop_front();
742 if (varRequestIdQueue.empty()) {
747 if (varRequestIdQueue.empty()) {
743 qCDebug(LOG_VariableController())
748 qCDebug(LOG_VariableController())
744 << tr("TORM Erase REQUEST because it has been accepted") << varId;
749 << tr("TORM Erase REQUEST because it has been accepted") << varId;
745 m_VarIdToVarRequestIdQueueMap.erase(varId);
750 m_VarIdToVarRequestIdQueueMap.erase(varId);
746 }
751 }
747 }
752 }
748 else {
753 else {
749 qCCritical(LOG_VariableController())
754 qCCritical(LOG_VariableController())
750 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
755 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
751 }
756 }
752
757
753 return varRequestId;
758 return varRequestId;
754 }
759 }
755
760
756 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
761 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
757 {
762 {
758
763
759 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
764 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
760 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
765 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
761 bool processVariableUpdate = true;
766 bool processVariableUpdate = true;
762 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
767 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
763 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
768 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
764 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
769 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
765 ++varIdToVarRequestMapIt) {
770 ++varIdToVarRequestMapIt) {
766 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
771 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
767 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
772 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
768 << processVariableUpdate;
773 << processVariableUpdate;
769 }
774 }
770
775
771 if (processVariableUpdate) {
776 if (processVariableUpdate) {
772 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
777 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
773 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
778 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
774 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
779 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
775 auto &varRequest = varIdToVarRequestMapIt->second;
780 auto &varRequest = varIdToVarRequestMapIt->second;
776 var->setRange(varRequest.m_RangeRequested);
781 var->setRange(varRequest.m_RangeRequested);
777 var->setCacheRange(varRequest.m_CacheRangeRequested);
782 var->setCacheRange(varRequest.m_CacheRangeRequested);
778 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
783 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
779 << varRequest.m_RangeRequested;
784 << varRequest.m_RangeRequested;
780 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
785 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
781 << varRequest.m_CacheRangeRequested;
786 << varRequest.m_CacheRangeRequested;
782 var->mergeDataSeries(varRequest.m_DataSeries);
787 var->mergeDataSeries(varRequest.m_DataSeries);
783 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
788 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
784 << varRequest.m_DataSeries->range();
789 << varRequest.m_DataSeries->range();
785 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
790 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
786
791
787 /// @todo MPL: confirm
792 /// @todo MPL: confirm
788 // Variable update is notified only if there is no pending request for it
793 // Variable update is notified only if there is no pending request for it
789 // if
794 // if
790 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
795 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
791 // == 0) {
796 // == 0) {
792 emit var->updated();
797 emit var->updated();
793 // }
798 // }
794 }
799 }
795 else {
800 else {
796 qCCritical(LOG_VariableController())
801 qCCritical(LOG_VariableController())
797 << tr("Impossible to update data to a null variable");
802 << tr("Impossible to update data to a null variable");
798 }
803 }
799 }
804 }
800
805
801 // cleaning varRequestId
806 // cleaning varRequestId
802 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
807 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
803 << m_VarRequestIdToVarIdVarRequestMap.size();
808 << m_VarRequestIdToVarIdVarRequestMap.size();
804 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
809 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
805 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
810 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
806 << m_VarRequestIdToVarIdVarRequestMap.size();
811 << m_VarRequestIdToVarIdVarRequestMap.size();
807 }
812 }
808 }
813 }
809 else {
814 else {
810 qCCritical(LOG_VariableController())
815 qCCritical(LOG_VariableController())
811 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
816 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
812 }
817 }
813 }
818 }
814
819
815 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
820 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
816 {
821 {
817 // cleaning varRequestId
822 // cleaning varRequestId
818 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
823 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
819
824
820 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
825 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
821 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
826 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
822 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
827 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
823 varRequestIdQueue.erase(
828 varRequestIdQueue.erase(
824 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
829 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
825 varRequestIdQueue.end());
830 varRequestIdQueue.end());
826 if (varRequestIdQueue.empty()) {
831 if (varRequestIdQueue.empty()) {
827 varIdToVarRequestIdQueueMapIt
832 varIdToVarRequestIdQueueMapIt
828 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
833 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
829 }
834 }
830 else {
835 else {
831 ++varIdToVarRequestIdQueueMapIt;
836 ++varIdToVarRequestIdQueueMapIt;
832 }
837 }
833 }
838 }
834 }
839 }
@@ -1,228 +1,232
1 #include <Variable/RenameVariableDialog.h>
1 #include <Variable/RenameVariableDialog.h>
2 #include <Variable/Variable.h>
2 #include <Variable/Variable.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableInspectorWidget.h>
4 #include <Variable/VariableInspectorWidget.h>
5 #include <Variable/VariableMenuHeaderWidget.h>
5 #include <Variable/VariableMenuHeaderWidget.h>
6 #include <Variable/VariableModel.h>
6 #include <Variable/VariableModel.h>
7
7
8 #include <ui_VariableInspectorWidget.h>
8 #include <ui_VariableInspectorWidget.h>
9
9
10 #include <QMouseEvent>
10 #include <QMouseEvent>
11 #include <QSortFilterProxyModel>
11 #include <QSortFilterProxyModel>
12 #include <QStyledItemDelegate>
12 #include <QStyledItemDelegate>
13 #include <QWidgetAction>
13 #include <QWidgetAction>
14
14
15 #include <SqpApplication.h>
15 #include <SqpApplication.h>
16
16
17 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
17 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
18
18
19
19
20 class QProgressBarItemDelegate : public QStyledItemDelegate {
20 class QProgressBarItemDelegate : public QStyledItemDelegate {
21
21
22 public:
22 public:
23 QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {}
23 QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {}
24
24
25 void paint(QPainter *painter, const QStyleOptionViewItem &option,
25 void paint(QPainter *painter, const QStyleOptionViewItem &option,
26 const QModelIndex &index) const
26 const QModelIndex &index) const
27 {
27 {
28 auto data = index.data(Qt::DisplayRole);
28 auto data = index.data(Qt::DisplayRole);
29 auto progressData = index.data(VariableRoles::ProgressRole);
29 auto progressData = index.data(VariableRoles::ProgressRole);
30 if (data.isValid() && progressData.isValid()) {
30 if (data.isValid() && progressData.isValid()) {
31 auto name = data.value<QString>();
31 auto name = data.value<QString>();
32 auto progress = progressData.value<double>();
32 auto progress = progressData.value<double>();
33 if (progress > 0) {
33 if (progress > 0) {
34 auto cancelButtonWidth = 20;
34 auto cancelButtonWidth = 20;
35 auto progressBarOption = QStyleOptionProgressBar{};
35 auto progressBarOption = QStyleOptionProgressBar{};
36 auto progressRect = option.rect;
36 auto progressRect = option.rect;
37 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
37 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
38 progressBarOption.rect = progressRect;
38 progressBarOption.rect = progressRect;
39 progressBarOption.minimum = 0;
39 progressBarOption.minimum = 0;
40 progressBarOption.maximum = 100;
40 progressBarOption.maximum = 100;
41 progressBarOption.progress = progress;
41 progressBarOption.progress = progress;
42 progressBarOption.text
42 progressBarOption.text
43 = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%");
43 = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%");
44 progressBarOption.textVisible = true;
44 progressBarOption.textVisible = true;
45 progressBarOption.textAlignment = Qt::AlignCenter;
45 progressBarOption.textAlignment = Qt::AlignCenter;
46
46
47
47
48 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption,
48 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption,
49 painter);
49 painter);
50
50
51 // Cancel button
51 // Cancel button
52 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
52 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
53 option.rect.height());
53 option.rect.height());
54 auto buttonOption = QStyleOptionButton{};
54 auto buttonOption = QStyleOptionButton{};
55 buttonOption.rect = buttonRect;
55 buttonOption.rect = buttonRect;
56 buttonOption.text = "X";
56 buttonOption.text = "X";
57
57
58 QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
58 QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
59 }
59 }
60 else {
60 else {
61 QStyledItemDelegate::paint(painter, option, index);
61 QStyledItemDelegate::paint(painter, option, index);
62 }
62 }
63 }
63 }
64 else {
64 else {
65 QStyledItemDelegate::paint(painter, option, index);
65 QStyledItemDelegate::paint(painter, option, index);
66 }
66 }
67 }
67 }
68
68
69 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
69 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
70 const QModelIndex &index)
70 const QModelIndex &index)
71 {
71 {
72 if (event->type() == QEvent::MouseButtonRelease) {
72 if (event->type() == QEvent::MouseButtonRelease) {
73 auto data = index.data(Qt::DisplayRole);
73 auto data = index.data(Qt::DisplayRole);
74 auto progressData = index.data(VariableRoles::ProgressRole);
74 auto progressData = index.data(VariableRoles::ProgressRole);
75 if (data.isValid() && progressData.isValid()) {
75 if (data.isValid() && progressData.isValid()) {
76 auto cancelButtonWidth = 20;
76 auto cancelButtonWidth = 20;
77 auto progressRect = option.rect;
77 auto progressRect = option.rect;
78 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
78 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
79 // Cancel button
79 // Cancel button
80 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
80 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
81 option.rect.height());
81 option.rect.height());
82
82
83 auto e = (QMouseEvent *)event;
83 auto e = (QMouseEvent *)event;
84 auto clickX = e->x();
84 auto clickX = e->x();
85 auto clickY = e->y();
85 auto clickY = e->y();
86
86
87 auto x = buttonRect.left(); // the X coordinate
87 auto x = buttonRect.left(); // the X coordinate
88 auto y = buttonRect.top(); // the Y coordinate
88 auto y = buttonRect.top(); // the Y coordinate
89 auto w = buttonRect.width(); // button width
89 auto w = buttonRect.width(); // button width
90 auto h = buttonRect.height(); // button height
90 auto h = buttonRect.height(); // button height
91
91
92 if (clickX > x && clickX < x + w) {
92 if (clickX > x && clickX < x + w) {
93 if (clickY > y && clickY < y + h) {
93 if (clickY > y && clickY < y + h) {
94 auto variableModel = sqpApp->variableController().variableModel();
94 auto variableModel = sqpApp->variableController().variableModel();
95 variableModel->abortProgress(index);
95 variableModel->abortProgress(index);
96 }
96 }
97 return true;
97 }
98 }
98 else {
99 else {
99 QStyledItemDelegate::editorEvent(event, model, option, index);
100 return QStyledItemDelegate::editorEvent(event, model, option, index);
100 }
101 }
101 }
102 }
102 else {
103 else {
103 QStyledItemDelegate::editorEvent(event, model, option, index);
104 return QStyledItemDelegate::editorEvent(event, model, option, index);
104 }
105 }
105 }
106 }
106 else {
107 else {
107 QStyledItemDelegate::editorEvent(event, model, option, index);
108 return QStyledItemDelegate::editorEvent(event, model, option, index);
108 }
109 }
110
111
112 return QStyledItemDelegate::editorEvent(event, model, option, index);
109 }
113 }
110 };
114 };
111
115
112 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
116 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
113 : QWidget{parent},
117 : QWidget{parent},
114 ui{new Ui::VariableInspectorWidget},
118 ui{new Ui::VariableInspectorWidget},
115 m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}}
119 m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}}
116 {
120 {
117 ui->setupUi(this);
121 ui->setupUi(this);
118
122
119 // Sets model for table
123 // Sets model for table
120 // auto sortFilterModel = new QSortFilterProxyModel{this};
124 // auto sortFilterModel = new QSortFilterProxyModel{this};
121 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
125 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
122
126
123 auto variableModel = sqpApp->variableController().variableModel();
127 auto variableModel = sqpApp->variableController().variableModel();
124 ui->tableView->setModel(variableModel);
128 ui->tableView->setModel(variableModel);
125
129
126 // Adds extra signal/slot between view and model, so the view can be updated instantly when
130 // Adds extra signal/slot between view and model, so the view can be updated instantly when
127 // there is a change of data in the model
131 // there is a change of data in the model
128 connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
132 connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
129 SLOT(refresh()));
133 SLOT(refresh()));
130
134
131 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
135 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
132 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
136 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
133
137
134 // Fixes column sizes
138 // Fixes column sizes
135 auto model = ui->tableView->model();
139 auto model = ui->tableView->model();
136 const auto count = model->columnCount();
140 const auto count = model->columnCount();
137 for (auto i = 0; i < count; ++i) {
141 for (auto i = 0; i < count; ++i) {
138 ui->tableView->setColumnWidth(
142 ui->tableView->setColumnWidth(
139 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
143 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
140 }
144 }
141
145
142 // Sets selection options
146 // Sets selection options
143 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
147 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
144 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
148 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
145
149
146 // Connection to show a menu when right clicking on the tree
150 // Connection to show a menu when right clicking on the tree
147 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
151 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
148 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
152 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
149 &VariableInspectorWidget::onTableMenuRequested);
153 &VariableInspectorWidget::onTableMenuRequested);
150 }
154 }
151
155
152 VariableInspectorWidget::~VariableInspectorWidget()
156 VariableInspectorWidget::~VariableInspectorWidget()
153 {
157 {
154 delete ui;
158 delete ui;
155 }
159 }
156
160
157 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
161 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
158 {
162 {
159 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
163 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
160
164
161 // Gets the model to retrieve the underlying selected variables
165 // Gets the model to retrieve the underlying selected variables
162 auto model = sqpApp->variableController().variableModel();
166 auto model = sqpApp->variableController().variableModel();
163 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
167 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
164 for (const auto &selectedRow : qAsConst(selectedRows)) {
168 for (const auto &selectedRow : qAsConst(selectedRows)) {
165 if (auto selectedVariable = model->variable(selectedRow.row())) {
169 if (auto selectedVariable = model->variable(selectedRow.row())) {
166 selectedVariables.push_back(selectedVariable);
170 selectedVariables.push_back(selectedVariable);
167 }
171 }
168 }
172 }
169
173
170 QMenu tableMenu{};
174 QMenu tableMenu{};
171
175
172 // Emits a signal so that potential receivers can populate the menu before displaying it
176 // Emits a signal so that potential receivers can populate the menu before displaying it
173 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
177 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
174
178
175 // Adds menu-specific actions
179 // Adds menu-specific actions
176 if (!selectedVariables.isEmpty()) {
180 if (!selectedVariables.isEmpty()) {
177 tableMenu.addSeparator();
181 tableMenu.addSeparator();
178
182
179 // 'Rename' and 'Duplicate' actions (only if one variable selected)
183 // 'Rename' and 'Duplicate' actions (only if one variable selected)
180 if (selectedVariables.size() == 1) {
184 if (selectedVariables.size() == 1) {
181 auto selectedVariable = selectedVariables.front();
185 auto selectedVariable = selectedVariables.front();
182
186
183 auto duplicateFun = [&selectedVariable]() {
187 auto duplicateFun = [&selectedVariable]() {
184 sqpApp->variableController().cloneVariable(selectedVariable);
188 sqpApp->variableController().cloneVariable(selectedVariable);
185 };
189 };
186
190
187 tableMenu.addAction(tr("Duplicate"), duplicateFun);
191 tableMenu.addAction(tr("Duplicate"), duplicateFun);
188
192
189 auto renameFun = [&selectedVariable, &model, this]() {
193 auto renameFun = [&selectedVariable, &model, this]() {
190 // Generates forbidden names (names associated to existing variables)
194 // Generates forbidden names (names associated to existing variables)
191 auto allVariables = model->variables();
195 auto allVariables = model->variables();
192 auto forbiddenNames = QVector<QString>(allVariables.size());
196 auto forbiddenNames = QVector<QString>(allVariables.size());
193 std::transform(allVariables.cbegin(), allVariables.cend(), forbiddenNames.begin(),
197 std::transform(allVariables.cbegin(), allVariables.cend(), forbiddenNames.begin(),
194 [](const auto &variable) { return variable->name(); });
198 [](const auto &variable) { return variable->name(); });
195
199
196 RenameVariableDialog dialog{selectedVariable->name(), forbiddenNames, this};
200 RenameVariableDialog dialog{selectedVariable->name(), forbiddenNames, this};
197 if (dialog.exec() == QDialog::Accepted) {
201 if (dialog.exec() == QDialog::Accepted) {
198 selectedVariable->setName(dialog.name());
202 selectedVariable->setName(dialog.name());
199 }
203 }
200 };
204 };
201
205
202 tableMenu.addAction(tr("Rename..."), renameFun);
206 tableMenu.addAction(tr("Rename..."), renameFun);
203 }
207 }
204
208
205 // 'Delete' action
209 // 'Delete' action
206 auto deleteFun = [&selectedVariables]() {
210 auto deleteFun = [&selectedVariables]() {
207 sqpApp->variableController().deleteVariables(selectedVariables);
211 sqpApp->variableController().deleteVariables(selectedVariables);
208 };
212 };
209
213
210 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
214 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
211 }
215 }
212
216
213 if (!tableMenu.isEmpty()) {
217 if (!tableMenu.isEmpty()) {
214 // Generates menu header (inserted before first action)
218 // Generates menu header (inserted before first action)
215 auto firstAction = tableMenu.actions().first();
219 auto firstAction = tableMenu.actions().first();
216 auto headerAction = new QWidgetAction{&tableMenu};
220 auto headerAction = new QWidgetAction{&tableMenu};
217 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
221 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
218 tableMenu.insertAction(firstAction, headerAction);
222 tableMenu.insertAction(firstAction, headerAction);
219
223
220 // Displays menu
224 // Displays menu
221 tableMenu.exec(QCursor::pos());
225 tableMenu.exec(QCursor::pos());
222 }
226 }
223 }
227 }
224
228
225 void VariableInspectorWidget::refresh() noexcept
229 void VariableInspectorWidget::refresh() noexcept
226 {
230 {
227 ui->tableView->viewport()->update();
231 ui->tableView->viewport()->update();
228 }
232 }
General Comments 0
You need to be logged in to leave comments. Login now