diff --git a/src/gui/widgets/template_list_widget.cpp b/src/gui/widgets/template_list_widget.cpp index 5b562c46b..92aebaecc 100644 --- a/src/gui/widgets/template_list_widget.cpp +++ b/src/gui/widgets/template_list_widget.cpp @@ -1,6 +1,6 @@ /* * Copyright 2012, 2013 Thomas Schöps - * Copyright 2012-2020 Kai Pastor + * Copyright 2012-2020, 2025 Kai Pastor * * This file is part of OpenOrienteering. * @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -282,6 +283,9 @@ TemplateListWidget::TemplateListWidget(Map& map, MapView& main_view, MapEditorCo position_action = edit_menu->addAction(tr("Positioning...")); position_action->setCheckable(true); edit_menu->addSeparator(); + custom_name_action = edit_menu->addAction(tr("Enter custom name..."), this, &TemplateListWidget::enterCustomname); + show_name_action = edit_menu->addAction(tr("Show filename"), this, &TemplateListWidget::showCustomOrFilename); + edit_menu->addSeparator(); import_action = edit_menu->addAction(tr("Import and remove"), this, &TemplateListWidget::importClicked); #if WITH_COVE @@ -490,6 +494,9 @@ void TemplateListWidget::updateButtons() vectorize_enabled = qobject_cast(temp) && temp->getTemplateState() == Template::Loaded; } + show_name_action->setText(temp->getCustomnamePreference() ? tr("Show filename") : tr("Show custom name")); + show_name_action->setVisible(!temp->getTemplateCustomname().isEmpty()); + } else if (current_row >= 0) { @@ -1042,5 +1049,36 @@ void TemplateListWidget::showOpacitySlider(int row) dialog.exec(); } +void TemplateListWidget::enterCustomname() +{ + auto* templ = currentTemplate(); + if (templ) + { + bool ok; + const auto previous_customname = templ->getTemplateCustomname(); + const auto text = QInputDialog::getText(this, tr("Enter custom name"), tr("Custom name:"), QLineEdit::Normal, previous_customname, &ok); + if (ok) + { + templ->setTemplateCustomname(text); + templ->setCustomnamePreference(!text.isEmpty()); + if (previous_customname != text) + { + map.setTemplatesDirty(); // only mark as dirty if custom name has changed + updateButtons(); + } + } + } +} + +void TemplateListWidget::showCustomOrFilename() +{ + auto* templ = currentTemplate(); + if (templ) + { + templ->setCustomnamePreference(!templ->getCustomnamePreference()); // don't mark as dirty + updateButtons(); + } +} + } // namespace OpenOrienteering diff --git a/src/gui/widgets/template_list_widget.h b/src/gui/widgets/template_list_widget.h index 85505d44d..009ec8d94 100644 --- a/src/gui/widgets/template_list_widget.h +++ b/src/gui/widgets/template_list_widget.h @@ -1,6 +1,6 @@ /* * Copyright 2012, 2013 Thomas Schöps - * Copyright 2020 Kai Pastor + * Copyright 2020, 2025 Kai Pastor * * This file is part of OpenOrienteering. * @@ -142,6 +142,9 @@ class TemplateListWidget : public QWidget void showOpacitySlider(int row); + void enterCustomname(); + void showCustomOrFilename(); + private: Map& map; MapView& main_view; @@ -159,6 +162,8 @@ class TemplateListWidget : public QWidget QAction* duplicate_action; QAction* move_by_hand_action; QAction* position_action; + QAction* custom_name_action; + QAction* show_name_action; QAction* import_action; QAction* georef_action; QAction* vectorize_action; @@ -179,4 +184,4 @@ class TemplateListWidget : public QWidget } // namespace OpenOrienteering -#endif +#endif // OPENORIENTEERING_TEMPLATE_LIST_WIDGET_H diff --git a/src/templates/template.cpp b/src/templates/template.cpp index cbb74f776..69d910fc7 100644 --- a/src/templates/template.cpp +++ b/src/templates/template.cpp @@ -290,6 +290,11 @@ void Template::saveTemplateConfiguration(QXmlStreamWriter& xml, bool open, const primary_path = relative_path; xml.writeAttribute(QString::fromLatin1("path"), primary_path); xml.writeAttribute(QString::fromLatin1("relpath"), relative_path); + if (!template_custom_name.isEmpty()) + { + xml.writeAttribute(QString::fromLatin1("customname"), getTemplateCustomname()); + xml.writeAttribute(QString::fromLatin1("custompref"), QString::fromLatin1(getCustomnamePreference() ? "true" : "false")); + } if (template_group) { @@ -349,6 +354,11 @@ std::unique_ptr