From a6a71d87706a91ca619ef3aca5db406e932f453a Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 3 Dec 2015 18:47:38 +0300 Subject: [PATCH] [qt] Editor Dialog UI. --- qt/editor_dialog.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++ qt/editor_dialog.hpp | 15 +++++++ qt/qt.pro | 2 + 3 files changed, 111 insertions(+) create mode 100644 qt/editor_dialog.cpp create mode 100644 qt/editor_dialog.hpp diff --git a/qt/editor_dialog.cpp b/qt/editor_dialog.cpp new file mode 100644 index 0000000000..a0b5f73685 --- /dev/null +++ b/qt/editor_dialog.cpp @@ -0,0 +1,94 @@ +#include "qt/editor_dialog.hpp" + +#include "search/result.hpp" + +#include "indexer/classificator.hpp" +#include "indexer/feature.hpp" +#include "indexer/feature_meta.hpp" + +#include "std/set.hpp" +#include "std/vector.hpp" + +#include +#include +#include +#include +#include +#include + +#include + +using feature::Metadata; + +EditorDialog::EditorDialog(QWidget * parent, FeatureType const & feature) : QDialog(parent) +{ + QVBoxLayout * vLayout = new QVBoxLayout(); + + // First uneditable row: feature types. + string strTypes; + feature.ForEachType([&strTypes](uint32_t type) + { + strTypes += classif().GetReadableObjectName(type) + " "; + }); + QHBoxLayout * typesRow = new QHBoxLayout(); + 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. + QVBoxLayout * metaRows = new QVBoxLayout(); + // TODO(mgsergio): Load editable fields from metadata. + vector editableMetadataFields; + // TODO(AlexZ): Temporary enable only existing meta information fields. + // Final editor should have all editable fields enabled. + editableMetadataFields = feature.GetMetadata().GetPresentTypes(); +/* + // Merge editable fields for all feature's types. + feature.ForEachType([&editableMetadataFields](uint32_t type) + { + auto const editableFields = osm::Editor::EditableMetadataForType(type); + editableMetadataFields.insert(editableFields.begin(), editableFields.end()); + }); +*/ + // Equals to editableMetadataFields, used to retrieve text entered by user. + vector metaFieldEditors; + for (auto const field : editableMetadataFields) + { + QHBoxLayout * fieldRow = new QHBoxLayout(); + fieldRow->addWidget(new QLabel(QString::fromStdString(DebugPrint(field) + ":"))); + QLineEdit * lineEdit = new QLineEdit(QString::fromStdString(feature.GetMetadata().Get(field))); + fieldRow->addWidget(lineEdit); + metaFieldEditors.push_back(lineEdit); + metaRows->addLayout(fieldRow); + } + ASSERT_EQUAL(editableMetadataFields.size(), metaFieldEditors.size(), ()); + vLayout->addLayout(metaRows); + + // Dialog buttons. + QDialogButtonBox * buttonBox = new QDialogButtonBox( + QDialogButtonBox::Cancel | QDialogButtonBox::Save); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + // Delete button should send custom int return value from dialog. + QPushButton * deletePOIButton = new QPushButton("Delete POI"); + QSignalMapper * signalMapper = new QSignalMapper(); + connect(deletePOIButton, SIGNAL(clicked()), signalMapper, SLOT(map())); + signalMapper->setMapping(deletePOIButton, QDialogButtonBox::DestructiveRole); + connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(done(int))); + buttonBox->addButton(deletePOIButton, QDialogButtonBox::DestructiveRole); + QHBoxLayout * buttonsRowLayout = new QHBoxLayout(); + buttonsRowLayout->addWidget(buttonBox); + vLayout->addLayout(buttonsRowLayout); + + setLayout(vLayout); + setWindowTitle("POI Editor"); +} diff --git a/qt/editor_dialog.hpp b/qt/editor_dialog.hpp new file mode 100644 index 0000000000..f17fd5e14b --- /dev/null +++ b/qt/editor_dialog.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "std/string.hpp" + +#include + +class FeatureType; +class QLineEdit; + +class EditorDialog : public QDialog +{ + Q_OBJECT +public: + EditorDialog(QWidget * parent, FeatureType const & feature); +}; diff --git a/qt/qt.pro b/qt/qt.pro index 2745d28ee6..bf3ff6a56c 100644 --- a/qt/qt.pro +++ b/qt/qt.pro @@ -111,6 +111,7 @@ SOURCES += \ update_dialog.cpp \ qtoglcontext.cpp \ qtoglcontextfactory.cpp \ + editor_dialog.cpp \ HEADERS += \ mainwindow.hpp \ @@ -124,5 +125,6 @@ HEADERS += \ update_dialog.hpp \ qtoglcontext.hpp \ qtoglcontextfactory.hpp \ + editor_dialog.hpp \ RESOURCES += res/resources.qrc