Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2016-04-26 20:48:19 +0300
committerAlex Zolotarev <alex@maps.me>2016-05-01 10:28:03 +0300
commit861cdb910ca40f48dbaf8e096707f0b3b912bb42 (patch)
tree9599e020017dde614929b28a07aceead73363319 /editor
parent0b20c90890459444778897c1fa5cd6a68538f30a (diff)
[editor] Implemented search of a category for a newly added object.
Diffstat (limited to 'editor')
-rw-r--r--editor/editor.pro1
-rw-r--r--editor/new_feature_categories.cpp65
-rw-r--r--editor/new_feature_categories.hpp49
3 files changed, 103 insertions, 12 deletions
diff --git a/editor/editor.pro b/editor/editor.pro
index 1d44a39150..c8b3f768b9 100644
--- a/editor/editor.pro
+++ b/editor/editor.pro
@@ -12,6 +12,7 @@ SOURCES += \
changeset_wrapper.cpp \
editor_config.cpp \
editor_notes.cpp \
+ new_feature_categories.cpp \
opening_hours_ui.cpp \
osm_auth.cpp \
osm_feature_matcher.cpp \
diff --git a/editor/new_feature_categories.cpp b/editor/new_feature_categories.cpp
new file mode 100644
index 0000000000..8b235d1db8
--- /dev/null
+++ b/editor/new_feature_categories.cpp
@@ -0,0 +1,65 @@
+#include "new_feature_categories.hpp"
+
+#include "indexer/categories_holder.hpp"
+#include "indexer/classificator.hpp"
+
+#include "base/stl_helpers.hpp"
+
+#include "std/algorithm.hpp"
+
+namespace osm
+{
+NewFeatureCategories::NewFeatureCategories(editor::EditorConfig const & config)
+{
+ // TODO(mgsergio): Load types user can create from XML file.
+ // TODO: Not every editable type can be created by user.
+ // TODO(mgsergio): Store in Settings:: recent history of created types and use them here.
+ // Max history items count shoud be set in the config.
+ Classificator const & cl = classif();
+ for (auto const & classificatorType : config.GetTypesThatCanBeAdded())
+ {
+ uint32_t const type = cl.GetTypeByReadableObjectName(classificatorType);
+ if (type == 0)
+ {
+ LOG(LWARNING, ("Unknown type in Editor's config:", classificatorType));
+ continue;
+ }
+ m_types.push_back(type);
+ }
+}
+
+void NewFeatureCategories::AddLanguage(string const & lang)
+{
+ auto const langCode = CategoriesHolder::MapLocaleToInteger(lang);
+ vector<string> names;
+ names.reserve(m_types.size());
+ for (auto const & type : m_types)
+ {
+ m_index.AddCategoryByTypeAndLang(type, langCode);
+ names.push_back(m_index.GetCategoriesHolder().GetReadableFeatureType(type, langCode));
+ }
+ my::SortUnique(names);
+ m_categoryNames[lang] = names;
+}
+
+vector<string> NewFeatureCategories::Search(string const & query, string const & lang) const
+{
+ auto const langCode = CategoriesHolder::MapLocaleToInteger(lang);
+ vector<uint32_t> resultTypes;
+ m_index.GetAssociatedTypes(query, resultTypes);
+
+ vector<string> result(resultTypes.size());
+ for (size_t i = 0; i < result.size(); ++i)
+ result[i] = m_index.GetCategoriesHolder().GetReadableFeatureType(resultTypes[i], langCode);
+ my::SortUnique(result);
+ return result;
+}
+
+vector<string> NewFeatureCategories::GetAllCategoryNames(string const & lang)
+{
+ auto const it = m_categoryNames.find(lang);
+ if (it == m_categoryNames.end())
+ return {};
+ return it->second;
+}
+} // namespace osm
diff --git a/editor/new_feature_categories.hpp b/editor/new_feature_categories.hpp
index c4b3a84200..eb4d45f3c6 100644
--- a/editor/new_feature_categories.hpp
+++ b/editor/new_feature_categories.hpp
@@ -1,25 +1,50 @@
#pragma once
+#include "editor/editor_config.hpp"
+
+#include "indexer/categories_index.hpp"
+
+#include "base/macros.hpp"
+
#include "std/cstdint.hpp"
+#include "std/map.hpp"
#include "std/string.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"
namespace osm
{
-/// Category is an UI synonym to our internal "classificator type".
-struct Category
+// This class holds an index of categories that can be set for a newly added feature.
+class NewFeatureCategories
{
- Category(uint32_t type, string const & name) : m_type(type), m_name(name) {}
- /// Feature type from classificator.
- uint32_t m_type;
- /// Localized category name. English is used by default.
- string m_name;
-};
+public:
+ NewFeatureCategories(editor::EditorConfig const & config);
-struct NewFeatureCategories
-{
- vector<Category> m_lastUsed;
- vector<Category> m_allSorted;
+ NewFeatureCategories(NewFeatureCategories && other)
+ : m_index(move(other.m_index))
+ , m_types(move(other.m_types))
+ , m_categoryNames(move(other.m_categoryNames))
+ {
+ }
+
+ // Adds all known synonyms in language |lang| for all categories that
+ // can be applied to a newly added feature.
+ void AddLanguage(string const & lang);
+
+ // Returns names (in language |lang|) of categories that have a synonym containing
+ // the substring |query| (in any language that was added before).
+ // The returned list is sorted.
+ vector<string> Search(string const & query, string const & lang) const;
+
+ // Returns all registered names of categories in language |lang|.
+ // The returned list is sorted.
+ vector<string> GetAllCategoryNames(string const & lang);
+
+private:
+ indexer::CategoriesIndex m_index;
+ vector<uint32_t> m_types;
+ map<string, vector<string>> m_categoryNames;
+
+ DISALLOW_COPY(NewFeatureCategories);
};
} // namespace osm