summaryrefslogtreecommitdiff
path: root/svx/source/styles
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-02-07 16:13:27 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-03-01 00:29:23 +0000
commit4a7a89b97b0b6464f8375926d98044634d06b4ee (patch)
tree669bc858797ac675acebd6ee526dd5ef9213df9e /svx/source/styles
parent1309e6332d7ff2bd1f9b6bf87385b8b570e59158 (diff)
create a default theme when SdrPage and SdrModel are created
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 <quikee@gmail.com>
Diffstat (limited to 'svx/source/styles')
-rw-r--r--svx/source/styles/ColorSets.cxx34
1 files changed, 26 insertions, 8 deletions
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<ColorSets> 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