[qt] EditDialog.

This commit is contained in:
Alex Zolotarev 2015-12-04 15:49:43 +03:00 committed by Sergey Yershov
parent a6c6408b05
commit 48d5b57ece
2 changed files with 70 additions and 25 deletions

View file

@ -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;
}

View file

@ -1,5 +1,9 @@
#pragma once
#include "indexer/feature_meta.hpp"
#include "coding/multilang_utf8_string.hpp"
#include "std/string.hpp"
#include <QtWidgets/QDialog>
@ -12,4 +16,6 @@ class EditorDialog : public QDialog
Q_OBJECT
public:
EditorDialog(QWidget * parent, FeatureType const & feature);
StringUtf8Multilang GetEditedNames() const;
feature::Metadata GetEditedMetadata() const;
};