From 4a7a89b97b0b6464f8375926d98044634d06b4ee Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Tue, 7 Feb 2023 16:13:27 +0900 Subject: create a default theme when SdrPage and SdrModel are created MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For a document it is expected that it always has a theme available so we need to create a theme with some default attributes set (a default color scheme for now) when we create a SdrModel and SdrPage (only for Writer currently). This also changes some ColorSets, SdrPage, SdrModel methods, to use better return types (cost& instead of raw pointers and vice versa depending on the use case). Change-Id: I874247784b845109e42567e3f45647dda46ccf3b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146816 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- svx/source/styles/ColorSets.cxx | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'svx/source/styles') diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index 145babb7d98d..438a9a36b01c 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -19,10 +19,18 @@ namespace svx { ColorSets::ColorSets() -{} +{ + init(); +} + +ColorSets& ColorSets::get() +{ + static std::optional sColorSet; + if (!sColorSet) + sColorSet = ColorSets(); + return *sColorSet; +} -ColorSets::~ColorSets() -{} void ColorSets::init() { @@ -140,19 +148,29 @@ void ColorSets::init() } } -const model::ColorSet& ColorSets::getColorSet(std::u16string_view rName) +model::ColorSet const* ColorSets::getColorSet(std::u16string_view rName) const { for (const model::ColorSet & rColorSet : maColorSets) { if (rColorSet.getName() == rName) - return rColorSet; + return &rColorSet; } - return maColorSets[0]; + return nullptr; } -void ColorSets::insert(model::ColorSet const& rColorSet) +void ColorSets::insert(model::ColorSet const& rNewColorSet) { - maColorSets.push_back(rColorSet); + for (model::ColorSet& rColorSet : maColorSets) + { + if (rColorSet.getName() == rNewColorSet.getName()) + { + rColorSet = rNewColorSet; + return; + } + } + + // color set not found, so insert it + maColorSets.push_back(rNewColorSet); } } // end of namespace svx -- cgit