Skip to content

Commit

Permalink
Merge pull request #16676 from RomanPudashkin/update_4.0.2
Browse files Browse the repository at this point in the history
update_4.0.2
  • Loading branch information
RomanPudashkin committed Mar 6, 2023
2 parents 769b3af + 15d2c68 commit dbe7c6d
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 44 deletions.
4 changes: 4 additions & 0 deletions src/converter/internal/compat/backendapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ RetVal<project::INotationProjectPtr> BackendApi::openProject(const io::path_t& p
}

notation->setViewMode(ViewMode::PAGE);
for (IExcerptNotationPtr excerpt : notationProject->masterNotation()->excerpts().val) {
excerpt->notation()->setViewMode(ViewMode::PAGE);
}

return RetVal<INotationProjectPtr>::make_ok(notationProject);
}
Expand Down Expand Up @@ -565,6 +568,7 @@ Ret BackendApi::doExportScorePartsPdfs(const IMasterNotationPtr masterNotation,
jsonForPdfs["scoreBin"] = QString::fromLatin1(scoreBin);

INotationPtrList notations;
notations.push_back(masterNotation->notation());

QJsonArray partsArray;
QJsonArray partsNamesArray;
Expand Down
2 changes: 0 additions & 2 deletions src/engraving/engravingproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ bool EngravingProject::writeMscz(MscWriter& writer, bool onlySelection, bool cre
m_masterScore->update();
}

m_isCorruptedUponLoading = false;

return ok;
}

Expand Down
13 changes: 9 additions & 4 deletions src/inspector/models/abstractinspectormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,15 @@ void AbstractInspectorModel::initPropertyItem(PropertyItem* propertyItem,
});
}

void AbstractInspectorModel::loadPropertyItem(PropertyItem* propertyItem,
std::function<QVariant(const QVariant&)> convertElementPropertyValueFunc)
void AbstractInspectorModel::loadPropertyItem(PropertyItem* propertyItem, ConvertPropertyValueFunc convertElementPropertyValueFunc)
{
if (!propertyItem || m_elementList.isEmpty()) {
loadPropertyItem(propertyItem, m_elementList, convertElementPropertyValueFunc);
}

void AbstractInspectorModel::loadPropertyItem(PropertyItem* propertyItem, const QList<EngravingItem*>& elements,
ConvertPropertyValueFunc convertElementPropertyValueFunc)
{
if (!propertyItem || elements.isEmpty()) {
return;
}

Expand All @@ -535,7 +540,7 @@ void AbstractInspectorModel::loadPropertyItem(PropertyItem* propertyItem,

bool isUndefined = false;

for (const mu::engraving::EngravingItem* element : m_elementList) {
for (const mu::engraving::EngravingItem* element : elements) {
IF_ASSERT_FAILED(element) {
continue;
}
Expand Down
5 changes: 4 additions & 1 deletion src/inspector/models/abstractinspectormodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ public slots:
PointFPropertyItem* buildPointFPropertyItem(const mu::engraving::Pid& pid, std::function<void(const mu::engraving::Pid propertyId,
const QVariant& newValue)> onPropertyChangedCallBack = nullptr);

void loadPropertyItem(PropertyItem* propertyItem, std::function<QVariant(const QVariant&)> convertElementPropertyValueFunc = nullptr);
using ConvertPropertyValueFunc = std::function<QVariant(const QVariant&)>;
void loadPropertyItem(PropertyItem* propertyItem, ConvertPropertyValueFunc convertElementPropertyValueFunc = nullptr);
void loadPropertyItem(PropertyItem* propertyItem, const QList<engraving::EngravingItem*>& elements,
ConvertPropertyValueFunc convertElementPropertyValueFunc = nullptr);

bool isNotationExisting() const;

Expand Down
51 changes: 24 additions & 27 deletions src/inspector/models/general/appearance/appearancesettingsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,35 @@ void AppearanceSettingsModel::createProperties()
m_color = buildPropertyItem(Pid::COLOR);
m_arrangeOrder = buildPropertyItem(Pid::Z);
m_offset = buildPointFPropertyItem(Pid::OFFSET, [this](const mu::engraving::Pid, const QVariant& newValue) {
onOffsetChanged(newValue);
setPropertyValue(m_elementsForOffsetProperty, Pid::OFFSET, newValue);
});
}

void AppearanceSettingsModel::requestElements()
{
m_elementList = m_repository->takeAllElements();

static const std::unordered_set<ElementType> applyOffsetToChordTypes {
ElementType::NOTE,
ElementType::STEM,
ElementType::HOOK,
};

QSet<EngravingItem*> elementsForOffsetProperty;

for (EngravingItem* element : m_elementList) {
if (!mu::contains(applyOffsetToChordTypes, element->type())) {
elementsForOffsetProperty.insert(element);
continue;
}

EngravingItem* parent = element->parentItem();
if (parent && parent->isChord()) {
elementsForOffsetProperty.insert(parent);
}
}

m_elementsForOffsetProperty = elementsForOffsetProperty.values();
}

void AppearanceSettingsModel::loadProperties()
Expand Down Expand Up @@ -110,37 +132,12 @@ void AppearanceSettingsModel::loadProperties(const PropertyIdSet& propertyIdSet)
}

if (mu::contains(propertyIdSet, Pid::OFFSET)) {
loadPropertyItem(m_offset);
loadPropertyItem(m_offset, m_elementsForOffsetProperty);
}

emit isSnappedToGridChanged(isSnappedToGrid());
}

void AppearanceSettingsModel::onOffsetChanged(const QVariant& offset)
{
QList<EngravingItem*> items;

static const std::unordered_set<ElementType> applyOffsetToChordTypes {
ElementType::NOTE,
ElementType::STEM,
ElementType::HOOK,
};

for (EngravingItem* item : m_elementList) {
if (!mu::contains(applyOffsetToChordTypes, item->type())) {
items.push_back(item);
continue;
}

EngravingItem* parent = item->parentItem();
if (parent && parent->isChord()) {
items.push_back(parent);
}
}

setPropertyValue(items, Pid::OFFSET, offset);
}

Page* AppearanceSettingsModel::page() const
{
return toPage(m_elementList.first()->findAncestor(ElementType::PAGE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public slots:
private:
void onNotationChanged(const mu::engraving::PropertyIdSet& changedPropertyIdSet,
const mu::engraving::StyleIdSet& changedStyleIdSet) override;
void onOffsetChanged(const QVariant& offset);

void loadProperties(const mu::engraving::PropertyIdSet& allowedPropertyIdSet);

mu::engraving::Page* page() const;
Expand All @@ -88,6 +86,8 @@ public slots:
PropertyItem* m_color = nullptr;
PropertyItem* m_arrangeOrder = nullptr;
PointFPropertyItem* m_offset = nullptr;

QList<engraving::EngravingItem*> m_elementsForOffsetProperty;
};
}

Expand Down
21 changes: 19 additions & 2 deletions src/inspector/models/general/generalsettingsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,31 @@ void GeneralSettingsModel::createProperties()
onVisibleChanged(newValue.toBool());
});

m_isSmall = buildPropertyItem(Pid::SMALL, [this](const mu::engraving::Pid, const QVariant& newValue) {
setPropertyValue(m_elementsForIsSmallProperty, Pid::SMALL, newValue.toBool());
});

m_isAutoPlaceAllowed = buildPropertyItem(Pid::AUTOPLACE);
m_isPlayable = buildPropertyItem(Pid::PLAY);
m_isSmall = buildPropertyItem(Pid::SMALL);
}

