diff --git a/src/gdal/ogr_file_format.cpp b/src/gdal/ogr_file_format.cpp index 37ac197cd..6e7fd8a83 100644 --- a/src/gdal/ogr_file_format.cpp +++ b/src/gdal/ogr_file_format.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 Kai Pastor + * Copyright 2016-2023 Kai Pastor * * This file is part of OpenOrienteering. * @@ -1166,6 +1166,7 @@ OgrFileImport::ObjectList OgrFileImport::importGeometryCollection(OGRFeatureH fe Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geometry) { + object_properties.clear(); auto style = OGR_F_GetStyleString(feature); auto symbol = getSymbol(Symbol::Point, style); if (symbol->getType() == Symbol::Point) @@ -1175,15 +1176,9 @@ Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geo return object; } - if (symbol->getType() == Symbol::Text) + if (symbol->getType() == Symbol::Text && !object_properties.isEmpty()) { - 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 = object_properties.value(QLatin1String("label")).toString(); if (label.startsWith(QLatin1Char{'{'}) && label.endsWith(QLatin1Char{'}'})) { label.remove(0, 1); @@ -1204,13 +1199,13 @@ Object* OgrFileImport::importPointGeometry(OGRFeatureH feature, OGRGeometryH geo object->setText(label); bool ok; - auto anchor = QStringRef(&description, 1, 2).toInt(&ok); + auto anchor = object_properties.value(QLatin1String("anchor"), 1).toInt(&ok); if (ok) { applyLabelAnchor(anchor, object); } - - auto angle = QStringRef(&description, 3, split-3).toDouble(&ok); + + auto angle = object_properties.value(QLatin1String("angle"), 0.0).toDouble(&ok); if (ok) { object->setRotation(qDegreesToRadians(angle)); @@ -1676,21 +1671,15 @@ TextSymbol* OgrFileImport::getSymbolForLabel(OGRStyleToolH tool, const QByteArra map->addSymbol(copy.release(), map->getNumSymbols()); } + object_properties.insert(QLatin1String("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) + object_properties.insert(QLatin1String("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) + object_properties.insert(QLatin1String("angle"), QVariant(angle)); return text_symbol; } diff --git a/src/gdal/ogr_file_format_p.h b/src/gdal/ogr_file_format_p.h index 79d797bd2..055228702 100644 --- a/src/gdal/ogr_file_format_p.h +++ b/src/gdal/ogr_file_format_p.h @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 Kai Pastor + * Copyright 2016-2023 Kai Pastor * * This file is part of OpenOrienteering. * @@ -356,6 +356,8 @@ class OgrFileImport : public Importer QHash colors; MapColor* default_pen_color; + QVariantHash object_properties; + MapCoordConstructor to_map_coord; ogr::unique_srs map_srs;