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>2015-12-04 15:49:43 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:03:53 +0300
commit48d5b57ece38222e1f06045452e4270a3897d804 (patch)
treee807c9cae6a31e44a482e09877464df941d63935 /qt/editor_dialog.cpp
parenta6c6408b05345868bf068b8cec56570dd3f5c2b8 (diff)
[qt] EditDialog.
Diffstat (limited to 'qt/editor_dialog.cpp')
-rw-r--r--qt/editor_dialog.cpp89
1 files changed, 64 insertions, 25 deletions
diff --git a/qt/editor_dialog.cpp b/qt/editor_dialog.cpp
index a0b5f73685..07241787a5 100644
--- a/qt/editor_dialog.cpp
+++ b/qt/editor_dialog.cpp
@@ -4,7 +4,7 @@
#include "indexer/classificator.hpp"
#include "indexer/feature.hpp"
-#include "indexer/feature_meta.hpp"
+#include "indexer/osm_editor.hpp"
#include "std/set.hpp"
#include "std/vector.hpp"
@@ -34,43 +34,55 @@ EditorDialog::EditorDialog(QWidget * parent, FeatureType const & feature) : QDia
typesRow->addWidget(new QLabel("Types:"));
typesRow->addWidget(new QLabel(QString::fromStdString(strTypes)));
vLayout->addLayout(typesRow);
- // Second row: Name label and text input.
- QHBoxLayout * nameRow = new QHBoxLayout();
- nameRow->addWidget(new QLabel("Name:"));
- // TODO(AlexZ): Print names in all available languages.
- string defaultName, intName;
- feature.GetPreferredNames(defaultName, intName);
- QLineEdit * lineEditName = new QLineEdit(QString::fromStdString(defaultName));
- nameRow->addWidget(lineEditName);
- vLayout->addLayout(nameRow);
- // More rows: All metadata rows.
+ // Rows block: Name(s) label(s) and text input.
+ char const * defaultLangStr = StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::DEFAULT_CODE);
+ // Default name editor is always displayed, even if feature name is empty.
+ QHBoxLayout * defaultNameRow = new QHBoxLayout();
+ defaultNameRow->addWidget(new QLabel(QString("Name:")));
+ QLineEdit * defaultNamelineEdit = new QLineEdit();
+ defaultNamelineEdit->setObjectName(defaultLangStr);
+ defaultNameRow->addWidget(defaultNamelineEdit);
+ vLayout->addLayout(defaultNameRow);
+
+ feature.ForEachNameRef([&vLayout, &defaultNamelineEdit](int8_t langCode, string const & name) -> bool
+ {
+ if (langCode == StringUtf8Multilang::DEFAULT_CODE)
+ defaultNamelineEdit->setText(QString::fromStdString(name));
+ else
+ {
+ QHBoxLayout * nameRow = new QHBoxLayout();
+ char const * langStr = StringUtf8Multilang::GetLangByCode(langCode);
+ nameRow->addWidget(new QLabel(QString("Name:") + langStr));
+ QLineEdit * lineEditName = new QLineEdit(QString::fromStdString(name));
+ lineEditName->setObjectName(langStr);
+ nameRow->addWidget(lineEditName);
+ vLayout->addLayout(nameRow);
+ }
+ return true; // true is needed to enumerate all languages.
+ });
+
+ // All metadata rows.
QVBoxLayout * metaRows = new QVBoxLayout();
- // TODO(mgsergio): Load editable fields from metadata.
- vector<Metadata::EType> editableMetadataFields;
- // TODO(AlexZ): Temporary enable only existing meta information fields.
- // Final editor should have all editable fields enabled.
- editableMetadataFields = feature.GetMetadata().GetPresentTypes();
-/*
+ // TODO(mgsergio): Load editable fields from metadata. Features can have several types, so we merge all editable fields here.
+ set<Metadata::EType> editableMetadataFields;
// Merge editable fields for all feature's types.
feature.ForEachType([&editableMetadataFields](uint32_t type)
{
- auto const editableFields = osm::Editor::EditableMetadataForType(type);
+ auto const editableFields = osm::Editor::Instance().EditableMetadataForType(type);
editableMetadataFields.insert(editableFields.begin(), editableFields.end());
});
-*/
- // Equals to editableMetadataFields, used to retrieve text entered by user.
- vector<QLineEdit *> metaFieldEditors;
- for (auto const field : editableMetadataFields)
+ for (Metadata::EType const field : editableMetadataFields)
{
+ QString const fieldName = QString::fromStdString(DebugPrint(field));
QHBoxLayout * fieldRow = new QHBoxLayout();
- fieldRow->addWidget(new QLabel(QString::fromStdString(DebugPrint(field) + ":")));
+ fieldRow->addWidget(new QLabel(fieldName + ":"));
QLineEdit * lineEdit = new QLineEdit(QString::fromStdString(feature.GetMetadata().Get(field)));
+ // Mark line editor to query it's text value when editing is finished.
+ lineEdit->setObjectName(fieldName);
fieldRow->addWidget(lineEdit);
- metaFieldEditors.push_back(lineEdit);
metaRows->addLayout(fieldRow);
}
- ASSERT_EQUAL(editableMetadataFields.size(), metaFieldEditors.size(), ());
vLayout->addLayout(metaRows);
// Dialog buttons.
@@ -92,3 +104,30 @@ EditorDialog::EditorDialog(QWidget * parent, FeatureType const & feature) : QDia
setLayout(vLayout);
setWindowTitle("POI Editor");
}
+
+StringUtf8Multilang EditorDialog::GetEditedNames() const
+{
+ StringUtf8Multilang names;
+ for (int8_t langCode = StringUtf8Multilang::DEFAULT_CODE; langCode < StringUtf8Multilang::MAX_SUPPORTED_LANGUAGES; ++langCode)
+ {
+ QLineEdit * le = findChild<QLineEdit *>(StringUtf8Multilang::GetLangByCode(langCode));
+ if (!le)
+ continue;
+ string const name = le->text().toStdString();
+ if (!name.empty())
+ names.AddString(langCode, name);
+ }
+ return names;
+}
+
+Metadata EditorDialog::GetEditedMetadata() const
+{
+ Metadata metadata;
+ for (int type = Metadata::FMD_CUISINE; type < Metadata::FMD_COUNT; ++type)
+ {
+ QLineEdit * editor = findChild<QLineEdit *>(QString::fromStdString(DebugPrint(static_cast<Metadata::EType>(type))));
+ if (editor)
+ metadata.Set(static_cast<Metadata::EType>(type), editor->text().toStdString());
+ }
+ return metadata;
+}