Dropped UserMarkManager and UserMarksController.

This commit is contained in:
Daria Volvenkova 2018-02-01 03:03:28 +03:00 committed by Roman Kuznetsov
parent 7e4cc74bf9
commit 79daba4551
16 changed files with 78 additions and 130 deletions

View file

@ -29,13 +29,13 @@ string GetDefaultStyle() { return kSupportedColors[0]; }
} // style
ApiMarkPoint::ApiMarkPoint(m2::PointD const & ptOrg, UserMarkManager * manager)
: UserMark(ptOrg, manager, UserMark::Type::API)
ApiMarkPoint::ApiMarkPoint(m2::PointD const & ptOrg)
: UserMark(ptOrg, UserMark::Type::API)
{}
ApiMarkPoint::ApiMarkPoint(string const & name, string const & id, string const & style,
m2::PointD const & ptOrg, UserMarkManager * manager)
: UserMark(ptOrg, manager, UserMark::Type::API),
m2::PointD const & ptOrg)
: UserMark(ptOrg, UserMark::Type::API),
m_name(name),
m_id(id),
m_style(style)

View file

@ -20,10 +20,10 @@ string GetDefaultStyle();
class ApiMarkPoint : public UserMark
{
public:
ApiMarkPoint(m2::PointD const & ptOrg, UserMarkManager * manager);
ApiMarkPoint(m2::PointD const & ptOrg);
ApiMarkPoint(string const & name, string const & id, string const & style,
m2::PointD const & ptOrg, UserMarkManager * manager);
m2::PointD const & ptOrg);
drape_ptr<SymbolNameZoomInfo> GetSymbolNames() const override;
m2::PointD GetPixelOffset() const override;

View file

@ -28,14 +28,13 @@
#include <map>
#include <memory>
Bookmark::Bookmark(m2::PointD const & ptOrg, UserMarkManager * manager, size_t categoryId)
: Base(ptOrg, manager, UserMark::BOOKMARK)
Bookmark::Bookmark(m2::PointD const & ptOrg, size_t categoryId)
: Base(ptOrg, UserMark::BOOKMARK)
, m_categoryId(categoryId)
{}
Bookmark::Bookmark(BookmarkData const & data, m2::PointD const & ptOrg,
UserMarkManager * manager, size_t categoryId)
: Base(ptOrg, manager, UserMark::BOOKMARK)
Bookmark::Bookmark(BookmarkData const & data, m2::PointD const & ptOrg, size_t categoryId)
: Base(ptOrg, UserMark::BOOKMARK)
, m_data(data)
, m_categoryId(categoryId)
{}
@ -140,7 +139,7 @@ Track const * BookmarkCategory::GetTrack(size_t index) const
BookmarkCategory::BookmarkCategory(std::string const & name,
size_t index,
Listeners const & listeners)
: Base(0.0 /* bookmarkDepth */, UserMark::Type::BOOKMARK, listeners)
: Base(UserMark::Type::BOOKMARK, listeners)
, m_name(name)
, m_index(index)
{}
@ -229,8 +228,7 @@ class KMLParser
std::string const result = s.substr(1);
return style::GetSupportedStyle(result, m_name, style::GetDefaultStyle());
}
UserMarkManager * m_manager;
BookmarkCategory & m_category;
std::vector<std::string> m_tags;
@ -370,9 +368,8 @@ class KMLParser
}
public:
KMLParser(UserMarkManager * manager, BookmarkCategory & cat)
: m_manager(manager),
m_category(cat)
KMLParser(BookmarkCategory & cat)
: m_category(cat)
{
Reset();
}
@ -420,7 +417,7 @@ public:
{
if (GEOMETRY_TYPE_POINT == m_geometryType)
{
Bookmark * bm = static_cast<Bookmark *>(m_category.CreateUserMark(m_manager, m_org));
Bookmark * bm = static_cast<Bookmark *>(m_category.CreateUserMark(m_org));
bm->SetData(BookmarkData(m_name, m_type, m_description, m_scale, m_timeStamp));
}
else if (GEOMETRY_TYPE_LINE == m_geometryType)
@ -577,10 +574,10 @@ std::string BookmarkCategory::GetDefaultType()
return style::GetDefaultStyle();
}
bool BookmarkCategory::LoadFromKML(UserMarkManager * manager, ReaderPtr<Reader> const & reader)
bool BookmarkCategory::LoadFromKML(ReaderPtr<Reader> const & reader)
{
ReaderSource<ReaderPtr<Reader> > src(reader);
KMLParser parser(manager, *this);
KMLParser parser(*this);
if (!ParseXML(src, parser, true))
{
LOG(LWARNING, ("XML read error. Probably, incorrect file encoding."));
@ -590,15 +587,14 @@ bool BookmarkCategory::LoadFromKML(UserMarkManager * manager, ReaderPtr<Reader>
}
// static
std::unique_ptr<BookmarkCategory> BookmarkCategory::CreateFromKMLFile(UserMarkManager * manager,
std::string const & file,
std::unique_ptr<BookmarkCategory> BookmarkCategory::CreateFromKMLFile(std::string const & file,
size_t index,
Listeners const & listeners)
{
auto cat = my::make_unique<BookmarkCategory>("", index, listeners);
try
{
if (cat->LoadFromKML(manager, my::make_unique<FileReader>(file)))
if (cat->LoadFromKML(my::make_unique<FileReader>(file)))
cat->m_file = file;
else
cat.reset();
@ -797,9 +793,9 @@ void BookmarkCategory::SaveToKML(std::ostream & s)
s << kmlFooter;
}
UserMark * BookmarkCategory::AllocateUserMark(UserMarkManager * manager, m2::PointD const & ptOrg)
UserMark * BookmarkCategory::AllocateUserMark(m2::PointD const & ptOrg)
{
return new Bookmark(ptOrg, manager, m_index);
return new Bookmark(ptOrg, m_index);
}
bool BookmarkCategory::SaveToKMLFile()

View file

@ -74,10 +74,9 @@ class Bookmark : public UserMark
{
using Base = UserMark;
public:
Bookmark(m2::PointD const & ptOrg, UserMarkManager * manager, size_t categoryId);
Bookmark(m2::PointD const & ptOrg, size_t categoryId);
Bookmark(BookmarkData const & data, m2::PointD const & ptOrg,
UserMarkManager * manager, size_t categoryId);
Bookmark(BookmarkData const & data, m2::PointD const & ptOrg, size_t categoryId);
void SetData(BookmarkData const & data);
BookmarkData const & GetData() const;
@ -144,7 +143,7 @@ protected:
/// @name Theese fuctions are public for unit tests only.
/// You don't need to call them from client code.
//@{
bool LoadFromKML(UserMarkManager * manager, ReaderPtr<Reader> const & reader);
bool LoadFromKML(ReaderPtr<Reader> const & reader);
void SaveToKML(std::ostream & s);
/// Uses the same file name from which was loaded, or
@ -152,14 +151,13 @@ protected:
bool SaveToKMLFile();
/// @return nullptr in the case of error
static std::unique_ptr<BookmarkCategory> CreateFromKMLFile(UserMarkManager * manager,
std::string const & file,
static std::unique_ptr<BookmarkCategory> CreateFromKMLFile(std::string const & file,
size_t index,
Listeners const & listeners);
//@}
protected:
UserMark * AllocateUserMark(UserMarkManager * manager, m2::PointD const & ptOrg) override;
UserMark * AllocateUserMark(m2::PointD const & ptOrg) override;
private:
std::vector<std::unique_ptr<Track>> m_tracks;

View file

@ -125,8 +125,8 @@ BookmarkManager::BookmarkManager(Callbacks && callbacks)
m_userMarkLayers[UserMark::LOCAL_ADS] = my::make_unique<LocalAdsMarkContainer>();
m_userMarkLayers[UserMark::DEBUG_MARK] = my::make_unique<DebugUserMarkContainer>();
m_selectionMark = my::make_unique<StaticMarkPoint>(this);
m_myPositionMark = my::make_unique<MyPositionMarkPoint>(this);
m_selectionMark = my::make_unique<StaticMarkPoint>();
m_myPositionMark = my::make_unique<MyPositionMarkPoint>();
}
BookmarkManager::~BookmarkManager()
@ -135,11 +135,6 @@ BookmarkManager::~BookmarkManager()
}
////////////////////////////
float BookmarkManager::GetPointDepth(size_t categoryId) const
{
return FindContainer(categoryId)->GetPointDepth();
}
void BookmarkManager::NotifyChanges(size_t categoryId)
{
FindContainer(categoryId)->NotifyChanges();
@ -224,7 +219,7 @@ UserMark const * BookmarkManager::FindMarkInRect(size_t categoryId, m2::AnyRectD
UserMark * BookmarkManager::CreateUserMark(size_t categoryId, m2::PointD const & ptOrg)
{
return FindContainer(categoryId)->CreateUserMark(this, ptOrg);
return FindContainer(categoryId)->CreateUserMark(ptOrg);
}
void BookmarkManager::SetIsVisible(size_t categoryId, bool visible)
@ -299,7 +294,7 @@ void BookmarkManager::LoadBookmarks()
for (auto const & file : files)
{
size_t const id = m_nextCategoryId++;
auto cat = BookmarkCategory::CreateFromKMLFile(this, dir + file, id, m_bookmarksListeners);
auto cat = BookmarkCategory::CreateFromKMLFile(dir + file, id, m_bookmarksListeners);
if (m_needTeardown)
return;
@ -340,7 +335,7 @@ void BookmarkManager::LoadBookmarkRoutine(std::string const & filePath, bool isT
else
{
auto const id = m_nextCategoryId++;
auto cat = BookmarkCategory::CreateFromKMLFile(this, fileSavePath.get(), id, m_bookmarksListeners);
auto cat = BookmarkCategory::CreateFromKMLFile(fileSavePath.get(), id, m_bookmarksListeners);
if (m_needTeardown)
return;
@ -470,7 +465,7 @@ size_t BookmarkManager::AddBookmark(size_t categoryId, m2::PointD const & ptOrg,
BookmarkCategory * cat = GetBmCategory(categoryId);
auto bookmark = static_cast<Bookmark *>(cat->CreateUserMark(this, ptOrg));
auto bookmark = static_cast<Bookmark *>(cat->CreateUserMark(ptOrg));
bookmark->SetData(bm);
cat->SetIsVisible(true);
cat->SaveToKMLFile();
@ -777,7 +772,7 @@ void BookmarkManager::MergeCategories(CategoriesCollection && newCategories)
for (size_t i = 0, sz = newCat->GetUserMarkCount(); i < sz; ++i)
{
auto srcBookmark = static_cast<Bookmark const *>(newCat->GetUserMark(i));
auto bookmark = static_cast<Bookmark *>(existingCat->CreateUserMark(this, srcBookmark->GetPivot()));
auto bookmark = static_cast<Bookmark *>(existingCat->CreateUserMark(srcBookmark->GetPivot()));
bookmark->SetData(srcBookmark->GetData());
}
existingCat->AppendTracks(newCat->StealTracks());

View file

@ -20,7 +20,7 @@
#include <boost/optional.hpp>
class BookmarkManager final : public UserMarkManager
class BookmarkManager final
{
using CategoriesCollection = std::map<size_t, std::unique_ptr<BookmarkCategory>>;
using CategoryIter = CategoriesCollection::iterator;
@ -67,7 +67,6 @@ public:
~BookmarkManager();
//////////////////
float GetPointDepth(size_t categoryId) const override;
void NotifyChanges(size_t categoryId);
size_t GetUserMarkCount(size_t categoryId) const;
UserMark const * GetUserMark(size_t categoryId, size_t index) const;

View file

@ -16,9 +16,8 @@ float const kLocalAdsSecondaryTextSize = 10.0f;
float const kSecondaryOffsetY = 2.0;
} // namespace
LocalAdsMark::LocalAdsMark(m2::PointD const & ptOrg,
UserMarkManager * manager)
: UserMark(ptOrg, manager, Type::LOCAL_ADS)
LocalAdsMark::LocalAdsMark(m2::PointD const & ptOrg)
: UserMark(ptOrg, Type::LOCAL_ADS)
{
m_titleDecl.m_anchor = dp::Top;
m_titleDecl.m_primaryTextFont.m_color = df::GetColorConstant(kLocalAdsPrimaryText);

View file

@ -19,7 +19,7 @@ struct LocalAdsMarkData
class LocalAdsMark : public UserMark
{
public:
LocalAdsMark(m2::PointD const & ptOrg, UserMarkManager * manager);
LocalAdsMark(m2::PointD const & ptOrg);
virtual ~LocalAdsMark() {}
df::RenderState::DepthLayer GetDepthLayer() const override;

View file

@ -21,8 +21,8 @@ float const kRouteMarkSecondaryOffsetY = 2.0f;
float const kTransitMarkTextSize = 12.0f;
} // namespace
RouteMarkPoint::RouteMarkPoint(m2::PointD const & ptOrg, UserMarkManager * manager)
: UserMark(ptOrg, manager, Type::ROUTING)
RouteMarkPoint::RouteMarkPoint(m2::PointD const & ptOrg)
: UserMark(ptOrg, Type::ROUTING)
{
m_titleDecl.m_anchor = dp::Top;
m_titleDecl.m_primaryTextFont.m_color = df::GetColorConstant(kRouteMarkPrimaryText);
@ -416,8 +416,8 @@ void RoutePointsLayout::NotifyChanges()
m_manager.NotifyChanges(UserMark::Type::ROUTING);
}
TransitMark::TransitMark(m2::PointD const & ptOrg, UserMarkManager * manager)
: UserMark(ptOrg, manager, Type::TRANSIT)
TransitMark::TransitMark(m2::PointD const & ptOrg)
: UserMark(ptOrg, Type::TRANSIT)
{}
void TransitMark::SetFeatureId(FeatureID featureId)

View file

@ -27,7 +27,7 @@ struct RouteMarkData
class RouteMarkPoint : public UserMark
{
public:
RouteMarkPoint(m2::PointD const & ptOrg, UserMarkManager * manager);
RouteMarkPoint(m2::PointD const & ptOrg);
virtual ~RouteMarkPoint() {}
bool IsVisible() const override { return m_markData.m_isVisible; }
@ -106,7 +106,7 @@ private:
class TransitMark : public UserMark
{
public:
TransitMark(m2::PointD const & ptOrg, UserMarkManager * manager);
TransitMark(m2::PointD const & ptOrg);
virtual ~TransitMark() {}
df::RenderState::DepthLayer GetDepthLayer() const override { return df::RenderState::TransitMarkLayer; }

View file

@ -28,8 +28,8 @@ std::vector<std::string> const kPreparingSymbols =
};
} // namespace
SearchMarkPoint::SearchMarkPoint(m2::PointD const & ptOrg, UserMarkManager * manager)
: UserMark(ptOrg, manager, UserMark::Type::SEARCH)
SearchMarkPoint::SearchMarkPoint(m2::PointD const & ptOrg)
: UserMark(ptOrg, UserMark::Type::SEARCH)
{}
drape_ptr<df::UserPointMark::SymbolNameZoomInfo> SearchMarkPoint::GetSymbolNames() const

View file

@ -26,7 +26,7 @@ class BookmarkManager;
class SearchMarkPoint : public UserMark
{
public:
SearchMarkPoint(m2::PointD const & ptOrg, UserMarkManager * manager);
SearchMarkPoint(m2::PointD const & ptOrg);
drape_ptr<SymbolNameZoomInfo> GetSymbolNames() const override;

View file

@ -7,8 +7,8 @@
#include "base/string_utils.hpp"
UserMark::UserMark(m2::PointD const & ptOrg, UserMarkManager * manager, UserMark::Type type)
: m_ptOrg(ptOrg), m_manager(manager), m_type(type), m_id(type)
UserMark::UserMark(m2::PointD const & ptOrg, UserMark::Type type)
: m_ptOrg(ptOrg), m_type(type)
{}
m2::PointD const & UserMark::GetPivot() const
@ -36,8 +36,8 @@ ms::LatLon UserMark::GetLatLon() const
return MercatorBounds::ToLatLon(m_ptOrg);
}
StaticMarkPoint::StaticMarkPoint(UserMarkManager * manager)
: UserMark(m2::PointD{}, manager, UserMark::Type::STATIC)
StaticMarkPoint::StaticMarkPoint()
: UserMark(m2::PointD{}, UserMark::Type::STATIC)
{}
void StaticMarkPoint::SetPtOrg(m2::PointD const & ptOrg)
@ -46,12 +46,12 @@ void StaticMarkPoint::SetPtOrg(m2::PointD const & ptOrg)
m_ptOrg = ptOrg;
}
MyPositionMarkPoint::MyPositionMarkPoint(UserMarkManager * manager)
: StaticMarkPoint(manager)
MyPositionMarkPoint::MyPositionMarkPoint()
: StaticMarkPoint()
{}
DebugMarkPoint::DebugMarkPoint(const m2::PointD & ptOrg, UserMarkManager * manager)
: UserMark(ptOrg, manager, UserMark::Type::DEBUG_MARK)
DebugMarkPoint::DebugMarkPoint(const m2::PointD & ptOrg)
: UserMark(ptOrg, UserMark::Type::DEBUG_MARK)
{}
drape_ptr<df::UserPointMark::SymbolNameZoomInfo> DebugMarkPoint::GetSymbolNames() const

View file

@ -13,8 +13,6 @@
#include "std/unique_ptr.hpp"
#include "std/utility.hpp"
class UserMarkManager;
class UserMark : public df::UserPointMark
{
public:
@ -45,7 +43,7 @@ public:
PREDEFINED_COUNT = BOOKMARK
};
UserMark(m2::PointD const & ptOrg, UserMarkManager * container, UserMark::Type type);
UserMark(m2::PointD const & ptOrg, UserMark::Type type);
// df::UserPointMark overrides.
bool IsDirty() const override { return m_isDirty; }
@ -77,9 +75,7 @@ protected:
void SetDirty() { m_isDirty = true; }
m2::PointD m_ptOrg;
mutable UserMarkManager * m_manager;
Type m_type;
size_t m_id;
private:
mutable bool m_isDirty = true;
@ -90,7 +86,7 @@ private:
class StaticMarkPoint : public UserMark
{
public:
explicit StaticMarkPoint(UserMarkManager * manager);
explicit StaticMarkPoint();
drape_ptr<SymbolNameZoomInfo> GetSymbolNames() const override { return nullptr; }
@ -100,7 +96,7 @@ public:
class MyPositionMarkPoint : public StaticMarkPoint
{
public:
explicit MyPositionMarkPoint(UserMarkManager * manager);
explicit MyPositionMarkPoint();
void SetUserPosition(m2::PointD const & pt, bool hasPosition)
{
@ -116,7 +112,7 @@ private:
class DebugMarkPoint : public UserMark
{
public:
DebugMarkPoint(m2::PointD const & ptOrg, UserMarkManager * manager);
DebugMarkPoint(m2::PointD const & ptOrg);
drape_ptr<SymbolNameZoomInfo> GetSymbolNames() const override;
};

View file

@ -53,10 +53,9 @@ df::MarkGroupID GenerateMarkGroupId(UserMarkContainer const * cont)
}
} // namespace
UserMarkContainer::UserMarkContainer(double layerDepth, UserMark::Type type,
UserMarkContainer::UserMarkContainer(UserMark::Type type,
Listeners const & listeners)
: m_layerDepth(layerDepth)
, m_type(type)
: m_type(type)
, m_listeners(listeners)
{
m_flags.set();
@ -192,11 +191,6 @@ df::UserLineMark const * UserMarkContainer::GetUserLineMark(size_t index) const
return nullptr;
}
float UserMarkContainer::GetPointDepth() const
{
return static_cast<float>(m_layerDepth);
}
bool UserMarkContainer::IsVisible() const
{
return m_flags[VisibleFlag];
@ -207,11 +201,11 @@ bool UserMarkContainer::IsDrawable() const
return m_flags[DrawableFlag];
}
UserMark * UserMarkContainer::CreateUserMark(UserMarkManager * manager, m2::PointD const & ptOrg)
UserMark * UserMarkContainer::CreateUserMark(m2::PointD const & ptOrg)
{
// Push front an user mark.
SetDirty();
m_userMarks.push_front(unique_ptr<UserMark>(AllocateUserMark(manager, ptOrg)));
m_userMarks.push_front(unique_ptr<UserMark>(AllocateUserMark(ptOrg)));
m_userMarksDict.insert(make_pair(m_userMarks.front()->GetId(), m_userMarks.front().get()));
m_createdMarks.insert(m_userMarks.front()->GetId());
return m_userMarks.front().get();

View file

@ -17,32 +17,7 @@
#include <memory>
#include <set>
class UserMarksController
{
protected:
friend class BookmarkManager;
virtual size_t GetUserMarkCount() const = 0;
virtual UserMark::Type GetType() const = 0;
virtual void SetIsVisible(bool isVisible) = 0;
virtual UserMark * CreateUserMark(UserMarkManager * manager, m2::PointD const & ptOrg) = 0;
virtual UserMark const * GetUserMark(size_t index) const = 0;
virtual UserMark * GetUserMarkForEdit(size_t index) = 0;
virtual void DeleteUserMark(size_t index) = 0;
virtual void Clear() = 0;
virtual void Update() = 0;
virtual void NotifyChanges() = 0;
};
class UserMarkManager
{
public:
virtual float GetPointDepth(size_t id) const = 0;
};
class UserMarkContainer : public df::UserMarksProvider
, public UserMarksController
{
public:
using TUserMarksList = std::deque<std::unique_ptr<UserMark>>;
@ -64,7 +39,7 @@ public:
NotifyChangesFn m_deleteListener;
};
UserMarkContainer(double layerDepth, UserMark::Type type,
UserMarkContainer(UserMark::Type type,
Listeners const & listeners = Listeners());
~UserMarkContainer() override;
@ -94,27 +69,23 @@ protected:
void AcceptChanges(df::MarkIDCollection & createdMarks,
df::MarkIDCollection & removedMarks) override;
float GetPointDepth() const;
bool IsVisible() const;
bool IsDrawable() const override;
size_t GetUserMarkCount() const override;
UserMark const * GetUserMark(size_t index) const override;
UserMark::Type GetType() const override final;
// UserMarksController implementation.
UserMark * CreateUserMark(UserMarkManager * manager, m2::PointD const & ptOrg) override;
UserMark * GetUserMarkForEdit(size_t index) override;
void DeleteUserMark(size_t index) override;
void Clear() override;
void SetIsVisible(bool isVisible) override;
void Update() override;
void NotifyChanges() override;
bool IsDrawable() const;
size_t GetUserMarkCount() const;
UserMark const * GetUserMark(size_t index) const;
UserMark::Type GetType() const;
UserMark * CreateUserMark(m2::PointD const & ptOrg);
UserMark * GetUserMarkForEdit(size_t index);
void DeleteUserMark(size_t index);
void Clear();
void SetIsVisible(bool isVisible);
void Update();
void NotifyChanges();
protected:
void SetDirty();
virtual UserMark * AllocateUserMark(UserMarkManager * manager, m2::PointD const & ptOrg) = 0;
virtual UserMark * AllocateUserMark(m2::PointD const & ptOrg) = 0;
private:
void NotifyListeners();
@ -139,12 +110,12 @@ class SpecifiedUserMarkContainer : public UserMarkContainer
{
public:
explicit SpecifiedUserMarkContainer()
: UserMarkContainer(0.0 /* layer depth */, UserMarkType)
: UserMarkContainer(UserMarkType)
{}
protected:
UserMark * AllocateUserMark(UserMarkManager * manager, m2::PointD const & ptOrg) override
UserMark * AllocateUserMark(m2::PointD const & ptOrg) override
{
return new MarkPointClassType(ptOrg, manager);
return new MarkPointClassType(ptOrg);
}
};