void GeneralSettingsModel::requestElements()
{
m_elementList = m_repository->takeAllElements();

QSet<EngravingItem*> elementsForIsSmallProperty;

for (EngravingItem* element : m_elementList) {
EngravingItem* chord = element->findAncestor(ElementType::CHORD);

if (chord) {
elementsForIsSmallProperty.insert(chord);
} else {
elementsForIsSmallProperty.insert(element);
}
}

m_elementsForIsSmallProperty = elementsForIsSmallProperty.values();
}

void GeneralSettingsModel::loadProperties()
Expand Down Expand Up @@ -98,7 +115,7 @@ void GeneralSettingsModel::loadProperties(const mu::engraving::PropertyIdSet& pr
}

if (mu::contains(propertyIdSet, Pid::SMALL)) {
loadPropertyItem(m_isSmall);
loadPropertyItem(m_isSmall, m_elementsForIsSmallProperty);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/inspector/models/general/generalsettingsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public slots:

PlaybackProxyModel* m_playbackProxyModel = nullptr;
AppearanceSettingsModel* m_appearanceSettingsModel = nullptr;

QList<engraving::EngravingItem*> m_elementsForIsSmallProperty;
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/playback/internal/playbackcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ void PlaybackController::init()
globalContext()->currentProjectChanged().onNotify(this, [this]() {
if (m_currentSequenceId != -1) {
resetCurrentSequence();
}

if (!globalContext()->currentProject()) {
return;
}

Expand Down
38 changes: 38 additions & 0 deletions src/project/internal/exportprojectscenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "async/async.h"

#include "translation.h"
#include "defer.h"
#include "log.h"

using namespace mu::project;
Expand Down Expand Up @@ -113,6 +114,15 @@ bool ExportProjectScenario::exportScores(const notation::INotationPtrList& notat
}
}

// Backup view modes
std::vector<ViewMode> viewModes = this->viewModes(notations);
setViewModes(notations, ViewMode::PAGE);

DEFER {
// Restore view modes
setViewModes(notations, viewModes);
};

bool isCreatingOnlyOneFile = this->isCreatingOnlyOneFile(notations, unitType);

// If isCreatingOnlyOneFile, the save dialog has already asked whether to replace
Expand Down Expand Up @@ -361,3 +371,31 @@ void ExportProjectScenario::openFolder(const io::path_t& path) const
LOGE() << "Could not open folder: " << path.toQString();
}
}

