[qt] Editor Dialog shows/edits addresses.

This commit is contained in:
Alex Zolotarev 2016-01-14 14:38:43 +03:00 committed by Sergey Yershov
parent 99d014ccae
commit 2187f415f0
3 changed files with 80 additions and 30 deletions

View file

@ -470,7 +470,7 @@ void DrawWidget::ShowPOIEditor(FeatureType & feature)
{
// Show Edit POI dialog.
auto & editor = osm::Editor::Instance();
EditorDialog dlg(this, feature);
EditorDialog dlg(this, feature, *m_framework);
int const result = dlg.exec();
if (result == QDialog::Accepted)
{

View file

@ -1,5 +1,7 @@
#include "qt/editor_dialog.hpp"
#include "map/framework.hpp"
#include "search/result.hpp"
#include "indexer/classificator.hpp"
@ -11,6 +13,7 @@
#include "std/set.hpp"
#include "std/vector.hpp"
#include <QtWidgets/QComboBox>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
@ -22,8 +25,13 @@
using feature::Metadata;
EditorDialog::EditorDialog(QWidget * parent, FeatureType const & feature) : QDialog(parent)
constexpr char const * kStreetObjectName = "street";
constexpr char const * kHouseNumberObjectName = "houseNumber";
EditorDialog::EditorDialog(QWidget * parent, FeatureType const & feature, Framework & frm) : QDialog(parent)
{
osm::Editor & editor = osm::Editor::Instance();
QVBoxLayout * vLayout = new QVBoxLayout();
// First uneditable row: feature types.
@ -37,35 +45,61 @@ EditorDialog::EditorDialog(QWidget * parent, FeatureType const & feature) : QDia
typesRow->addWidget(new QLabel(QString::fromStdString(strTypes)));
vLayout->addLayout(typesRow);
if (osm::Editor::Instance().IsNameEditable(feature))
{
// 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);
bool const readOnlyName = !editor.IsNameEditable(feature);
// 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->setReadOnly(readOnlyName);
defaultNamelineEdit->setObjectName(defaultLangStr);
defaultNameRow->addWidget(defaultNamelineEdit);
vLayout->addLayout(defaultNameRow);
feature.ForEachNameRef([&vLayout, &defaultNamelineEdit](int8_t langCode, string const & name) -> bool
feature.ForEachNameRef([&](int8_t langCode, string const & name) -> bool
{
if (langCode == StringUtf8Multilang::DEFAULT_CODE)
defaultNamelineEdit->setText(QString::fromStdString(name));
else
{
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.
});
}
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->setReadOnly(readOnlyName);
lineEditName->setObjectName(langStr);
nameRow->addWidget(lineEditName);
vLayout->addLayout(nameRow);
}
return true; // true is needed to enumerate all languages.
});
// Address rows.
bool const readOnlyAddress = !editor.IsAddressEditable(feature);
vector<string> nearbyStreets = frm.GetNearbyFeatureStreets(feature);
// If feature does not have a specified street, display empty combo box.
search::AddressInfo const info = frm.GetFeatureAddressInfo(feature);
if (info.m_street.empty())
nearbyStreets.insert(nearbyStreets.begin(), "");
QHBoxLayout * streetRow = new QHBoxLayout();
streetRow->addWidget(new QLabel(QString("Street:")));
QComboBox * cmb = new QComboBox();
for (auto const & street : nearbyStreets)
cmb->addItem(street.c_str());
cmb->setEditable(!readOnlyAddress);
cmb->setEnabled(!readOnlyAddress);
cmb->setObjectName(kStreetObjectName);
streetRow->addWidget(cmb) ;
vLayout->addLayout(streetRow);
QHBoxLayout * houseRow = new QHBoxLayout();
houseRow->addWidget(new QLabel(QString("House Number:")));
QLineEdit * houseLineEdit = new QLineEdit();
houseLineEdit->setText(info.m_house.c_str());
houseLineEdit->setReadOnly(readOnlyAddress);
houseLineEdit->setObjectName(kHouseNumberObjectName);
houseRow->addWidget(houseLineEdit);
vLayout->addLayout(houseRow);
// All metadata rows.
QVBoxLayout * metaRows = new QVBoxLayout();
@ -129,3 +163,16 @@ Metadata EditorDialog::GetEditedMetadata() const
}
return metadata;
}
string EditorDialog::GetEditedStreet() const
{
QComboBox const * cmb = findChild<QComboBox *>();
if (cmb->count())
return cmb->itemText(0).toStdString();
return string();
}
string EditorDialog::GetEditedHouseNumber() const
{
return findChild<QLineEdit *>(kHouseNumberObjectName)->text().toStdString();
}

View file

@ -9,13 +9,16 @@
#include <QtWidgets/QDialog>
class FeatureType;
class Framework;
class QLineEdit;
class EditorDialog : public QDialog
{
Q_OBJECT
public:
EditorDialog(QWidget * parent, FeatureType const & feature);
EditorDialog(QWidget * parent, FeatureType const & feature, Framework & frm);
StringUtf8Multilang GetEditedNames() const;
feature::Metadata GetEditedMetadata() const;
string GetEditedStreet() const;
string GetEditedHouseNumber() const;
};