forked from organicmaps/organicmaps
review fixes
This commit is contained in:
parent
ae5272bc47
commit
99f189642f
16 changed files with 184 additions and 170 deletions
|
@ -45,4 +45,4 @@
|
|||
android:text="@string/add_language"
|
||||
android:textAppearance="@style/MwmTextAppearance.Button" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -81,8 +81,8 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
|
||||
private MultilanguageAdapter mNamesAdapter;
|
||||
private TextView mNamesCaption;
|
||||
private TextView mAddLanguage;
|
||||
private TextView mMoreLanguages;
|
||||
private TextView mAddLanguage;
|
||||
private TextView mMoreLanguages;
|
||||
|
||||
private TextView mStreet;
|
||||
private EditText mHouseNumber;
|
||||
|
@ -329,10 +329,13 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
{
|
||||
mNamesCaption = (TextView) view.findViewById(R.id.show_additional_names);
|
||||
mNamesCaption.setOnClickListener(this);
|
||||
|
||||
mAddLanguage = (TextView) view.findViewById(R.id.add_langs);
|
||||
mAddLanguage.setOnClickListener(this);
|
||||
|
||||
mMoreLanguages = (TextView) view.findViewById(R.id.more_names);
|
||||
mMoreLanguages.setOnClickListener(this);
|
||||
|
||||
mNamesView = (RecyclerView) view.findViewById(R.id.recycler);
|
||||
mNamesView.setNestedScrollingEnabled(false);
|
||||
mNamesView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
|
@ -505,23 +508,23 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
private void refreshNamesCaption()
|
||||
{
|
||||
if (mNamesAdapter.getNamesCount() <= mNamesAdapter.getMandatoryNamesCount())
|
||||
setNamesArrowDrawable(0);
|
||||
setNamesArrow(0 /* arrowResourceId */); // bind arrow with empty resource (do not draw arrow)
|
||||
else if (mNamesAdapter.areAdditionalLanguagesShown())
|
||||
setNamesArrowDrawable(R.drawable.ic_expand_less);
|
||||
setNamesArrow(R.drawable.ic_expand_less);
|
||||
else
|
||||
setNamesArrowDrawable(R.drawable.ic_expand_more);
|
||||
setNamesArrow(R.drawable.ic_expand_more);
|
||||
|
||||
boolean showAddLanguage = mNamesAdapter.getNamesCount() <= mNamesAdapter.getMandatoryNamesCount() ||
|
||||
mNamesAdapter.areAdditionalLanguagesShown();
|
||||
|
||||
UiUtils.showIf(showAddLanguage, mAddLanguage);
|
||||
UiUtils.showIf(!showAddLanguage, mMoreLanguages);
|
||||
|
||||
}
|
||||
|
||||
private void setNamesArrowDrawable(@DrawableRes int right)
|
||||
// Bind arrow in the top right corner of names caption with needed resource.
|
||||
private void setNamesArrow(@DrawableRes int arrowResourceId)
|
||||
{
|
||||
if(0 == right)
|
||||
if (arrowResourceId == 0)
|
||||
{
|
||||
mNamesCaption.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||||
return;
|
||||
|
@ -530,7 +533,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
mNamesCaption.setCompoundDrawablesWithIntrinsicBounds(
|
||||
null,
|
||||
null,
|
||||
Graphics.tint(getActivity(), right, R.attr.iconTint),
|
||||
Graphics.tint(getActivity(), arrowResourceId, R.attr.iconTint),
|
||||
null);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,9 +73,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
|
|||
sNames.clear();
|
||||
for (LocalizedName name : names)
|
||||
{
|
||||
if (name.code == LocalizedName.DEFAULT_LANG_CODE)
|
||||
continue;
|
||||
sNames.add(name);
|
||||
addName(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,6 +158,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
|
|||
case OPENING_HOURS:
|
||||
case STREET:
|
||||
case CUISINE:
|
||||
case LANGUAGE:
|
||||
editMapObject();
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -64,18 +64,18 @@ public class MultilanguageAdapter extends RecyclerView.Adapter<MultilanguageAdap
|
|||
return mAdditionalLanguagesShown;
|
||||
}
|
||||
|
||||
public void showAdditionalLanguages(boolean showAdditionalLanguages)
|
||||
public void showAdditionalLanguages(boolean show)
|
||||
{
|
||||
if(mAdditionalLanguagesShown == showAdditionalLanguages)
|
||||
if (mAdditionalLanguagesShown == show)
|
||||
return;
|
||||
|
||||
mAdditionalLanguagesShown = showAdditionalLanguages;
|
||||
mAdditionalLanguagesShown = show;
|
||||
|
||||
if(mNames.size() != mMandatoryNamesCount)
|
||||
if (mNames.size() != mMandatoryNamesCount)
|
||||
{
|
||||
if(showAdditionalLanguages)
|
||||
if (show)
|
||||
{
|
||||
notifyItemRangeInserted(mMandatoryNamesCount , mNames.size() - mMandatoryNamesCount);
|
||||
notifyItemRangeInserted(mMandatoryNamesCount, mNames.size() - mMandatoryNamesCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -2,26 +2,29 @@ package com.mapswithme.maps.editor.data;
|
|||
|
||||
/**
|
||||
* Class which contains array of localized names with following priority:
|
||||
* 1. Names for Mwm languages;
|
||||
* 2. User`s language name;
|
||||
* 3. International name;
|
||||
* 4. Other names;
|
||||
* 1. Names for Mwm languages;
|
||||
* 2. User`s language name;
|
||||
* 3. Other names;
|
||||
* and mandatoryNamesCount - count of names which should be always shown.
|
||||
*/
|
||||
public class NamesDataSource {
|
||||
private final LocalizedName[] mNames;
|
||||
private final int mMandatoryNamesCount;
|
||||
public class NamesDataSource
|
||||
{
|
||||
private final LocalizedName[] mNames;
|
||||
private final int mMandatoryNamesCount;
|
||||
|
||||
public NamesDataSource(LocalizedName[] names, int mandatoryNamesCount) {
|
||||
this.mNames = names;
|
||||
this.mMandatoryNamesCount = mandatoryNamesCount;
|
||||
}
|
||||
public NamesDataSource(LocalizedName[] names, int mandatoryNamesCount)
|
||||
{
|
||||
this.mNames = names;
|
||||
this.mMandatoryNamesCount = mandatoryNamesCount;
|
||||
}
|
||||
|
||||
public LocalizedName[] getNames() {
|
||||
return mNames;
|
||||
}
|
||||
public LocalizedName[] getNames()
|
||||
{
|
||||
return mNames;
|
||||
}
|
||||
|
||||
public int getMandatoryNamesCount() {
|
||||
return mMandatoryNamesCount;
|
||||
}
|
||||
public int getMandatoryNamesCount()
|
||||
{
|
||||
return mMandatoryNamesCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,3 +114,18 @@ UNIT_TEST(MultilangString_LangNames)
|
|||
auto const international = StringUtf8Multilang::GetLangIndex("int_name");
|
||||
TEST_EQUAL(langs[international].m_code, "int_name", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(MultilangString_HasString)
|
||||
{
|
||||
StringUtf8Multilang s;
|
||||
s.AddString(0, "xxx");
|
||||
s.AddString(18, "yyy");
|
||||
s.AddString(63, "zzz");
|
||||
|
||||
TEST(s.HasString(0), ());
|
||||
TEST(s.HasString(18), ());
|
||||
TEST(s.HasString(63), ());
|
||||
|
||||
TEST(!s.HasString(1), ());
|
||||
TEST(!s.HasString(32), ());
|
||||
}
|
||||
|
|
|
@ -139,6 +139,17 @@ bool StringUtf8Multilang::GetString(int8_t lang, string & utf8s) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool StringUtf8Multilang::HasString(int8_t lang) const
|
||||
{
|
||||
for(size_t i = 0; i < m_s.size(); i = GetNextIndex(i))
|
||||
{
|
||||
if ((m_s[i] & 0x3F) == lang)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
|
|
@ -105,6 +105,8 @@ public:
|
|||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HasString(int8_t lang) const;
|
||||
|
||||
int8_t FindString(string const & utf8s) const;
|
||||
|
||||
|
|
|
@ -38,25 +38,21 @@ bool ExtractName(StringUtf8Multilang const & names, int8_t const langCode,
|
|||
return true;
|
||||
}
|
||||
|
||||
size_t PushMwmLanguages(StringUtf8Multilang const & names, vector<string> const & mwmLanguages, vector<osm::LocalizedName> & result)
|
||||
size_t PushMwmLanguages(StringUtf8Multilang const & names, vector<int8_t> const & mwmLanguages,
|
||||
vector<osm::LocalizedName> & result)
|
||||
{
|
||||
size_t count = 0;
|
||||
auto langCode = StringUtf8Multilang::kUnsupportedLanguageCode;
|
||||
static size_t const kMaxCountMwmLanguages = 2;
|
||||
|
||||
for (auto const & language : mwmLanguages)
|
||||
|
||||
for (size_t i = 0; i < mwmLanguages.size() && count < kMaxCountMwmLanguages; ++i)
|
||||
{
|
||||
langCode = StringUtf8Multilang::GetLangIndex(language);
|
||||
if (ExtractName(names, langCode, result))
|
||||
if (ExtractName(names, mwmLanguages[i], result))
|
||||
++count;
|
||||
|
||||
if (count >= kMaxCountMwmLanguages)
|
||||
return count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace osm
|
||||
{
|
||||
|
@ -100,37 +96,42 @@ StringUtf8Multilang const & EditableMapObject::GetName() const { return m_name;
|
|||
|
||||
NamesDataSource EditableMapObject::GetNamesDataSource() const
|
||||
{
|
||||
return GetNamesDataSource(m_name, GetMwmLanguages(), languages::GetCurrentNorm());
|
||||
const auto mwmInfo = GetID().m_mwmId.GetInfo();
|
||||
|
||||
if (!mwmInfo)
|
||||
return NamesDataSource();
|
||||
|
||||
vector<int8_t> mwmLanguages;
|
||||
mwmInfo->GetRegionData().GetLanguages(mwmLanguages);
|
||||
|
||||
auto const userLangCode = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm());
|
||||
|
||||
return GetNamesDataSource(m_name, mwmLanguages, userLangCode);
|
||||
}
|
||||
|
||||
// static
|
||||
NamesDataSource EditableMapObject::GetNamesDataSource(StringUtf8Multilang const & source,
|
||||
vector<string> const & nativeMwmLanguages,
|
||||
string const & userLanguage)
|
||||
vector<int8_t> const & mwmLanguages,
|
||||
int8_t const userLangCode)
|
||||
{
|
||||
NamesDataSource result;
|
||||
auto & names = result.names;
|
||||
auto & mandatoryCount = result.mandatoryNamesCount;
|
||||
// Push Mwm languages.
|
||||
mandatoryCount = PushMwmLanguages(source, nativeMwmLanguages, names);
|
||||
mandatoryCount = PushMwmLanguages(source, mwmLanguages, names);
|
||||
|
||||
// Push user's language.
|
||||
auto const langCode = StringUtf8Multilang::GetLangIndex(userLanguage);
|
||||
if (ExtractName(source, langCode, names))
|
||||
++mandatoryCount;
|
||||
|
||||
// Push international language.
|
||||
if (ExtractName(source, StringUtf8Multilang::kInternationalCode, names))
|
||||
if (ExtractName(source, userLangCode, names))
|
||||
++mandatoryCount;
|
||||
|
||||
// Push other languages.
|
||||
source.ForEach([&names, mandatoryCount](int8_t code, string const & name) -> bool {
|
||||
source.ForEach([&names, mandatoryCount](int8_t const code, string const & name) -> bool {
|
||||
// Exclude default name.
|
||||
if (StringUtf8Multilang::kDefaultCode == code)
|
||||
return true;
|
||||
|
||||
auto const mandatoryNamesEnd = names.begin() + mandatoryCount;
|
||||
// Exclude languages which already in container (languages with top priority).
|
||||
// Exclude languages which are already in container (languages with top priority).
|
||||
auto const it = find_if(
|
||||
names.begin(), mandatoryNamesEnd,
|
||||
[code](LocalizedName const & localizedName) { return localizedName.m_code == code; });
|
||||
|
@ -171,44 +172,37 @@ void EditableMapObject::SetName(string name, int8_t langCode)
|
|||
return;
|
||||
|
||||
ASSERT_NOT_EQUAL(StringUtf8Multilang::kDefaultCode, langCode,
|
||||
("You trying to set ", name,
|
||||
" as default, but direct editing of default name is deprecated."));
|
||||
("Direct editing of default name is deprecated."));
|
||||
|
||||
if (!Editor::Instance().WasDefaultNameSaved(GetID()) &&
|
||||
CanUseAsDefaultName(langCode, m_name, GetMwmLanguages()))
|
||||
if (!Editor::Instance().OriginalFeatureHasDefaultName(GetID()))
|
||||
{
|
||||
m_name.AddString(StringUtf8Multilang::kDefaultCode, name);
|
||||
const auto mwmInfo = GetID().m_mwmId.GetInfo();
|
||||
|
||||
if (mwmInfo)
|
||||
{
|
||||
vector<int8_t> mwmLanguages;
|
||||
mwmInfo->GetRegionData().GetLanguages(mwmLanguages);
|
||||
|
||||
if (CanUseAsDefaultName(langCode, mwmLanguages))
|
||||
m_name.AddString(StringUtf8Multilang::kDefaultCode, name);
|
||||
}
|
||||
}
|
||||
|
||||
m_name.AddString(langCode, name);
|
||||
}
|
||||
|
||||
// static
|
||||
bool EditableMapObject::CanUseAsDefaultName(int8_t const langCode, StringUtf8Multilang const & name,
|
||||
vector<string> const & nativeMwmLanguages)
|
||||
bool EditableMapObject::CanUseAsDefaultName(int8_t const lang, vector<int8_t> const & mwmLanguages)
|
||||
{
|
||||
auto index = StringUtf8Multilang::kUnsupportedLanguageCode;
|
||||
string unused;
|
||||
|
||||
// Languages priority: 1. Mwm languages 2. International language.
|
||||
for (auto const & language : nativeMwmLanguages)
|
||||
for (auto const & mwmLang : mwmLanguages)
|
||||
{
|
||||
index = StringUtf8Multilang::GetLangIndex(language);
|
||||
if (StringUtf8Multilang::kUnsupportedLanguageCode == mwmLang)
|
||||
continue;
|
||||
|
||||
if (StringUtf8Multilang::kUnsupportedLanguageCode == index)
|
||||
return false;
|
||||
|
||||
if (langCode == index)
|
||||
if (lang == mwmLang)
|
||||
return true;
|
||||
|
||||
// A name with a higher priority was added already.
|
||||
if (name.GetString(index, unused))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (langCode == StringUtf8Multilang::kInternationalCode)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,7 @@ struct LocalizedName
|
|||
// Class which contains vector of localized names with following priority:
|
||||
// 1. Names for Mwm languages
|
||||
// 2. User`s language name
|
||||
// 3. International name
|
||||
// 4. Other names
|
||||
// 3. Other names
|
||||
// and mandatoryNamesCount - count of names which should be always shown.
|
||||
struct NamesDataSource
|
||||
{
|
||||
|
@ -130,23 +129,13 @@ public:
|
|||
static bool ValidateWebsite(string const & site);
|
||||
static bool ValidateEmail(string const & email);
|
||||
|
||||
// TODO dummy, should be removed.
|
||||
static vector<string> const & GetMwmLanguages()
|
||||
{
|
||||
static vector<string> const kNativelanguagesForMwm = {"de", "fr"};
|
||||
|
||||
return kNativelanguagesForMwm;
|
||||
}
|
||||
// TODO dummy, should be removed.
|
||||
|
||||
// Check whether langCode can be used as default name.
|
||||
static bool CanUseAsDefaultName(int8_t const langCode, StringUtf8Multilang const & name,
|
||||
vector<string> const & nativeMwmLanguages);
|
||||
static bool CanUseAsDefaultName(int8_t const langCode, vector<int8_t> const & nativeMwmLanguages);
|
||||
|
||||
// See comment for NamesDataSource class.
|
||||
static NamesDataSource GetNamesDataSource(StringUtf8Multilang const & source,
|
||||
vector<string> const & nativeMwmLanguages,
|
||||
string const & userLanguage);
|
||||
vector<int8_t> const & nativeMwmLanguages,
|
||||
int8_t const userLanguage);
|
||||
|
||||
private:
|
||||
string m_houseNumber;
|
||||
|
|
|
@ -6,6 +6,11 @@ namespace
|
|||
{
|
||||
using osm::EditableMapObject;
|
||||
|
||||
int8_t const GetLangCode(char const * ch)
|
||||
{
|
||||
return StringUtf8Multilang::GetLangIndex(ch);
|
||||
}
|
||||
|
||||
UNIT_TEST(EditableMapObject_SetWebsite)
|
||||
{
|
||||
EditableMapObject emo;
|
||||
|
@ -129,100 +134,94 @@ UNIT_TEST(EditableMapObject_ValidateEmail)
|
|||
UNIT_TEST(EditableMapObject_CanUseAsDefaultName)
|
||||
{
|
||||
EditableMapObject emo;
|
||||
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("de"), emo.GetName(), {"de", "fr"}),
|
||||
("Check possibility to use Mwm language code"));
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("fr"), emo.GetName(), {"de", "fr"}),
|
||||
("Check possibility to use Mwm language code"));
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("int_name"), emo.GetName(), {"de", "fr"}),
|
||||
("Check possibility to use international language code"));
|
||||
vector<int8_t> const nativeMwmLanguages {GetLangCode("de"), GetLangCode("fr")};
|
||||
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(100, emo.GetName(), {"de", "fr"}),
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(GetLangCode("de"), nativeMwmLanguages),
|
||||
("Check possibility to use Mwm language code"));
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(GetLangCode("fr"), nativeMwmLanguages),
|
||||
("Check possibility to use Mwm language code"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(GetLangCode("int_name"), nativeMwmLanguages),
|
||||
("Check possibility to use international language code"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(100, nativeMwmLanguages),
|
||||
("Incorrect language code is not supported"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("en"), emo.GetName(), {"abcd"}),
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(GetLangCode("en"), {GetLangCode("abcd")}),
|
||||
("Incorrect Mwm language name is not supported"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("en"), emo.GetName(), {"de", "fr"}),
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(GetLangCode("en"), nativeMwmLanguages),
|
||||
("Can not to use language which not Mwm language or international"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("ru"), emo.GetName(), {"de", "fr"}),
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(GetLangCode("ru"), nativeMwmLanguages),
|
||||
("Check possibility to use user`s language code"));
|
||||
|
||||
// Trying to use language codes in reverse priority.
|
||||
StringUtf8Multilang names;
|
||||
names.AddString(StringUtf8Multilang::GetLangIndex("int_name"), "international name");
|
||||
names.AddString(GetLangCode("fr"), "second mwm language");
|
||||
emo.SetName(names);
|
||||
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("int_name"), emo.GetName(), {"de", "fr"}),
|
||||
("It is possible to fix typo for international language"));
|
||||
|
||||
names.AddString(StringUtf8Multilang::GetLangIndex("fr"), "second mwm language");
|
||||
emo.SetName(names);
|
||||
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("fr"), emo.GetName(), {"de", "fr"}),
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(GetLangCode("fr"), nativeMwmLanguages),
|
||||
("It is possible to fix typo"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("int_name"), emo.GetName(), {"de", "fr"}),
|
||||
("Name on language with high priority was already entered"));
|
||||
|
||||
names.AddString(StringUtf8Multilang::GetLangIndex("de"), "first mwm language");
|
||||
names.AddString(GetLangCode("de"), "first mwm language");
|
||||
emo.SetName(names);
|
||||
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("de"), emo.GetName(), {"de", "fr"}),
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(GetLangCode("de"), nativeMwmLanguages),
|
||||
("It is possible to fix typo"));
|
||||
TEST(EditableMapObject::CanUseAsDefaultName(GetLangCode("fr"), nativeMwmLanguages),
|
||||
("It is possible to fix typo"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("fr"), emo.GetName(), {"de", "fr"}),
|
||||
("Name on language with high priority was already entered"));
|
||||
TEST(!EditableMapObject::CanUseAsDefaultName(StringUtf8Multilang::GetLangIndex("int_name"), emo.GetName(), {"de", "fr"}),
|
||||
("Name on language with high priority was already entered"));
|
||||
}
|
||||
|
||||
UNIT_TEST(EditableMapObject_GetNamesDataSource)
|
||||
{
|
||||
EditableMapObject emo;
|
||||
StringUtf8Multilang names;
|
||||
names.AddString(0, "Default name");
|
||||
names.AddString(1, "Eng name");
|
||||
names.AddString(7, "Int name");
|
||||
names.AddString(6, "De name");
|
||||
names.AddString(8, "Ru name");
|
||||
names.AddString(9, "Sv name");
|
||||
names.AddString(12, "By name");
|
||||
names.AddString(14, "Ko name");
|
||||
names.AddString(20, "It name");
|
||||
|
||||
names.AddString(GetLangCode("default"), "Default name");
|
||||
names.AddString(GetLangCode("en"), "Eng name");
|
||||
names.AddString(GetLangCode("int_name"), "Int name");
|
||||
names.AddString(GetLangCode("de"), "De name");
|
||||
names.AddString(GetLangCode("ru"), "Ru name");
|
||||
names.AddString(GetLangCode("sv"), "Sv name");
|
||||
names.AddString(GetLangCode("be"), "By name");
|
||||
names.AddString(GetLangCode("ko"), "Ko name");
|
||||
names.AddString(GetLangCode("it"), "It name");
|
||||
emo.SetName(names);
|
||||
|
||||
auto const namesDataSource =
|
||||
EditableMapObject::GetNamesDataSource(emo.GetName(), {"de", "fr"}, "ko");
|
||||
vector<int8_t> nativeMwmLanguages = {GetLangCode("de"), GetLangCode("fr")};
|
||||
|
||||
TEST(namesDataSource.names.size() == 9, ("All names except the default should be pushed into "
|
||||
auto const namesDataSource =
|
||||
EditableMapObject::GetNamesDataSource(emo.GetName(), nativeMwmLanguages, GetLangCode("ko"));
|
||||
|
||||
TEST_EQUAL(namesDataSource.names.size(), 9, ("All names except the default should be pushed into "
|
||||
"data source plus empty mandatory names"));
|
||||
TEST(namesDataSource.mandatoryNamesCount == 4,
|
||||
("Mandatory names count should be equal == Mwm languages + user`s language + international "
|
||||
"language"));
|
||||
TEST(namesDataSource.names[0].m_code == 6 /*de*/,
|
||||
("Deutsch name should be first as first language in Mwm"));
|
||||
TEST(namesDataSource.names[1].m_code == 3 /*fr*/,
|
||||
("French name should be second as second language in Mwm"));
|
||||
TEST(namesDataSource.names[2].m_code == 14 /*ko*/,
|
||||
("Korean name should be third because user`s language should be followed by Mwm languages"));
|
||||
TEST(namesDataSource.names[3].m_code == 7 /*int*/,
|
||||
("International name should be fourth because International language should be followed by "
|
||||
"user`s language"));
|
||||
TEST_EQUAL(namesDataSource.mandatoryNamesCount, 3,
|
||||
("Mandatory names count should be equal == Mwm languages + user`s language"));
|
||||
TEST_EQUAL(namesDataSource.names[0].m_code, GetLangCode("de"),
|
||||
("Deutsch name should be first as first language in Mwm"));
|
||||
TEST_EQUAL(namesDataSource.names[1].m_code, GetLangCode("fr"),
|
||||
("French name should be second as second language in Mwm"));
|
||||
TEST_EQUAL(namesDataSource.names[2].m_code, GetLangCode("ko"),
|
||||
("Korean name should be third because user`s language should be followed by Mwm languages"));
|
||||
|
||||
{
|
||||
vector<int8_t> nativeMwmLanguages = {GetLangCode("de"), GetLangCode("fr")};
|
||||
|
||||
auto const namesDataSource =
|
||||
EditableMapObject::GetNamesDataSource(emo.GetName(), {"int_name"}, "int_name");
|
||||
TEST(namesDataSource.names.size() == 8,
|
||||
("All names except the default should be pushed into data source"));
|
||||
TEST(namesDataSource.mandatoryNamesCount == 1,
|
||||
("Mandatory names count should be equal == Mwm languages + user`s language + "
|
||||
"international language. Excluding repetiton"));
|
||||
EditableMapObject::GetNamesDataSource(emo.GetName(), nativeMwmLanguages, GetLangCode("fr"));
|
||||
TEST_EQUAL(namesDataSource.names.size(), 9,
|
||||
("All names except the default should be pushed into data source"));
|
||||
TEST_EQUAL(namesDataSource.mandatoryNamesCount, 2,
|
||||
("Mandatory names count should be equal == Mwm languages + user`s language. "
|
||||
"Excluding repetiton"));
|
||||
}
|
||||
{
|
||||
vector<int8_t> nativeMwmLanguages = {GetLangCode("fr"), GetLangCode("fr")};
|
||||
|
||||
auto const namesDataSource =
|
||||
EditableMapObject::GetNamesDataSource(emo.GetName(), {"fr", "fr"}, "fr");
|
||||
TEST(namesDataSource.names.size() == 9, ("All names except the default should be pushed into "
|
||||
EditableMapObject::GetNamesDataSource(emo.GetName(), nativeMwmLanguages, GetLangCode("fr"));
|
||||
TEST_EQUAL(namesDataSource.names.size(), 9,
|
||||
("All names except the default should be pushed into "
|
||||
"data source plus empty mandatory names"));
|
||||
TEST(namesDataSource.mandatoryNamesCount == 2,
|
||||
("Mandatory names count should be equal == Mwm languages + user`s language + "
|
||||
"international language. Excluding repetiton"));
|
||||
TEST_EQUAL(namesDataSource.mandatoryNamesCount, 1,
|
||||
("Mandatory names count should be equal == Mwm languages + user`s language. "
|
||||
"Excluding repetiton"));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -426,14 +426,11 @@ bool Editor::IsCreatedFeature(FeatureID const & fid)
|
|||
return fid.m_index >= kStartIndexForCreatedFeatures;
|
||||
}
|
||||
|
||||
bool Editor::WasDefaultNameSaved(FeatureID const & fid) const
|
||||
bool Editor::OriginalFeatureHasDefaultName(FeatureID const & fid) const
|
||||
{
|
||||
if (IsCreatedFeature(fid))
|
||||
return false;
|
||||
|
||||
if (FeatureStatus::Created == GetFeatureStatus(fid))
|
||||
return false;
|
||||
|
||||
auto const originalFeaturePtr = m_getOriginalFeatureFn(fid);
|
||||
if (!originalFeaturePtr)
|
||||
{
|
||||
|
@ -442,7 +439,9 @@ bool Editor::WasDefaultNameSaved(FeatureID const & fid) const
|
|||
return false;
|
||||
}
|
||||
|
||||
return originalFeaturePtr->HasName();
|
||||
auto const & names = originalFeaturePtr->GetNames();
|
||||
|
||||
return names.HasString(StringUtf8Multilang::kDefaultCode);
|
||||
}
|
||||
|
||||
/// Several cases should be handled while saving changes:
|
||||
|
|
|
@ -167,8 +167,8 @@ public:
|
|||
// Use GetFeatureStatus(fid) instead. This function is used when a feature is
|
||||
// not yet saved and we have to know if it was modified or created.
|
||||
static bool IsCreatedFeature(FeatureID const & fid);
|
||||
// Returns true in case when original feature from mwm has default name
|
||||
bool WasDefaultNameSaved(FeatureID const & fid) const;
|
||||
// Returns true if the original feature has default name.
|
||||
bool OriginalFeatureHasDefaultName(FeatureID const & fid) const;
|
||||
|
||||
private:
|
||||
// TODO(AlexZ): Synchronize Save call/make it on a separate thread.
|
||||
|
|
|
@ -3007,7 +3007,7 @@ void Framework::CreateNote(ms::LatLon const & latLon, FeatureID const & fid,
|
|||
DeactivateMapSelection(true /* notifyUI */);
|
||||
}
|
||||
|
||||
bool Framework::WasDefaultNameSaved(FeatureID const & fid) const
|
||||
bool Framework::OriginalFeatureHasDefaultName(FeatureID const & fid) const
|
||||
{
|
||||
return osm::Editor::Instance().WasDefaultNameSaved(fid);
|
||||
return osm::Editor::Instance().OriginalFeatureHasDefaultName(fid);
|
||||
}
|
||||
|
|
|
@ -716,7 +716,7 @@ private:
|
|||
//@}
|
||||
|
||||
public:
|
||||
bool WasDefaultNameSaved(FeatureID const & fid) const;
|
||||
bool OriginalFeatureHasDefaultName(FeatureID const & fid) const;
|
||||
|
||||
private:
|
||||
DECLARE_THREAD_CHECKER(m_threadChecker);
|
||||
|
|
|
@ -62,7 +62,7 @@ EditorDialog::EditorDialog(QWidget * parent, osm::EditableMapObject & emo)
|
|||
|
||||
auto const namesDataSource = emo.GetNamesDataSource();
|
||||
|
||||
for (osm::LocalizedName const & ln : namesDataSource.names)
|
||||
for (auto const & ln : namesDataSource.names)
|
||||
{
|
||||
if (ln.m_code == StringUtf8Multilang::kDefaultCode)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue