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
9 changes: 9 additions & 0 deletions src/core/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,15 @@ void Map::setOtherDirty()
setHasUnsavedChanges(true);
}


void Map::clearAuxiliarySymbolProperties()
{
for (auto* symbol : symbols)
{
symbol->clearAuxiliaryProperties();
}
}

// slot
void Map::undoCleanChanged(bool is_clean)
{
Expand Down
4 changes: 3 additions & 1 deletion src/core/map.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012-2014 Thomas Schöps
* Copyright 2013-2020, 2024 Kai Pastor
* Copyright 2013-2020, 2024, 2025 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -1375,6 +1375,8 @@ public slots:
*/
void setOtherDirty();

/** Removes all auxiliary symbol properties from all symbols. */
void clearAuxiliarySymbolProperties();

// Static

Expand Down
4 changes: 4 additions & 0 deletions src/core/objects/text_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <QtGlobal>
#include <QFontMetricsF>
#include <QMetaType>
#include <QPointF>
#include <QRectF>
#include <QString>
Expand Down Expand Up @@ -393,4 +394,7 @@ const TextObjectLineInfo*TextObject::getLineInfo(int i) const

} // namespace OpenOrienteering

Q_DECLARE_METATYPE(OpenOrienteering::TextObject::HorizontalAlignment)
Q_DECLARE_METATYPE(OpenOrienteering::TextObject::VerticalAlignment)

#endif // OPENORIENTEERING_TEXT_OBJECT_H
4 changes: 2 additions & 2 deletions src/core/symbols/symbol.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2020, 2022, 2024 Kai Pastor
* Copyright 2012-2020, 2022, 2024, 2025 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -40,7 +40,6 @@
#include <QPointF>
#include <QRectF>
#include <QStringRef>
#include <QVariant>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>

Expand Down Expand Up @@ -89,6 +88,7 @@ Symbol::Symbol(const Symbol& proto)
, is_hidden { proto.is_hidden }
, is_protected { proto.is_protected }
, is_rotatable { proto.is_rotatable }
, auxiliary_properties ( proto.auxiliary_properties )
{
// nothing else
}
Expand Down
22 changes: 22 additions & 0 deletions src/core/symbols/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QMetaType>
#include <QRgb>
#include <QString>
#include <QVariant>

class QXmlStreamReader;
class QXmlStreamWriter;
Expand Down Expand Up @@ -528,6 +529,26 @@ class Symbol
*/
virtual int getMinimumLength() const;

/**
* Sets an auxiliary property of this symbol.
*/
void setAuxiliaryProperty(int key, QVariant value) { auxiliary_properties.insert(key, value); }

/**
* Returns an auxiliary property of this symbol.
*/
QVariant getAuxiliaryProperty(int key) const { return auxiliary_properties.value(key); }

/**
* Returns an auxiliary property of this symbol or a default value.
*/
QVariant getAuxiliaryProperty(int key, QVariant default_value) const { return auxiliary_properties.value(key, default_value); }

/**
* Removes all auxiliary properties of this symbol.
*/
void clearAuxiliaryProperties() { auxiliary_properties.clear(); }

protected:
/**
* Sets the rotatability state of the symbol.
Expand Down Expand Up @@ -650,6 +671,7 @@ class Symbol
bool is_hidden; /// \see isHidden()
bool is_protected; /// \see isProtected()
bool is_rotatable = false;
QHash<int, QVariant> auxiliary_properties; /// For temporary use during import. Not to be saved on export.
};


Expand Down
29 changes: 21 additions & 8 deletions src/fileformats/ocd_file_import.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2022, 2024, 2025 Kai Pastor
* Copyright 2022, 2024-2026 Matthias Kühlewein
*
* Some parts taken from file_format_oc*d8{.h,_p.h,cpp} which are
* Copyright 2012 Pete Curtis
Expand Down Expand Up @@ -97,7 +98,18 @@ static QTextCodec* codecFromSettings()

} // namespace

namespace {

/**
* For using the auxiliary properties
*/
enum OcdFileImportProperties
{
HAlign = 0,
VAlign = 1
};

} // namespace


OcdFileImport::OcdImportedPathObject::~OcdImportedPathObject() = default;
Expand Down Expand Up @@ -330,6 +342,7 @@ void OcdFileImport::importImplementation()
importView(file);
}
}
map->clearAuxiliarySymbolProperties();

// No deep copy during import
FILEFORMAT_ASSERT(file.byteArray().constData() == buffer.constData());
Expand Down Expand Up @@ -1923,7 +1936,7 @@ Object* OcdFileImport::importObject(const O& ocd_object, MapPart* part)
auto t = new TextObject(symbol);
t->setText(getObjectText(ocd_object));
t->setRotation(convertAngle(ocd_object.angle));
t->setHorizontalAlignment(text_halign_map.value(symbol));
t->setHorizontalAlignment((symbol->getAuxiliaryProperty(OcdFileImportProperties::HAlign).value<TextObject::HorizontalAlignment>()));
// Vertical alignment is set in fillTextPathCoords().

// Text objects need special path translation
Expand Down Expand Up @@ -2251,7 +2264,7 @@ bool OcdFileImport::fillTextPathCoords(TextObject *object, TextSymbol *symbol, q
// anchor point
MapCoord coord = convertOcdPoint(ocd_points[0]);
object->setAnchorPosition(coord.nativeX(), coord.nativeY());
object->setVerticalAlignment(text_valign_map.value(symbol));
object->setVerticalAlignment((symbol->getAuxiliaryProperty(OcdFileImportProperties::VAlign).value<TextObject::VerticalAlignment>()));
}

return true;
Expand All @@ -2277,32 +2290,32 @@ void OcdFileImport::setBasicAttributes(OcdFileImport::OcdImportedTextSymbol* sym
switch (attributes.alignment & Ocd::HAlignMask)
{
case Ocd::HAlignLeft:
text_halign_map[symbol] = TextObject::AlignLeft;
symbol->setAuxiliaryProperty(OcdFileImportProperties::HAlign, QVariant(TextObject::AlignLeft));
break;
case Ocd::HAlignRight:
text_halign_map[symbol] = TextObject::AlignRight;
symbol->setAuxiliaryProperty(OcdFileImportProperties::HAlign, QVariant(TextObject::AlignRight));
break;
case Ocd::HAlignJustified:
/// \todo Implement justified alignment
addSymbolWarning(symbol, tr("Justified alignment is not supported."));
Q_FALLTHROUGH();
default:
text_halign_map[symbol] = TextObject::AlignHCenter;
symbol->setAuxiliaryProperty(OcdFileImportProperties::HAlign, QVariant(TextObject::AlignHCenter));
}

switch (attributes.alignment & Ocd::VAlignMask)
{
case Ocd::VAlignTop:
text_valign_map[symbol] = TextObject::AlignTop;
symbol->setAuxiliaryProperty(OcdFileImportProperties::VAlign, QVariant(TextObject::AlignTop));
break;
case Ocd::VAlignMiddle:
text_valign_map[symbol] = TextObject::AlignVCenter;
symbol->setAuxiliaryProperty(OcdFileImportProperties::VAlign, QVariant(TextObject::AlignVCenter));
break;
default:
addSymbolWarning(symbol, tr("Vertical alignment '%1' is not supported.").arg(attributes.alignment & Ocd::VAlignMask));
Q_FALLTHROUGH();
case Ocd::VAlignBottom:
text_valign_map[symbol] = TextObject::AlignBaseline;
symbol->setAuxiliaryProperty(OcdFileImportProperties::VAlign, QVariant(TextObject::AlignBaseline));
}

if (attributes.char_spacing != 0)
Expand Down
12 changes: 3 additions & 9 deletions src/fileformats/ocd_file_import.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 Kai Pastor
* Copyright 2013-2022, 2025 Kai Pastor
*
* Some parts taken from file_format_oc*d8{.h,_p.h,cpp} which are
* Copyright 2012 Pete Curtis
Expand Down Expand Up @@ -84,7 +84,7 @@ class OcdFileImport : public Importer
QString unnumbered_text;
};

// Helper classes that provide to core classes' protected members
// Helper classes that provide access to core classes' protected members

