8#include "EditPlacemarkDialog.h"
9#include "ui_EditPlacemarkDialog.h"
10#include "ui_ElevationWidget.h"
14#include <QColorDialog>
19#include "FormattedTextWidget.h"
20#include "GeoDataIconStyle.h"
21#include "GeoDataLabelStyle.h"
22#include "GeoDataPlacemark.h"
23#include "GeoDataStyle.h"
24#include "MarbleLocale.h"
26#include "StyleBuilder.h"
27#include "osm/OsmPlacemarkData.h"
28#include "osm/OsmRelationManagerWidget.h"
29#include "osm/OsmTagEditorWidget.h"
37 Private(GeoDataPlacemark *placemark);
40 GeoDataPlacemark *m_placemark;
43 QColorDialog *m_iconColorDialog;
44 QColorDialog *m_labelColorDialog;
47 QString m_initialDescription;
48 QString m_initialName;
49 GeoDataCoordinates m_initialCoords;
50 GeoDataStyle m_initialStyle;
51 GeoDataPlacemark::GeoDataVisualCategory m_initialVisualCategory;
52 OsmPlacemarkData m_initialOsmData;
53 QString m_styleColorTabName;
54 bool m_initialIsPlacemarkVisible;
55 bool m_initialIsBaloonVisible;
56 bool m_initialDescriptionIsCDATA;
57 bool m_hadInitialOsmData;
59 Ui::ElevationWidget *m_elevationWidget;
60 OsmTagEditorWidget *m_osmTagEditorWidget;
61 OsmRelationManagerWidget *m_osmRelationManagerWidget;
62 MarbleLocale::MeasureUnit m_elevationUnit;
63 QString m_initialTargetId;
68 : Ui::UiEditPlacemarkDialog()
69 , m_placemark(placemark)
70 , m_iconColorDialog(nullptr)
71 , m_labelColorDialog(nullptr)
72 , m_osmTagEditorWidget(nullptr)
73 , m_osmRelationManagerWidget(nullptr)
79EditPlacemarkDialog::Private::~Private()
81 delete m_elevationWidget;
82 delete m_osmTagEditorWidget;
83 delete m_osmRelationManagerWidget;
84 delete m_iconColorDialog;
85 delete m_labelColorDialog;
90 , d(new Private(placemark))
95 d->m_initialStyle = *placemark->style();
97 d->m_initialVisualCategory = placemark->visualCategory();
99 d->m_hadInitialOsmData = placemark->hasOsmData();
100 if (d->m_hadInitialOsmData) {
101 d->m_initialOsmData = placemark->osmData();
105 if (placemark->name().isNull()) {
106 placemark->setName(tr(
"Untitled Placemark"));
109 d->m_header->setId(placemark->id());
110 d->m_initialId = placemark->id();
111 d->m_header->setName(placemark->name());
112 d->m_initialName = placemark->name();
113 d->m_isPlacemarkVisible->setChecked(placemark->isVisible());
114 d->m_initialIsPlacemarkVisible = placemark->isVisible();
115 d->m_header->setIconLink(placemark->style()->iconStyle().iconPath());
116 d->m_header->setTargetId(placemark->targetId());
117 d->m_initialTargetId = placemark->targetId();
118 auto marbleWidget =
dynamic_cast<MarbleWidget *
>(parent);
119 if (marbleWidget !=
nullptr) {
120 const AngleUnit defaultAngleUnit = marbleWidget->defaultAngleUnit();
125 d->m_header->setNotation(notation);
127 connect(d->m_header, SIGNAL(valueChanged()),
this, SLOT(updateTextAnnotation()));
129 d->m_formattedTextWidget->setText(placemark->description());
130 d->m_initialDescription = placemark->description();
131 d->m_initialDescriptionIsCDATA = placemark->descriptionIsCDATA();
132 d->m_isBalloonVisible->setChecked(placemark->isBalloonVisible());
133 d->m_initialIsBaloonVisible = placemark->isBalloonVisible();
135 d->m_header->setLatitude(placemark->coordinate().latitude(GeoDataCoordinates::Degree));
136 d->m_header->setLongitude(placemark->coordinate().longitude(GeoDataCoordinates::Degree));
137 d->m_initialCoords =
GeoDataCoordinates(d->m_header->longitude(), d->m_header->latitude(), 0, GeoDataCoordinates::Degree);
143 d->m_osmTagEditorWidget =
new OsmTagEditorWidget(placemark,
this);
144 d->tabWidget->addTab(d->m_osmTagEditorWidget, tr(
"Tags"));
145 connect(d->m_osmTagEditorWidget, &OsmTagEditorWidget::placemarkChanged,
this, &EditPlacemarkDialog::updateTextAnnotation);
148 d->m_osmRelationManagerWidget =
new OsmRelationManagerWidget(placemark, relations,
this);
149 d->tabWidget->addTab(d->m_osmRelationManagerWidget, tr(
"Relations"));
150 connect(d->m_osmRelationManagerWidget, &OsmRelationManagerWidget::relationCreated,
this, &EditPlacemarkDialog::relationCreated);
154 d->m_elevationWidget =
new Ui::ElevationWidget;
155 auto elevationTab =
new QWidget;
156 d->m_elevationWidget->
setupUi(elevationTab);
157 d->tabWidget->addTab(elevationTab, tr(
"Elevation"));
158 qreal altitude = d->m_placemark->coordinate().altitude();
159 MarbleLocale *locale = MarbleGlobal::getInstance()->locale();
160 if (altitude == 0.0) {
161 switch (locale->measurementSystem()) {
162 case MarbleLocale::MetricSystem:
163 d->m_elevationUnit = MarbleLocale::Meter;
165 case MarbleLocale::ImperialSystem:
166 d->m_elevationUnit = MarbleLocale::Foot;
168 case MarbleLocale::NauticalSystem:
169 d->m_elevationUnit = MarbleLocale::NauticalMile;
173 d->m_elevationWidget->elevationSpinBox->setSuffix(locale->unitAbbreviation((d->m_elevationUnit)));
175 qreal convertedAltitude;
176 const MarbleLocale::MeasurementSystem currentSystem = locale->measurementSystem();
177 locale->meterToTargetUnit(altitude, currentSystem, convertedAltitude, d->m_elevationUnit);
178 d->m_elevationWidget->elevationSpinBox->setValue(convertedAltitude);
179 d->m_elevationWidget->elevationSpinBox->setSuffix(locale->unitAbbreviation(d->m_elevationUnit));
183 d->m_iconScale->setValue(placemark->style()->iconStyle().scale());
186 d->m_labelScale->setValue(placemark->style()->labelStyle().scale());
190 const GeoDataLabelStyle labelStyle = placemark->style()->labelStyle();
191 const GeoDataIconStyle iconStyle = placemark->style()->iconStyle();
193 QPixmap labelPixmap(d->m_labelButton->iconSize().width(), d->m_labelButton->iconSize().height());
194 labelPixmap.fill(labelStyle.color());
195 d->m_labelButton->setIcon(
QIcon(labelPixmap));
197 QPixmap iconPixmap(d->m_iconButton->iconSize().width(), d->m_iconButton->iconSize().height());
198 iconPixmap.fill(iconStyle.color());
199 d->m_iconButton->setIcon(
QIcon(iconPixmap));
204 d->m_labelColorDialog->setCurrentColor(labelStyle.color());
211 d->m_iconColorDialog->setCurrentColor(iconStyle.color());
231EditPlacemarkDialog::~EditPlacemarkDialog()
238 d->m_labelColorDialog->setCurrentColor(color);
239 updateLabelDialog(color);
244 return d->m_header->idFilter();
249 return d->m_header->targetIdList();
254 return d->m_header->isTargetIdVisible();
259 return d->m_header->isIdVisible();
264 d->m_header->setLatitude(d->m_placemark->coordinate().latitude(GeoDataCoordinates::Degree));
265 d->m_header->setLongitude(d->m_placemark->coordinate().longitude(GeoDataCoordinates::Degree));
270 d->m_header->setIdFilter(filter);
280 d->m_header->setTargetIdVisible(
visible);
285 d->m_header->setIdVisible(
visible);
290 return d->m_isReadOnly;
295 d->m_isReadOnly = state;
296 d->m_header->setReadOnly(state);
297 d->m_formattedTextWidget->setReadOnly(state);
298 d->m_isBalloonVisible->setDisabled(state);
299 d->m_isPlacemarkVisible->setDisabled(state);
300 d->style_color_tab->setDisabled(state);
303void EditPlacemarkDialog::updateTextAnnotation()
308 d->m_placemark->setDescription(d->m_formattedTextWidget->text());
310 d->m_placemark->setDescriptionCDATA(
true);
311 d->m_placemark->setName(d->m_header->name());
312 d->m_placemark->setCoordinate(
GeoDataCoordinates(d->m_header->longitude(), d->m_header->latitude(), 0, GeoDataCoordinates::Degree));
314 d->m_placemark->setVisible(d->m_isPlacemarkVisible->isChecked());
315 d->m_placemark->setBalloonVisible(d->m_isBalloonVisible->isChecked());
316 d->m_placemark->setId(d->m_header->id());
317 d->m_placemark->setTargetId(d->m_header->targetId());
319 if (!d->m_header->iconLink().isEmpty()) {
320 GeoDataStyle::Ptr newStyle(
new GeoDataStyle(*d->m_placemark->style()));
322 newStyle->iconStyle().setIconPath(d->m_header->iconLink());
325 newStyle->iconStyle().setScale(d->m_iconScale->value());
326 newStyle->labelStyle().setScale(d->m_labelScale->value());
327 newStyle->iconStyle().setColor(d->m_iconColorDialog->currentColor());
328 newStyle->labelStyle().setColor(d->m_labelColorDialog->currentColor());
329 d->m_placemark->setStyle(newStyle);
331 const OsmPlacemarkData osmData = d->m_osmTagEditorWidget->placemarkData();
332 const GeoDataPlacemark::GeoDataVisualCategory
category = StyleBuilder::determineVisualCategory(osmData);
333 if (category != GeoDataPlacemark::None) {
334 d->m_placemark->setStyle(GeoDataStyle::Ptr());
335 d->m_placemark->setVisualCategory(category);
339 Q_EMIT textAnnotationUpdated(d->m_placemark);
342void EditPlacemarkDialog::checkFields()
349 if (d->m_header->name().isEmpty()) {
350 QMessageBox::warning(
this, tr(
"No name specified"), tr(
"Please specify a name for this placemark."));
351 }
else if (isIdFieldVisible() && d->m_header->id().isEmpty()) {
352 QMessageBox::warning(
this, tr(
"No ID specified"), tr(
"Please specify a ID for this placemark."));
353 }
else if (isIdFieldVisible() && !d->m_header->isIdValid()) {
354 QMessageBox::warning(
this, tr(
"ID is invalid"), tr(
"Please specify a valid ID for this placemark."));
355 }
else if (d->m_header->iconLink().isEmpty() && d->m_placemark->visualCategory() == GeoDataPlacemark::None) {
356 QMessageBox::warning(
this, tr(
"No image specified"), tr(
"Please specify an icon for this placemark or add a valid tag."));
357 }
else if (!d->m_header->iconLink().isEmpty() && !
QFileInfo::exists(d->m_header->iconLink())) {
358 QMessageBox::warning(
this, tr(
"Invalid icon path"), tr(
"Please specify a valid path for the icon file."));
364void EditPlacemarkDialog::updateLabelDialog(
const QColor &color)
369 QPixmap labelPixmap(d->m_labelButton->iconSize().width(), d->m_labelButton->iconSize().height());
370 labelPixmap.fill(color);
371 d->m_labelButton->setIcon(
QIcon(labelPixmap));
374void EditPlacemarkDialog::updateIconDialog(
const QColor &color)
379 QPixmap iconPixmap(d->m_iconButton->iconSize().width(), d->m_iconButton->iconSize().height());
380 iconPixmap.fill(color);
381 d->m_iconButton->setIcon(
QIcon(iconPixmap));
384void EditPlacemarkDialog::updatePlacemarkAltitude()
390 qreal altitude = d->m_elevationWidget->elevationSpinBox->value();
392 switch (d->m_elevationUnit) {
393 case MarbleLocale::Meter:
395 case MarbleLocale::Milimeter:
398 case MarbleLocale::Kilometer:
399 altitude *= KM2METER;
401 case MarbleLocale::Centimeter:
404 case MarbleLocale::Foot:
407 case MarbleLocale::Inch:
410 case MarbleLocale::Yard:
413 case MarbleLocale::Mile:
414 altitude *= MI2KM * KM2METER;
416 case MarbleLocale::NauticalMile:
417 altitude *= NM2KM * KM2METER;
424 d->m_placemark->setCoordinate(coord);
427void EditPlacemarkDialog::restoreInitial(
int result)
429 if (isReadOnly() || result) {
433 if (d->m_placemark->name() != d->m_initialName) {
434 d->m_placemark->setName(d->m_initialName);
437 if (isIdFieldVisible() && d->m_placemark->id() != d->m_initialId) {
438 d->m_placemark->setId(d->m_initialId);
441 if (isTargetIdFieldVisible() && d->m_placemark->targetId() != d->m_initialTargetId) {
442 d->m_placemark->setTargetId(d->m_initialTargetId);
445 if (d->m_placemark->description() != d->m_initialDescription) {
446 d->m_placemark->setDescription(d->m_initialDescription);
449 if (d->m_placemark->descriptionIsCDATA() != d->m_initialDescriptionIsCDATA) {
450 d->m_placemark->setDescriptionCDATA(d->m_initialDescriptionIsCDATA);
453 if (d->m_placemark->coordinate().latitude(GeoDataCoordinates::Degree) != d->m_initialCoords.latitude(GeoDataCoordinates::Degree)
454 || d->m_placemark->coordinate().longitude(GeoDataCoordinates::Degree) != d->m_initialCoords.longitude(GeoDataCoordinates::Degree)) {
455 d->m_placemark->setCoordinate(d->m_initialCoords);
458 if (d->m_placemark->visualCategory() != d->m_initialVisualCategory) {
459 d->m_placemark->setVisualCategory(d->m_initialVisualCategory);
462 if (*d->m_placemark->style() != d->m_initialStyle) {
463 d->m_placemark->setStyle(GeoDataStyle::Ptr(
new GeoDataStyle(d->m_initialStyle)));
466 if (d->m_placemark->isVisible() != d->m_initialIsPlacemarkVisible) {
467 d->m_placemark->setVisible(d->m_initialIsPlacemarkVisible);
470 if (d->m_hadInitialOsmData) {
471 d->m_placemark->setOsmData(d->m_initialOsmData);
474 if (d->m_placemark->isBalloonVisible() != d->m_initialIsBaloonVisible) {
475 d->m_placemark->setVisible(d->m_initialIsBaloonVisible);
478 Q_EMIT textAnnotationUpdated(d->m_placemark);
483#include "moc_EditPlacemarkDialog.cpp"
A 3d point representation.
void setAltitude(const qreal altitude)
set the altitude of the Point in meters
Notation
enum used to specify the notation / numerical system
@ Decimal
"Decimal" notation (base-10)
The EditPlacemarkDialog class deals with customizing placemarks.
void setLabelColor(const QColor &color)
setLabelColor tells the dialog what the label color is
void setTargetIdFieldVisible(bool visible)
setTargetIdFieldVisible tells the dialog whether targetId field should be shown.
void setReadOnly(bool state)
Protecting data from input fields changes.
bool isIdFieldVisible() const
isIdFieldVisible tells if targetId field is shown.
void setIdFilter(const QStringList &filter)
setIdFilter sets filter for id of placemark.
void setTargetIds(const QStringList &targetIds)
setTargetIds sets ids which could be target of placemark.
bool isReadOnly() const
isReadOnly tells whether the data from input fields is protected
void updateDialogFields()
updateDialogFields is connected to a signal from AnnotatePlugin in order to update some fields in the...
bool isTargetIdFieldVisible() const
isTargetIdFieldVisible tells if targetId field is shown.
QStringList idFilter() const
idFilter gets filter for id of placemark
QStringList targetIds() const
targetIds gets ids which could be target of placemark.
void setIdFieldVisible(bool visible)
setIdFieldVisible tells the dialog whether id field should be shown.
A 3d point representation.
a class representing a point of interest on the map
an addressable style group
Category category(StandardShortcut 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.
void colorSelected(const QColor &color)
void finished(int result)
void valueChanged(double d)
bool exists(const QString &path)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)