Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/gui/widgets/template_list_widget.cpp
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -49,6 +49,7 @@
#include <QLabel>
#include <QLatin1Char>
#include <QLatin1String>
#include <QLineEdit>
#include <QList>
#include <QLocale>
#include <QMenu>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -490,6 +494,9 @@ void TemplateListWidget::updateButtons()
vectorize_enabled = qobject_cast<TemplateImage*>(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)
{
Expand Down Expand Up @@ -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
9 changes: 7 additions & 2 deletions src/gui/widgets/template_list_widget.h
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -142,6 +142,9 @@ class TemplateListWidget : public QWidget

void showOpacitySlider(int row);

void enterCustomname();
void showCustomOrFilename();

private:
Map& map;
MapView& main_view;
Expand All @@ -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;
Expand All @@ -179,4 +184,4 @@ class TemplateListWidget : public QWidget

} // namespace OpenOrienteering

#endif
#endif // OPENORIENTEERING_TEMPLATE_LIST_WIDGET_H
10 changes: 10 additions & 0 deletions src/templates/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -349,6 +354,11 @@ std::unique_ptr<Template> Template::loadTemplateConfiguration(QXmlStreamReader&
temp->setTemplateRelativePath(attributes.value(QLatin1String("relpath")).toString());
if (attributes.hasAttribute(QLatin1String("name")))
temp->template_file = attributes.value(QLatin1String("name")).toString();
if (attributes.hasAttribute(QLatin1String("customname")))
{
temp->template_custom_name = attributes.value(QLatin1String("customname")).toString();
temp->custom_name_preference = (attributes.value(QLatin1String("custompref")) == QLatin1String("true"));
}
temp->is_georeferenced = (attributes.value(QLatin1String("georef")) == QLatin1String("true"));
if (attributes.hasAttribute(QLatin1String("group")))
temp->template_group = attributes.value(QLatin1String("group")).toInt();
Expand Down
16 changes: 14 additions & 2 deletions src/templates/template.h
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -530,6 +530,12 @@ Q_OBJECT

inline const QString& getTemplateFilename() const {return template_file;}

inline const QString& getTemplateCustomname() const {return template_custom_name;}
inline void setTemplateCustomname(const QString& template_custom_name) {this->template_custom_name = template_custom_name;}

inline bool getCustomnamePreference() const {return custom_name_preference;}
inline void setCustomnamePreference(bool custom_name_preference) {this->custom_name_preference = custom_name_preference;}

/// Changes the path and filename only. Does not do any reloading etc.
void setTemplateFileInfo(const QFileInfo& file_info);

Expand Down Expand Up @@ -753,6 +759,12 @@ Q_OBJECT
/// Can be empty as long as the map file has not been saved yet.
QString template_relative_path;

/// The custom name of the template set by the user
QString template_custom_name;

/// User preference to show custom name instead of filename
bool custom_name_preference = false;

/// The template lifetime state
State template_state = Configuring;

Expand Down Expand Up @@ -811,4 +823,4 @@ Q_OBJECT
Q_DECLARE_OPERATORS_FOR_FLAGS(OpenOrienteering::Template::ScribbleOptions)


#endif
#endif // OPENORIENTEERING_TEMPLATE_H
8 changes: 4 additions & 4 deletions src/templates/template_table_model.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Kai Pastor
* Copyright 2020, 2025 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -176,7 +176,7 @@ QVariant TemplateTableModel::headerData(int section, Qt::Orientation orientation
break;
case nameColumn():
if (role == Qt::DisplayRole)
return QCoreApplication::translate("OpenOrienteering::TemplateListWidget", "Filename");
return QCoreApplication::translate("OpenOrienteering::TemplateListWidget", "Filename / Custom name");
break;
}
}
Expand Down Expand Up @@ -309,14 +309,14 @@ QVariant TemplateTableModel::templateData(Template* temp, const QModelIndex &ind
break;
Q_FALLTHROUGH();
case combined(nameColumn(), Qt::DisplayRole):
return temp->getTemplateFilename();
return temp->getCustomnamePreference() ? temp->getTemplateCustomname() : temp->getTemplateFilename();

case combined(visibilityColumn(), Qt::ToolTipRole):
if (!touchMode())
break;
Q_FALLTHROUGH();
case combined(nameColumn(), Qt::ToolTipRole):
return temp->getTemplatePath();
return temp->getCustomnamePreference() ? temp->getTemplatePath() : temp->getTemplateCustomname();
}

if (role == Qt::UserRole)
Expand Down