Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11565 confirmation dialog for reset preferences and fixes #25400

Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d755e82
#11565: Added a confirmation dialog for when the "Reset preferences" …
krasko78 Oct 25, 2024
f35ac21
#11565: Made the General page update upon Reset Preferences
krasko78 Oct 26, 2024
ef4f7bd
#11565: Made the Canvas page update upon Reset Preferences
krasko78 Oct 26, 2024
7093590
#11565: Made the Save & Publish page update upon Reset Preferences
krasko78 Oct 26, 2024
a57fe6f
#11565: Made the Note Input page update on Reset Preferences
krasko78 Oct 26, 2024
97fcf55
#11565: Made the Braille page update upon Reset Preferences
krasko78 Oct 26, 2024
de14305
#11565: Made the Advanced page update upon Reset Preferences
krasko78 Oct 27, 2024
3efe3c3
#11565: Made the Update page update on Reset Preferences
krasko78 Oct 27, 2024
0e162bb
#11565: Made the Import page update upon Reset Preferences
krasko78 Oct 28, 2024
0354323
#11565: Made the MIDI Mappings page update on Reset Preferences
krasko78 Oct 28, 2024
6505a2c
#11565: Made the Audio & MIDI page update on Reset Preferences
krasko78 Oct 28, 2024
85e4df8
Made the Score page update on Reset Preferences
krasko78 Oct 31, 2024
65dfd57
#11565: Added "This action cannot be undone." to the confirmation dia…
krasko78 Oct 31, 2024
5644455
#11565: Refinements to the resetting of the General page
krasko78 Oct 31, 2024
761d0b5
#11565: Refinements to the resetting of the Canvas page
krasko78 Oct 31, 2024
831cac7
#11565: Refinements to the resetting of the Note input page
krasko78 Oct 31, 2024
2ba60a9
#11565: Refinements to the resetting of the Advanced page
krasko78 Nov 1, 2024
3d9a024
#11565: Refinements to the resetting of the Import page
krasko78 Nov 1, 2024
9550b82
#11565: Refinements to the resetting of the Score page
krasko78 Nov 1, 2024
9182f7c
#11565: Fixing the coding style
krasko78 Nov 1, 2024
9e4d37e
#11565: Fixing a conflict with DEFAULT_DEVICE_ID (failing Linux build…
krasko78 Nov 1, 2024
8072952
#11565: Fixing the tests
krasko78 Nov 1, 2024
628dfa7
#11565: Fixing the tests
krasko78 Nov 1, 2024
ebea4ba
Merge branch 'master' into 11565-ConfirmationDialogForResetPreference…
krasko78 Nov 18, 2024
0194b2d
11565: Minor improvements
krasko78 Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/appshell/iappshellconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define MU_APPSHELL_IAPPSHELLCONFIGURATION_H

#include "modularity/imoduleinterface.h"
#include "types/retval.h"
#include "types/ret.h"

#include "io/path.h"
#include "appshelltypes.h"
Expand All @@ -42,9 +42,11 @@ class IAppShellConfiguration : MODULE_EXPORT_INTERFACE

virtual StartupModeType startupModeType() const = 0;
virtual void setStartupModeType(StartupModeType type) = 0;
virtual muse::async::Notification startupModeTypeChanged() const = 0;

virtual muse::io::path_t startupScorePath() const = 0;
virtual void setStartupScorePath(const muse::io::path_t& scorePath) = 0;
virtual muse::async::Notification startupScorePathChanged() const = 0;

virtual muse::io::path_t userDataPath() const = 0;

Expand Down
17 changes: 17 additions & 0 deletions src/appshell/internal/appshellconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ void AppShellConfiguration::init()
settings()->setDefaultValue(HAS_COMPLETED_FIRST_LAUNCH_SETUP, Val(false));

settings()->setDefaultValue(STARTUP_MODE_TYPE, Val(StartupModeType::StartEmpty));
settings()->valueChanged(STARTUP_MODE_TYPE).onReceive(this, [this](const Val&) {
m_startupModeTypeChanged.notify();
});

settings()->setDefaultValue(STARTUP_SCORE_PATH, Val(projectConfiguration()->myFirstProjectPath().toStdString()));
settings()->valueChanged(STARTUP_SCORE_PATH).onReceive(this, [this](const Val&) {
m_startupScorePathChanged.notify();
});

