LCOV - code coverage report
Current view: top level - src/engraving/editing - editexcerpt.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 24.4 % 78 19
Test Date: 2026-11-05 04:07:02

            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) 2025 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 "editexcerpt.h"
      24              : 
      25              : using namespace mu::engraving;
      26              : 
      27              : //---------------------------------------------------------
      28              : //   AddExcerpt
      29              : //---------------------------------------------------------
      30              : 
      31            2 : AddExcerpt::AddExcerpt(Excerpt* ex)
      32            2 :     : excerpt(ex)
      33            2 : {}
      34              : 
      35            0 : AddExcerpt::~AddExcerpt()
      36              : {
      37            0 :     if (deleteExcerpt) {
      38            0 :         delete excerpt;
      39            0 :         excerpt = nullptr;
      40              :     }
      41            0 : }
      42              : 
      43            0 : void AddExcerpt::undo()
      44              : {
      45            0 :     deleteExcerpt = true;
      46            0 :     excerpt->masterScore()->removeExcerpt(excerpt);
      47            0 : }
      48              : 
      49            2 : void AddExcerpt::redo()
      50              : {
      51            2 :     deleteExcerpt = false;
      52            2 :     excerpt->masterScore()->addExcerpt(excerpt);
      53            2 : }
      54              : 
      55            2 : std::vector<EngravingObject*> AddExcerpt::objectItems() const
      56              : {
      57            2 :     if (excerpt) {
      58            2 :         if (MasterScore* score = excerpt->masterScore()) {
      59            6 :             return { score };
      60              :         }
      61              :     }
      62              : 
      63            0 :     return {};
      64              : }
      65              : 
      66              : //---------------------------------------------------------
      67              : //   RemoveExcerpt
      68              : //---------------------------------------------------------
      69              : 
      70            2 : RemoveExcerpt::RemoveExcerpt(Excerpt* ex)
      71            2 :     : excerpt(ex)
      72              : {
      73            2 :     index = muse::indexOf(excerpt->masterScore()->excerpts(), excerpt);
      74            2 : }
      75              : 
      76            0 : RemoveExcerpt::~RemoveExcerpt()
      77              : {
      78            0 :     if (deleteExcerpt) {
      79            0 :         delete excerpt;
      80            0 :         excerpt = nullptr;
      81              :     }
      82            0 : }
      83              : 
      84            0 : void RemoveExcerpt::undo()
      85              : {
      86            0 :     deleteExcerpt = false;
      87            0 :     excerpt->masterScore()->addExcerpt(excerpt, index);
      88            0 : }
      89              : 
      90            2 : void RemoveExcerpt::redo()
      91              : {
      92            2 :     deleteExcerpt = true;
      93            2 :     excerpt->masterScore()->removeExcerpt(excerpt);
      94            2 : }
      95              : 
      96            0 : std::vector<EngravingObject*> RemoveExcerpt::objectItems() const
      97              : {
      98            0 :     if (excerpt) {
      99            0 :         if (MasterScore* score = excerpt->masterScore()) {
     100            0 :             return { score };
     101              :         }
     102              :     }
     103              : 
     104            0 :     return {};
     105              : }
     106              : 
     107              : //---------------------------------------------------------
     108              : //   SwapExcerpt
     109              : //---------------------------------------------------------
     110              : 
     111            0 : void SwapExcerpt::flip()
     112              : {
     113            0 :     Excerpt* tmp = score->excerpts().at(pos1);
     114            0 :     score->excerpts()[pos1] = score->excerpts().at(pos2);
     115            0 :     score->excerpts()[pos2] = tmp;
     116            0 :     score->setExcerptsChanged(true);
     117            0 : }
     118              : 
     119              : //---------------------------------------------------------
     120              : //   ChangeExcerptTitle
     121              : //---------------------------------------------------------
     122              : 
     123            0 : void ChangeExcerptTitle::flip()
     124              : {
     125            0 :     String s = title;
     126            0 :     title = excerpt->name();
     127            0 :     excerpt->setName(s);
     128            0 :     excerpt->masterScore()->setExcerptsChanged(true);
     129            0 : }
     130              : 
     131              : //---------------------------------------------------------
     132              : //   AddPartToExcerpt
     133              : //---------------------------------------------------------
     134              : 
     135            0 : AddPartToExcerpt::AddPartToExcerpt(Excerpt* e, Part* p, size_t targetPartIdx)
     136            0 :     : m_excerpt(e), m_part(p), m_targetPartIdx(targetPartIdx)
     137              : {
     138            0 :     assert(m_excerpt);
     139            0 :     assert(m_part);
     140            0 : }
     141              : 
     142            0 : void AddPartToExcerpt::undo()
     143              : {
     144            0 :     muse::remove(m_excerpt->parts(), m_part);
     145              : 
     146            0 :     if (Score* score = m_excerpt->excerptScore()) {
     147            0 :         score->removePart(m_part);
     148              :     }
     149            0 : }
     150              : 
     151            0 : void AddPartToExcerpt::redo()
     152              : {
     153            0 :     std::vector<Part*>& excerptParts = m_excerpt->parts();
     154            0 :     if (m_targetPartIdx < excerptParts.size()) {
     155            0 :         excerptParts.insert(excerptParts.begin() + m_targetPartIdx, m_part);
     156              :     } else {
     157            0 :         excerptParts.push_back(m_part);
     158              :     }
     159              : 
     160            0 :     if (Score* score = m_excerpt->excerptScore()) {
     161            0 :         score->insertPart(m_part, m_targetPartIdx);
     162              :     }
     163            0 : }
     164              : 
     165            0 : void AddPartToExcerpt::cleanup(bool wasDone)
     166              : {
     167            0 :     if (!wasDone) {
     168            0 :         delete m_part;
     169            0 :         m_part = nullptr;
     170              :     }
     171            0 : }
        

Generated by: LCOV version 2.0-1