diff --git a/include/Data/DateTimeRangeHelper.h b/include/Data/DateTimeRangeHelper.h index 1d7da1f..35ad32c 100644 --- a/include/Data/DateTimeRangeHelper.h +++ b/include/Data/DateTimeRangeHelper.h @@ -15,6 +15,8 @@ #include #include +enum class TransformationType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; + namespace DateTimeRangeHelper { @@ -40,6 +42,7 @@ namespace DateTimeRangeHelper { SciQLop::numeric::almost_equal(range1.center(), range2.center(),1); } + /** * @brief computeTransformation such as range2 = zoom*range1 + shift * @param range1 @@ -60,6 +63,24 @@ namespace DateTimeRangeHelper { return transformation; } + inline TransformationType getTransformationType(const DateTimeRange& range1, const DateTimeRange& range2) + { + auto transformation = computeTransformation (range1,range2); + if(transformation.has_value ()) + { + if(SciQLop::numeric::almost_equal(transformation->zoom,1.)) + { + if(transformation->shift > 0.) + return TransformationType::PanRight; + return TransformationType::PanLeft; + } + if(transformation->zoom > 0.) + return TransformationType::ZoomOut; + return TransformationType::ZoomIn; + } + return TransformationType::Unknown; + } + } #endif // SCIQLOP_DATETIMERANGEHELPER_H diff --git a/include/Variable/VariableController2.h b/include/Variable/VariableController2.h index 1d4409b..15677a0 100644 --- a/include/Variable/VariableController2.h +++ b/include/Variable/VariableController2.h @@ -37,7 +37,13 @@ public: void synchronize(const std::shared_ptr& var, const std::shared_ptr& with); + //This should be somewhere else VC has nothing to do with MIMEData QByteArray mimeData(const std::vector> &variables) const; + const std::vector> variables(QByteArray mimeData); + + const std::shared_ptr& operator[] (int index) const; + std::shared_ptr operator[] (int index); + signals: void variableAdded(const std::shared_ptr&); diff --git a/src/Variable/VariableController2.cpp b/src/Variable/VariableController2.cpp index cf95e4c..fbc0967 100644 --- a/src/Variable/VariableController2.cpp +++ b/src/Variable/VariableController2.cpp @@ -61,6 +61,15 @@ class VariableController2::VariableController2Private return _variables[variable]; } + inline std::shared_ptr variable(int index) + { + QReadLocker lock{&_lock}; + [[unlikely]] + if(!_variables.size() > index) + SCIQLOP_ERROR(threadSafeVaraiblesMaps,"Index is out of bounds"); + return _variables.values()[index]; + } + inline const std::vector> variables() { std::vector> vars; @@ -239,6 +248,16 @@ public: return newVar; } + std::shared_ptr variable(QUuid ID) + { + return _maps.variable(ID); + } + + std::shared_ptr variable(int index) + { + return _maps.variable(index); + } + std::shared_ptr cloneVariable(const std::shared_ptr& variable) { auto newVar = variable->clone(); @@ -356,3 +375,29 @@ QByteArray VariableController2::mimeData(const std::vector> VariableController2::variables(QByteArray mimeData) +{ + std::vector> variables; + QDataStream stream{mimeData}; + + QVariantList ids; + stream >> ids; + + for (const auto& id : ids) { + auto uuid = QUuid{id.toByteArray()}; + variables.push_back (impl->variable(uuid)); + } + + return variables; +} + +const std::shared_ptr &VariableController2::operator[](int index) const +{ + return impl->variable (index); +} + +std::shared_ptr VariableController2::operator[](int index) +{ + return impl->variable (index); +}