diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2024-03-01 22:11:14 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-03-04 11:50:45 +0100 |
commit | 04c73e27491feaf21e0a2c9288aee5a9f9850386 (patch) | |
tree | a289cb1ca4a23205192486313f1e16c5c9b89673 /svx | |
parent | cf4df3e51b609613134e3146f526d8e6b07946c3 (diff) |
cool#8327 use tools::JsonWriter for theme colors
Change-Id: Iebca3781910f9e28100258da8266d51f673f31d8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164232
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 20 | ||||
-rw-r--r-- | svx/source/theme/ThemeColorChangerCommon.cxx | 8 | ||||
-rw-r--r-- | svx/source/theme/ThemeColorPaletteManager.cxx | 21 |
3 files changed, 19 insertions, 30 deletions
diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index e4fd8b2d1fa2..fda9803c9d03 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -21,6 +21,7 @@ #include <comphelper/propertyvalue.hxx> #include <tools/urlobj.hxx> +#include <tools/json_writer.hxx> #include <osl/file.hxx> #include <unotools/pathoptions.hxx> #include <sfx2/objsh.hxx> @@ -467,9 +468,9 @@ void PaletteManager::DispatchColorCommand(const OUString& aCommand, const NamedC } // TODO: make it generic, send any palette -void PaletteManager::generateJSON(boost::property_tree::ptree& aTree, const std::set<Color>& rColors) +void PaletteManager::generateJSON(tools::JsonWriter& aTree, const std::set<Color>& rColors) { - boost::property_tree::ptree aColorListTree; + auto aColorListTree = aTree.startArray("DocumentColors"); sal_uInt32 nStartIndex = 1; const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); @@ -479,26 +480,21 @@ void PaletteManager::generateJSON(boost::property_tree::ptree& aTree, const std: auto aColorIt = rColors.begin(); while (aColorIt != rColors.end()) { - boost::property_tree::ptree aColorRowTree; + auto aColorRowTree = aTree.startStruct(); + auto aColorRowTree2 = aTree.startArray(""); for (sal_uInt32 nColumn = 0; nColumn < nColumnCount; nColumn++) { - boost::property_tree::ptree aColorTree; + auto aColorTree = aTree.startStruct(); OUString sName = aNamePrefix + OUString::number(nStartIndex++); - aColorTree.put("Value", aColorIt->AsRGBHexString().toUtf8()); - aColorTree.put("Name", sName); - - aColorRowTree.push_back(std::make_pair("", aColorTree)); + aTree.put("Value", aColorIt->AsRGBHexString().toUtf8()); + aTree.put("Name", sName); aColorIt++; if (aColorIt == rColors.end()) break; } - - aColorListTree.push_back(std::make_pair("", aColorRowTree)); } - - aTree.add_child("DocumentColors", aColorListTree); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/theme/ThemeColorChangerCommon.cxx b/svx/source/theme/ThemeColorChangerCommon.cxx index 120a6bea03d9..39a20bd3441f 100644 --- a/svx/source/theme/ThemeColorChangerCommon.cxx +++ b/svx/source/theme/ThemeColorChangerCommon.cxx @@ -31,6 +31,7 @@ #include <svx/xdef.hxx> #include <svx/xlnclit.hxx> #include <svx/xflclit.hxx> +#include <tools/json_writer.hxx> using namespace css; @@ -176,17 +177,14 @@ void notifyLOK(std::shared_ptr<model::ColorSet> const& pColorSet, if (comphelper::LibreOfficeKit::isActive()) { svx::ThemeColorPaletteManager aManager(pColorSet); - std::stringstream aStream; - boost::property_tree::ptree aTree; + tools::JsonWriter aTree; if (pColorSet) aManager.generateJSON(aTree); if (rDocumentColors.size()) PaletteManager::generateJSON(aTree, rDocumentColors); - boost::property_tree::write_json(aStream, aTree); - - SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, OString(aStream.str())); + SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, aTree.finishAndGetAsOString()); } } diff --git a/svx/source/theme/ThemeColorPaletteManager.cxx b/svx/source/theme/ThemeColorPaletteManager.cxx index 4ba2ddfe8312..ae2fe2f0bdfd 100644 --- a/svx/source/theme/ThemeColorPaletteManager.cxx +++ b/svx/source/theme/ThemeColorPaletteManager.cxx @@ -15,6 +15,7 @@ #include <svx/strings.hrc> #include <docmodel/theme/ColorSet.hxx> #include <docmodel/color/ComplexColorJSON.hxx> +#include <tools/json_writer.hxx> #include <array> @@ -125,23 +126,22 @@ svx::ThemePaletteCollection ThemeColorPaletteManager::generate() return aThemePaletteCollection; } -void ThemeColorPaletteManager::generateJSON(boost::property_tree::ptree& aTree) +void ThemeColorPaletteManager::generateJSON(tools::JsonWriter& aTree) { svx::ThemePaletteCollection aThemePaletteCollection = generate(); - boost::property_tree::ptree aColorListTree; + auto aColorListTree = aTree.startArray("ThemeColors"); for (size_t nEffect = 0; nEffect < 6; ++nEffect) { - boost::property_tree::ptree aColorRowTree; + auto aColorRowTree = aTree.startStruct(); for (size_t nIndex = 0; nIndex < 12; ++nIndex) { auto const& rColorData = aThemePaletteCollection.maColors[nIndex]; auto const& rEffectData = rColorData.maEffects[nEffect]; - boost::property_tree::ptree aColorTree; - aColorTree.put("Value", rEffectData.maColor.AsRGBHexString().toUtf8()); - aColorTree.put("Name", rEffectData.maColorName.toUtf8()); + aTree.put("Value", rEffectData.maColor.AsRGBHexString().toUtf8()); + aTree.put("Name", rEffectData.maColorName.toUtf8()); model::ComplexColor aComplexColor; aComplexColor.setThemeColor(rColorData.meThemeColorType); @@ -149,15 +149,10 @@ void ThemeColorPaletteManager::generateJSON(boost::property_tree::ptree& aTree) { model::TransformationType::LumMod, rEffectData.mnLumMod }); aComplexColor.addTransformation( { model::TransformationType::LumOff, rEffectData.mnLumOff }); - boost::property_tree::ptree aDataTree; - model::color::convertToJSONTree(aDataTree, aComplexColor); - aColorTree.add_child("Data", aDataTree); - aColorRowTree.push_back(std::make_pair("", aColorTree)); + auto aDataTree = aTree.startNode("Data"); + model::color::convertToJSONTree(aTree, aComplexColor); } - aColorListTree.push_back(std::make_pair("", aColorRowTree)); } - - aTree.add_child("ThemeColors", aColorListTree); } } // end svx namespace |