Marble

OsmRelationEditorDialog.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2015 Stanciu Marius-Valeriu <[email protected]>
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 
25 namespace Marble {
26 
27 
28 OsmRelationEditorDialog::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 
65 OsmRelationEditorDialog::~OsmRelationEditorDialog()
66 {
67  delete m_dummyPlacemark;
68 }
69 
70 void 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 
78 void 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 
void addTag(const QString &key, const QString &value)
addTag this function inserts a string key=value mapping, equivalent to the <tag k="@p key" v="@p valu...
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
static void initializeOsmData(GeoDataPlacemark *placemark)
initializeOsmData assigns valid osmData to a placemark that does not have it.
virtual void accept()
Binds a QML item to a specific geodetic location in screen coordinates.
OsmPlacemarkData & osmData()
Quick, safe accessor to the placemark's OsmPlacemarkData stored within it's ExtendedData.
void addLayout(QLayout *layout, int stretch)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool containsTagKey(const QString &key) const
containsTagKey returns true if the tag hash contains an entry with the key as key
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Oct 4 2023 04:09:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.