diff --git a/drape_frontend/user_mark_generator.cpp b/drape_frontend/user_mark_generator.cpp index 2632139575..8768804606 100644 --- a/drape_frontend/user_mark_generator.cpp +++ b/drape_frontend/user_mark_generator.cpp @@ -35,9 +35,9 @@ void UserMarkGenerator::RemoveUserMarks(drape_ptr && ids) if (ids == nullptr) return; for (auto const & id : ids->m_marksID) - m_marks.erase(id); + m_marks.erase(id); for (auto const & id : ids->m_linesID) - m_lines.erase(id); + m_lines.erase(id); } void UserMarkGenerator::SetUserMarks(drape_ptr && marks) diff --git a/map/bookmark.cpp b/map/bookmark.cpp index 75b676cbd6..b1768dd729 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -22,10 +22,11 @@ #include "base/stl_add.hpp" #include "base/string_utils.hpp" -#include "std/algorithm.hpp" -#include "std/auto_ptr.hpp" -#include "std/fstream.hpp" -#include "std/iterator.hpp" +#include +#include +#include +#include +#include Bookmark::Bookmark(m2::PointD const & ptOrg, UserMarkContainer * container) : TBase(ptOrg, container) @@ -55,7 +56,7 @@ dp::Anchor Bookmark::GetAnchor() const return dp::Bottom; } -string Bookmark::GetSymbolName() const +std::string Bookmark::GetSymbolName() const { return GetType(); } @@ -77,22 +78,22 @@ void Bookmark::SetCreationAnimationShown(bool shown) m_hasCreationAnimation = !shown; } -string const & Bookmark::GetName() const +std::string const & Bookmark::GetName() const { return m_data.GetName(); } -void Bookmark::SetName(string const & name) +void Bookmark::SetName(std::string const & name) { m_data.SetName(name); } -string const & Bookmark::GetType() const +std::string const & Bookmark::GetType() const { return m_data.GetType(); } -void Bookmark::SetType(string const & type) +void Bookmark::SetType(std::string const & type) { m_data.SetType(type); } @@ -102,12 +103,12 @@ m2::RectD Bookmark::GetViewport() const return m2::RectD(GetPivot(), GetPivot()); } -string const & Bookmark::GetDescription() const +std::string const & Bookmark::GetDescription() const { return m_data.GetDescription(); } -void Bookmark::SetDescription(string const & description) +void Bookmark::SetDescription(std::string const & description) { m_data.SetDescription(description); } @@ -132,7 +133,7 @@ void Bookmark::SetScale(double scale) m_data.SetScale(scale); } -void BookmarkCategory::AddTrack(unique_ptr && track) +void BookmarkCategory::AddTrack(std::unique_ptr && track) { SetDirty(); m_tracks.push_back(move(track)); @@ -143,7 +144,7 @@ Track const * BookmarkCategory::GetTrack(size_t index) const return (index < m_tracks.size() ? m_tracks[index].get() : 0); } -BookmarkCategory::BookmarkCategory(string const & name, Framework & framework) +BookmarkCategory::BookmarkCategory(std::string const & name, Framework & framework) : TBase(0.0 /* bookmarkDepth */, UserMarkType::BOOKMARK_MARK, framework) , m_name(name) { @@ -181,17 +182,17 @@ void BookmarkCategory::DeleteTrack(size_t index) namespace { - string const kPlacemark = "Placemark"; - string const kStyle = "Style"; - string const kDocument = "Document"; - string const kStyleMap = "StyleMap"; - string const kStyleUrl = "styleUrl"; - string const kPair = "Pair"; + std::string const kPlacemark = "Placemark"; + std::string const kStyle = "Style"; + std::string const kDocument = "Document"; + std::string const kStyleMap = "StyleMap"; + std::string const kStyleUrl = "styleUrl"; + std::string const kPair = "Pair"; - string const kDefaultTrackColor = "DefaultTrackColor"; + std::string const kDefaultTrackColor = "DefaultTrackColor"; float const kDefaultTrackWidth = 5.0f; - string PointToString(m2::PointD const & org) + std::string PointToString(m2::PointD const & org) { double const lon = MercatorBounds::XToLon(org.x); double const lat = MercatorBounds::YToLat(org.y); @@ -213,31 +214,31 @@ namespace class KMLParser { // Fixes icons which are not supported by MapsWithMe. - string GetSupportedBMType(string const & s) const + std::string GetSupportedBMType(std::string const & s) const { // Remove leading '#' symbol. ASSERT(!s.empty(), ()); - string const result = s.substr(1); + std::string const result = s.substr(1); return style::GetSupportedStyle(result, m_name, style::GetDefaultStyle()); } BookmarkCategory & m_category; UserMarksController & m_controller; - vector m_tags; + std::vector m_tags; GeometryType m_geometryType; m2::PolylineD m_points; dp::Color m_trackColor; - string m_styleId; - string m_mapStyleId; - string m_styleUrlKey; - map m_styleUrl2Color; - map m_mapStyle2Style; + std::string m_styleId; + std::string m_mapStyleId; + std::string m_styleUrlKey; + std::map m_styleUrl2Color; + std::map m_mapStyle2Style; - string m_name; - string m_type; - string m_description; + std::string m_name; + std::string m_type; + std::string m_description; time_t m_timeStamp; m2::PointD m_org; @@ -261,7 +262,7 @@ namespace m_geometryType = GEOMETRY_TYPE_UNKNOWN; } - bool ParsePoint(string const & s, char const * delim, m2::PointD & pt) + bool ParsePoint(std::string const & s, char const * delim, m2::PointD & pt) { // order in string is: lon, lat, z @@ -285,7 +286,7 @@ namespace return false; } - void SetOrigin(string const & s) + void SetOrigin(std::string const & s) { m_geometryType = GEOMETRY_TYPE_POINT; @@ -294,7 +295,7 @@ namespace m_org = pt; } - void ParseLineCoordinates(string const & s, char const * blockSeparator, char const * coordSeparator) + void ParseLineCoordinates(std::string const & s, char const * blockSeparator, char const * coordSeparator) { m_geometryType = GEOMETRY_TYPE_LINE; @@ -337,15 +338,15 @@ namespace return false; } - void ParseColor(string const & value) + void ParseColor(std::string const & value) { - string fromHex = FromHex(value); + std::string fromHex = FromHex(value); ASSERT(fromHex.size() == 4, ("Invalid color passed")); // Color positions in HEX – aabbggrr m_trackColor = dp::Color(fromHex[3], fromHex[2], fromHex[1], fromHex[0]); } - bool GetColorForStyle(string const & styleUrl, dp::Color & color) + bool GetColorForStyle(std::string const & styleUrl, dp::Color & color) { if (styleUrl.empty()) return false; @@ -373,15 +374,15 @@ namespace m_category.ReleaseController(); } - bool Push(string const & name) + bool Push(std::string const & name) { m_tags.push_back(name); return true; } - void AddAttr(string const & attr, string const & value) + void AddAttr(std::string const & attr, std::string const & value) { - string attrInLowerCase = attr; + std::string attrInLowerCase = attr; strings::AsciiToLower(attrInLowerCase); if (IsValidAttribute(kStyle, value, attrInLowerCase)) @@ -390,18 +391,19 @@ namespace m_mapStyleId = value; } - bool IsValidAttribute(string const & type, string const & value, string const & attrInLowerCase) const + bool IsValidAttribute(std::string const & type, std::string const & value, + std::string const & attrInLowerCase) const { return (GetTagFromEnd(0) == type && !value.empty() && attrInLowerCase == "id"); } - string const & GetTagFromEnd(size_t n) const + std::string const & GetTagFromEnd(size_t n) const { ASSERT_LESS(n, m_tags.size(), ()); return m_tags[m_tags.size() - n - 1]; } - void Pop(string const & tag) + void Pop(std::string const & tag) { ASSERT_EQUAL(m_tags.back(), tag, ()); @@ -441,16 +443,16 @@ namespace m_tags.pop_back(); } - void CharData(string value) + void CharData(std::string value) { strings::Trim(value); size_t const count = m_tags.size(); if (count > 1 && !value.empty()) { - string const & currTag = m_tags[count - 1]; - string const & prevTag = m_tags[count - 2]; - string const ppTag = count > 3 ? m_tags[count - 3] : string(); + std::string const & currTag = m_tags[count - 1]; + std::string const & prevTag = m_tags[count - 2]; + std::string const ppTag = count > 3 ? m_tags[count - 3] : std::string(); if (prevTag == kDocument) { @@ -472,7 +474,7 @@ namespace if (!GetColorForStyle(value, m_trackColor)) { // Remove leading '#' symbol. - string styleId = m_mapStyle2Style[value.substr(1)]; + std::string styleId = m_mapStyle2Style[value.substr(1)]; if (!styleId.empty()) GetColorForStyle(styleId, m_trackColor); } @@ -564,7 +566,7 @@ namespace }; } -string BookmarkCategory::GetDefaultType() +std::string BookmarkCategory::GetDefaultType() { return style::GetDefaultStyle(); } @@ -582,9 +584,9 @@ bool BookmarkCategory::LoadFromKML(ReaderPtr const & reader) } } -BookmarkCategory * BookmarkCategory::CreateFromKMLFile(string const & file, Framework & framework) +BookmarkCategory * BookmarkCategory::CreateFromKMLFile(std::string const & file, Framework & framework) { - auto_ptr cat(new BookmarkCategory("", framework)); + std::auto_ptr cat(new BookmarkCategory("", framework)); try { if (cat->LoadFromKML(make_unique(file))) @@ -672,17 +674,17 @@ char const * kmlFooter = namespace { - inline void SaveStringWithCDATA(ostream & stream, string const & s) + inline void SaveStringWithCDATA(std::ostream & stream, std::string const & s) { // According to kml/xml spec, we need to escape special symbols with CDATA - if (s.find_first_of("<&") != string::npos) + if (s.find_first_of("<&") != std::string::npos) stream << ""; else stream << s; } } -void BookmarkCategory::SaveToKML(ostream & s) +void BookmarkCategory::SaveToKML(std::ostream & s) { s << kmlHeader; @@ -725,7 +727,7 @@ void BookmarkCategory::SaveToKML(ostream & s) time_t const timeStamp = bm->GetTimeStamp(); if (timeStamp != my::INVALID_TIME_STAMP) { - string const strTimeStamp = my::TimestampToString(timeStamp); + std::string const strTimeStamp = my::TimestampToString(timeStamp); ASSERT_EQUAL(strTimeStamp.size(), 20, ("We always generate fixed length UTC-format timestamp")); s << " " << strTimeStamp << "\n"; } @@ -800,7 +802,7 @@ namespace } } -string BookmarkCategory::RemoveInvalidSymbols(string const & name) +std::string BookmarkCategory::RemoveInvalidSymbols(std::string const & name) { // Remove not allowed symbols strings::UniString uniName = strings::MakeUniString(name); @@ -808,13 +810,13 @@ string BookmarkCategory::RemoveInvalidSymbols(string const & name) return (uniName.empty() ? "Bookmarks" : strings::ToUtf8(uniName)); } -string BookmarkCategory::GenerateUniqueFileName(const string & path, string name) +std::string BookmarkCategory::GenerateUniqueFileName(const std::string & path, std::string name) { - string const kmlExt(BOOKMARKS_FILE_EXTENSION); + std::string const kmlExt(BOOKMARKS_FILE_EXTENSION); // check if file name already contains .kml extension size_t const extPos = name.rfind(kmlExt); - if (extPos != string::npos) + if (extPos != std::string::npos) { // remove extension ASSERT_GREATER_OR_EQUAL(name.size(), kmlExt.size(), ()); @@ -824,7 +826,7 @@ string BookmarkCategory::GenerateUniqueFileName(const string & path, string name } size_t counter = 1; - string suffix; + std::string suffix; while (Platform::IsFileExistsByFullPath(path + name + suffix + kmlExt)) suffix = strings::to_string(counter++); return (path + name + suffix + kmlExt); @@ -837,18 +839,18 @@ UserMark * BookmarkCategory::AllocateUserMark(m2::PointD const & ptOrg) bool BookmarkCategory::SaveToKMLFile() { - string oldFile; + std::string oldFile; // Get valid file name from category name - string const name = RemoveInvalidSymbols(m_name); + std::string const name = RemoveInvalidSymbols(m_name); if (!m_file.empty()) { size_t i2 = m_file.find_last_of('.'); - if (i2 == string::npos) + if (i2 == std::string::npos) i2 = m_file.size(); size_t i1 = m_file.find_last_of("\\/"); - if (i1 == string::npos) + if (i1 == std::string::npos) i1 = 0; else ++i1; @@ -863,13 +865,13 @@ bool BookmarkCategory::SaveToKMLFile() else m_file = GenerateUniqueFileName(GetPlatform().SettingsDir(), name); - string const fileTmp = m_file + ".tmp"; + std::string const fileTmp = m_file + ".tmp"; try { // First, we save to the temporary file /// @todo On Windows UTF-8 file names are not supported. - ofstream of(fileTmp.c_str(), std::ios_base::out | std::ios_base::trunc); + std::ofstream of(fileTmp.c_str(), std::ios_base::out | std::ios_base::trunc); SaveToKML(of); of.flush(); diff --git a/map/bookmark.hpp b/map/bookmark.hpp index 2b343deb28..2d519a2944 100644 --- a/map/bookmark.hpp +++ b/map/bookmark.hpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace anim { @@ -112,7 +113,7 @@ private: class BookmarkCategory : public UserMarkContainer { typedef UserMarkContainer TBase; - vector> m_tracks; + std::vector> m_tracks; std::string m_name; /// Stores file name from which category was loaded @@ -151,7 +152,7 @@ public: /// @name Tracks routine. //@{ - void AddTrack(unique_ptr && track); + void AddTrack(std::unique_ptr && track); Track const * GetTrack(size_t index) const; inline size_t GetTracksCount() const { return m_tracks.size(); } void DeleteTrack(size_t index); diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index dca2246431..ee4c44b9af 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -13,9 +13,9 @@ #include "base/macros.hpp" #include "base/stl_add.hpp" -#include "std/algorithm.hpp" #include "std/target_os.hpp" -#include "std/vector.hpp" + +#include BookmarkManager::BookmarkManager(Framework & f) : m_framework(f) @@ -74,7 +74,7 @@ void BookmarkManager::LoadBookmarks() void BookmarkManager::LoadBookmark(string const & filePath) { - unique_ptr cat(BookmarkCategory::CreateFromKMLFile(filePath, m_framework)); + std::unique_ptr cat(BookmarkCategory::CreateFromKMLFile(filePath, m_framework)); if (cat) m_categories.emplace_back(std::move(cat)); } @@ -151,7 +151,7 @@ size_t BookmarkManager::LastEditedBMCategory() return 0; } -string BookmarkManager::LastEditedBMType() const +std::string BookmarkManager::LastEditedBMType() const { return (m_lastType.empty() ? BookmarkCategory::GetDefaultType() : m_lastType); } @@ -161,7 +161,7 @@ BookmarkCategory * BookmarkManager::GetBmCategory(size_t index) const return (index < m_categories.size() ? m_categories[index].get() : 0); } -size_t BookmarkManager::CreateBmCategory(string const & name) +size_t BookmarkManager::CreateBmCategory(std::string const & name) { m_categories.emplace_back(new BookmarkCategory(name, m_framework)); return (m_categories.size() - 1); diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 85dc54588a..b14b4df97b 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -3,24 +3,27 @@ #include "map/bookmark.hpp" #include "map/user_mark_container.hpp" +#include "geometry/any_rect2d.hpp" + #include #include - +#include +#include class Framework; class PaintEvent; class BookmarkManager : private noncopyable { - using CategoriesCollection = std::vector>; + using CategoriesCollection = std::vector>; using CategoryIter = CategoriesCollection::iterator; - using UserMarkLayers = std::vector>; + using UserMarkLayers = std::vector>; CategoriesCollection m_categories; - string m_lastCategoryUrl; - string m_lastType; + std::string m_lastCategoryUrl; + std::string m_lastType; Framework & m_framework; @@ -50,14 +53,14 @@ public: void ReplaceBookmark(size_t catIndex, size_t bmIndex, BookmarkData const & bm); size_t LastEditedBMCategory(); - string LastEditedBMType() const; + std::string LastEditedBMType() const; inline size_t GetBmCategoriesCount() const { return m_categories.size(); } /// @returns 0 if category is not found BookmarkCategory * GetBmCategory(size_t index) const; - size_t CreateBmCategory(string const & name); + size_t CreateBmCategory(std::string const & name); /// @name Delete bookmarks category with all bookmarks. /// @return true if category was deleted diff --git a/map/track.cpp b/map/track.cpp index 6271c73acb..cb7d0408ce 100644 --- a/map/track.cpp +++ b/map/track.cpp @@ -64,7 +64,7 @@ float Track::GetWidth(size_t layerIndex) const float Track::GetDepth(size_t layerIndex) const { - return 0 + layerIndex * 10; + return layerIndex * 10; } std::vector const & Track::GetPoints() const diff --git a/map/user_mark.cpp b/map/user_mark.cpp index 58d8bdc3c3..5693d23373 100644 --- a/map/user_mark.cpp +++ b/map/user_mark.cpp @@ -48,11 +48,6 @@ UserMarkContainer const * UserMark::GetContainer() const return m_container; } -void UserMark::SetDirty() -{ - m_isDirty = true; -} - ms::LatLon UserMark::GetLatLon() const { return MercatorBounds::ToLatLon(m_ptOrg); diff --git a/map/user_mark.hpp b/map/user_mark.hpp index 71ae0da086..1c0b33d671 100644 --- a/map/user_mark.hpp +++ b/map/user_mark.hpp @@ -21,6 +21,8 @@ class UserMark : public df::UserPointMark { DISALLOW_COPY_AND_MOVE(UserMark); public: + static uint16_t constexpr kDefaultUserMarkProirity = 0xFFFF; + enum class Type { API, @@ -46,7 +48,7 @@ public: dp::GLState::DepthLayer GetDepthLayer() const override; bool HasCreationAnimation() const override; drape_ptr GetTitleDecl() const override { return nullptr; } - uint16_t GetProirity() const override { return 0xFFFF; } + uint16_t GetProirity() const override { return kDefaultUserMarkProirity; } bool SymbolHasPriority() const override { return false; } bool TitleHasPriority() const override { return false; } int GetMinZoom() const override { return 1; } @@ -56,7 +58,7 @@ public: virtual Type GetMarkType() const = 0; protected: - void SetDirty(); + void SetDirty() { m_isDirty = true; } m2::PointD m_ptOrg; mutable UserMarkContainer * m_container; diff --git a/map/user_mark_container.cpp b/map/user_mark_container.cpp index 8ba1b813a1..2f6ad57f06 100644 --- a/map/user_mark_container.cpp +++ b/map/user_mark_container.cpp @@ -252,7 +252,9 @@ void UserMarkContainer::DeleteUserMark(size_t index) m_userMarks.erase(m_userMarks.begin() + index); } else + { LOG(LWARNING, ("Trying to delete non-existing item at index", index)); + } } void UserMarkContainer::AcceptChanges(std::vector & removedMarks) diff --git a/map/user_mark_container.hpp b/map/user_mark_container.hpp index b77193da6b..990e4ceb45 100644 --- a/map/user_mark_container.hpp +++ b/map/user_mark_container.hpp @@ -51,20 +51,20 @@ public: UserMarkContainer(double layerDepth, UserMarkType type, Framework & fm); virtual ~UserMarkContainer(); - // If not found mark on rect result is nullptr - // If mark is found in "d" return distance from rect center - // In multiple select choose mark with min(d) + // If not found mark on rect result is nullptr. + // If mark is found in "d" return distance from rect center. + // In multiple select choose mark with min(d). UserMark const * FindMarkInRect(m2::AnyRectD const & rect, double & d) const; static void InitStaticMarks(UserMarkContainer * container); static PoiMarkPoint * UserMarkForPoi(); static MyPositionMarkPoint * UserMarkForMyPostion(); - /// never save reference on UserMarksController + // Never save references to UserMarksController! UserMarksController & RequestController(); void ReleaseController(); - /// Render info + // UserMarksProvider implementation. size_t GetUserPointCount() const override; df::UserPointMark const * GetUserPointMark(size_t index) const override; @@ -72,6 +72,8 @@ public: df::UserLineMark const * GetUserLineMark(size_t index) const override; bool IsDirty() const override; + + // Discard isDirty flag, return id collection of removed marks since previous method call. void AcceptChanges(std::vector & removedMarks) override; float GetPointDepth() const; @@ -83,7 +85,7 @@ public: UserMarkType GetType() const override final; protected: - /// UserMarksController implementation + // UserMarksController implementation. UserMark * CreateUserMark(m2::PointD const & ptOrg) override; UserMark * GetUserMarkForEdit(size_t index) override; void DeleteUserMark(size_t index) override;