LCOV - code coverage report
Current view: top level - src/engraving/dom - bracketitem.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 33.8 % 80 27
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) 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 "bracketitem.h"
      24              : 
      25              : #include "property.h"
      26              : #include "score.h"
      27              : #include "staff.h"
      28              : 
      29              : #include "../editing/editstaffbrackets.h"
      30              : 
      31              : using namespace mu;
      32              : 
      33              : namespace mu::engraving {
      34          943 : BracketItem::BracketItem(DummyParentOr<EngravingItem> parent)
      35          943 :     : EngravingItem(ElementType::BRACKET_ITEM, parent)
      36              : {
      37          943 : }
      38              : 
      39            3 : BracketItem::BracketItem(DummyParentOr<EngravingItem> parent, BracketType bracketType, size_t span)
      40            3 :     : EngravingItem(ElementType::BRACKET_ITEM, parent), m_bracketType(bracketType), m_bracketSpan(span)
      41              : {
      42            3 : }
      43              : 
      44            0 : EngravingItem* BracketItem::clone() const
      45              : {
      46            0 :     return new BracketItem(*this);
      47              : }
      48              : 
      49            3 : Staff* BracketItem::startStaff() const
      50              : {
      51            3 :     return score() ? score()->staff(m_startStaffIdx) : nullptr;
      52              : }
      53              : 
      54          624 : PropertyValue BracketItem::getProperty(Pid id) const
      55              : {
      56          624 :     switch (id) {
      57            0 :     case Pid::SYSTEM_BRACKET:
      58            0 :         return int(m_bracketType);
      59          204 :     case Pid::BRACKET_COLUMN:
      60          204 :         return m_column;
      61          213 :     case Pid::BRACKET_SPAN:
      62          213 :         return static_cast<int>(m_bracketSpan);
      63            0 :     case Pid::STAFF_LONG_NAME:
      64            0 :         return longName();
      65            0 :     case Pid::STAFF_SHORT_NAME:
      66            0 :         return shortName();
      67            0 :     case Pid::GROUP_BRACKET_SHOW_TEXT:
      68            0 :         return m_showText;
      69            0 :     case Pid::GROUP_BRACKET_SHOW_BRACKET:
      70            0 :         return m_showBracket;
      71          207 :     default:
      72          207 :         return EngravingItem::getProperty(id);
      73              :     }
      74              : }
      75              : 
      76           41 : bool BracketItem::setProperty(Pid id, const PropertyValue& v)
      77              : {
      78           41 :     switch (id) {
      79            0 :     case Pid::SYSTEM_BRACKET:
      80            0 :         EditStaffBrackets::setBracketType(score(), startStaffIdx(), column(), BracketType(v.toInt())); // change bracket type global
      81            0 :         break;
      82            0 :     case Pid::BRACKET_COLUMN:
      83            0 :         EditStaffBrackets::changeBracketColumn(score(), startStaffIdx(), column(), static_cast<size_t>(v.toInt()));
      84            0 :         break;
      85           41 :     case Pid::BRACKET_SPAN:
      86           41 :         m_bracketSpan = static_cast<size_t>(v.toInt());
      87           41 :         break;
      88            0 :     case Pid::VISIBLE:
      89            0 :         setVisible(v.toBool());
      90            0 :         break;
      91            0 :     case Pid::STAFF_LONG_NAME:
      92            0 :         m_name.setLongName(v.value<String>());
      93            0 :         break;
      94            0 :     case Pid::STAFF_SHORT_NAME:
      95            0 :         m_name.setShortName(v.value<String>());
      96            0 :         break;
      97            0 :     case Pid::GROUP_BRACKET_SHOW_TEXT:
      98            0 :         m_showText = v.toBool();
      99            0 :         break;
     100            0 :     case Pid::GROUP_BRACKET_SHOW_BRACKET:
     101            0 :         m_showBracket = v.toBool();
     102            0 :         break;
     103            0 :     default:
     104            0 :         return EngravingItem::setProperty(id, v);
     105              :     }
     106           41 :     score()->setLayoutAll();
     107           41 :     return true;
     108              : }
     109              : 
     110          204 : PropertyValue BracketItem::propertyDefault(Pid id) const
     111              : {
     112          204 :     switch (id) {
     113            0 :     case Pid::SYSTEM_BRACKET:
     114            0 :         return int(BracketType::NORMAL);
     115            0 :     case Pid::BRACKET_COLUMN:
     116            0 :         return size_t(0);
     117            0 :     case Pid::STAFF_LONG_NAME:
     118            0 :         return muse::mtrc("systemBrackets", "GROUP");
     119            0 :     case Pid::STAFF_SHORT_NAME:
     120            0 :         return muse::mtrc("systemBrackets", "GR.", "Short for GROUP");
     121            0 :     case Pid::GROUP_BRACKET_SHOW_TEXT:
     122              :     case Pid::GROUP_BRACKET_SHOW_BRACKET:
     123            0 :         return true;
     124          204 :     default:
     125          204 :         return EngravingItem::propertyDefault(id);
     126              :     }
     127              : }
     128              : 
     129            0 : bool BracketItem::intersects(const BracketItem* other) const
     130              : {
     131            0 :     staff_idx_t firstOfOther = other->startStaffIdx();
     132            0 :     staff_idx_t lastOfOther = firstOfOther + other->bracketSpan() - 1;
     133            0 :     return intersects(firstOfOther, lastOfOther);
     134              : }
     135              : 
     136            0 : bool BracketItem::intersects(staff_idx_t first, staff_idx_t last) const
     137              : {
     138            0 :     staff_idx_t firstOfThis = m_startStaffIdx;
     139            0 :     staff_idx_t lastOfThis = firstOfThis + bracketSpan() - 1;
     140            0 :     return firstOfThis <= last && lastOfThis >= first;
     141              : }
     142              : }
        

Generated by: LCOV version 2.0-1