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
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2016-02-12 21:50:43 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:21:18 +0300
commit0ac3f7c5b0b55a5ec344b656913e2c3218a9dc6f (patch)
tree0a1fae2fb864fcb16da286858f766e391d0fb97b /indexer
parentaad9bc9bc6d260d5ac754d3f6a205e7fd6315b62 (diff)
[editor] Better GetEditableProperties implementation.
Diffstat (limited to 'indexer')
-rw-r--r--indexer/ftypes_matcher.cpp5
-rw-r--r--indexer/ftypes_matcher.hpp2
-rw-r--r--indexer/osm_editor.cpp74
-rw-r--r--indexer/osm_editor.hpp17
4 files changed, 39 insertions, 59 deletions
diff --git a/indexer/ftypes_matcher.cpp b/indexer/ftypes_matcher.cpp
index 9dad8933bb..798a168fca 100644
--- a/indexer/ftypes_matcher.cpp
+++ b/indexer/ftypes_matcher.cpp
@@ -45,11 +45,6 @@ bool BaseChecker::operator() (vector<uint32_t> const & types) const
return false;
}
-bool BaseChecker::HasTypeValue(uint32_t const type) const
-{
- return find(m_types.begin(), m_types.end(), type) != m_types.end();
-}
-
IsPeakChecker::IsPeakChecker()
{
Classificator const & c = classif();
diff --git a/indexer/ftypes_matcher.hpp b/indexer/ftypes_matcher.hpp
index 48bb6348fd..e767abbb4f 100644
--- a/indexer/ftypes_matcher.hpp
+++ b/indexer/ftypes_matcher.hpp
@@ -30,8 +30,6 @@ public:
bool operator() (feature::TypesHolder const & types) const;
bool operator() (FeatureType const & ft) const;
bool operator() (vector<uint32_t> const & types) const;
- // Simple type equality comparison. No magic like in IsMatched.
- bool HasTypeValue(uint32_t const type) const;
static uint32_t PrepareToMatch(uint32_t type, uint8_t level);
};
diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp
index a39103e941..15d87e2600 100644
--- a/indexer/osm_editor.cpp
+++ b/indexer/osm_editor.cpp
@@ -445,7 +445,7 @@ void Editor::Save(string const & fullFilePath) const
if (doc)
{
- auto const & tmpFileName = fullFilePath + ".tmp";
+ string const tmpFileName = fullFilePath + ".tmp";
if (!doc.save_file(tmpFileName.data(), " "))
LOG(LERROR, ("Can't save map edits into", tmpFileName));
else if (!my::RenameFileX(tmpFileName, fullFilePath))
@@ -619,63 +619,45 @@ vector<uint32_t> Editor::GetFeaturesByStatus(MwmSet::MwmId const & mwmId, Featur
return features;
}
-vector<Metadata::EType> Editor::EditableMetadataForType(FeatureType const & feature) const
+EditableProperties Editor::GetEditableProperties(FeatureType const & feature) const
{
- // TODO(mgsergio): Load editable fields into memory from XML and query them here.
+ // TODO(mgsergio): Load editable fields into memory from XML config and query them here.
+ EditableProperties editable;
feature::TypesHolder const types(feature);
- set<Metadata::EType> fields;
- auto const & isBuilding = ftypes::IsBuildingChecker::Instance();
- for (auto type : types)
+ for (uint32_t const type : types)
{
+ // TODO(mgsergio): If some fields for one type are marked as "NOT edited" in the config,
+ // they should have priority over same "edited" fields in other feature's types.
auto const * desc = GetTypeDescription(type);
if (desc)
{
- for (auto field : desc->m_fields)
- fields.insert(field);
- // If address is editable, many metadata fields are editable too.
- if (desc->m_address)
- {
- fields.insert(EType::FMD_EMAIL);
- fields.insert(EType::FMD_OPEN_HOURS);
- fields.insert(EType::FMD_PHONE_NUMBER);
- fields.insert(EType::FMD_WEBSITE);
- }
- }
- else if (isBuilding.HasTypeValue(type))
- {
- // Post boxes and post offices have editable postcode field defined separately.
- fields.insert(EType::FMD_POSTCODE);
+ editable.m_name = desc->m_name;
+ editable.m_address = desc->m_address;
+
+ for (EType const field : desc->m_fields)
+ editable.m_metadata.push_back(field);
}
}
- return {begin(fields), end(fields)};
-}
+ // Buildings are processed separately.
+ // TODO(mgsergio): Activate this code by XML config variable.
+ if (ftypes::IsBuildingChecker::Instance()(feature))
+ editable.m_address = true;
-bool Editor::IsNameEditable(FeatureType const & feature) const
-{
- feature::TypesHolder const types(feature);
- for (auto type : types)
+ // If address is editable, many metadata fields are editable too.
+ if (editable.m_address)
{
- auto const * typeDesc = GetTypeDescription(type);
- if (typeDesc && typeDesc->m_name)
- return true;
+ // TODO(mgsergio): Load address-related editable properties from XML config.
+ editable.m_metadata.push_back(EType::FMD_EMAIL);
+ editable.m_metadata.push_back(EType::FMD_OPEN_HOURS);
+ editable.m_metadata.push_back(EType::FMD_PHONE_NUMBER);
+ editable.m_metadata.push_back(EType::FMD_WEBSITE);
+ // Post boxes and post offices should have editable postcode field defined separately.
+ editable.m_metadata.push_back(EType::FMD_POSTCODE);
}
- return false;
-}
-bool Editor::IsAddressEditable(FeatureType const & feature) const
-{
- feature::TypesHolder const types(feature);
- auto & isBuilding = ftypes::IsBuildingChecker::Instance();
- for (auto type : types)
- {
- // Building addresses are always editable.
- if (isBuilding.HasTypeValue(type))
- return true;
- auto const * typeDesc = GetTypeDescription(type);
- if (typeDesc && typeDesc->m_address)
- return true;
- }
- return false;
+ // Avoid possible duplicates.
+ my::SortUnique(editable.m_metadata);
+ return editable;
}
bool Editor::HaveSomethingToUpload() const
diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp
index 4339517cf4..6ddbe1e425 100644
--- a/indexer/osm_editor.hpp
+++ b/indexer/osm_editor.hpp
@@ -13,11 +13,20 @@
#include "std/ctime.hpp"
#include "std/function.hpp"
#include "std/map.hpp"
-#include "std/set.hpp"
#include "std/string.hpp"
+#include "std/vector.hpp"
namespace osm
{
+/// Holds information to construct editor's UI.
+struct EditableProperties
+{
+ bool m_name = false;
+ bool m_address = false;
+ vector<feature::Metadata::EType> m_metadata;
+ bool IsEditable() const { return m_name || m_address || !m_metadata.empty(); }
+};
+
class Editor final
{
Editor() = default;
@@ -93,11 +102,7 @@ public:
string const & editedStreet = "",
string const & editedHouseNumber = "");
- vector<feature::Metadata::EType> EditableMetadataForType(FeatureType const & feature) const;
- /// @returns true if feature's name is editable.
- bool IsNameEditable(FeatureType const & feature) const;
- /// @returns true if street and house number are editable.
- bool IsAddressEditable(FeatureType const & feature) const;
+ EditableProperties GetEditableProperties(FeatureType const & feature) const;
bool HaveSomethingToUpload() const;
using TChangesetTags = map<string, string>;