MuseScore/src/instrumentsscene/view/instrumentsettingsmodel.cpp
HemantAntony af078d7779 Fix #9745: Changed instrument connection to instrument title and instrument name
Prior to this commit, if you were to change the part name in the
instruments dialog, it would automatically get updated in the instrument
title (the text for the corresponding instrument button). However, with
this commit, this "connection" is changed to instrument name and the
instrument title, that is, if you now change the instrument name, the
same would be the instrument title. Also, this commit does not fix the
entire issue. Another problem mentioned in this issue had been fixed
earlier in a separate pull request #10014
2022-01-07 17:54:48 +05:30

177 lines
4.8 KiB
C++

/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "instrumentsettingsmodel.h"
#include "log.h"
#include "translation.h"
using namespace mu::instrumentsscene;
using namespace mu::notation;
using namespace mu::framework;
InstrumentSettingsModel::InstrumentSettingsModel(QObject* parent)
: QObject(parent)
{
}
void InstrumentSettingsModel::load(const QVariant& instrument)
{
if (!notationParts()) {
return;
}
QVariantMap map = instrument.toMap();
m_instrumentKey.partId = ID(map["partId"]);
m_instrumentKey.instrumentId = map["instrumentId"].toString();
const Part* part = notationParts()->part(m_instrumentKey.partId);
if (!part) {
return;
}
m_partName = part->partName();
m_instrumentName = part->instrument()->name();
m_instrumentAbbreviature = part->instrument()->abbreviature();
context()->currentNotationChanged().onNotify(this, [this]() {
emit isMainScoreChanged();
});
emit dataChanged();
}
void InstrumentSettingsModel::replaceInstrument()
{
if (!masterNotationParts()) {
return;
}
RetVal<Instrument> selectedInstrument = selectInstrumentsScenario()->selectInstrument(m_instrumentKey);
if (!selectedInstrument.ret) {
LOGE() << selectedInstrument.ret.toString();
return;
}
const Instrument& newInstrument = selectedInstrument.val;
masterNotationParts()->replaceInstrument(m_instrumentKey, newInstrument);
m_instrumentKey.instrumentId = newInstrument.id();
m_instrumentName = newInstrument.name();
m_instrumentAbbreviature = newInstrument.abbreviature();
emit dataChanged();
}
void InstrumentSettingsModel::resetAllFormatting()
{
if (!masterNotationParts() || !notationParts()) {
return;
}
std::string title = mu::trc("instruments", "Are you sure you want to reset all formatting?");
std::string body = mu::trc("instruments", "This action can not be undone");
IInteractive::Button button = interactive()->question(title, body, {
IInteractive::Button::No,
IInteractive::Button::Yes
}).standardButton();
if (button == IInteractive::Button::No) {
return;
}
const Part* masterPart = masterNotationParts()->part(m_instrumentKey.partId);
notationParts()->replacePart(m_instrumentKey.partId, masterPart->clone());
}
QString InstrumentSettingsModel::instrumentName() const
{
return m_instrumentName;
}
QString InstrumentSettingsModel::partName() const
{
return m_partName;
}
QString InstrumentSettingsModel::abbreviature() const
{
return m_instrumentAbbreviature;
}
bool InstrumentSettingsModel::isMainScore() const
{
return currentNotation() == currentMasterNotation();
}
void InstrumentSettingsModel::setInstrumentName(const QString& name)
{
if (m_instrumentName == name || !notationParts()) {
return;
}
m_instrumentName = name;
notationParts()->setInstrumentName(m_instrumentKey, name);
}
void InstrumentSettingsModel::setPartName(const QString& name)
{
if (m_partName == name || !notationParts()) {
return;
}
m_partName = name;
notationParts()->setPartName(m_instrumentKey.partId, name);
}
void InstrumentSettingsModel::setAbbreviature(const QString& abbreviature)
{
if (m_instrumentAbbreviature == abbreviature || !notationParts()) {
return;
}
m_instrumentAbbreviature = abbreviature;
notationParts()->setInstrumentAbbreviature(m_instrumentKey, abbreviature);
}
INotationPtr InstrumentSettingsModel::currentNotation() const
{
return context()->currentNotation();
}
INotationPtr InstrumentSettingsModel::currentMasterNotation() const
{
IMasterNotationPtr master = context()->currentMasterNotation();
return master ? master->notation() : nullptr;
}
INotationPartsPtr InstrumentSettingsModel::notationParts() const
{
INotationPtr notation = currentNotation();
return notation ? notation->parts() : nullptr;
}
INotationPartsPtr InstrumentSettingsModel::masterNotationParts() const
{
INotationPtr notation = currentMasterNotation();
return notation ? notation->parts() : nullptr;
}