Marble

RemoveItemEditWidget.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Mihail Ivchenko <ematirov@gmail.com>
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
17namespace Marble {
18
19RemoveItemEditWidget::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
45bool RemoveItemEditWidget::editable() const
46{
47 return m_button->isEnabled();
48}
49
50void 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
59void RemoveItemEditWidget::setDefaultFeatureId( const QString &featureId )
60{
61 if( m_comboBox->currentIndex() == -1 ) {
62 m_comboBox->setCurrentIndex( m_comboBox->findText( featureId ) );
63 }
64}
65
66void RemoveItemEditWidget::setEditable( bool editable )
67{
68 m_button->setEnabled( editable );
69}
70
71void RemoveItemEditWidget::save()
72{
73 animatedUpdateElement()->update()->getDelete()->child(0)->setTargetId( m_comboBox->currentText() );
74 emit editingDone(m_index);
75}
76
77GeoDataAnimatedUpdate* 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"
This file contains the headers for MarbleWidget.
KGuiItem save()
Binds a QML item to a specific geodetic location in screen coordinates.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void setSpacing(int spacing) override
void setPixmap(const QPixmap &)
void setText(const QString &)
void clear()
QString first(qsizetype n) const const
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 Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.