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 <QHBoxLayout>
9#include <QLabel>
10
11#include "GeoDataDelete.h"
12#include "GeoDataUpdate.h"
13#include "MarblePlacemarkModel.h"
14#include "MarbleWidget.h"
15#include "geodata/data/GeoDataAnimatedUpdate.h"
16
17namespace Marble
18{
19
20RemoveItemEditWidget::RemoveItemEditWidget(const QModelIndex &index, QWidget *parent)
21 : QWidget(parent)
22 , m_index(index)
23 , m_button(new QToolButton)
24 , m_comboBox(new QComboBox)
25{
26 auto layout = new QHBoxLayout(this);
27 layout->setSpacing(5);
28
29 auto iconLabel = new QLabel;
30 iconLabel->setPixmap(QPixmap(QStringLiteral(":/icons/remove.png")));
31 layout->addWidget(iconLabel);
32
33 auto comboBoxLabel = new QLabel;
34 comboBoxLabel->setText(tr("Choose item:"));
35 layout->addWidget(comboBoxLabel);
36
37 layout->addWidget(m_comboBox);
38
39 m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png")));
40 connect(m_button, &QAbstractButton::clicked, this, &RemoveItemEditWidget::save);
41 layout->addWidget(m_button);
42}
43
44bool RemoveItemEditWidget::editable() const
45{
46 return m_button->isEnabled();
47}
48
49void RemoveItemEditWidget::setFeatureIds(const QStringList &ids)
50{
51 QString id = animatedUpdateElement()->update()->getDelete()->first().targetId();
52 QString current = m_comboBox->currentIndex() == -1 ? id : m_comboBox->currentText();
53 m_comboBox->clear();
54 m_comboBox->addItems(ids);
55 m_comboBox->setCurrentIndex(m_comboBox->findText(current));
56}
57
58void RemoveItemEditWidget::setDefaultFeatureId(const QString &featureId)
59{
60 if (m_comboBox->currentIndex() == -1) {
61 m_comboBox->setCurrentIndex(m_comboBox->findText(featureId));
62 }
63}
64
65void RemoveItemEditWidget::setEditable(bool editable)
66{
67 m_button->setEnabled(editable);
68}
69
70void RemoveItemEditWidget::save()
71{
72 animatedUpdateElement()->update()->getDelete()->child(0)->setTargetId(m_comboBox->currentText());
73 Q_EMIT editingDone(m_index);
74}
75
76GeoDataAnimatedUpdate *RemoveItemEditWidget::animatedUpdateElement()
77{
78 auto object = qvariant_cast<GeoDataObject *>(m_index.data(MarblePlacemarkModel::ObjectPointerRole));
79 Q_ASSERT(object);
80 auto animatedUpdate = geodata_cast<GeoDataAnimatedUpdate>(object);
81 Q_ASSERT(animatedUpdate);
82 return animatedUpdate;
83}
84
85} // namespace Marble
86
87#include "moc_RemoveItemEditWidget.cpp"
This file contains the headers for MarbleWidget.
Binds a QML item to a specific geodetic location in screen coordinates.
void clicked(bool checked)
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 Dec 20 2024 11:52:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.