Skip to content

Commit 19d5f80

Browse files
committed
Upgrade old settings key
1 parent 76612f9 commit 19d5f80

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/engraving/internal/engravingconfiguration.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ using namespace mu::engraving;
4343
static const Settings::Key DEFAULT_STYLE_FILE_PATH("engraving", "engraving/style/defaultStyleFile");
4444
static const Settings::Key PART_STYLE_FILE_PATH("engraving", "engraving/style/partStyleFile");
4545

46-
static const Settings::Key INVERT_SCORE_COLOR("engraving", "engraving/scoreColorInversion");
4746
static const Settings::Key SCORE_COLOR_INVERSION_MODE("engraving", "engraving/scoreColorInversionMode");
4847

4948
static const Settings::Key ALL_VOICES_COLOR("engraving", "engraving/colors/allVoicesColor");
@@ -86,17 +85,22 @@ void EngravingConfiguration::init()
8685
m_partStyleFilePathChanged.send(val.toPath());
8786
});
8887

89-
// TODO: How to upgrade old setting to new one?
90-
settings()->setDefaultValue(INVERT_SCORE_COLOR, Val(false));
91-
settings()->valueChanged(INVERT_SCORE_COLOR).onReceive(nullptr, [this](const Val&) {
92-
m_scoreInversionChanged.notify();
93-
});
94-
9588
settings()->setDefaultValue(SCORE_COLOR_INVERSION_MODE, Val(ScoreInversionMode::Disabled));
9689
settings()->valueChanged(SCORE_COLOR_INVERSION_MODE).onReceive(nullptr, [this](const Val&) {
9790
m_scoreInversionChanged.notify();
9891
});
9992

93+
// Upgrade old scoreColorInversion setting to new inversion mode
94+
{
95+
static const Settings::Key INVERT_SCORE_COLOR_deprecated("engraving", "engraving/scoreColorInversion");
96+
if (!settings()->contains(SCORE_COLOR_INVERSION_MODE) && settings()->contains(INVERT_SCORE_COLOR_deprecated)) {
97+
ScoreInversionMode mode
98+
= settings()->value(INVERT_SCORE_COLOR_deprecated).toBool() ? ScoreInversionMode::Always : ScoreInversionMode::Disabled;
99+
settings()->setSharedValue(SCORE_COLOR_INVERSION_MODE, Val(mode));
100+
settings()->remove(INVERT_SCORE_COLOR_deprecated);
101+
}
102+
}
103+
100104
for (voice_idx_t voice = 0; voice < VOICES; ++voice) {
101105
Settings::Key key("engraving", "engraving/colors/voice" + std::to_string(voice + 1));
102106

src/framework/global/settings.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ io::path_t Settings::filePath() const
6868
return m_settings->fileName();
6969
}
7070

71+
void Settings::remove(const Key& key)
72+
{
73+
#ifdef MUSE_MODULE_MULTIINSTANCES
74+
muse::mi::WriteResourceLockGuard resource_lock(multiInstancesProvider.get(), SETTINGS_RESOURCE_NAME);
75+
#endif
76+
m_settings->remove(QString::fromStdString(key.key));
77+
}
78+
79+
bool Settings::contains(const Key& key) const
80+
{
81+
#ifdef MUSE_MODULE_MULTIINSTANCES
82+
muse::mi::ReadResourceLockGuard resource_lock(multiInstancesProvider.get(), SETTINGS_RESOURCE_NAME);
83+
#endif
84+
return m_settings->contains(QString::fromStdString(key.key));
85+
}
86+
7187
const Settings::Items& Settings::items() const
7288
{
7389
return m_isTransactionStarted ? m_localSettings : m_items;

src/framework/global/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class Settings
112112

113113
io::path_t filePath() const;
114114

115+
void remove(const Key& key);
116+
bool contains(const Key& key) const;
117+
115118
private:
116119
Settings();
117120
~Settings();

0 commit comments

Comments
 (0)