LCOV - code coverage report
Current view: top level - muse/framework/diagnostics - diagnosticutils.h Coverage Total Hit
Test: filtered_coverage.info Lines: 60.0 % 30 18
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-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              : #ifndef MUSE_DIAGNOSTICS_DIAGNOSTICUTILS_H
      23              : #define MUSE_DIAGNOSTICS_DIAGNOSTICUTILS_H
      24              : 
      25              : #include <QObject>
      26              : 
      27              : #include "types/uri.h"
      28              : #include "log.h"
      29              : 
      30              : namespace muse::diagnostics {
      31            9 : inline bool isDiagnosticObject(const QObject* obj, bool print = false)
      32              : {
      33            9 :     if (print) {
      34            0 :         LOGI() << "objectName: " << obj->objectName() << ", className: " << obj->metaObject()->className();
      35              :     }
      36            9 :     if (obj->objectName().toLower().contains("diagnostic")) {
      37            0 :         return true;
      38              :     }
      39            9 :     return false;
      40              : }
      41              : 
      42            9 : inline bool isDiagnosticChild(const QObject* obj, bool print = false)
      43              : {
      44           15 :     for (const QObject* ch : obj->children()) {
      45            6 :         if (isDiagnosticObject(ch, print)) {
      46            0 :             return true;
      47              :         }
      48              : 
      49            6 :         if (isDiagnosticChild(ch, print)) {
      50            0 :             return true;
      51              :         }
      52              :     }
      53              : 
      54            9 :     return false;
      55              : }
      56              : 
      57            3 : inline bool isDiagnosticParent(const QObject* obj, bool print = false)
      58              : {
      59            3 :     QObject* prn = obj->parent();
      60            3 :     if (!prn) {
      61            3 :         return false;
      62              :     }
      63              : 
      64            0 :     if (isDiagnosticObject(prn, print)) {
      65            0 :         return true;
      66              :     }
      67              : 
      68            0 :     return isDiagnosticParent(prn, print);
      69              : }
      70              : 
      71            3 : inline bool isDiagnosticHierarchy(const QObject* obj, bool print = false)
      72              : {
      73            3 :     if (isDiagnosticObject(obj, print)) {
      74            0 :         return true;
      75              :     }
      76            3 :     if (isDiagnosticParent(obj, print)) {
      77            0 :         return true;
      78              :     }
      79            3 :     if (isDiagnosticChild(obj, print)) {
      80            0 :         return true;
      81              :     }
      82            3 :     return false;
      83              : }
      84              : 
      85            0 : inline bool isDiagnosticsUri(const muse::Uri& uri)
      86              : {
      87            0 :     return QString::fromStdString(uri.toString()).startsWith("muse://diagnostics");
      88              : }
      89              : 
      90              : inline std::vector<muse::Uri> removeDiagnosticsUri(const std::vector<muse::Uri>& uris)
      91              : {
      92              :     std::vector<muse::Uri> nuris;
      93              :     for (const muse::Uri& uri : uris) {
      94              :         if (!isDiagnosticsUri(uri)) {
      95              :             nuris.push_back(uri);
      96              :         }
      97              :     }
      98              :     return nuris;
      99              : }
     100              : 
     101              : inline muse::Uri diagnosticCurrentUri(const std::vector<muse::Uri>& stack)
     102              : {
     103              :     std::vector<muse::Uri> uris = removeDiagnosticsUri(stack);
     104              :     if (!uris.empty()) {
     105              :         return uris.back();
     106              :     }
     107              :     return muse::Uri();
     108              : }
     109              : }
     110              : 
     111              : #endif // MUSE_DIAGNOSTICS_DIAGNOSTICUTILS_H
        

Generated by: LCOV version 2.0-1