LCOV - code coverage report
Current view: top level - src/engraving/dom - connector.h Coverage Total Hit
Test: filtered_coverage.info Lines: 90.0 % 10 9
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              : #ifndef MU_ENGRAVING_CONNECTOR_H
      24              : #define MU_ENGRAVING_CONNECTOR_H
      25              : 
      26              : #include "global/allocator.h"
      27              : 
      28              : #include "location.h"
      29              : #include "../types/types.h"
      30              : 
      31              : namespace mu::engraving {
      32              : class EngravingItem;
      33              : class EngravingObject;
      34              : class Score;
      35              : 
      36              : //---------------------------------------------------------
      37              : //   @@ ConnectorInfo
      38              : ///    Stores a general information on various connecting
      39              : ///    elements (currently only spanners) including their
      40              : ///    endpoints locations.
      41              : ///    Base class of helper classes used to read and write
      42              : ///    such elements.
      43              : //---------------------------------------------------------
      44              : 
      45              : class ConnectorInfo
      46              : {
      47            0 :     OBJECT_ALLOCATOR(engraving, ConnectorInfo)
      48              : 
      49              : public:
      50              :     ConnectorInfo(const EngravingItem* current, int track = -1, Fraction = { -1, 1 });
      51              :     ConnectorInfo(const Score* score, const Location& currentLocation);
      52         3903 :     virtual ~ConnectorInfo() = default;
      53              : 
      54              :     ConnectorInfo* prev() const { return m_prev; }
      55              :     ConnectorInfo* next() const { return m_next; }
      56              :     ConnectorInfo* start();
      57              :     ConnectorInfo* end();
      58              : 
      59         3902 :     ElementType type() const { return m_type; }
      60         3902 :     const Location& location() const { return m_currentLoc; }
      61              : 
      62              :     bool connect(ConnectorInfo* other);
      63              :     bool finished() const;
      64              : 
      65              :     // for reconnection of broken connectors
      66              :     int connectionDistance(const ConnectorInfo& c2) const;
      67              :     void forceConnect(ConnectorInfo* c2);
      68              : 
      69        16958 :     bool hasPrevious() const { return m_prevLoc.measure() != INT_MIN; }
      70        12432 :     bool hasNext() const { return m_nextLoc.measure() != INT_MIN; }
      71         3902 :     bool isStart() const { return !hasPrevious() && hasNext(); }
      72              :     bool isMiddle() const { return hasPrevious() && hasNext(); }
      73         1951 :     bool isEnd() const { return hasPrevious() && !hasNext(); }
      74              : 
      75              : protected:
      76              : 
      77              :     void updateLocation(const EngravingItem* e, Location& i, bool clipboardmode);
      78              :     void updateCurrentInfo(bool clipboardmode);
      79         7806 :     bool currentUpdated() const { return m_currentUpdated; }
      80         3903 :     void setCurrentUpdated(bool v) { m_currentUpdated = v; }
      81              : 
      82              :     ConnectorInfo* findFirst();
      83              :     const ConnectorInfo* findFirst() const;
      84              :     ConnectorInfo* findLast();
      85              :     const ConnectorInfo* findLast() const;
      86              : 
      87              :     ElementType m_type = ElementType::INVALID;
      88              :     Location m_currentLoc;
      89              :     Location m_prevLoc = Location::absolute();
      90              :     Location m_nextLoc = Location::absolute();
      91              : 
      92              :     ConnectorInfo* m_prev = nullptr;
      93              :     ConnectorInfo* m_next = nullptr;
      94              : 
      95              : private:
      96              :     bool finishedLeft() const;
      97              :     bool finishedRight() const;
      98              : 
      99              :     static int orderedConnectionDistance(const ConnectorInfo& c1, const ConnectorInfo& c2);
     100              : 
     101              :     const EngravingItem* m_current = nullptr;
     102              :     bool m_currentUpdated = false;
     103              :     const Score* m_score = nullptr;
     104              : };
     105              : } // namespace mu::engraving
     106              : #endif
        

Generated by: LCOV version 2.0-1