diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-11-22 09:25:58 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-11-22 09:35:47 +0200 |
commit | 96bbca5a8c72b2c92e493931178f9341808b69d3 (patch) | |
tree | 3f63f88c5d91b7590b88745d42efbf3460127e3f | |
parent | 6bb1e977eafc61af39d47df083bb3de13205fae9 (diff) | |
download | qtlocation-mapboxgl-upstream/style-persistent-transition-options.tar.gz |
[core] Add Style::setPersistentTransitionOptionsupstream/style-persistent-transition-options
-rw-r--r-- | include/mbgl/style/style.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/style/style_impl.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/style/style_impl.hpp | 2 | ||||
-rw-r--r-- | test/style/style.test.cpp | 7 |
5 files changed, 23 insertions, 1 deletions
diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index d6fdbd8f2c..2c708e4ac7 100644 --- a/include/mbgl/style/style.hpp +++ b/include/mbgl/style/style.hpp @@ -3,6 +3,7 @@ #include <mbgl/style/transition_options.hpp> #include <mbgl/map/camera.hpp> #include <mbgl/util/geo.hpp> +#include <mbgl/util/optional.hpp> #include <string> #include <vector> @@ -39,6 +40,9 @@ public: TransitionOptions getTransitionOptions() const; void setTransitionOptions(const TransitionOptions&); + // Overrides style or runtime-defined transition options. This is meant to persist between style changes. + void setPersistentTransitionOptions(optional<TransitionOptions>); + // Light Light* getLight(); const Light* getLight() const; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index bd8631fc52..5dd40efb98 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -47,6 +47,11 @@ void Style::setTransitionOptions(const TransitionOptions& options) { impl->setTransitionOptions(options); } +void Style::setPersistentTransitionOptions(optional<TransitionOptions> options) { + impl->mutated = true; + impl->setPersistentTransitionOptions(options); +} + void Style::setLight(std::unique_ptr<Light> light) { impl->setLight(std::move(light)); } diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp index 760e2bc396..1e31216be8 100644 --- a/src/mbgl/style/style_impl.cpp +++ b/src/mbgl/style/style_impl.cpp @@ -130,8 +130,12 @@ void Style::Impl::setTransitionOptions(const TransitionOptions& options) { transitionOptions = options; } +void Style::Impl::setPersistentTransitionOptions(optional<TransitionOptions> options) { + persistentTransitionOptions = options; +} + TransitionOptions Style::Impl::getTransitionOptions() const { - return transitionOptions; + return persistentTransitionOptions.value_or(transitionOptions); } void Style::Impl::addSource(std::unique_ptr<Source> source) { diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp index 3dc222bfad..a25428cfac 100644 --- a/src/mbgl/style/style_impl.hpp +++ b/src/mbgl/style/style_impl.hpp @@ -75,6 +75,7 @@ public: TransitionOptions getTransitionOptions() const; void setTransitionOptions(const TransitionOptions&); + void setPersistentTransitionOptions(optional<TransitionOptions>); void setLight(std::unique_ptr<Light>); Light* getLight() const; @@ -112,6 +113,7 @@ private: Collection<Source> sources; Collection<Layer> layers; TransitionOptions transitionOptions; + optional<TransitionOptions> persistentTransitionOptions; std::unique_ptr<Light> light; // Defaults diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index 2371e91107..2e2ce0c39a 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -43,6 +43,13 @@ TEST(Style, Properties) { ASSERT_EQ("", style.getName()); ASSERT_EQ(60, *style.getDefaultCamera().pitch); + const TransitionOptions immediateOptions { { Milliseconds(0) }, { Milliseconds(0) } }; + style.setPersistentTransitionOptions(immediateOptions); + style.loadJSON(R"STYLE({"transition": { "duration": 500, "delay": 50 }})STYLE"); + ASSERT_EQ(Milliseconds(0), *style.getTransitionOptions().duration); + ASSERT_EQ(Milliseconds(0), *style.getTransitionOptions().delay); + + style.setPersistentTransitionOptions({}); style.loadJSON(R"STYLE({})STYLE"); ASSERT_EQ(Milliseconds(300), *style.getTransitionOptions().duration); ASSERT_EQ(optional<Duration> {}, style.getTransitionOptions().delay); |