tdf#165742 Step 5.9e: Store enumerated geography parameters as enums
The projection type and region type are described in the OOXML spec as enumerated values. Store them internally as such, converting from string on input and to string on output. Change-Id: I5ee9b6996362bf8cc8db28fc921f3b95bfb7ff46 Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2065 Tested-by: Jenkins CPCI <releng@collaboraoffice.com> Reviewed-by: Tomaž Vajngerl <tomaz.vajngerl@collabora.com> (cherry picked from commit 00cb914655c1250656f81eed96ffd9df198387fb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204761 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
committed by
Xisco Fauli
parent
1612b95a6b
commit
8bf5b36ce1
@@ -150,13 +150,13 @@ void DataSeriesProperties::AddPropertiesToVector(
|
||||
|
||||
rOutProperties.emplace_back( "GeographyProjectionType",
|
||||
PROP_DATASERIES_GEOGRAPHY_PROJECTION_TYPE,
|
||||
cppu::UnoType<OUString>::get(),
|
||||
cppu::UnoType<sal_Int32>::get(), // Actually enum GeoProjectionType
|
||||
beans::PropertyAttribute::BOUND
|
||||
| beans::PropertyAttribute::MAYBEVOID );
|
||||
|
||||
rOutProperties.emplace_back( "GeographyViewedRegionType",
|
||||
PROP_DATASERIES_GEOGRAPHY_VIEWED_REGION_TYPE,
|
||||
cppu::UnoType<OUString>::get(),
|
||||
cppu::UnoType<sal_Int32>::get(), // Actually enum GeoMappingLevel
|
||||
beans::PropertyAttribute::BOUND
|
||||
| beans::PropertyAttribute::MAYBEVOID );
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
|
||||
oox/source/drawingml/chart/datatablecontext \
|
||||
oox/source/drawingml/chart/geographycontext \
|
||||
oox/source/drawingml/chart/geographyconverter \
|
||||
oox/source/drawingml/chart/geographymodel \
|
||||
oox/source/drawingml/chart/datatableconverter \
|
||||
oox/source/drawingml/chart/modelbase \
|
||||
oox/source/drawingml/chart/objectformatter \
|
||||
|
||||
@@ -12,9 +12,37 @@
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <rtl/ustring.hxx>
|
||||
#include <sal/types.h>
|
||||
|
||||
namespace oox::drawingml::chart
|
||||
{
|
||||
// ST_GeoProjectionType
|
||||
enum class GeoProjectionType : sal_Int32
|
||||
{
|
||||
Mercator,
|
||||
Miller,
|
||||
Robinson,
|
||||
Albers,
|
||||
};
|
||||
|
||||
// ST_GeoMappingLevel
|
||||
enum class GeoMappingLevel : sal_Int32
|
||||
{
|
||||
DataOnly,
|
||||
PostalCode,
|
||||
County,
|
||||
State,
|
||||
CountryRegion,
|
||||
CountryRegionList,
|
||||
World,
|
||||
Autodetect,
|
||||
};
|
||||
|
||||
GeoProjectionType geoProjectionTypeFromString(std::u16string_view rStr);
|
||||
OUString geoProjectionTypeToString(GeoProjectionType eType);
|
||||
|
||||
GeoMappingLevel geoMappingLevelFromString(std::u16string_view rStr);
|
||||
OUString geoMappingLevelToString(GeoMappingLevel eLevel);
|
||||
struct GeoAddressModel
|
||||
{
|
||||
std::optional<OUString> mosAddress1;
|
||||
@@ -165,8 +193,8 @@ struct GeoCacheModel
|
||||
|
||||
struct GeographyModel
|
||||
{
|
||||
std::optional<OUString> mosProjectionType;
|
||||
std::optional<OUString> mosViewedRegionType;
|
||||
std::optional<GeoProjectionType> moeProjectionType;
|
||||
std::optional<GeoMappingLevel> moeViewedRegionType;
|
||||
std::optional<OUString> mosCultureLanguage;
|
||||
std::optional<OUString> mosCultureRegion;
|
||||
std::optional<OUString> mosAttribution;
|
||||
|
||||
@@ -761,10 +761,12 @@ GeoClearModel geoClearFromPropertyValues(const uno::Sequence<beans::PropertyValu
|
||||
|
||||
void convertGeography(const GeographyModel& rModel, PropertySet& rSeriesProp)
|
||||
{
|
||||
if (rModel.mosProjectionType.has_value())
|
||||
rSeriesProp.setProperty(PROP_GeographyProjectionType, *rModel.mosProjectionType);
|
||||
if (rModel.mosViewedRegionType.has_value())
|
||||
rSeriesProp.setProperty(PROP_GeographyViewedRegionType, *rModel.mosViewedRegionType);
|
||||
if (rModel.moeProjectionType.has_value())
|
||||
rSeriesProp.setProperty(PROP_GeographyProjectionType,
|
||||
static_cast<sal_Int32>(*rModel.moeProjectionType));
|
||||
if (rModel.moeViewedRegionType.has_value())
|
||||
rSeriesProp.setProperty(PROP_GeographyViewedRegionType,
|
||||
static_cast<sal_Int32>(*rModel.moeViewedRegionType));
|
||||
if (rModel.mosCultureLanguage.has_value())
|
||||
rSeriesProp.setProperty(PROP_GeographyCultureLanguage, *rModel.mosCultureLanguage);
|
||||
if (rModel.mosCultureRegion.has_value())
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <drawingml/chart/geographymodel.hxx>
|
||||
|
||||
namespace oox::drawingml::chart
|
||||
{
|
||||
GeoProjectionType geoProjectionTypeFromString(std::u16string_view rStr)
|
||||
{
|
||||
if (rStr == u"miller")
|
||||
return GeoProjectionType::Miller;
|
||||
if (rStr == u"robinson")
|
||||
return GeoProjectionType::Robinson;
|
||||
if (rStr == u"albers")
|
||||
return GeoProjectionType::Albers;
|
||||
return GeoProjectionType::Mercator;
|
||||
}
|
||||
|
||||
OUString geoProjectionTypeToString(GeoProjectionType eType)
|
||||
{
|
||||
switch (eType)
|
||||
{
|
||||
case GeoProjectionType::Miller:
|
||||
return u"miller"_ustr;
|
||||
case GeoProjectionType::Robinson:
|
||||
return u"robinson"_ustr;
|
||||
case GeoProjectionType::Albers:
|
||||
return u"albers"_ustr;
|
||||
case GeoProjectionType::Mercator:
|
||||
return u"mercator"_ustr;
|
||||
}
|
||||
return u"mercator"_ustr;
|
||||
}
|
||||
|
||||
GeoMappingLevel geoMappingLevelFromString(std::u16string_view rStr)
|
||||
{
|
||||
if (rStr == u"postalCode")
|
||||
return GeoMappingLevel::PostalCode;
|
||||
if (rStr == u"county")
|
||||
return GeoMappingLevel::County;
|
||||
if (rStr == u"state")
|
||||
return GeoMappingLevel::State;
|
||||
if (rStr == u"countryRegion")
|
||||
return GeoMappingLevel::CountryRegion;
|
||||
if (rStr == u"countryRegionList")
|
||||
return GeoMappingLevel::CountryRegionList;
|
||||
if (rStr == u"world")
|
||||
return GeoMappingLevel::World;
|
||||
if (rStr == u"autodetect")
|
||||
return GeoMappingLevel::Autodetect;
|
||||
return GeoMappingLevel::DataOnly;
|
||||
}
|
||||
|
||||
OUString geoMappingLevelToString(GeoMappingLevel eLevel)
|
||||
{
|
||||
switch (eLevel)
|
||||
{
|
||||
case GeoMappingLevel::PostalCode:
|
||||
return u"postalCode"_ustr;
|
||||
case GeoMappingLevel::County:
|
||||
return u"county"_ustr;
|
||||
case GeoMappingLevel::State:
|
||||
return u"state"_ustr;
|
||||
case GeoMappingLevel::CountryRegion:
|
||||
return u"countryRegion"_ustr;
|
||||
case GeoMappingLevel::CountryRegionList:
|
||||
return u"countryRegionList"_ustr;
|
||||
case GeoMappingLevel::World:
|
||||
return u"world"_ustr;
|
||||
case GeoMappingLevel::Autodetect:
|
||||
return u"autodetect"_ustr;
|
||||
case GeoMappingLevel::DataOnly:
|
||||
return u"dataOnly"_ustr;
|
||||
}
|
||||
return u"dataOnly"_ustr;
|
||||
}
|
||||
|
||||
} // namespace oox::drawingml::chart
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -863,8 +863,12 @@ ContextHandlerRef LayoutPropsContext::onCreateContext( sal_Int32 nElement, const
|
||||
case CX_TOKEN( geography ):
|
||||
{
|
||||
auto& rGeo = mrModel.mxGeography.emplace();
|
||||
rGeo.mosProjectionType = rAttribs.getString( XML_projectionType );
|
||||
rGeo.mosViewedRegionType = rAttribs.getString( XML_viewedRegionType );
|
||||
std::optional<OUString> sPT = rAttribs.getString( XML_projectionType );
|
||||
if (sPT.has_value())
|
||||
rGeo.moeProjectionType = geoProjectionTypeFromString( *sPT );
|
||||
std::optional<OUString> sVR = rAttribs.getString( XML_viewedRegionType );
|
||||
if (sVR.has_value())
|
||||
rGeo.moeViewedRegionType = geoMappingLevelFromString( *sVR );
|
||||
rGeo.mosCultureLanguage = rAttribs.getString( XML_cultureLanguage );
|
||||
rGeo.mosCultureRegion = rAttribs.getString( XML_cultureRegion );
|
||||
rGeo.mosAttribution = rAttribs.getString( XML_attribution );
|
||||
|
||||
@@ -268,25 +268,32 @@ void exportGeography(const uno::Reference<beans::XPropertySet>& xSeriesProp,
|
||||
if (!xSeriesProp.is())
|
||||
return;
|
||||
|
||||
OUString sProjectionType, sViewedRegionType, sCultureLanguage, sCultureRegion, sAttribution;
|
||||
sal_Int32 nProjType = 0, nViewedRegion = 0;
|
||||
OUString sCultureLanguage, sCultureRegion, sAttribution;
|
||||
uno::Any aPT = xSeriesProp->getPropertyValue(u"GeographyProjectionType"_ustr);
|
||||
uno::Any aVR = xSeriesProp->getPropertyValue(u"GeographyViewedRegionType"_ustr);
|
||||
uno::Any aCL = xSeriesProp->getPropertyValue(u"GeographyCultureLanguage"_ustr);
|
||||
uno::Any aCR = xSeriesProp->getPropertyValue(u"GeographyCultureRegion"_ustr);
|
||||
uno::Any aAT = xSeriesProp->getPropertyValue(u"GeographyAttribution"_ustr);
|
||||
|
||||
bool bHasPT = (aPT >>= sProjectionType);
|
||||
bool bHasVR = (aVR >>= sViewedRegionType);
|
||||
bool bHasPT = (aPT >>= nProjType);
|
||||
bool bHasVR = (aVR >>= nViewedRegion);
|
||||
bool bHasCL = (aCL >>= sCultureLanguage);
|
||||
bool bHasCR = (aCR >>= sCultureRegion);
|
||||
bool bHasAT = (aAT >>= sAttribution);
|
||||
|
||||
OUString sProjStr, sViewedStr;
|
||||
if (bHasPT)
|
||||
sProjStr = geoProjectionTypeToString(static_cast<GeoProjectionType>(nProjType));
|
||||
if (bHasVR)
|
||||
sViewedStr = geoMappingLevelToString(static_cast<GeoMappingLevel>(nViewedRegion));
|
||||
|
||||
if (!bHasPT && !bHasVR && !bHasCL && !bHasCR && !bHasAT)
|
||||
return;
|
||||
|
||||
pFS->startElement(FSNS(XML_cx, XML_geography), XML_projectionType,
|
||||
bHasPT ? sProjectionType.toUtf8().getStr() : nullptr, XML_viewedRegionType,
|
||||
bHasVR ? sViewedRegionType.toUtf8().getStr() : nullptr, XML_cultureLanguage,
|
||||
bHasPT ? sProjStr.toUtf8().getStr() : nullptr, XML_viewedRegionType,
|
||||
bHasVR ? sViewedStr.toUtf8().getStr() : nullptr, XML_cultureLanguage,
|
||||
bHasCL ? sCultureLanguage.toUtf8().getStr() : nullptr, XML_cultureRegion,
|
||||
bHasCR ? sCultureRegion.toUtf8().getStr() : nullptr, XML_attribution,
|
||||
bHasAT ? sAttribution.toUtf8().getStr() : nullptr);
|
||||
|
||||
Reference in New Issue
Block a user