8#include "EditBookmarkDialog.h"
9#include "ui_EditBookmarkDialog.h"
11#include "BookmarkManager.h"
12#include "GeoDataCoordinates.h"
13#include "GeoDataData.h"
14#include "GeoDataDocument.h"
15#include "GeoDataExtendedData.h"
16#include "GeoDataFolder.h"
17#include "GeoDataIconStyle.h"
18#include "GeoDataLookAt.h"
19#include "GeoDataPlacemark.h"
20#include "GeoDataPoint.h"
21#include "GeoDataStyle.h"
22#include "MarbleDirs.h"
25#include "NewBookmarkFolderDialog.h"
26#include "ReverseGeocodingRunnerManager.h"
33class EditBookmarkDialogPrivate
36 MarbleWidget *m_widget;
37 ReverseGeocodingRunnerManager *m_manager;
38 BookmarkManager *m_bookmarkManager;
39 GeoDataCoordinates m_bookmarkCoordinates;
41 Ui::UiEditBookmarkDialog m_ui;
43 EditBookmarkDialogPrivate(EditBookmarkDialog *q, BookmarkManager *bookmarkManager);
45 void initComboBox(
const GeoDataContainer *
const container,
int level = 0);
49 void setFolderName(
const QString &name);
53 void openNewFolderDialog();
55 void retrieveGeocodeResult(
const GeoDataCoordinates &coordinates,
const GeoDataPlacemark &placemark);
57 void updateCoordinates();
60 EditBookmarkDialog *
const q;
63EditBookmarkDialogPrivate::EditBookmarkDialogPrivate(EditBookmarkDialog *q_, BookmarkManager *bookmarkManager)
66 , m_bookmarkManager(bookmarkManager)
73void EditBookmarkDialogPrivate::initialize()
76 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
77 m_ui.m_header->setPositionVisible(!smallScreen);
78 m_ui.m_header->setIdVisible(
false);
79 m_ui.m_header->setIconLink(MarbleDirs::path(QStringLiteral(
"bitmaps/bookmark.png")));
80 QObject::connect(m_ui.m_newFolderButton, SIGNAL(clicked()), q, SLOT(openNewFolderDialog()));
81 QObject::connect(m_ui.m_header, SIGNAL(valueChanged()), q, SLOT(updateCoordinates()));
83 m_ui.m_folders->clear();
84 initComboBox(m_bookmarkManager->document());
87void EditBookmarkDialogPrivate::initComboBox(
const GeoDataContainer *
const container,
int level)
89 m_bookmarkManager->ensureDefaultFolder();
90 for (GeoDataFolder *folder : container->folderList()) {
94 m_ui.m_folders->addItem(name, folderVariant);
95 if (!folder->folderList().isEmpty()) {
96 initComboBox(folder, level + 1);
101void EditBookmarkDialogPrivate::setFolderName(
const QString &name)
103 for (
int i = 0; i < m_ui.m_folders->count(); ++i) {
104 if (m_ui.m_folders->itemText(i) == name) {
105 m_ui.m_folders->setCurrentIndex(i);
111EditBookmarkDialog::EditBookmarkDialog(BookmarkManager *bookmarkManager,
QWidget *parent)
113 , d(new EditBookmarkDialogPrivate(this, bookmarkManager))
118void EditBookmarkDialog::setCoordinates(
const GeoDataCoordinates &coordinates)
120 d->m_bookmarkCoordinates = coordinates;
121 QObject::disconnect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
123 if (d->m_ui.m_header->name().isEmpty()) {
124 d->m_ui.m_header->setName(coordinates.toString());
127 d->m_ui.m_header->setLongitude(coordinates.longitude(GeoDataCoordinates::Degree));
128 d->m_ui.m_header->setLatitude(coordinates.latitude(GeoDataCoordinates::Degree));
129 QObject::connect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
132void EditBookmarkDialog::setRange(qreal range)
137void EditBookmarkDialog::setName(
const QString &text)
139 QObject::disconnect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
140 d->m_ui.m_header->setName(text);
141 d->m_ui.m_header->selectAll();
142 QObject::connect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
145void EditBookmarkDialog::setDescription(
const QString &text)
147 QObject::disconnect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
148 d->m_ui.m_description->setText(text);
149 QObject::connect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
152void EditBookmarkDialog::setFolderName(
const QString &name)
154 d->setFolderName(name);
157void EditBookmarkDialog::setIconLink(
const QString &iconLink)
159 QObject::disconnect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
160 d->m_ui.m_header->setIconLink(iconLink);
161 QObject::connect(d->m_ui.m_header, SIGNAL(valueChanged()),
this, SLOT(updateCoordinates()));
164void EditBookmarkDialog::setMarbleWidget(MarbleWidget *widget)
166 d->m_widget = widget;
167 const AngleUnit defaultAngleUnit = d->m_widget->defaultAngleUnit();
168 const GeoDataCoordinates::Notation notation = (defaultAngleUnit ==
DecimalDegree) ? GeoDataCoordinates::Decimal
169 : (defaultAngleUnit ==
DMSDegree) ? GeoDataCoordinates::DMS
171 GeoDataCoordinates::
UTM;
172 d->m_ui.m_header->setNotation(notation);
174 d->m_manager =
new ReverseGeocodingRunnerManager(d->m_widget->model(),
this);
176 SIGNAL(reverseGeocodingFinished(GeoDataCoordinates, GeoDataPlacemark)),
178 SLOT(retrieveGeocodeResult(GeoDataCoordinates, GeoDataPlacemark)));
181void EditBookmarkDialog::setReverseGeocodeName()
187 d->m_manager->reverseGeocoding(d->m_bookmarkCoordinates);
190EditBookmarkDialog::~EditBookmarkDialog()
195void EditBookmarkDialogPrivate::retrieveGeocodeResult(
const GeoDataCoordinates &coordinates,
const GeoDataPlacemark &placemark)
197 Q_UNUSED(coordinates)
198 GeoDataExtendedData data = placemark.extendedData();
200 qreal
distance = m_widget->distance() * KM2METER;
203 if (distance >= 3500) {
204 bookmarkName = data.value(QStringLiteral(
"country")).value().toString();
205 }
else if (distance >= 200) {
206 bookmarkName = append(data.value(QStringLiteral(
"city")).value().
toString(), data.value(QStringLiteral(
"state")).value().
toString());
207 bookmarkName = append(bookmarkName, data.value(QStringLiteral(
"country")).value().
toString());
209 bookmarkName = append(data.value(QStringLiteral(
"road")).value().
toString(), data.value(QStringLiteral(
"city")).value().
toString());
210 bookmarkName = append(bookmarkName, data.value(QStringLiteral(
"country")).value().
toString());
214 bookmarkName = placemark.address();
217 m_ui.m_header->setName(bookmarkName);
218 m_ui.m_header->selectAll();
225 }
else if (bookmark.
isEmpty()) {
230 return bookmark + QStringLiteral(
", ") + text;
233void EditBookmarkDialogPrivate::openNewFolderDialog()
237 m_bookmarkManager->addNewBookmarkFolder(m_bookmarkManager->document(), dialog->folderName());
238 m_ui.m_folders->clear();
239 initComboBox(m_bookmarkManager->document());
240 setFolderName(dialog->folderName());
245void EditBookmarkDialogPrivate::updateCoordinates()
247 m_bookmarkCoordinates.setLongitude(m_ui.m_header->longitude(), GeoDataCoordinates::Degree);
248 m_bookmarkCoordinates.setLatitude(m_ui.m_header->latitude(), GeoDataCoordinates::Degree);
251GeoDataPlacemark EditBookmarkDialog::bookmark()
const
254 GeoDataPlacemark bookmark;
255 bookmark.setName(
name());
256 bookmark.setDescription(description());
257 GeoDataStyle::Ptr newStyle(
new GeoDataStyle(*bookmark.style()));
258 newStyle->iconStyle().setIconPath(iconLink());
259 bookmark.setStyle(newStyle);
261 bookmark.setDescriptionCDATA(
true);
262 bookmark.setCoordinate(coordinates());
264 auto lookat =
new GeoDataLookAt;
265 lookat->setCoordinates(coordinates());
266 lookat->setRange(range());
267 bookmark.setAbstractView(lookat);
270 bookmark.extendedData().addValue(GeoDataData(QStringLiteral(
"isBookmark"),
true));
272 if (d->m_widget !=
nullptr) {
273 const QString celestialName = d->m_widget->model()->planetId();
275 bookmark.extendedData().addValue(GeoDataData(QStringLiteral(
"celestialBody"), celestialName));
282QString EditBookmarkDialog::name()
const
284 return d->m_ui.m_header->name();
287GeoDataFolder *EditBookmarkDialog::folder()
const
289 return qvariant_cast<GeoDataFolder *>(d->m_ui.m_folders->itemData(d->m_ui.m_folders->currentIndex()));
292QString EditBookmarkDialog::description()
const
294 return d->m_ui.m_description->toPlainText();
297GeoDataCoordinates EditBookmarkDialog::coordinates()
const
299 return d->m_bookmarkCoordinates;
302qreal EditBookmarkDialog::range()
const
307QString EditBookmarkDialog::iconLink()
const
309 return d->m_ui.m_header->iconLink();
314#include "moc_EditBookmarkDialog.cpp"
This file contains the headers for MarbleModel.
char * toString(const EngineQuery &query)
QString name(StandardAction id)
Binds a QML item to a specific geodetic location in screen coordinates.
AngleUnit
This enum is used to choose the unit chosen to measure angles.
@ DMSDegree
Degrees in DMS notation.
@ DecimalDegree
Degrees in decimal notation.
KOSM_EXPORT double distance(const std::vector< const OSM::Node * > &path, Coordinate coord)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
bool isEmpty() const const
QString repeated(qsizetype times) const const
void setValue(QVariant &&value)