Marble

OsmRelationEditorDialog.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Stanciu Marius-Valeriu <stanciumarius94@gmail.com>
4//
5
6// self
7#include "OsmRelationEditorDialog.h"
8
9// Marble
10#include "GeoDataData.h"
11#include "GeoDataExtendedData.h"
12#include "GeoDataPlacemark.h"
13#include "OsmObjectManager.h"
14#include "OsmPlacemarkData.h"
15#include "OsmTagEditorWidget.h"
16
17// Qt
18#include <QDialogButtonBox>
19#include <QHBoxLayout>
20#include <QLabel>
21#include <QLineEdit>
22#include <QMessageBox>
23#include <QVBoxLayout>
24
25namespace Marble
26{
27
28OsmRelationEditorDialog::OsmRelationEditorDialog(OsmPlacemarkData *relationData, QWidget *parent)
29 : QDialog(parent)
30{
31 m_relationData = relationData;
32 auto layout = new QVBoxLayout(this);
33
34 // Name input area
35 auto nameLayout = new QHBoxLayout();
36 auto nameLabel = new QLabel(tr("Name"), this);
37 m_nameLineEdit = new QLineEdit(this);
38 m_nameLineEdit->setText(relationData->tagValue(QStringLiteral("name")));
39 nameLayout->addWidget(nameLabel);
40 nameLayout->addWidget(m_nameLineEdit);
41 layout->addLayout(nameLayout);
42
43 // Tag editor area
44 // A dummy placemark is needed because the OsmTagEditorWidget works with placemarks
45 m_dummyPlacemark = new GeoDataPlacemark();
46 // "osmRelaation=yes" entry is added to its ExtendedData to let the widget know
47 // its special relation status
48 GeoDataExtendedData extendedData;
49 extendedData.addValue(GeoDataData(QStringLiteral("osmRelation"), QStringLiteral("yes")));
50 m_dummyPlacemark->setExtendedData(extendedData);
51 m_dummyPlacemark->setOsmData(*m_relationData);
52 OsmObjectManager::initializeOsmData(m_dummyPlacemark);
53 m_tagEditor = new OsmTagEditorWidget(m_dummyPlacemark, this);
54 layout->addWidget(m_tagEditor);
55
56 // Button box area
58 layout->addWidget(m_buttonBox);
59
60 connect(m_buttonBox, &QDialogButtonBox::accepted, this, &OsmRelationEditorDialog::checkFields);
62}
63
64OsmRelationEditorDialog::~OsmRelationEditorDialog()
65{
66 delete m_dummyPlacemark;
67}
68
69void OsmRelationEditorDialog::finish()
70{
71 // Updating the relation data with the edited one
72 m_dummyPlacemark->osmData().addTag(QStringLiteral("name"), m_nameLineEdit->text());
73 *m_relationData = m_dummyPlacemark->osmData();
74 accept();
75}
76
77void OsmRelationEditorDialog::checkFields()
78{
79 if (m_nameLineEdit->text().isEmpty()) {
80 QMessageBox::warning(this, tr("No name specified"), tr("Please specify a name for this relation."));
81 } else if (!m_dummyPlacemark->osmData().containsTagKey(QStringLiteral("type"))) {
82 QMessageBox::warning(this, tr("No type tag specified"), tr("Please add a type tag for this relation."));
83 } else {
84 finish();
85 }
86}
87
88}
89
90#include "moc_OsmRelationEditorDialog.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
virtual void reject()
StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.