diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2014-10-05 09:24:40 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:29:20 +0300 |
commit | 8e7b4371361544d28462a54b83903f783b992b2b (patch) | |
tree | e736a87a56e8d946c36a5e86788cc5710b2cac3a /map/country_tree.cpp | |
parent | 4a32bc33e666fe2ddc2f785e434a2dc50cc409b8 (diff) |
review fixes
Diffstat (limited to 'map/country_tree.cpp')
-rw-r--r-- | map/country_tree.cpp | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/map/country_tree.cpp b/map/country_tree.cpp index 51df5a8482..a2a534f2c0 100644 --- a/map/country_tree.cpp +++ b/map/country_tree.cpp @@ -42,21 +42,8 @@ inline TIndex GetIndexParent(TIndex const & index) CountryTree::CountryTree(Framework * framework) : m_framework(framework) { - auto statusChangedFn = [this](TIndex const & index) - { - int childPosition = GetChildPosition(index); - if (childPosition != -1) - m_itemCallback(childPosition); - }; - - auto progressChangedFn = [this](TIndex const & index, LocalAndRemoteSizeT const & progress) - { - int childPosition = GetChildPosition(index); - if (childPosition != -1) - m_progressCallback(childPosition, progress); - }; - - m_subscribeSlotID = m_framework->Storage().Subscribe(statusChangedFn, progressChangedFn); + m_subscribeSlotID = m_framework->Storage().Subscribe(bind(&CountryTree::NotifyStatusChanged, this, _1), + bind(&CountryTree::NotifyProgressChanged, this, _1, _2)); } CountryTree::~CountryTree() @@ -147,14 +134,14 @@ void CountryTree::CancelDownloading(int childPosition) m_framework->Storage().DeleteFromDownloader(GetChild(childPosition)); } -void CountryTree::SetItemChangedListener(TItemChangedFn const & callback) +void CountryTree::SetListener(CountryTreeListener * listener) { - m_itemCallback = callback; + m_listener = listener; } -void CountryTree::SetItemProgressListener(TItemProgressChangedFn const & callback) +void CountryTree::ResetListener() { - m_progressCallback = callback; + m_listener = nullptr; } TIndex const & CountryTree::GetCurrentRoot() const @@ -180,17 +167,35 @@ TIndex const & CountryTree::GetChild(int childPosition) const return m_levelItems[ChildItemsOffset + childPosition]; } -int CountryTree::GetChildPosition(const TIndex & index) +int CountryTree::GetChildPosition(TIndex const & index) { int result = -1; if (HasRoot()) { - for (size_t i = ChildItemsOffset; i < m_levelItems.size(); ++i) - { - if (m_levelItems[i] == index) - result = i; - } + auto iter = find(m_levelItems.begin(), m_levelItems.end(), index); + if (iter != m_levelItems.end()) + result = distance(m_levelItems.begin(), iter) - ChildItemsOffset - 1; } return result; } + +void CountryTree::NotifyStatusChanged(TIndex const & index) +{ + if (m_listener != nullptr) + { + int position = GetChildPosition(index); + if (position != -1) + m_listener->ItemStatusChanged(position); + } +} + +void CountryTree::NotifyProgressChanged(TIndex const & index, LocalAndRemoteSizeT const & sizes) +{ + if (m_listener != nullptr) + { + int position = GetChildPosition(index); + if (position != -1) + m_listener->ItemProgressChanged(position, sizes); + } +} |