LCOV - code coverage report
Current view: top level - src/engraving/api/v1 - excerpt.h Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 17 0
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_APIV1_EXCERPT_H
      24              : #define MU_ENGRAVING_APIV1_EXCERPT_H
      25              : 
      26              : #include <QQmlEngine>
      27              : #include <QQmlListProperty>
      28              : 
      29              : #include "engraving/dom/excerpt.h"
      30              : 
      31              : namespace mu::engraving::apiv1 {
      32              : class Score;
      33              : 
      34              : //---------------------------------------------------------
      35              : //   Excerpt
      36              : //    Wrapper class for Excerpt
      37              : //
      38              : //   This is based on the wrapper in scoreelement.h, which
      39              : //   we cannot use here, because mu::engraving::Excerpt is not derived
      40              : //   from mu::engraving::ScoreElement.
      41              : //   Since a plugin should never need to create an Excerpt
      42              : //   instance by itself, we don't care for Ownership here.
      43              : //---------------------------------------------------------
      44              : 
      45              : class Excerpt : public QObject
      46              : {
      47              :     Q_OBJECT
      48              :     /// The score object for this part
      49              :     Q_PROPERTY(apiv1::Score * partScore READ partScore)
      50              :     /// The title of this part
      51              :     Q_PROPERTY(QString title READ title)
      52              : 
      53              : protected:
      54              :     /// \cond MS_INTERNAL
      55              :     mu::engraving::Excerpt* const e;
      56              :     /// \endcond
      57              : 
      58              : public:
      59              :     /// \cond MS_INTERNAL
      60            0 :     Excerpt(mu::engraving::Excerpt* m_e = nullptr)
      61            0 :         : QObject(), e(m_e) {}
      62              :     Excerpt(const Excerpt&) = delete;
      63              :     Excerpt& operator=(const Excerpt&) = delete;
      64            0 :     virtual ~Excerpt() {}
      65              : 
      66              :     Score* partScore();
      67            0 :     QString title() { return e->name(); }
      68              :     /// \endcond
      69              : 
      70              :     /// Checks whether two variables represent the same object. \since MuseScore 3.3
      71            0 :     Q_INVOKABLE bool is(apiv1::Excerpt* other) { return other && e == other->e; }
      72              : };
      73              : 
      74              : //---------------------------------------------------------
      75              : //   wrap
      76              : ///   \cond PLUGIN_API \private \endcond
      77              : ///   \relates Excerpt
      78              : //---------------------------------------------------------
      79              : 
      80              : template<class Wrapper, class T>
      81            0 : Wrapper* excerptWrap(T* t)
      82              : {
      83            0 :     Wrapper* w = t ? new Wrapper(t) : nullptr;
      84              :     // All wrapper objects should belong to JavaScript code.
      85            0 :     QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
      86            0 :     return w;
      87              : }
      88              : 
      89              : extern Excerpt* excerptWrap(mu::engraving::Excerpt* e);
      90              : 
      91              : //---------------------------------------------------------
      92              : //   qml access to containers of Excerpt
      93              : //
      94              : //   QmlExcerptsListAccess provides a convenience interface
      95              : //   for QQmlListProperty providing read-only access to
      96              : //   plugins for Excerpts containers.
      97              : //
      98              : //   based on QmlListAccess in scoreelement.h
      99              : //---------------------------------------------------------
     100              : 
     101              : template<typename T, class Container>
     102              : class QmlExcerptsListAccess : public QQmlListProperty<T>
     103              : {
     104              : public:
     105            0 :     QmlExcerptsListAccess(QObject* obj, Container& container)
     106            0 :         : QQmlListProperty<T>(obj, &container, &count, &at) {}
     107              : 
     108            0 :     static qsizetype count(QQmlListProperty<T>* l)
     109              :     {
     110            0 :         return static_cast<Container*>(l->data)->size();
     111              :     }
     112              : 
     113            0 :     static T* at(QQmlListProperty<T>* l, qsizetype i)
     114              :     {
     115            0 :         return excerptWrap<T>(static_cast<Container*>(l->data)->at(i));
     116              :     }
     117              : };
     118              : 
     119              : template<typename T, class Container>
     120            0 : QmlExcerptsListAccess<T, Container> wrapExcerptsContainerProperty(const QObject* obj, Container& c)
     121              : {
     122            0 :     return QmlExcerptsListAccess<T, Container>(const_cast<QObject*>(obj), c);
     123              : }
     124              : }
     125              : 
     126              : #endif
        

Generated by: LCOV version 2.0-1