Marble

RemoveItemEditWidget.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2015 Mihail Ivchenko <[email protected]>
4 //
5 
6 #include "RemoveItemEditWidget.h"
7 
8 #include <QLabel>
9 #include <QHBoxLayout>
10 
11 #include "MarbleWidget.h"
12 #include "geodata/data/GeoDataAnimatedUpdate.h"
13 #include "GeoDataUpdate.h"
14 #include "GeoDataDelete.h"
15 #include "MarblePlacemarkModel.h"
16 
17 namespace Marble {
18 
19 RemoveItemEditWidget::RemoveItemEditWidget( const QModelIndex &index, QWidget *parent ) :
20  QWidget( parent ),
21  m_index( index ),
22  m_button( new QToolButton ),
23  m_comboBox( new QComboBox )
24 {
25  QHBoxLayout *layout = new QHBoxLayout;
26  layout->setSpacing( 5 );
27 
28  QLabel* iconLabel = new QLabel;
29  iconLabel->setPixmap(QPixmap(QStringLiteral(":/icons/remove.png")));
30  layout->addWidget( iconLabel );
31 
32  QLabel* comboBoxLabel = new QLabel;
33  comboBoxLabel->setText( tr( "Choose item:" ) );
34  layout->addWidget( comboBoxLabel );
35 
36  layout->addWidget( m_comboBox );
37 
38  m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png")));
39  connect(m_button, SIGNAL(clicked()), this, SLOT(save()));
40  layout->addWidget( m_button );
41 
42  setLayout( layout );
43 }
44 
45 bool RemoveItemEditWidget::editable() const
46 {
47  return m_button->isEnabled();
48 }
49 
50 void RemoveItemEditWidget::setFeatureIds( const QStringList &ids )
51 {
52  QString id = animatedUpdateElement()->update()->getDelete()->first().targetId();
53  QString current = m_comboBox->currentIndex() == -1 ? id : m_comboBox->currentText();
54  m_comboBox->clear();
55  m_comboBox->addItems( ids );
56  m_comboBox->setCurrentIndex( m_comboBox->findText( current ) );
57 }
58 
59 void RemoveItemEditWidget::setDefaultFeatureId( const QString &featureId )
60 {
61  if( m_comboBox->currentIndex() == -1 ) {
62  m_comboBox->setCurrentIndex( m_comboBox->findText( featureId ) );
63  }
64 }
65 
66 void RemoveItemEditWidget::setEditable( bool editable )
67 {
68  m_button->setEnabled( editable );
69 }
70 
71 void RemoveItemEditWidget::save()
72 {
73  animatedUpdateElement()->update()->getDelete()->child(0)->setTargetId( m_comboBox->currentText() );
74  emit editingDone(m_index);
75 }
76 
77 GeoDataAnimatedUpdate* RemoveItemEditWidget::animatedUpdateElement()
78 {
79  GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );
80  Q_ASSERT( object );
81  auto animatedUpdate = geodata_cast<GeoDataAnimatedUpdate>(object);
82  Q_ASSERT(animatedUpdate);
83  return animatedUpdate;
84 }
85 
86 } // namespace Marble
87 
88 #include "moc_RemoveItemEditWidget.cpp"
void setText(const QString &)
void clear()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
@ ObjectPointerRole
The pointer to a specific object.
Binds a QML item to a specific geodetic location in screen coordinates.
void setSpacing(int spacing)
void setPixmap(const QPixmap &)
QAction * save(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 04:07:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.