##// END OF EJS Templates
Few methods added to ease integration in existing GUI...
jeandet -
r25:5f4f9560990b
parent child
Show More
@@ -15,6 +15,8
15 #include <Common/Numeric.h>
15 #include <Common/Numeric.h>
16 #include <Data/DateTimeRange.h>
16 #include <Data/DateTimeRange.h>
17
17
18 enum class TransformationType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
19
18 namespace DateTimeRangeHelper {
20 namespace DateTimeRangeHelper {
19
21
20
22
@@ -40,6 +42,7 namespace DateTimeRangeHelper {
40 SciQLop::numeric::almost_equal<double>(range1.center(), range2.center(),1);
42 SciQLop::numeric::almost_equal<double>(range1.center(), range2.center(),1);
41 }
43 }
42
44
45
43 /**
46 /**
44 * @brief computeTransformation such as range2 = zoom*range1 + shift
47 * @brief computeTransformation such as range2 = zoom*range1 + shift
45 * @param range1
48 * @param range1
@@ -60,6 +63,24 namespace DateTimeRangeHelper {
60 return transformation;
63 return transformation;
61 }
64 }
62
65
66 inline TransformationType getTransformationType(const DateTimeRange& range1, const DateTimeRange& range2)
67 {
68 auto transformation = computeTransformation (range1,range2);
69 if(transformation.has_value ())
70 {
71 if(SciQLop::numeric::almost_equal(transformation->zoom,1.))
72 {
73 if(transformation->shift > 0.)
74 return TransformationType::PanRight;
75 return TransformationType::PanLeft;
76 }
77 if(transformation->zoom > 0.)
78 return TransformationType::ZoomOut;
79 return TransformationType::ZoomIn;
80 }
81 return TransformationType::Unknown;
82 }
83
63 }
84 }
64
85
65 #endif // SCIQLOP_DATETIMERANGEHELPER_H
86 #endif // SCIQLOP_DATETIMERANGEHELPER_H
@@ -37,7 +37,13 public:
37
37
38 void synchronize(const std::shared_ptr<Variable>& var, const std::shared_ptr<Variable>& with);
38 void synchronize(const std::shared_ptr<Variable>& var, const std::shared_ptr<Variable>& with);
39
39
40 //This should be somewhere else VC has nothing to do with MIMEData
40 QByteArray mimeData(const std::vector<std::shared_ptr<Variable>> &variables) const;
41 QByteArray mimeData(const std::vector<std::shared_ptr<Variable>> &variables) const;
42 const std::vector<std::shared_ptr<Variable>> variables(QByteArray mimeData);
43
44 const std::shared_ptr<Variable>& operator[] (int index) const;
45 std::shared_ptr<Variable> operator[] (int index);
46
41
47
42 signals:
48 signals:
43 void variableAdded(const std::shared_ptr<Variable>&);
49 void variableAdded(const std::shared_ptr<Variable>&);
@@ -61,6 +61,15 class VariableController2::VariableController2Private
61 return _variables[variable];
61 return _variables[variable];
62 }
62 }
63
63
64 inline std::shared_ptr<Variable> variable(int index)
65 {
66 QReadLocker lock{&_lock};
67 [[unlikely]]
68 if(!_variables.size() > index)
69 SCIQLOP_ERROR(threadSafeVaraiblesMaps,"Index is out of bounds");
70 return _variables.values()[index];
71 }
72
64 inline const std::vector<std::shared_ptr<Variable>> variables()
73 inline const std::vector<std::shared_ptr<Variable>> variables()
65 {
74 {
66 std::vector<std::shared_ptr<Variable>> vars;
75 std::vector<std::shared_ptr<Variable>> vars;
@@ -239,6 +248,16 public:
239 return newVar;
248 return newVar;
240 }
249 }
241
250
251 std::shared_ptr<Variable> variable(QUuid ID)
252 {
253 return _maps.variable(ID);
254 }
255
256 std::shared_ptr<Variable> variable(int index)
257 {
258 return _maps.variable(index);
259 }
260
242 std::shared_ptr<Variable> cloneVariable(const std::shared_ptr<Variable>& variable)
261 std::shared_ptr<Variable> cloneVariable(const std::shared_ptr<Variable>& variable)
243 {
262 {
244 auto newVar = variable->clone();
263 auto newVar = variable->clone();
@@ -356,3 +375,29 QByteArray VariableController2::mimeData(const std::vector<std::shared_ptr<Varia
356 }
375 }
357 return encodedData;
376 return encodedData;
358 }
377 }
378
379 const std::vector<std::shared_ptr<Variable>> VariableController2::variables(QByteArray mimeData)
380 {
381 std::vector<std::shared_ptr<Variable>> variables;
382 QDataStream stream{mimeData};
383
384 QVariantList ids;
385 stream >> ids;
386
387 for (const auto& id : ids) {
388 auto uuid = QUuid{id.toByteArray()};
389 variables.push_back (impl->variable(uuid));
390 }
391
392 return variables;
393 }
394
395 const std::shared_ptr<Variable> &VariableController2::operator[](int index) const
396 {
397 return impl->variable (index);
398 }
399
400 std::shared_ptr<Variable> VariableController2::operator[](int index)
401 {
402 return impl->variable (index);
403 }
General Comments 0
You need to be logged in to leave comments. Login now