std::vector<ViewMode> ExportProjectScenario::viewModes(const notation::INotationPtrList& notations) const
{
std::vector<ViewMode> modes;
for (INotationPtr notation : notations) {
modes.push_back(notation->painting()->viewMode());
}

return modes;
}

void ExportProjectScenario::setViewModes(const notation::INotationPtrList& notations,
const std::vector<notation::ViewMode>& viewModes) const
{
IF_ASSERT_FAILED(notations.size() == viewModes.size()) {
return;
}

for (size_t i = 0; i < notations.size(); ++i) {
notations[i]->painting()->setViewMode(viewModes[i]);
}
}

void ExportProjectScenario::setViewModes(const notation::INotationPtrList& notations, ViewMode viewMode) const
{
std::vector<notation::ViewMode> modes(notations.size(), viewMode);
setViewModes(notations, modes);
}
4 changes: 4 additions & 0 deletions src/project/internal/exportprojectscenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class ExportProjectScenario : public IExportProjectScenario, public async::Async

void openFolder(const io::path_t& path) const;

std::vector<notation::ViewMode> viewModes(const notation::INotationPtrList& notations) const;
void setViewModes(const notation::INotationPtrList& notations, const std::vector<notation::ViewMode>& viewModes) const;
void setViewModes(const notation::INotationPtrList& notations, notation::ViewMode viewMode) const;

mutable FileConflictPolicy m_fileConflictPolicy = FileConflictPolicy::Undefined;
mutable INotationWriterPtr m_currentWriter;
mutable std::string m_currentSuffix;
Expand Down
12 changes: 6 additions & 6 deletions src/project/internal/projectactionscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,13 @@ bool ProjectActionsController::askIfUserAgreesToSaveCorruptedScore(const SaveLoc
if (newlyCreated) {
showErrCorruptedScoreCannotBeSaved(location, errorText);
} else {
warnCorruptedScoreCannotBeSavedOnCloud(errorText, newlyCreated);
warnCorruptedScoreCannotBeSavedOnCloud(errorText, !newlyCreated);
}

return false;
}
case SaveLocationType::Local:
return askIfUserAgreesToSaveCorruptedScoreLocally(errorText, newlyCreated);
return askIfUserAgreesToSaveCorruptedScoreLocally(errorText, !newlyCreated);
case SaveLocationType::Undefined:
return false;
}
Expand All @@ -972,15 +972,15 @@ void ProjectActionsController::warnCorruptedScoreCannotBeSavedOnCloud(const std:
IInteractive::ButtonDatas buttons;
buttons.push_back(interactive()->buttonData(IInteractive::Button::Cancel));

IInteractive::ButtonData saveCopyBtn(IInteractive::Button::CustomButton, trc("project", "Save as…"), canRevert /*accent*/);
IInteractive::ButtonData saveCopyBtn(IInteractive::Button::CustomButton, trc("project", "Save as…"), !canRevert /*accent*/);
buttons.push_back(saveCopyBtn);

int defaultBtn = saveCopyBtn.btn;

IInteractive::ButtonData revertToLastSavedBtn(saveCopyBtn.btn + 1, trc("project", "Revert to last saved"),
true /*accent*/);

if (!canRevert) {
if (canRevert) {
buttons.push_back(revertToLastSavedBtn);
defaultBtn = revertToLastSavedBtn.btn;
}
Expand All @@ -999,8 +999,8 @@ bool ProjectActionsController::askIfUserAgreesToSaveCorruptedScoreLocally(const
bool canRevert)
{
std::string title = trc("project", "This score has become corrupted and contains errors");
std::string body = canRevert ? trc("project", "You can continue saving it locally, although the file may become unusable. "
"You can try to fix the errors manually, or get help for this issue on musescore.org.")
std::string body = !canRevert ? trc("project", "You can continue saving it locally, although the file may become unusable. "
"You can try to fix the errors manually, or get help for this issue on musescore.org.")
: trc("project", "You can continue saving it locally, although the file may become unusable. "
"To preserve your score, revert to the last saved version, or fix the errors manually. "
"You can also get help for this issue on musescore.org.");
Expand Down

0 comments on commit dbe7c6d

Please sign in to comment.