LCOV - code coverage report
Current view: top level - muse/framework/global - settings.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 4 4
Test Date: 2026-11-19 04:14:36

            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) 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              : #pragma once
      24              : 
      25              : #include <string>
      26              : 
      27              : #include "types/val.h"
      28              : #include "async/channel.h"
      29              : #include "io/path.h"
      30              : 
      31              : #include "muse_framework_config.h"
      32              : #ifdef MUSE_MODULE_MULTIWINDOWS
      33              : #include "modularity/ioc.h"
      34              : #include "multiwindows/imultiwindowsprovider.h"
      35              : #endif
      36              : 
      37              : //! NOTE We are gradually abandoning Qt in non-GUI classes.
      38              : //! This settings interface is almost independent of Qt,
      39              : //! QSettings are used only in the implementation for compatibility with current settings.
      40              : //! Perhaps in the future this will be changed.
      41              : 
      42              : class QSettings;
      43              : 
      44              : namespace muse {
      45              : class Settings
      46              : {
      47              : #ifdef MUSE_MODULE_MULTIWINDOWS
      48              :     GlobalInject<muse::mi::IMultiWindowsProvider> multiwindowsProvider;
      49              : #endif
      50              : public:
      51              :     static Settings* instance();
      52              : 
      53              :     struct Key
      54              :     {
      55              :         std::string moduleName;
      56              :         std::string key;
      57              : 
      58          507 :         Key() = default;
      59              :         Key(std::string moduleName, std::string key);
      60              : 
      61              :         bool isNull() const;
      62              :         bool operator==(const Key& k) const;
      63              :         bool operator<(const Key& k) const;
      64              :     };
      65              : 
      66              :     struct Item
      67              :     {
      68              :         Key key;
      69              :         Val value;
      70              :         Val defaultValue;
      71              :         std::string description;
      72              : 
      73              :         bool canBeManuallyEdited = false;
      74              :         Val minValue;
      75              :         Val maxValue;
      76              : 
      77         3034 :         bool isNull() const { return key.isNull(); }
      78              :     };
      79              : 
      80              :     using Items = std::map<Key, Item>;
      81              : 
      82              :     const Items& items() const;
      83              : 
      84              :     //! NOTE Use the given directory instead of the default one, must be called before load
      85              :     void setDataPath(const io::path_t& path);
      86              : 
      87              :     void reload();
      88              :     void load();
      89              : 
      90              :     void reset(bool keepDefaultSettings = false, bool notifyAboutChanges = true, bool notifyOtherInstances = true);
      91              : 
      92              :     const Val& value(const Key& key) const;
      93              :     const Val& defaultValue(const Key& key) const;
      94              : 
      95              :     //! NOTE Will be write to global config and sync between all instances
      96              :     void setSharedValue(const Key& key, const Val& value);
      97              : 
      98              :     //! NOTE Will be write to global config and NOT sync between instances
      99              :     void setLocalValue(const Key& key, const Val& value);
     100              : 
     101              :     void setDefaultValue(const Key& key, const Val& value);
     102              : 
     103              :     void setDescription(const Key& key, const std::string& value);
     104              : 
     105              :     void setCanBeManuallyEdited(const Settings::Key& key, bool canBeManuallyEdited, const Val& minValue = Val(),
     106              :                                 const Val& maxValue = Val());
     107              : 
     108              :     void beginTransaction(bool notifyToOtherInstances = true);
     109              :     void commitTransaction(bool notifyToOtherInstances = true);
     110              :     void rollbackTransaction(bool notifyToOtherInstances = true);
     111              : 
     112              :     async::Channel<Val> valueChanged(const Key& key) const;
     113              : 
     114              :     io::path_t filePath() const;
     115              : 
     116              : private:
     117              :     Settings();
     118              :     ~Settings();
     119              : 
     120              :     Item& findItem(const Key& key) const;
     121              :     async::Channel<Val>& findChannel(const Key& key) const;
     122              : 
     123              :     void insertNewItem(const Key& key, const Val& value);
     124              : 
     125              :     Items readItems() const;
     126              :     void writeValue(const Key& key, const Val& value);
     127              : 
     128              :     io::path_t dataPath() const;
     129              :     QSettings* qsettings() const;
     130              : 
     131              :     mutable QSettings* m_settings = nullptr;
     132              :     io::path_t m_dataPath;
     133              :     mutable Items m_items;
     134              :     mutable Items m_localSettings;
     135              :     mutable bool m_isTransactionStarted = false;
     136              :     mutable std::map<Key, async::Channel<Val> > m_channels;
     137              : };
     138              : 
     139        41414 : inline Settings* settings()
     140              : {
     141        41414 :     return Settings::instance();
     142              : }
     143              : }
        

Generated by: LCOV version 2.0-1