LCOV - code coverage report
Current view: top level - src/engraving/dom - playcounttext.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 57.9 % 57 33
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 "playcounttext.h"
      24              : 
      25              : #include "../editing/transaction/undostack.h"
      26              : #include "../types/typesconv.h"
      27              : 
      28              : #include "barline.h"
      29              : #include "measure.h"
      30              : #include "score.h"
      31              : 
      32              : using namespace mu::engraving;
      33              : 
      34              : static ElementStyle playCountStyle {
      35              :     { Sid::repeatPlayCountPlacement, Pid::PLACEMENT },
      36              :     { Sid::repeatPlayCountMinDistance, Pid::MIN_DISTANCE },
      37              : };
      38              : 
      39            6 : PlayCountText::PlayCountText(DummyParentOr<Segment> parent, TextStyleType tid)
      40            6 :     : TextBase(ElementType::PLAY_COUNT_TEXT, parent, tid, ElementFlag::SYSTEM | ElementFlag::ON_STAFF)
      41              : {
      42            6 :     initElementStyle(&playCountStyle);
      43            6 : }
      44              : 
      45            0 : void PlayCountText::endEdit(EditData& ed)
      46              : {
      47            0 :     if (textWasEdited(ed)) {
      48            0 :         score()->startCmd(TranslatableString("undoableAction", "Update play count text"));
      49            0 :         barline()->undoChangeProperty(Pid::PLAY_COUNT_TEXT, xmlText());
      50            0 :         barline()->undoChangeProperty(Pid::PLAY_COUNT_TEXT_SETTING, AutoCustomHide::CUSTOM);
      51            0 :         score()->endCmd();
      52              :     }
      53            0 :     TextBase::endEdit(ed);
      54            0 : }
      55              : 
      56           66 : PropertyValue PlayCountText::getProperty(Pid id) const
      57              : {
      58           66 :     switch (id) {
      59            6 :     case Pid::PLAY_COUNT_TEXT_SETTING:
      60            6 :         return m_playCountTextSetting;
      61            6 :     case Pid::PLAY_COUNT_TEXT:
      62            6 :         return m_playCountCustomText;
      63           54 :     default:
      64           54 :         return TextBase::getProperty(id);
      65              :     }
      66              : }
      67              : 
      68          108 : bool PlayCountText::setProperty(Pid id, const PropertyValue& v)
      69              : {
      70          108 :     Segment* s = segment();
      71          108 :     Measure* m = s ? s->measure() : nullptr;
      72              : 
      73          108 :     switch (id) {
      74            0 :     case Pid::PLAY_COUNT_TEXT_SETTING:
      75            0 :         m_playCountTextSetting = v.value<AutoCustomHide>();
      76            0 :         if (playCountTextSetting() == AutoCustomHide::CUSTOM && playCountCustomText().isEmpty()) {
      77            0 :             int repeatCount = m ? m->repeatCount() : 2;
      78            0 :             String text = TConv::translatedUserName(style().styleV(Sid::repeatPlayCountPreset).value<RepeatPlayCountPreset>()).arg(
      79            0 :                 repeatCount);
      80            0 :             undoChangeProperty(Pid::PLAY_COUNT_TEXT, text);
      81            0 :         }
      82            0 :         break;
      83            0 :     case Pid::PLAY_COUNT_TEXT:
      84            0 :         m_playCountCustomText = v.value<String>();
      85            0 :         break;
      86          108 :     default:
      87          108 :         return TextBase::setProperty(id, v);
      88              :     }
      89            0 :     triggerLayout();
      90            0 :     return true;
      91              : }
      92              : 
      93           66 : PropertyValue PlayCountText::propertyDefault(Pid propertyId) const
      94              : {
      95           66 :     Segment* s = segment();
      96           66 :     Measure* m = s ? s->measure() : nullptr;
      97              : 
      98           66 :     switch (propertyId) {
      99            6 :     case Pid::PLAY_COUNT_TEXT_SETTING:
     100           12 :         return AutoCustomHide::AUTO;
     101            6 :     case Pid::PLAY_COUNT_TEXT: {
     102            6 :         int repeatCount = m ? m->repeatCount() : 2;
     103            6 :         return TConv::translatedUserName(style().styleV(Sid::repeatPlayCountPreset).value<RepeatPlayCountPreset>()).arg(repeatCount);
     104              :     }
     105           54 :     default:
     106           54 :         return TextBase::propertyDefault(propertyId);
     107              :     }
     108              : }
     109              : 
     110            0 : RectF PlayCountText::drag(EditData& ed)
     111              : {
     112              :     // Not TextBase::drag because we don't allow reanchoring on drag
     113            0 :     return EngravingItem::drag(ed);
     114              : }
     115              : 
     116            6 : mu::engraving::BarLine* mu::engraving::PlayCountText::barline() const
     117              : {
     118            6 :     Segment* seg = segment();
     119            6 :     EngravingItem* el = seg ? seg->element(track()) : nullptr;
     120              : 
     121            6 :     return toBarLine(el);
     122              : }
        

Generated by: LCOV version 2.0-1