class OcdImportedAreaSymbol : public AreaSymbol
{
Expand Down Expand Up @@ -292,7 +292,7 @@ class OcdFileImport : public Importer
* Mapper normally generates symbol icons in the required size, but OCD
* format carries user-defined rastern icons. These imported low resolution
* icons needs to be kept and used only if they are really different from
* the default icons generatored by Mapper.
* the default icons generated by Mapper.
*/
template< class OcdBaseSymbol >
void dropRedundantIcon(Symbol* symbol, const OcdBaseSymbol& ocd_base_symbol);
Expand Down Expand Up @@ -349,12 +349,6 @@ class OcdFileImport : public Importer
/// maps OCD symbol number to oo-mapper symbol object
QHash<unsigned int, Symbol *> symbol_index;

/// maps OO Mapper text symbol pointer to OCD defined horizontal alignment (stored in objects instead of symbols in OO Mapper)
QHash<Symbol*, TextObject::HorizontalAlignment> text_halign_map;

/// maps OO Mapper text symbol pointer to OCD defined vertical alignment (stored in objects instead of symbols in OO Mapper)
QHash<Symbol*, TextObject::VerticalAlignment> text_valign_map;

/// maps OCD symbol number to rectangle information struct
QHash<int, RectangleInfo> rectangle_info;

Expand Down
51 changes: 27 additions & 24 deletions src/gdal/ogr_file_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <cstddef>
#include <functional>
#include <iterator>
#include <memory>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -608,6 +607,19 @@ namespace {

} // namespace

namespace {

/**
* For using the auxiliary properties
*/
enum OgrFileImportProperties
{
label = 0,
angle = 1,
anchor = 2
};

} // namespace


// ### OgrFileImportFormat ###
Expand Down Expand Up @@ -923,6 +935,9 @@ bool OgrFileImport::importImplementation()
.arg(tr("Not enough coordinates.")));
}

if (map)
map->clearAuxiliarySymbolProperties();

return true;
}

Expand Down Expand Up @@ -1177,15 +1192,9 @@ Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geo
return object;
}

if (symbol->getType() == Symbol::Text)
if (symbol->getType() == Symbol::Text && !symbol->getAuxiliaryProperty(OgrFileImportProperties::label).isNull())
{
const auto& description = symbol->getDescription();
auto length = description.length();
auto split = description.indexOf(QLatin1Char(' '));
FILEFORMAT_ASSERT(split > 0);
FILEFORMAT_ASSERT(split < length);

auto label = description.right(length - split - 1);
auto label = symbol->getAuxiliaryProperty(OgrFileImportProperties::label).toString();
if (label.startsWith(QLatin1Char{'{'}) && label.endsWith(QLatin1Char{'}'}))
{
label.remove(0, 1);
Expand All @@ -1206,13 +1215,13 @@ Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geo
object->setText(label);

bool ok;
auto anchor = QStringRef(&description, 1, 2).toInt(&ok);
auto anchor = symbol->getAuxiliaryProperty(OgrFileImportProperties::anchor, 1).toInt(&ok);
if (ok)
{
applyLabelAnchor(anchor, object);
}
auto angle = QStringRef(&description, 3, split-3).toDouble(&ok);

auto angle = symbol->getAuxiliaryProperty(OgrFileImportProperties::angle, 0.0).toDouble(&ok);
if (ok)
{
object->setRotation(qDegreesToRadians(angle));
Expand Down Expand Up @@ -1678,21 +1687,15 @@ TextSymbol* OgrFileImport::getSymbolForLabel(OGRStyleToolH tool, const QByteArra
map->addSymbol(copy.release(), map->getNumSymbols());
}

text_symbol->setAuxiliaryProperty(OgrFileImportProperties::label, QVariant(QString::fromUtf8(label_string)));

auto anchor = qBound(1, OGR_ST_GetParamNum(tool, OGRSTLabelAnchor, &is_null), 12);
if (is_null)
anchor = 1;
if (!is_null)
text_symbol->setAuxiliaryProperty(OgrFileImportProperties::anchor, QVariant(anchor));

auto angle = OGR_ST_GetParamDbl(tool, OGRSTLabelAngle, &is_null);
if (is_null)
angle = 0.0;

QString description;
description.reserve(int(qstrlen(label_string) + 100));
description.append(QString::number(100 + anchor));
description.append(QString::number(angle, 'g', 1));
description.append(QLatin1Char(' '));
description.append(QString::fromUtf8(label_string));
text_symbol->setDescription(description);
if (!is_null)
text_symbol->setAuxiliaryProperty(OgrFileImportProperties::angle, QVariant(angle));

return text_symbol;
}
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2012-2020 Kai Pastor
# Copyright 2012-2020, 2025 Kai Pastor
#
# This file is part of OpenOrienteering.
#
Expand Down Expand Up @@ -190,6 +190,7 @@ add_unit_test(util_t ../src/util/util
add_system_test(coord_xml_t MANUAL)

# System tests
add_system_test(dxf_t)
add_system_test(file_format_t)
add_system_test(duplicate_equals_t)
add_system_test(map_t)
Expand Down
Loading