fileSystem()->makePath(sessionDataPath());
}
Expand All @@ -88,6 +95,11 @@ void AppShellConfiguration::setStartupModeType(StartupModeType type)
settings()->setSharedValue(STARTUP_MODE_TYPE, Val(type));
}

async::Notification AppShellConfiguration::startupModeTypeChanged() const
{
return m_startupModeTypeChanged;
}

muse::io::path_t AppShellConfiguration::startupScorePath() const
{
return settings()->value(STARTUP_SCORE_PATH).toString();
Expand All @@ -98,6 +110,11 @@ void AppShellConfiguration::setStartupScorePath(const muse::io::path_t& scorePat
settings()->setSharedValue(STARTUP_SCORE_PATH, Val(scorePath.toStdString()));
}

async::Notification AppShellConfiguration::startupScorePathChanged() const
{
return m_startupScorePathChanged;
}

muse::io::path_t AppShellConfiguration::userDataPath() const
{
return globalConfiguration()->userDataPath();
Expand Down
5 changes: 5 additions & 0 deletions src/appshell/internal/appshellconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class AppShellConfiguration : public IAppShellConfiguration, public muse::Inject

StartupModeType startupModeType() const override;
void setStartupModeType(StartupModeType type) override;
muse::async::Notification startupModeTypeChanged() const override;

muse::io::path_t startupScorePath() const override;
void setStartupScorePath(const muse::io::path_t& scorePath) override;
muse::async::Notification startupScorePathChanged() const override;

muse::io::path_t userDataPath() const override;

Expand Down Expand Up @@ -111,6 +113,9 @@ class AppShellConfiguration : public IAppShellConfiguration, public muse::Inject
muse::io::paths_t parseSessionProjectsPaths(const QByteArray& json) const;

QString m_preferencesDialogCurrentPageId;

muse::async::Notification m_startupModeTypeChanged;
muse::async::Notification m_startupScorePathChanged;
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/appshell/qml/Preferences/BraillePreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ PreferencesPage {
id: preferencesModel
}

Component.onCompleted: {
preferencesModel.load()
}

Column {
width: parent.width
spacing: root.sectionsSpacing
Expand Down
5 changes: 5 additions & 0 deletions src/appshell/qml/Preferences/ImportPreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ PreferencesPage {
spacing: root.sectionsSpacing

ImportStyleSection {
id: importStyleSection
styleFileImportPath: importPreferencesModel.styleFileImportPath
fileChooseTitle: importPreferencesModel.styleChooseTitle()
filePathFilter: importPreferencesModel.stylePathFilter()
Expand Down Expand Up @@ -145,4 +146,8 @@ PreferencesPage {
}
}
}

function reset() {
importStyleSection.reset()
}
}
4 changes: 4 additions & 0 deletions src/appshell/qml/Preferences/NoteInputPreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import "internal"
PreferencesPage {
id: root

Component.onCompleted: {
noteInputModel.load()
}

NoteInputPreferencesModel {
id: noteInputModel
}
Expand Down
4 changes: 4 additions & 0 deletions src/appshell/qml/Preferences/PreferencesDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ StyledDialogView {
navigation.order: 100000

onRevertFactorySettingsRequested: {
if (!preferencesModel.askForConfirmationOfPreferencesReset()) {
return;
}

var pages = preferencesModel.availablePages()

for (var i in pages) {
Expand Down
4 changes: 4 additions & 0 deletions src/appshell/qml/Preferences/UpdatePreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ PreferencesPage {
id: updateModel
}

Component.onCompleted: {
updateModel.load()
}

Column {
width: parent.width
spacing: root.sectionsSpacing
Expand Down
11 changes: 8 additions & 3 deletions src/appshell/qml/Preferences/internal/ImportStyleSection.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ BaseSection {
QtObject {
id: prv

property bool useStyleFile: root.styleFileImportPath !== ""
property bool useStyleFileExplicitlySet: root.styleFileImportPath !== ""
Copy link
Contributor Author

@krasko78 krasko78 Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were needed to properly update the Styles used for import controls on the Import page and fix these two bugs:
1. Open the Preferences dialog and navigate to the Import page.
2. Change Style used for import from Built-in style to Use style file.
3. Type a file if you want or skip this step.
4. Click Reset Preferences without closing the dialog.
Result: the Use style file radiobutton remains selected.

AND:
1. Open the Preferences dialog and navigate to the Import page.
2. Change Style used for import from Built-in style to Use style file.
3. Type something in the file textbox.
4. Delete the text in the file textbox.
Result: the Built-in style radiobutton becomes selected.

property bool useStyleFile: prv.useStyleFileExplicitlySet || root.styleFileImportPath !== ""
}

function reset() {
prv.useStyleFileExplicitlySet = false
}

RoundedRadioButton {
Expand All @@ -57,7 +62,7 @@ BaseSection {
navigation.column: 0

onToggled: {
prv.useStyleFile = false
prv.useStyleFileExplicitlySet = false
root.styleFileImportPathChangeRequested("")
}
}
Expand All @@ -81,7 +86,7 @@ BaseSection {
navigation.column: 0

onToggled: {
prv.useStyleFile = true
prv.useStyleFileExplicitlySet = true
}
}

Expand Down
40 changes: 34 additions & 6 deletions src/appshell/view/preferences/advancedpreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool AdvancedPreferencesModel::setData(const QModelIndex& index, const QVariant&

switch (role) {
case ValueRole:
changeVal(index.row(), value);
changeVal(index.row(), Val::fromQVariant(value));
emit dataChanged(index, index, { ValueRole });
return true;
default:
Expand Down Expand Up @@ -96,28 +96,56 @@ void AdvancedPreferencesModel::load()
for (auto it = items.cbegin(); it != items.cend(); ++it) {
if (it->second.canBeManuallyEdited) {
m_items << it->second;

muse::Settings::Key key = it->second.key;
settings()->valueChanged(key).onReceive(this, [this, key](const Val& val) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe each subsequent call to settings()->valueChanged(key).onReceive(this (with emphasis on the latter this) either overrides the previously registered callback or does nothing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate? Each subsequent call is for a different setting (key) => different notification channel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, you're definitely right!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Comments are always welcome. :)

QModelIndex index = findIndex(key);
if (!index.isValid() || m_items[index.row()].value == val) {
return;
}

changeModelVal(m_items[index.row()], val);
emit dataChanged(index, index, { ValueRole });
});
}
}

endResetModel();
}

void AdvancedPreferencesModel::changeVal(int index, QVariant newVal)
QModelIndex AdvancedPreferencesModel::findIndex(const muse::Settings::Key& key)
{
for (int i = 0; i < m_items.size(); ++i) {
if (m_items[i].key == key) {
return index(i, 0);
}
}
return QModelIndex();
}

void AdvancedPreferencesModel::changeVal(int index, const Val& newVal)
{
Settings::Item& item = m_items[index];
changeModelVal(item, newVal);
settings()->setSharedValue(item.key, item.value);
}

void AdvancedPreferencesModel::changeModelVal(Settings::Item& item, const Val& newVal)
{
if (item.value == newVal) {
return;
}
Val::Type type = item.value.type();
item.value = Val::fromQVariant(newVal);
item.value = newVal;
item.value.setType(type);

settings()->setSharedValue(item.key, item.value);
}

void AdvancedPreferencesModel::resetToDefault()
{
beginResetModel();

for (int i = 0; i < m_items.size(); ++i) {
changeVal(i, m_items[i].defaultValue.toQVariant());
changeVal(i, m_items[i].defaultValue);
}

endResetModel();
Expand Down
7 changes: 5 additions & 2 deletions src/appshell/view/preferences/advancedpreferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

#include <QAbstractListModel>

#include "async/asyncable.h"
#include "settings.h"

namespace mu::appshell {
class AdvancedPreferencesModel : public QAbstractListModel
class AdvancedPreferencesModel : public QAbstractListModel, public muse::async::Asyncable
{
Q_OBJECT

Expand All @@ -53,7 +54,9 @@ class AdvancedPreferencesModel : public QAbstractListModel
MaxValueRole
};

void changeVal(int index, QVariant newVal);
QModelIndex findIndex(const muse::Settings::Key& key);
void changeVal(int index, const muse::Val& newVal);
void changeModelVal(muse::Settings::Item& item, const muse::Val& newVal);
QString typeToString(muse::Val::Type type) const;

QList<muse::Settings::Item> m_items;
Expand Down
4 changes: 4 additions & 0 deletions src/appshell/view/preferences/audiomidipreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ void AudioMidiPreferencesModel::init()
emit midiOutputDeviceIdChanged();
});

midiConfiguration()->useMIDI20OutputChanged().onReceive(this, [this](bool) {
emit useMIDI20OutputChanged();
});

playbackConfiguration()->muteHiddenInstrumentsChanged().onReceive(this, [this](bool mute) {
emit muteHiddenInstrumentsChanged(mute);
});
Expand Down
15 changes: 15 additions & 0 deletions src/appshell/view/preferences/braillepreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ BraillePreferencesModel::BraillePreferencesModel(QObject* parent)
{
}

void BraillePreferencesModel::load()
{
brailleConfiguration()->braillePanelEnabledChanged().onNotify(this, [this]() {
emit braillePanelEnabledChanged(braillePanelEnabled());
});

brailleConfiguration()->intervalDirectionChanged().onNotify(this, [this]() {
emit intervalDirectionChanged(intervalDirection());
});

brailleConfiguration()->brailleTableChanged().onNotify(this, [this]() {
emit brailleTableChanged(brailleTable());
});
}

bool BraillePreferencesModel::braillePanelEnabled() const
{
return brailleConfiguration()->braillePanelEnabled();
Expand Down
5 changes: 4 additions & 1 deletion src/appshell/view/preferences/braillepreferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

#include <QObject>

#include "async/asyncable.h"
#include "modularity/ioc.h"
#include "braille/ibrailleconfiguration.h"

namespace mu::appshell {
class BraillePreferencesModel : public QObject, public muse::Injectable
class BraillePreferencesModel : public QObject, public muse::Injectable, public muse::async::Asyncable
{
Q_OBJECT

Expand All @@ -42,6 +43,8 @@ class BraillePreferencesModel : public QObject, public muse::Injectable
public:
explicit BraillePreferencesModel(QObject* parent = nullptr);

Q_INVOKABLE void load();

bool braillePanelEnabled() const;
QString brailleTable() const;
int intervalDirection() const;
Expand Down
26 changes: 19 additions & 7 deletions src/appshell/view/preferences/canvaspreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ void CanvasPreferencesModel::load()
setupConnections();
}

void CanvasPreferencesModel::setupConnections()
{
notationConfiguration()->defaultZoomChanged().onNotify(this, [this]() {
emit defaultZoomChanged();
});
notationConfiguration()->mouseZoomPrecisionChanged().onNotify(this, [this]() {
emit mouseZoomPrecisionChanged();
});
notationConfiguration()->canvasOrientation().ch.onReceive(this, [this](muse::Orientation) {
emit scrollPagesOrientationChanged();
});
notationConfiguration()->isLimitCanvasScrollAreaChanged().onNotify(this, [this]() {
emit limitScrollAreaChanged();
});
notationConfiguration()->selectionProximityChanged().onReceive(this, [this](int selectionProximity) {
emit selectionProximityChanged(selectionProximity);
});
}

QVariantList CanvasPreferencesModel::zoomTypes() const
{
QVariantList types = {
Expand Down Expand Up @@ -140,13 +159,6 @@ void CanvasPreferencesModel::setSelectionProximity(int proximity)
emit selectionProximityChanged(proximity);
}

void CanvasPreferencesModel::setupConnections()
{
notationConfiguration()->canvasOrientation().ch.onReceive(this, [this](muse::Orientation) {
emit scrollPagesOrientationChanged();
});
}

ZoomType CanvasPreferencesModel::defaultZoomType() const
{
return notationConfiguration()->defaultZoomType();
Expand Down
9 changes: 8 additions & 1 deletion src/appshell/view/preferences/generalpreferencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ void GeneralPreferencesModel::load()
languagesService()->needRestartToApplyLanguageChangeChanged().onReceive(this, [this](bool need) {
setIsNeedRestart(need);
});

configuration()->startupModeTypeChanged().onNotify(this, [this]() {
emit startupModesChanged();
});

configuration()->startupScorePathChanged().onNotify(this, [this]() {
emit startupModesChanged();
});
}

void GeneralPreferencesModel::checkUpdateForCurrentLanguage()
Expand Down Expand Up @@ -244,6 +252,5 @@ void GeneralPreferencesModel::setStartupScorePath(const QString& scorePath)
}

configuration()->setStartupScorePath(scorePath);

emit startupModesChanged();
}
Loading
Loading