File indexing completed on 2024-05-12 15:29:53

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2015 Stanciu Marius-Valeriu <stanciumarius94@gmail.com>
0004 //
0005 
0006 // self
0007 #include "OsmRelationEditorDialog.h"
0008 
0009 // Marble
0010 #include "OsmTagEditorWidget.h"
0011 #include "OsmPlacemarkData.h"
0012 #include "OsmObjectManager.h"
0013 #include "GeoDataPlacemark.h"
0014 #include "GeoDataExtendedData.h"
0015 #include "GeoDataData.h"
0016 
0017 // Qt
0018 #include <QVBoxLayout>
0019 #include <QHBoxLayout>
0020 #include <QMessageBox>
0021 #include <QLabel>
0022 #include <QLineEdit>
0023 #include <QDialogButtonBox>
0024 
0025 namespace Marble {
0026 
0027 
0028 OsmRelationEditorDialog::OsmRelationEditorDialog( OsmPlacemarkData *relationData, QWidget *parent ) :
0029     QDialog( parent )
0030 {
0031     m_relationData = relationData;
0032     QVBoxLayout *layout = new QVBoxLayout( this );
0033 
0034     // Name input area
0035     QHBoxLayout *nameLayout = new QHBoxLayout();
0036     QLabel *nameLabel = new QLabel( tr( "Name" ), this );
0037     m_nameLineEdit = new QLineEdit( this );
0038     m_nameLineEdit->setText(relationData->tagValue(QStringLiteral("name")));
0039     nameLayout->addWidget( nameLabel );
0040     nameLayout->addWidget( m_nameLineEdit );
0041     layout->addLayout( nameLayout );
0042 
0043     // Tag editor area
0044     // A dummy placemark is needed because the OsmTagEditorWidget works with placemarks
0045     m_dummyPlacemark = new GeoDataPlacemark();
0046     // "osmRelaation=yes" entry is added to its ExtendedData to let the widget know
0047     // its special relation status
0048     GeoDataExtendedData extendedData;
0049     extendedData.addValue(GeoDataData(QStringLiteral("osmRelation"), QStringLiteral("yes")));
0050     m_dummyPlacemark->setExtendedData( extendedData );
0051     m_dummyPlacemark->setOsmData( *m_relationData );
0052     OsmObjectManager::initializeOsmData( m_dummyPlacemark );
0053     m_tagEditor = new OsmTagEditorWidget( m_dummyPlacemark, this );
0054     layout->addWidget( m_tagEditor );
0055 
0056     // Button box area
0057     m_buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this );
0058     layout->addWidget( m_buttonBox );
0059 
0060     QObject::connect( m_buttonBox, SIGNAL(accepted()),
0061                        this, SLOT(checkFields()) );
0062     connect(m_buttonBox, SIGNAL(rejected()), SLOT(reject()));
0063 }
0064 
0065 OsmRelationEditorDialog::~OsmRelationEditorDialog()
0066 {
0067     delete m_dummyPlacemark;
0068 }
0069 
0070 void OsmRelationEditorDialog::finish()
0071 {
0072     // Updating the relation data with the edited one
0073     m_dummyPlacemark->osmData().addTag(QStringLiteral("name"), m_nameLineEdit->text());
0074     *m_relationData = m_dummyPlacemark->osmData();
0075     accept();
0076 }
0077 
0078 void OsmRelationEditorDialog::checkFields()
0079 {
0080     if ( m_nameLineEdit->text().isEmpty() ) {
0081         QMessageBox::warning( this,
0082                               tr( "No name specified" ),
0083                               tr( "Please specify a name for this relation." ) );
0084     }
0085     else if (!m_dummyPlacemark->osmData().containsTagKey(QStringLiteral("type"))) {
0086         QMessageBox::warning( this,
0087                               tr( "No type tag specified" ),
0088                               tr( "Please add a type tag for this relation." ) );
0089     }
0090     else {
0091         finish();
0092     }
0093 }
0094 
0095 }
0096 
0097 #include "moc_OsmRelationEditorDialog.cpp"
0098