Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "palettetree.h"
24 :
25 : #include <QBuffer>
26 :
27 : #include "engraving/rw/xmlreader.h"
28 : #include "engraving/rw/xmlwriter.h"
29 :
30 : using namespace mu::palette;
31 :
32 0 : void PaletteTree::insert(size_t idx, PalettePtr palette)
33 : {
34 0 : palettes.emplace(palettes.begin() + idx, palette);
35 0 : }
36 :
37 0 : void PaletteTree::append(PalettePtr palette)
38 : {
39 0 : palettes.emplace_back(palette);
40 0 : }
41 :
42 0 : bool PaletteTree::read(mu::engraving::XmlReader& e, bool pasteMode, const muse::modularity::ContextPtr& iocCtx)
43 : {
44 0 : while (e.readNextStartElement()) {
45 0 : const muse::AsciiStringView tag(e.name());
46 0 : if (tag == "Palette") {
47 0 : PalettePtr p = std::make_shared<Palette>(iocCtx);
48 0 : p->read(e, pasteMode);
49 0 : palettes.push_back(p);
50 0 : } else {
51 0 : e.unknown();
52 : }
53 : }
54 :
55 0 : return true;
56 : }
57 :
58 0 : void PaletteTree::write(mu::engraving::XmlWriter& xml, bool pasteMode) const
59 : {
60 0 : xml.startElement("PaletteBox", { { "version", engraving::Constants::MSC_VERSION_STR } }); // for compatibility with old palettes file format
61 :
62 0 : for (const PalettePtr& palette : palettes) {
63 0 : palette->write(xml, pasteMode);
64 : }
65 :
66 0 : xml.endElement();
67 0 : }
68 :
69 0 : void PaletteTree::retranslate()
70 : {
71 0 : for (const PalettePtr& palette : palettes) {
72 0 : palette->retranslate();
73 : }
74 0 : }
|