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 "OsmTagEditorWidget.h"
11#include "OsmPlacemarkData.h"
12#include "OsmObjectManager.h"
13#include "GeoDataPlacemark.h"
14#include "GeoDataExtendedData.h"
15#include "GeoDataData.h"
16
17// Qt
18#include <QVBoxLayout>
19#include <QHBoxLayout>
20#include <QMessageBox>
21#include <QLabel>
22#include <QLineEdit>
23#include <QDialogButtonBox>
24
25namespace Marble {
26
27
28OsmRelationEditorDialog::OsmRelationEditorDialog( OsmPlacemarkData *relationData, QWidget *parent ) :
29 QDialog( parent )
30{
31 m_relationData = relationData;
32 QVBoxLayout *layout = new QVBoxLayout( this );
33
34 // Name input area
35 QHBoxLayout *nameLayout = new QHBoxLayout();
36 QLabel *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 QObject::connect( m_buttonBox, SIGNAL(accepted()),
61 this, SLOT(checkFields()) );
62 connect(m_buttonBox, SIGNAL(rejected()), SLOT(reject()));
63}
64
65OsmRelationEditorDialog::~OsmRelationEditorDialog()
66{
67 delete m_dummyPlacemark;
68}
69
70void OsmRelationEditorDialog::finish()
71{
72 // Updating the relation data with the edited one
73 m_dummyPlacemark->osmData().addTag(QStringLiteral("name"), m_nameLineEdit->text());
74 *m_relationData = m_dummyPlacemark->osmData();
75 accept();
76}
77
78void OsmRelationEditorDialog::checkFields()
79{
80 if ( m_nameLineEdit->text().isEmpty() ) {
82 tr( "No name specified" ),
83 tr( "Please specify a name for this relation." ) );
84 }
85 else if (!m_dummyPlacemark->osmData().containsTagKey(QStringLiteral("type"))) {
87 tr( "No type tag specified" ),
88 tr( "Please add a type tag for this relation." ) );
89 }
90 else {
91 finish();
92 }
93}
94
95}
96
97#include "moc_OsmRelationEditorDialog.cpp"
98
Binds a QML item to a specific geodetic location in screen coordinates.
void addLayout(QLayout *layout, int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
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 Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.