Skip to content

Commit

Permalink
Implemented "migration dialog" v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereverzev committed Nov 30, 2020
1 parent 14523a5 commit 583c71c
Show file tree
Hide file tree
Showing 91 changed files with 1,154 additions and 404 deletions.
4 changes: 3 additions & 1 deletion global/settings/types/preferencekeys.h
Expand Up @@ -72,7 +72,9 @@
#define PREF_IMPORT_OVERTURE_CHARSET "import/overture/charset"
#define PREF_IMPORT_STYLE_STYLEFILE "import/style/styleFile"
#define PREF_IMPORT_COMPATIBILITY_RESET_ELEMENT_POSITIONS "import/compatibility/resetElementPositions"
#define PREF_IMPORT_SCORE_MIGRATION_ENABLED "import/compatibility/score_migration_enabled"
#define PREF_MIGRATION_DO_NOT_ASK_ME_AGAIN "import/compatibility/do_not_ask_me_again"
#define PREF_MIGRATION_APPLY_LELAND_STYLE "import/compatibility/apply_leland_style"
#define PREF_MIGRATION_APPLY_EDWIN_STYLE "import/compatibility/apply_edwin_style"
#define PREF_APP_PALETTESCALE "application/paletteScale"
#define PREF_IO_ALSA_DEVICE "io/alsa/device"
#define PREF_IO_ALSA_FRAGMENTS "io/alsa/fragments"
Expand Down
1 change: 1 addition & 0 deletions libmscore/mscore.h
Expand Up @@ -311,6 +311,7 @@ class MScore {
static void init();

static const MStyle& baseStyle() { return _baseStyle; }
static void setBaseStyle(const MStyle& style) { _baseStyle = style; }
static MStyle& defaultStyle() { return _defaultStyle; }
static const MStyle* defaultStyleForParts() { return _defaultStyleForParts; }

Expand Down
18 changes: 16 additions & 2 deletions libmscore/score.cpp
Expand Up @@ -4788,9 +4788,23 @@ QVariant Score::propertyDefault(Pid /*id*/) const
// setStyle
//---------------------------------------------------------

void Score::setStyle(const MStyle& s)
void Score::setStyle(const MStyle& s, const bool overlap)
{
style() = s;
if (!overlap) {
style() = s;
return;
}

MStyle styleCopy = s;

for (int i = static_cast<int>(Sid::NOSTYLE) + 1; i < static_cast<int>(Sid::STYLES); i++) {
Sid sid = static_cast<Sid>(i);

if (!style().isDefault(sid))
styleCopy.set(sid, style().value(sid));
}

style() = styleCopy;
}

//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions libmscore/score.h
Expand Up @@ -885,8 +885,8 @@ class Score : public QObject, public ScoreElement {
virtual MStyle& style() { return _style; }
virtual const MStyle& style() const { return _style; }

void setStyle(const MStyle& s);
bool loadStyle(const QString&, bool ign = false);
void setStyle(const MStyle& s, const bool overlap = false);
bool loadStyle(const QString&, bool ign = false, const bool overlap = false);
bool saveStyle(const QString&);

QVariant styleV(Sid idx) const { return style().value(idx); }
Expand Down
4 changes: 2 additions & 2 deletions libmscore/scorefile.cpp
Expand Up @@ -703,13 +703,13 @@ bool Score::saveFile(QFileInfo& info)
// loadStyle
//---------------------------------------------------------

bool Score::loadStyle(const QString& fn, bool ign)
bool Score::loadStyle(const QString& fn, bool ign, const bool overlap)
{
QFile f(fn);
if (f.open(QIODevice::ReadOnly)) {
MStyle st = style();
if (st.load(&f, ign)) {
undo(new ChangeStyle(this, st));
undo(new ChangeStyle(this, st, overlap));
return true;
}
else {
Expand Down
109 changes: 59 additions & 50 deletions libmscore/style.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion libmscore/style.h
Expand Up @@ -1403,7 +1403,7 @@ enum class Sid {
tupletMinDistance,

autoplaceEnabled,
qualityUpgradeAllowed,
usePre_3_6_defaults,

STYLES
///\}
Expand Down Expand Up @@ -1442,6 +1442,7 @@ class MStyle {

bool load(QFile* qf, bool ign = false);
void load(XmlReader& e);
void applyNewDefaults(const MStyle& other);
void save(XmlWriter& xml, bool optimize);
bool readProperties(XmlReader&);
bool readStyleValCompat(XmlReader&);
Expand Down
13 changes: 10 additions & 3 deletions libmscore/undo.cpp
Expand Up @@ -1637,8 +1637,8 @@ void ChangePart::flip(EditData*)
// ChangeStyle
//---------------------------------------------------------

ChangeStyle::ChangeStyle(Score* s, const MStyle& st)
: score(s), style(st)
ChangeStyle::ChangeStyle(Score* s, const MStyle& st, const bool overlapOnly)
: score(s), style(st), overlap(overlapOnly)
{
}

Expand All @@ -1655,11 +1655,18 @@ void ChangeStyle::flip(EditData*)
if (score->styleV(Sid::MusicalSymbolFont) != style.value(Sid::MusicalSymbolFont)) {
score->setScoreFont(ScoreFont::fontFactory(style.value(Sid::MusicalSymbolFont).toString()));
}
score->setStyle(style);

score->setStyle(style, overlap);
score->styleChanged();
style = tmp;
}

void ChangeStyle::undo(EditData* ed)
{
overlap = false;
UndoCommand::undo(ed);
}

//---------------------------------------------------------
// ChangeStyleVal::flip
//---------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion libmscore/undo.h
Expand Up @@ -677,10 +677,12 @@ class ChangePart : public UndoCommand {
class ChangeStyle : public UndoCommand {
Score* score;
MStyle style;
bool overlap = false;
void flip(EditData*) override;
void undo(EditData*) override;

public:
ChangeStyle(Score*, const MStyle&);
ChangeStyle(Score*, const MStyle&, const bool overlapOnly = false);
UNDO_NAME("ChangeStyle")
};

Expand Down
14 changes: 8 additions & 6 deletions mscore/CMakeLists.txt
Expand Up @@ -186,9 +186,10 @@ add_library(mscoreapp STATIC
templateBrowser.h textcursor.h textpalette.h texttools.h timedialog.h timeline.h timesigproperties.h
toolbarEditor.h toolbuttonmenu.h transposedialog.h tremolobarcanvas.h realizeharmonydialog.h
tupletdialog.h updatechecker.h waveview.h webpage.h workspace.h migration/scoremigrationdialog.h
migration/scoremigrationdialogmodel.h migration/scoremigrator_3_6.h migration/handlers/instrumentorderinghandler.h
migration/handlers/staffverticaljustificationhandler.h migration/handlers/resetallelementspositionshandler.h
migration/handlers/firstsystemindentationhandler.h
migration/scoremigrationdialogmodel.h migration/scoremigrator_3_6.h
migration/handlers/resetallelementspositionshandler.h
migration/handlers/styledefaultshandler.h migration/handlers/lelandstylehandler.h
migration/handlers/edwinstylehandler.h

recordbutton.h greendotbutton prefsdialog.h prefsdialog.cpp
stringutils.h stringutils.cpp
Expand Down Expand Up @@ -261,9 +262,10 @@ add_library(mscoreapp STATIC
script/script.cpp script/scriptentry.cpp script/testscript.cpp script/recorderwidget.cpp
qml/msqmlengine.cpp qml/nativemenu.cpp qml/nativetooltip.cpp
qmldockwidget.cpp migration/scoremigrationdialog.cpp migration/scoremigrationdialogmodel.cpp
migration/scoremigrator_3_6.cpp migration/handlers/instrumentorderinghandler.cpp
migration/handlers/staffverticaljustificationhandler.cpp migration/handlers/resetallelementspositionshandler.cpp
migration/handlers/firstsystemindentationhandler.cpp
migration/scoremigrator_3_6.cpp
migration/handlers/resetallelementspositionshandler.cpp
migration/handlers/styledefaultshandler.cpp migration/handlers/lelandstylehandler.cpp
migration/handlers/edwinstylehandler.cpp

${CLOUD_SRC}
${IMPORTMIDIUI_SRC}
Expand Down
24 changes: 24 additions & 0 deletions mscore/file.cpp
Expand Up @@ -93,6 +93,11 @@
#include "libmscore/chordlist.h"
#include "libmscore/mscore.h"
#include "thirdparty/qzip/qzipreader_p.h"
#include "migration/scoremigrator_3_6.h"
#include "migration/handlers/styledefaultshandler.h"
#include "migration/handlers/lelandstylehandler.h"
#include "migration/handlers/edwinstylehandler.h"
#include "migration/handlers/resetallelementspositionshandler.h"


namespace Ms {
Expand Down Expand Up @@ -2273,6 +2278,24 @@ Score::FileError readScore(MasterScore* score, QString name, bool ignoreVersionE
score->setCreated(true); // force save as for imported files
}

ScoreMigrator_3_6 migrator;

migrator.registerHandler(new StyleDefaultsHandler());

if (Ms::preferences.getBool(PREF_MIGRATION_DO_NOT_ASK_ME_AGAIN)) {

if (Ms::preferences.getBool(PREF_MIGRATION_APPLY_LELAND_STYLE))
migrator.registerHandler(new LelandStyleHandler());

if (Ms::preferences.getBool(PREF_MIGRATION_APPLY_EDWIN_STYLE))
migrator.registerHandler(new EdwinStyleHandler());

if (Ms::preferences.getString(PREF_IMPORT_COMPATIBILITY_RESET_ELEMENT_POSITIONS).contains("Yes"))
migrator.registerHandler(new ResetAllElementsPositionsHandler());
}

migrator.migrateScore(score);

for (Part* p : score->parts()) {
p->updateHarmonyChannels(false);
}
Expand All @@ -2287,6 +2310,7 @@ Score::FileError readScore(MasterScore* score, QString name, bool ignoreVersionE
score->updateExpressive(MuseScore::synthesizer("Fluid"));
score->setSaved(false);
score->update();
score->styleChanged();

if (!ignoreVersionError && !MScore::noGui)
if (!score->sanityCheck(QString()))
Expand Down
9 changes: 9 additions & 0 deletions mscore/migration/handlers/edwinstylehandler.cpp
@@ -0,0 +1,9 @@
#include "edwinstylehandler.h"

bool EdwinStyleHandler::handle(Ms::Score* score)
{
if (!score)
return false;

return score->loadStyle(":/styles/Edwin.mss", /*ign*/false, /*overlap*/true);
}
14 changes: 14 additions & 0 deletions mscore/migration/handlers/edwinstylehandler.h
@@ -0,0 +1,14 @@
#ifndef EDWINSTYLEHANDLER_H
#define EDWINSTYLEHANDLER_H

#include "migration/iscoremigrationhandler.h"

class EdwinStyleHandler : public IScoreMigrationHandler
{
public:
EdwinStyleHandler() = default;

bool handle(Ms::Score* score) override;
};

#endif // EDWINSTYLEHANDLER_H
11 changes: 0 additions & 11 deletions mscore/migration/handlers/firstsystemindentationhandler.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions mscore/migration/handlers/firstsystemindentationhandler.h

This file was deleted.

8 changes: 0 additions & 8 deletions mscore/migration/handlers/instrumentorderinghandler.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions mscore/migration/handlers/instrumentorderinghandler.h

This file was deleted.

9 changes: 9 additions & 0 deletions mscore/migration/handlers/lelandstylehandler.cpp
@@ -0,0 +1,9 @@
#include "lelandstylehandler.h"

bool LelandStyleHandler::handle(Ms::Score* score)
{
if (!score)
return false;

return score->loadStyle(":/styles/Leland.mss", /*ign*/false, /*overlap*/true);
}
14 changes: 14 additions & 0 deletions mscore/migration/handlers/lelandstylehandler.h
@@ -0,0 +1,14 @@
#ifndef LELANDSTYLEHANDLER_H
#define LELANDSTYLEHANDLER_H

#include "migration/iscoremigrationhandler.h"

class LelandStyleHandler : public IScoreMigrationHandler
{
public:
LelandStyleHandler() = default;

bool handle(Ms::Score* score) override;
};

#endif // LELANDSTYLEHANDLER_H
11 changes: 0 additions & 11 deletions mscore/migration/handlers/staffverticaljustificationhandler.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions mscore/migration/handlers/staffverticaljustificationhandler.h

This file was deleted.

31 changes: 31 additions & 0 deletions mscore/migration/handlers/styledefaultshandler.cpp
@@ -0,0 +1,31 @@
#include "styledefaultshandler.h"

#include <QFile>

bool StyleDefaultsHandler::handle(Ms::Score* score)
{
if (!score)
return false;

if (!score->styleB(Ms::Sid::usePre_3_6_defaults) && score->mscVersion() < Ms::MSCVERSION)
score->style().set(Ms::Sid::usePre_3_6_defaults, true);

Ms::MStyle baseStyle;

if (score->styleB(Ms::Sid::usePre_3_6_defaults)) {
QFile oldDefaultsFile(":/styles/Pre-3.6-defaults.mss");

if (!oldDefaultsFile.open(QIODevice::ReadOnly))
return false;

baseStyle.load(&oldDefaultsFile);

score->style().applyNewDefaults(baseStyle);
}

QVariant lul = baseStyle.value(Ms::Sid::pageTwosided);

Ms::MScore::setBaseStyle(baseStyle);

return true;
}
14 changes: 14 additions & 0 deletions mscore/migration/handlers/styledefaultshandler.h
@@ -0,0 +1,14 @@
#ifndef OLDSCOREHANDLER_H
#define OLDSCOREHANDLER_H

#include "migration/iscoremigrationhandler.h"

class StyleDefaultsHandler : public IScoreMigrationHandler
{
public:
StyleDefaultsHandler() = default;

bool handle(Ms::Score* score) override;
};

#endif // OLDSCOREHANDLER_H

0 comments on commit 583c71c

Please sign in to comment.