LCOV - code coverage report
Current view: top level - src/engraving/dom - engravingobject.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 89.4 % 368 329
Test Date: 2026-11-19 04:14:36

            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 "engravingobject.h"
      24              : 
      25              : #include <algorithm>
      26              : 
      27              : #include "global/containers.h"
      28              : 
      29              : #include "../editing/addremoveelement.h"
      30              : #include "../editing/editproperty.h"
      31              : #include "../editing/transaction/transaction.h"
      32              : #include "../editing/transaction/undostack.h"
      33              : #include "style/textstyle.h"
      34              : #include "types/typesconv.h"
      35              : 
      36              : #include "bracketitem.h"
      37              : #include "dummyparent.h"
      38              : #include "linkedobjects.h"
      39              : #include "masterscore.h"
      40              : #include "score.h"
      41              : #include "staff.h"
      42              : 
      43              : #include "log.h"
      44              : 
      45              : using namespace mu;
      46              : using namespace mu::engraving;
      47              : 
      48              : namespace mu::engraving {
      49              : ElementStyle const EngravingObject::EMPTY_STYLE;
      50              : 
      51       673551 : EngravingObject::EngravingObject(const ElementType& type, EngravingObject* parent)
      52       673551 :     : m_type(type)
      53              : {
      54       673551 :     IF_ASSERT_FAILED(this != parent) {
      55            0 :         return;
      56              :     }
      57              : 
      58       673551 :     if (type != ElementType::SCORE) {
      59       670786 :         assert(parent);
      60              :     }
      61              : 
      62              :     // The parent an object is constructed with is its parent: it is attached to it
      63              :     // right away. Passing the dummy means it is not attached to anything yet.
      64       673551 :     doSetParent(parent);
      65       673551 :     if (m_parent) {
      66       670786 :         doSetScore(m_parent->score());
      67              :     }
      68              : 
      69       673551 :     if (type == ElementType::SCORE) {
      70         2765 :         m_score = static_cast<Score*>(this);
      71              :     }
      72              : 
      73              :     // reg to debug
      74       673551 :     if (type != ElementType::SCORE) {
      75       670786 :         if (m_score && m_score->elementsProvider()) {
      76            0 :             m_score->elementsProvider()->reg(this);
      77              :         }
      78              :     }
      79            0 : }
      80              : 
      81        20720 : EngravingObject::EngravingObject(const EngravingObject& se)
      82              : {
      83        20720 :     m_type = se.m_type;
      84        20720 :     doSetParent(se.m_parent);
      85        20720 :     m_score = se.m_score;
      86        20720 :     m_elementStyle = se.m_elementStyle;
      87        20720 :     if (m_elementStyle) {
      88        20720 :         size_t n = m_elementStyle->size();
      89        20720 :         m_propertyFlagsList = new PropertyFlags[n];
      90        41184 :         for (size_t i = 0; i < n; ++i) {
      91        20464 :             m_propertyFlagsList[i] = se.m_propertyFlagsList[i];
      92              :         }
      93              :     }
      94        20720 :     m_links = 0;
      95              : 
      96              :     // reg to debug
      97        20720 :     if (m_type != ElementType::SCORE) {
      98        20720 :         if (m_score && m_score->elementsProvider()) {
      99            0 :             m_score->elementsProvider()->reg(this);
     100              :         }
     101              :     }
     102        20720 : }
     103              : 
     104              : //---------------------------------------------------------
     105              : //   ~ScoreElement
     106              : //---------------------------------------------------------
     107              : 
     108       650347 : EngravingObject::~EngravingObject()
     109              : {
     110       650347 :     if (m_parent) {
     111       647822 :         m_parent->removeChild(this);
     112              :     }
     113              : 
     114              :     {
     115       650347 :         bool isPaletteScore = score()->isPaletteScore();
     116       650347 :         bool canMoveToDummy = !this->isType(ElementType::ROOT_ITEM)
     117       645297 :                               && !this->isType(ElementType::DUMMY)
     118       642772 :                               && !this->isType(ElementType::SCORE)
     119      1295644 :                               && score()->dummy();
     120              : 
     121              :         // copy because moveToDummy might modify children
     122       650347 :         EngravingObjectList children = m_children;
     123       673490 :         for (EngravingObject* c : children) {
     124        23143 :             if (canMoveToDummy) {
     125        11801 :                 c->moveToDummy();
     126        11342 :             } else if (!isPaletteScore) {
     127        11342 :                 delete c;
     128              :             } else {
     129            0 :                 c->m_parent = nullptr;
     130              :             }
     131              :         }
     132              : 
     133       650347 :         m_children.clear();
     134       650347 :     }
     135              : 
     136       650347 :     if (score() && score()->elementsProvider()) {
     137            0 :         score()->elementsProvider()->unreg(this);
     138              :     }
     139              : 
     140       650347 :     if (m_links) {
     141        23824 :         m_links->remove(this);
     142        23824 :         if (m_links->empty()) {
     143        10701 :             delete m_links;
     144        10701 :             m_links = 0;
     145              :         }
     146              :     }
     147       650347 :     delete[] m_propertyFlagsList;
     148       650347 : }
     149              : 
     150       874072 : void EngravingObject::doSetParent(EngravingObject* p)
     151              : {
     152       874072 :     if (m_parent == p) {
     153       118755 :         return;
     154              :     }
     155              : 
     156       755317 :     IF_ASSERT_FAILED(p != this) {
     157            0 :         return;
     158              :     }
     159              : 
     160       755317 :     if (m_parent) {
     161        63811 :         m_parent->removeChild(this);
     162              :     }
     163              : 
     164       755317 :     m_parent = p;
     165              : 
     166       755317 :     if (m_parent) {
     167       755317 :         m_parent->addChild(this);
     168              :     }
     169              : }
     170              : 
     171       876643 : void EngravingObject::doSetScore(Score* sc)
     172              : {
     173       876643 :     if (m_score == sc) {
     174       201171 :         return;
     175              :     }
     176              : 
     177       675472 :     m_score = sc;
     178              : 
     179       678037 :     for (EngravingObject* ch : m_children) {
     180         2565 :         ch->doSetScore(sc);
     181              :     }
     182              : }
     183              : 
     184        12094 : void EngravingObject::moveToDummy()
     185              : {
     186        12094 :     Score* sc = score();
     187        12094 :     if (sc) {
     188        12094 :         if (sc->dummy() && sc->dummy() != this) {
     189        12094 :             setOwnershipParent(sc->dummy());
     190              :         }
     191              :     }
     192        12094 : }
     193              : 
     194          629 : static void collectChildrenItems(const EngravingObject* item, EngravingItemList& list, bool all)
     195              : {
     196         1863 :     for (EngravingObject* ch : item->children()) {
     197         1234 :         if (ch->isEngravingItem()) {
     198         1234 :             list.push_back(toEngravingItem(ch));
     199              : 
     200         1234 :             if (all) {
     201            0 :                 collectChildrenItems(ch, list, all);
     202              :             }
     203              :         }
     204              :     }
     205          629 : }
     206              : 
     207          629 : EngravingItemList EngravingObject::childrenItems(bool all) const
     208              : {
     209          629 :     EngravingItemList list;
     210          629 :     collectChildrenItems(this, list, all);
     211          629 :     return list;
     212            0 : }
     213              : 
     214         8167 : EngravingItemList EngravingObject::getChildren(bool includeInvisible) const
     215              : {
     216         8167 :     EngravingItemList childrenList;
     217        24631 :     auto collectChildren = [&](EngravingItem* item) {
     218        24631 :         if (item != this && (includeInvisible || item->visible())) {
     219        24627 :             childrenList.push_back(item);
     220              :         }
     221        32798 :     };
     222              : 
     223         8167 :     const_cast<EngravingObject*>(this)->scanElements(collectChildren);
     224              : 
     225         8167 :     return childrenList;
     226            0 : }
     227              : 
     228        23491 : void EngravingObject::setScore(Score* s)
     229              : {
     230        23491 :     doSetScore(s);
     231              : 
     232        23491 :     if (!m_parent) {
     233            0 :         return;
     234              :     }
     235              : 
     236        23491 :     if (m_parent->score() == s) {
     237        21657 :         return;
     238              :     }
     239              : 
     240         1834 :     if (m_parent->isType(ElementType::DUMMY)) {
     241           59 :         moveToDummy();
     242         1775 :     } else if (m_parent->isType(ElementType::SCORE)) {
     243            2 :         setOwnershipParent(s);
     244              :     }
     245              : }
     246              : 
     247       755317 : void EngravingObject::addChild(EngravingObject* o)
     248              : {
     249       755317 :     IF_ASSERT_FAILED(o != this) {
     250            0 :         return;
     251              :     }
     252              : 
     253       755317 :     m_children.push_back(o);
     254              : }
     255              : 
     256       711633 : void EngravingObject::removeChild(EngravingObject* o)
     257              : {
     258       711633 :     IF_ASSERT_FAILED(o->m_parent == this) {
     259            0 :         return;
     260              :     }
     261       711633 :     o->m_parent = nullptr;
     262              : 
     263              :     // Search from the back: a child is often unparented shortly after it was added, so it
     264              :     // still sits near the end of the list. That matters for the dummy, whose child list is
     265              :     // long-lived and large. Empirical evidence shows that searching from the back walks on
     266              :     // average orders-of-magnitude less list entries than searching from the front.
     267       711633 :     auto it = std::find(m_children.rbegin(), m_children.rend(), o);
     268       711633 :     if (it != m_children.rend()) {
     269      1423266 :         m_children.erase(std::next(it).base());
     270              :     }
     271              : }
     272              : 
     273       292415 : EngravingObject* EngravingObject::parent() const
     274              : {
     275       292415 :     return m_parent;
     276              : }
     277              : 
     278    131186396 : EngravingObject* EngravingObject::ownershipParent() const
     279              : {
     280    131186396 :     if (!m_parent || m_parent->isType(ElementType::DUMMY)) {
     281       943939 :         return nullptr;
     282              :     }
     283    130242457 :     return m_parent;
     284              : }
     285              : 
     286       179894 : void EngravingObject::setOwnershipParent(EngravingObject* p)
     287              : {
     288       179894 :     IF_ASSERT_FAILED(this != p) {
     289            0 :         return;
     290              :     }
     291              : 
     292       179894 :     if (!p) {
     293           93 :         moveToDummy();
     294           93 :         return;
     295              :     }
     296              : 
     297       179801 :     doSetParent(p);
     298       179801 :     if (m_parent) {
     299       179801 :         doSetScore(m_parent->score());
     300              :     }
     301              : }
     302              : 
     303    106907196 : Score* EngravingObject::score() const
     304              : {
     305    106907196 :     return m_score;
     306              : }
     307              : 
     308       292670 : MasterScore* EngravingObject::masterScore() const
     309              : {
     310       292670 :     return score()->masterScore();
     311              : }
     312              : 
     313            0 : bool EngravingObject::onSameScore(const EngravingObject* other) const
     314              : {
     315            0 :     return this->score() == other->score();
     316              : }
     317              : 
     318      1279998 : bool EngravingObject::isInScoreTree() const
     319              : {
     320      3016583 :     for (const EngravingObject* parent = ownershipParent(); parent; parent = parent->ownershipParent()) {
     321      2754816 :         if (parent->isScore()) {
     322      1018231 :             return true;
     323              :         }
     324              :     }
     325       261767 :     return false;
     326              : }
     327              : 
     328     18767933 : const MStyle& EngravingObject::style() const
     329              : {
     330     18767933 :     return score()->style();
     331              : }
     332              : 
     333      2040662 : PropertyDelegate EngravingObject::resolvePropertyDelegate(Pid) const
     334              : {
     335      2040662 :     return PropertyDelegate();
     336              : }
     337              : 
     338            0 : bool EngravingObject::hasPropertyDelegate(Pid pid) const
     339              : {
     340            0 :     return resolvePropertyDelegate(pid).hasDelegate;
     341              : }
     342              : 
     343           12 : EngravingObject* EngravingObject::propertyDelegate(Pid pid) const
     344              : {
     345           12 :     return resolvePropertyDelegate(pid).delegate;
     346              : }
     347              : 
     348              : //---------------------------------------------------------
     349              : //   propertyDefault
     350              : //---------------------------------------------------------
     351              : 
     352       118811 : PropertyValue EngravingObject::propertyDefault(Pid pid) const
     353              : {
     354       118811 :     Sid sid = getPropertyStyle(pid);
     355       118811 :     if (sid != Sid::NOSTYLE) {
     356        41849 :         return styleValue(pid, sid);
     357              :     }
     358              :     //      LOGD("<%s>(%d) not found in <%s>", propertyQmlName(pid), int(pid), typeName());
     359        76962 :     return PropertyValue();
     360              : }
     361              : 
     362              : //---------------------------------------------------------
     363              : //   initElementStyle
     364              : //---------------------------------------------------------
     365              : 
     366        44572 : void EngravingObject::initElementStyle(const ElementStyle* ss)
     367              : {
     368        44572 :     m_elementStyle = ss;
     369        44572 :     size_t n      = m_elementStyle->size();
     370        44572 :     delete[] m_propertyFlagsList;
     371        44572 :     m_propertyFlagsList = new PropertyFlags[n];
     372       163062 :     for (size_t i = 0; i < n; ++i) {
     373       118490 :         m_propertyFlagsList[i] = PropertyFlags::STYLED;
     374              :     }
     375       163062 :     for (const StyledProperty& spp : *m_elementStyle) {
     376              :         //            setProperty(spp.pid, styleValue(spp.pid, spp.sid));
     377       118490 :         setProperty(spp.pid, styleValue(spp.pid, getPropertyStyle(spp.pid)));
     378              :     }
     379        44572 : }
     380              : 
     381              : //---------------------------------------------------------
     382              : //   resetProperty
     383              : //---------------------------------------------------------
     384              : 
     385        61499 : void EngravingObject::resetProperty(Pid pid)
     386              : {
     387        61499 :     PropertyValue v = propertyDefault(pid);
     388        61499 :     if (v.isValid()) {
     389        61106 :         setProperty(pid, v);
     390        61106 :         PropertyFlags p = propertyFlags(pid);
     391        61106 :         if (p == PropertyFlags::UNSTYLED) {
     392          159 :             setPropertyFlags(pid, PropertyFlags::STYLED);
     393              :         }
     394              :     }
     395        61499 : }
     396              : 
     397              : //---------------------------------------------------------
     398              : //   undoResetProperty
     399              : //---------------------------------------------------------
     400              : 
     401          862 : void EngravingObject::undoResetProperty(Pid id)
     402              : {
     403          862 :     PropertyFlags f = propertyFlags(id);
     404          862 :     if (f == PropertyFlags::UNSTYLED) {
     405            0 :         f = PropertyFlags::STYLED;
     406              :     }
     407          862 :     undoChangeProperty(id, propertyDefault(id), f);
     408          862 : }
     409              : 
     410              : //---------------------------------------------------------
     411              : //   isStyled
     412              : //---------------------------------------------------------
     413              : 
     414      1597210 : bool EngravingObject::isStyled(Pid pid) const
     415              : {
     416      1597210 :     PropertyFlags f = propertyFlags(pid);
     417      1597210 :     return f == PropertyFlags::STYLED;
     418              : }
     419              : 
     420              : //---------------------------------------------------------
     421              : //   changeProperty
     422              : //---------------------------------------------------------
     423              : 
     424         6308 : static void changeProperty(EngravingObject* e, Pid t, const PropertyValue& st, PropertyFlags ps)
     425              : {
     426         6308 :     if (e->getProperty(t) != st || e->propertyFlags(t) != ps) {
     427         3265 :         if (e->isBracketItem()) {
     428            5 :             BracketItem* bi = toBracketItem(e);
     429            5 :             e->score()->undo(new ChangeBracketProperty(bi->startStaff(), bi->column(), t, st, ps));
     430              :         } else {
     431         3260 :             e->score()->undo(new ChangeProperty(e, t, st, ps));
     432              :         }
     433              :     }
     434         6308 : }
     435              : 
     436              : //---------------------------------------------------------
     437              : //   changeProperties
     438              : //---------------------------------------------------------
     439              : 
     440         6122 : static void changeProperties(EngravingObject* object, Pid propertyId, const PropertyValue& propertyValue, PropertyFlags propertyFlag)
     441              : {
     442         6122 :     const std::list<EngravingObject*> linkList = object->linkListForPropertyPropagation();
     443        12748 :     for (EngravingObject* linkedObject : linkList) {
     444         6626 :         if (linkedObject == object) {
     445         6126 :             changeProperty(object, propertyId, propertyValue, propertyFlag);
     446         6126 :             continue;
     447              :         }
     448              : 
     449          500 :         if (!object->isEngravingItem() || !linkedObject->isEngravingItem()) {
     450            0 :             continue;
     451              :         }
     452              : 
     453          500 :         EngravingItem* item = toEngravingItem(object);
     454          500 :         EngravingItem* linkedItem = toEngravingItem(linkedObject);
     455          500 :         PropertyPropagation propertyPropagate = item->propertyPropagation(linkedItem, propertyId);
     456          500 :         switch (propertyPropagate) {
     457          288 :         case PropertyPropagation::NONE:
     458          288 :             break;
     459          178 :         case PropertyPropagation::PROPAGATE:
     460          178 :             changeProperty(linkedObject, propertyId, propertyValue, propertyFlag);
     461          178 :             break;
     462           34 :         case PropertyPropagation::UNLINK:
     463           34 :             item->unlinkPropertyFromMaster(propertyId);
     464           34 :             break;
     465            0 :         default:
     466            0 :             break;
     467              :         }
     468              :     }
     469              : 
     470         6122 :     if (!object->isEngravingItem() || propertyGroup(propertyId) == PropertyGroup::POSITION) {
     471           52 :         return;
     472              :     }
     473              : 
     474         6070 :     EngravingItem* item = toEngravingItem(object);
     475         6070 :     for (EngravingItem* originItem : item->originItems()) {
     476              :         // This is a shared item: propagate to all origin items
     477            0 :         changeProperty(originItem, propertyId, propertyValue, propertyFlag);
     478              :     }
     479         6070 :     if (EngravingItem* sharedItem = item->sharedItem(); sharedItem && sharedItem->originItems().front() == item) {
     480              :         // This is the first origin item of the shared item: propagate to shared item
     481            4 :         changeProperty(sharedItem, propertyId, propertyValue, propertyFlag);
     482              :     }
     483         6122 : }
     484              : 
     485              : //---------------------------------------------------------
     486              : //   undoChangeProperty
     487              : //---------------------------------------------------------
     488              : 
     489         5614 : void EngravingObject::undoChangeProperty(Pid id, const PropertyValue& v)
     490              : {
     491         5614 :     undoChangeProperty(id, v, propertyFlags(id));
     492         5614 : }
     493              : 
     494         7053 : void EngravingObject::undoChangeProperty(Pid id, const PropertyValue& v, PropertyFlags ps)
     495              : {
     496         7053 :     if ((getProperty(id) == v) && (propertyFlags(id) == ps)) {
     497         3990 :         return;
     498              :     }
     499         3063 :     if (id == Pid::TEXT_STYLE) {
     500              :         //
     501              :         // change a list of properties
     502              :         //
     503            0 :         auto l = textStyle(v.value<TextStyleType>());
     504              :         // Change to ElementStyle defaults
     505            0 :         for (const auto& p : *l) {
     506            0 :             if (p.sid == Sid::NOSTYLE) {
     507            0 :                 break;
     508              :             }
     509            0 :             changeProperties(this, p.pid, style().styleV(p.sid), PropertyFlags::STYLED);
     510              :         }
     511         3063 :     } else if (id == Pid::EXCLUDE_FROM_OTHER_PARTS) {
     512           12 :         if (isEngravingItem() && getProperty(Pid::EXCLUDE_FROM_OTHER_PARTS) != v) {
     513           12 :             EngravingItem* delegate = toEngravingItem(propertyDelegate(id));
     514           12 :             if (delegate) {
     515            0 :                 delegate->manageExclusionFromParts(v.toBool());
     516              :             } else {
     517           12 :                 toEngravingItem(this)->manageExclusionFromParts(v.toBool());
     518              :             }
     519              :         }
     520         3051 :     } else if (id == Pid::VOICE_ASSIGNMENT) {
     521            0 :         if (v.value<VoiceAssignment>() != VoiceAssignment::CURRENT_VOICE_ONLY) {
     522            0 :             changeProperties(this, Pid::VOICE, voice_idx_t(0), ps);
     523              :         }
     524              :     }
     525         3063 :     changeProperties(this, id, v, ps);
     526         3063 :     if (id != Pid::GENERATED) {
     527         3059 :         changeProperties(this, Pid::GENERATED, false, PropertyFlags::NOSTYLE);
     528              :     }
     529              : }
     530              : 
     531              : //---------------------------------------------------------
     532              : //   undoPushProperty
     533              : //---------------------------------------------------------
     534              : 
     535           21 : void EngravingObject::undoPushProperty(Pid id)
     536              : {
     537           21 :     PropertyValue val = getProperty(id);
     538              : 
     539           21 :     Transaction& tx = masterScore()->transactionManager()->currentOrDummyTransaction();
     540           21 :     tx.pushWithoutPerforming(new ChangeProperty(this, id, val));
     541           21 : }
     542              : 
     543              : //---------------------------------------------------------
     544              : //   reset
     545              : //---------------------------------------------------------
     546              : 
     547           23 : void EngravingObject::reset()
     548              : {
     549           63 :     for (const StyledProperty& spp : *styledProperties()) {
     550           40 :         undoResetProperty(spp.pid);
     551              :     }
     552           23 : }
     553              : 
     554              : //---------------------------------------------------------
     555              : //   linkTo
     556              : //    link this to element
     557              : //---------------------------------------------------------
     558         9480 : void EngravingObject::linkTo(EngravingObject* element)
     559              : {
     560         9480 :     assert(element != this);
     561         9480 :     assert(!m_links);
     562              : 
     563         9480 :     if (element->links()) {
     564         2953 :         setLinks(element->m_links);
     565         2953 :         assert(m_links->contains(element));
     566              :     } else {
     567         6527 :         setLinks(new LinkedObjects());
     568         6527 :         m_links->push_back(element);
     569         6527 :         element->setLinks(m_links);
     570              :     }
     571         9480 :     assert(!m_links->contains(this));
     572         9480 :     m_links->push_back(this);
     573         9480 : }
     574              : 
     575              : //---------------------------------------------------------
     576              : //   unlink
     577              : //---------------------------------------------------------
     578              : 
     579           44 : void EngravingObject::unlink()
     580              : {
     581           44 :     if (!m_links) {
     582           19 :         return;
     583              :     }
     584              : 
     585           25 :     assert(m_links->contains(this));
     586           25 :     m_links->remove(this);
     587              : 
     588              :     // if link list is empty, remove list
     589           25 :     if (m_links->size() <= 1) {
     590           18 :         if (!m_links->empty()) {
     591           17 :             m_links->front()->m_links = nullptr;
     592              :         }
     593           18 :         delete m_links;
     594              :     }
     595           25 :     m_links = 0;   // this element is not linked anymore
     596              : }
     597              : 
     598              : //---------------------------------------------------------
     599              : //   isLinked
     600              : ///  return true if se is different and
     601              : ///  linked to this element
     602              : //---------------------------------------------------------
     603              : 
     604         2615 : bool EngravingObject::isLinked(EngravingObject* se) const
     605              : {
     606         2615 :     if (se == this || !m_links) {
     607         1423 :         return false;
     608              :     }
     609              : 
     610         1192 :     if (se == nullptr) {
     611         1126 :         return !m_links->empty() && m_links->mainElement() != this;
     612              :     }
     613              : 
     614           66 :     return m_links->contains(se);
     615              : }
     616              : 
     617              : //---------------------------------------------------------
     618              : //   undoUnlink
     619              : //---------------------------------------------------------
     620              : 
     621         1256 : void EngravingObject::undoUnlink()
     622              : {
     623         1256 :     if (m_links) {
     624          592 :         score()->undo(new Unlink(this));
     625              :     }
     626         1256 : }
     627              : 
     628        28373 : void EngravingObject::setLinks(LinkedObjects* le)
     629              : {
     630        28373 :     m_links = le;
     631        28373 : }
     632              : 
     633              : //---------------------------------------------------------
     634              : //   linkList
     635              : //---------------------------------------------------------
     636              : 
     637        18458 : std::list<EngravingObject*> EngravingObject::linkList() const
     638              : {
     639        18458 :     std::list<EngravingObject*> el;
     640        18458 :     if (m_links) {
     641          965 :         el = *m_links;
     642              :     } else {
     643        17493 :         el.push_back(const_cast<EngravingObject*>(this));
     644              :     }
     645        18458 :     return el;
     646            0 : }
     647              : 
     648              : //---------------------------------------------------------
     649              : //   getPropertyFlagsIdx
     650              : //---------------------------------------------------------
     651              : 
     652      1901404 : int EngravingObject::getPropertyFlagsIdx(Pid id) const
     653              : {
     654      1901404 :     int i = 0;
     655      5270783 :     for (const StyledProperty& p : *m_elementStyle) {
     656      3473684 :         if (p.pid == id) {
     657       104305 :             return i;
     658              :         }
     659      3369379 :         ++i;
     660              :     }
     661      1797099 :     return -1;
     662              : }
     663              : 
     664              : //---------------------------------------------------------
     665              : //   propertyFlags
     666              : //---------------------------------------------------------
     667              : 
     668      2083867 : PropertyFlags EngravingObject::propertyFlags(Pid id) const
     669              : {
     670              :     static PropertyFlags f = PropertyFlags::NOSTYLE;
     671              : 
     672      2083867 :     if (const PropertyDelegate d = resolvePropertyDelegate(id); d.hasDelegate) {
     673        12130 :         return d.delegate ? d.delegate->propertyFlags(id) : f;
     674              :     }
     675              : 
     676      2071737 :     int i = getPropertyFlagsIdx(id);
     677      2071737 :     if (i == -1) {
     678      1856152 :         return f;
     679              :     }
     680       215585 :     return m_propertyFlagsList[i];
     681              : }
     682              : 
     683              : //---------------------------------------------------------
     684              : //   setPropertyFlags
     685              : //---------------------------------------------------------
     686              : 
     687        21642 : void EngravingObject::setPropertyFlags(Pid id, PropertyFlags f)
     688              : {
     689        21642 :     if (const PropertyDelegate d = resolvePropertyDelegate(id); d.hasDelegate) {
     690         2159 :         if (d.delegate) {
     691          124 :             d.delegate->setPropertyFlags(id, f);
     692              :         }
     693         2159 :         return;
     694              :     }
     695              : 
     696        19483 :     int i = getPropertyFlagsIdx(id);
     697        19483 :     if (i == -1) {
     698         4960 :         return;
     699              :     }
     700        14523 :     m_propertyFlagsList[i] = f;
     701              : }
     702              : 
     703              : //---------------------------------------------------------
     704              : //   getPropertyStyle
     705              : //---------------------------------------------------------
     706              : 
     707       242451 : Sid EngravingObject::getPropertyStyle(Pid id) const
     708              : {
     709      1783384 :     for (const StyledProperty& p : *m_elementStyle) {
     710      1708677 :         if (p.pid == id) {
     711       167744 :             return p.sid;
     712              :         }
     713              :     }
     714        74707 :     return Sid::NOSTYLE;
     715              : }
     716              : 
     717              : //---------------------------------------------------------
     718              : //   styleChanged
     719              : //---------------------------------------------------------
     720              : 
     721        11126 : void EngravingObject::styleChanged()
     722              : {
     723        43840 :     for (const StyledProperty& spp : *m_elementStyle) {
     724        32714 :         PropertyFlags f = propertyFlags(spp.pid);
     725        32714 :         if (f == PropertyFlags::STYLED) {
     726        32559 :             setProperty(spp.pid, styleValue(spp.pid, getPropertyStyle(spp.pid)));
     727              :         }
     728              :     }
     729        11126 : }
     730              : 
     731       104472 : const char* EngravingObject::typeName() const
     732              : {
     733       104472 :     return TConv::toXml(type()).ascii();
     734              : }
     735              : 
     736            0 : TranslatableString EngravingObject::typeUserName() const
     737              : {
     738            0 :     return TConv::capitalizedUserName(type());
     739              : }
     740              : 
     741            0 : String EngravingObject::translatedTypeUserName() const
     742              : {
     743            0 :     return typeUserName().translated();
     744              : }
     745              : 
     746       108863 : EID EngravingObject::eid() const
     747              : {
     748       108863 :     return masterScore()->eidRegister()->EIDFromItem(this);
     749              : }
     750              : 
     751        39831 : void EngravingObject::setEID(EID id) const
     752              : {
     753        39831 :     masterScore()->eidRegister()->registerItemEID(id, this);
     754        39831 : }
     755              : 
     756        70301 : EID EngravingObject::assignNewEID() const
     757              : {
     758        70301 :     return masterScore()->eidRegister()->newEIDForItem(this);
     759              : }
     760              : 
     761              : //---------------------------------------------------------
     762              : //   isSLineSegment
     763              : //---------------------------------------------------------
     764              : 
     765         6142 : bool EngravingObject::isSLineSegment() const
     766              : {
     767        12284 :     return isHairpinSegment() || isOttavaSegment() || isPedalSegment()
     768         6142 :            || isTrillSegment() || isVoltaSegment() || isTextLineSegment()
     769         6140 :            || isGlissandoSegment() || isLetRingSegment() || isVibratoSegment() || isPalmMuteSegment()
     770        12284 :            || isGradualTempoChangeSegment() || isWhammyBarSegment();
     771              : }
     772              : 
     773              : //---------------------------------------------------------
     774              : //   isText
     775              : //---------------------------------------------------------
     776              : 
     777      3003467 : bool EngravingObject::isTextBase() const
     778              : {
     779      3003467 :     return muse::contains(TEXTBASE_TYPES, type());
     780              : }
     781              : 
     782              : //---------------------------------------------------------
     783              : //   styleValue
     784              : //---------------------------------------------------------
     785              : 
     786      1234820 : PropertyValue EngravingObject::styleValue(Pid pid, Sid sid) const
     787              : {
     788      1234820 :     switch (propertyType(pid)) {
     789            0 :     case P_TYPE::ABSOLUTE:
     790            0 :         return style().styleAbsolute(sid);
     791          647 :     case P_TYPE::POINT: {
     792          647 :         PointF val = style().styleV(sid).value<PointF>();
     793          647 :         if (offsetIsSpatiumDependent()) {
     794          647 :             val *= style().spatium();
     795          647 :             if (isEngravingItem()) {
     796          645 :                 const EngravingItem* e = toEngravingItem(this);
     797          645 :                 if (e->staff() && !e->systemFlag()) {
     798            3 :                     val *= e->staff()->staffMag(e->tick());
     799              :                 }
     800              :             }
     801              :         } else {
     802            0 :             val *= DPMM;
     803              :         }
     804          647 :         return val;
     805              :     }
     806      1234173 :     default:
     807      1234173 :         return style().styleV(sid);
     808              :     }
     809              : }
     810              : }
        

Generated by: LCOV version 2.0-1