LCOV - code coverage report
Current view: top level - src/engraving/editing - addremoveelement.h Coverage Total Hit
Test: filtered_coverage.info Lines: 81.2 % 32 26
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/segment.h"
      28              : 
      29              : namespace mu::engraving {
      30              : class AddElement : public UndoableCommand
      31              : {
      32        27337 :     OBJECT_ALLOCATOR(engraving, AddElement)
      33              : 
      34              :     EngravingItem* element = nullptr;
      35              : 
      36              :     void endUndoRedo(bool) const;
      37              :     void undo() override;
      38              :     void redo() override;
      39              : 
      40              : public:
      41              :     AddElement(EngravingItem*);
      42              :     EngravingItem* getElement() const { return element; }
      43              :     void cleanup(bool) override;
      44              :     const char* name() const override;
      45              : 
      46              :     bool matchesFilter(UndoableCommandFilter f, const EngravingItem* target) const override;
      47              : 
      48              :     std::vector<EngravingObject*> objectItems() const override;
      49              : 
      50         9348 :     UNDO_TYPE(CommandType::AddElement)
      51              : };
      52              : 
      53              : class RemoveElement : public UndoableCommand
      54              : {
      55        20897 :     OBJECT_ALLOCATOR(engraving, RemoveElement)
      56              : 
      57              :     EngravingItem* element = nullptr;
      58              : 
      59              : public:
      60              :     RemoveElement(EngravingItem*);
      61              :     void undo() override;
      62              :     void redo() override;
      63              :     void cleanup(bool) override;
      64              :     const char* name() const override;
      65              : 
      66              :     bool matchesFilter(UndoableCommandFilter f, const EngravingItem* target) const override;
      67              : 
      68              :     std::vector<EngravingObject*> objectItems() const override;
      69              : 
      70         7374 :     UNDO_TYPE(CommandType::RemoveElement)
      71              : };
      72              : 
      73              : class ChangeElement : public UndoableCommand
      74              : {
      75          129 :     OBJECT_ALLOCATOR(engraving, ChangeElement)
      76              : 
      77              :     EngravingItem* oldElement = nullptr;
      78              :     EngravingItem* newElement = nullptr;
      79              : 
      80              :     void flip() override;
      81              : 
      82              : public:
      83              :     ChangeElement(EngravingItem* oldElement, EngravingItem* newElement);
      84              : 
      85          105 :     UNDO_TYPE(CommandType::ChangeElement)
      86            0 :     UNDO_NAME("ChangeElement")
      87          315 :     UNDO_CHANGED_OBJECTS({ oldElement, newElement })
      88              : };
      89              : 
      90              : class ChangeParent : public UndoableCommand
      91              : {
      92          339 :     OBJECT_ALLOCATOR(engraving, ChangeParent)
      93              : 
      94              :     EngravingItem* element = nullptr;
      95              :     EngravingItem* parent = nullptr;
      96              :     staff_idx_t staffIdx = muse::nidx;
      97              : 
      98              :     void flip() override;
      99              : 
     100              : public:
     101          180 :     ChangeParent(EngravingItem* e, EngravingItem* p, staff_idx_t si)
     102          180 :         : element(e), parent(p), staffIdx(si) {}
     103              : 
     104          101 :     UNDO_TYPE(CommandType::ChangeParent)
     105            0 :     UNDO_NAME("ChangeParent")
     106          303 :     UNDO_CHANGED_OBJECTS({ element, parent })
     107              : };
     108              : 
     109              : class ChangeSegmentParent : public UndoableCommand
     110              : {
     111           12 :     OBJECT_ALLOCATOR(engraving, ChangeSegmentParent)
     112              : 
     113              :     Segment* segment = nullptr;
     114              :     Measure* parent = nullptr;
     115              :     Fraction tick;
     116              : 
     117              :     void flip() override;
     118              : 
     119              : public:
     120            8 :     ChangeSegmentParent(Segment* s, Measure* p, Fraction t)
     121            8 :         : segment(s), parent(p), tick(t) {}
     122              : 
     123            5 :     UNDO_TYPE(CommandType::ChangeParent)
     124            0 :     UNDO_NAME("ChangeSegmentParent")
     125           15 :     UNDO_CHANGED_OBJECTS({ segment })
     126              : };
     127              : 
     128              : class LinkUnlink : public UndoableCommand
     129              : {
     130            0 :     OBJECT_ALLOCATOR(engraving, LinkUnlink)
     131              : 
     132              :     bool mustDelete  { false };
     133              : 
     134              : protected:
     135              :     LinkedObjects* le = nullptr;
     136              :     EngravingObject* e = nullptr;
     137              : 
     138              :     void link();
     139              :     void unlink();
     140              : 
     141              : public:
     142         5477 :     LinkUnlink() {}
     143              :     ~LinkUnlink();
     144              : };
     145              : 
     146              : class Unlink : public LinkUnlink
     147              : {
     148         1065 :     OBJECT_ALLOCATOR(engraving, Unlink)
     149              : public:
     150              :     Unlink(EngravingObject*);
     151            7 :     void undo() override { link(); }
     152          539 :     void redo() override { unlink(); }
     153              : 
     154          121 :     UNDO_TYPE(CommandType::Unlink)
     155            0 :     UNDO_NAME("Unlink")
     156              : };
     157              : 
     158              : class Link : public LinkUnlink
     159              : {
     160         9775 :     OBJECT_ALLOCATOR(engraving, Link)
     161              : public:
     162              :     Link(EngravingObject*, EngravingObject*);
     163              : 
     164           71 :     void undo() override { unlink(); }
     165         4960 :     void redo() override { link(); }
     166              : 
     167          429 :     UNDO_TYPE(CommandType::Link)
     168            0 :     UNDO_NAME("Link")
     169              : 
     170              :     bool matchesFilter(UndoableCommandFilter f, const EngravingItem* target) const override;
     171              : };
     172              : }
        

Generated by: LCOV version 2.0-1