LCOV - code coverage report
Current view: top level - src/engraving/editing - editmeasures.h Coverage Total Hit
Test: filtered_coverage.info Lines: 81.8 % 44 36
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              : #pragma once
      24              : 
      25              : #include "transaction/undoablecommand.h"
      26              : 
      27              : #include "../dom/measure.h"
      28              : 
      29              : namespace mu::engraving {
      30              : class InsertRemoveMeasures : public UndoableCommand
      31              : {
      32            0 :     OBJECT_ALLOCATOR(engraving, InsertRemoveMeasures)
      33              : 
      34              :     MeasureBase* fm = nullptr;
      35              :     MeasureBase* lm = nullptr;
      36              : 
      37              :     static std::vector<Clef*> getCourtesyClefs(Measure* m);
      38              : 
      39              :     bool moveStc = true;
      40              : 
      41              : protected:
      42              :     void removeMeasures();
      43              :     void insertMeasures();
      44              : 
      45              : public:
      46          434 :     InsertRemoveMeasures(MeasureBase* _fm, MeasureBase* _lm, bool _moveStc)
      47          434 :         : fm(_fm), lm(_lm), moveStc(_moveStc) {}
      48              :     virtual void undo() override = 0;
      49              :     virtual void redo() override = 0;
      50          558 :     UNDO_CHANGED_OBJECTS({ fm, lm })
      51              : };
      52              : 
      53              : class RemoveMeasures : public InsertRemoveMeasures
      54              : {
      55          118 :     OBJECT_ALLOCATOR(engraving, RemoveMeasures)
      56              : public:
      57           62 :     RemoveMeasures(MeasureBase* m1, MeasureBase* m2, bool moveStc = true)
      58           62 :         : InsertRemoveMeasures(m1, m2, moveStc) {}
      59           10 :     void undo() override { insertMeasures(); }
      60           62 :     void redo() override { removeMeasures(); }
      61              : 
      62           60 :     UNDO_TYPE(CommandType::RemoveMeasures)
      63            0 :     UNDO_NAME("RemoveMeasures")
      64              : };
      65              : 
      66              : class InsertMeasures : public InsertRemoveMeasures
      67              : {
      68          734 :     OBJECT_ALLOCATOR(engraving, InsertMeasures)
      69              : public:
      70          372 :     InsertMeasures(MeasureBase* m1, MeasureBase* m2, bool moveStc = true)
      71          372 :         : InsertRemoveMeasures(m1, m2, moveStc) {}
      72          372 :     void redo() override { insertMeasures(); }
      73           18 :     void undo() override { removeMeasures(); }
      74              : 
      75          126 :     UNDO_TYPE(CommandType::InsertMeasures)
      76            0 :     UNDO_NAME("InsertMeasures")
      77              : };
      78              : 
      79              : class ChangeMeasureLen : public UndoableCommand
      80              : {
      81          130 :     OBJECT_ALLOCATOR(engraving, ChangeMeasureLen)
      82              : 
      83              :     Measure* measure = nullptr;
      84              :     Fraction len;
      85              : 
      86              :     void flip() override;
      87              : 
      88              : public:
      89              :     ChangeMeasureLen(Measure*, Fraction);
      90              : 
      91           79 :     UNDO_TYPE(CommandType::ChangeMeasureLen)
      92            0 :     UNDO_NAME("ChangeMeasureLen")
      93          237 :     UNDO_CHANGED_OBJECTS({ measure })
      94              : };
      95              : 
      96              : class ChangeMMRest : public UndoableCommand
      97              : {
      98           79 :     OBJECT_ALLOCATOR(engraving, ChangeMMRest)
      99              : 
     100              :     Measure* m;
     101              :     Measure* mmrest;
     102              : 
     103              :     void flip() override;
     104              : 
     105              : public:
     106           43 :     ChangeMMRest(Measure* _m, Measure* _mmr)
     107           43 :         : m(_m), mmrest(_mmr) {}
     108              : 
     109           30 :     UNDO_TYPE(CommandType::ChangeMMRest)
     110            0 :     UNDO_NAME("ChangeMMRest")
     111           90 :     UNDO_CHANGED_OBJECTS({ m, mmrest })
     112              : };
     113              : 
     114              : // ChangeMMRestNext & ChangeMMRestPrev SHOULD ONLY BE USED FOR MMRests
     115              : // Setting m_next & m_prev involves the score's MeasureList for regular measures
     116              : // This is handled through undo commands above
     117              : class ChangeMMRestNext : public UndoableCommand
     118              : {
     119          304 :     OBJECT_ALLOCATOR(engraving, ChangeMMRestNext)
     120              : 
     121              :     Measure* m_mmrest = nullptr;
     122              :     MeasureBase* m_next = nullptr;
     123              : 
     124              :     void flip() override;
     125              : 
     126              : public:
     127          163 :     ChangeMMRestNext(Measure* mmrest, MeasureBase* next)
     128          163 :         : m_mmrest(mmrest), m_next(next) {}
     129              : 
     130            0 :     UNDO_NAME("ChangeMMRestNext")
     131          186 :     UNDO_CHANGED_OBJECTS({ m_mmrest })
     132              : };
     133              : 
     134              : class ChangeMMRestPrev : public UndoableCommand
     135              : {
     136          304 :     OBJECT_ALLOCATOR(engraving, ChangeMMRestPrev)
     137              : 
     138              :     Measure* m_mmrest = nullptr;
     139              :     MeasureBase* m_prev = nullptr;
     140              : 
     141              :     void flip() override;
     142              : 
     143              : public:
     144          163 :     ChangeMMRestPrev(Measure* mmrest, MeasureBase* prev)
     145          163 :         : m_mmrest(mmrest), m_prev(prev) {}
     146              : 
     147            0 :     UNDO_NAME("ChangeMMRestPrev")
     148          186 :     UNDO_CHANGED_OBJECTS({ m_mmrest })
     149              : };
     150              : 
     151              : class ChangeMeasureRepeatCount : public UndoableCommand
     152              : {
     153           72 :     OBJECT_ALLOCATOR(engraving, ChangeMeasureRepeatCount)
     154              : 
     155              :     Measure* m = nullptr;
     156              :     int count = 0;
     157              :     staff_idx_t staffIdx = muse::nidx;
     158              : 
     159              :     void flip() override;
     160              : 
     161              : public:
     162           36 :     ChangeMeasureRepeatCount(Measure* _m, int _count, staff_idx_t _staffIdx)
     163           36 :         : m(_m), count(_count), staffIdx(_staffIdx) {}
     164              : 
     165           72 :     UNDO_TYPE(CommandType::ChangeMeasureRepeatCount)
     166            0 :     UNDO_NAME("ChangeMeasureRepeatCount")
     167          216 :     UNDO_CHANGED_OBJECTS({ m })
     168              : };
     169              : }
        

Generated by: LCOV version 2.0-1