restore a saved family after selecting a group
This commit is contained in:
parent
1a28927f1c
commit
b05049d628
|
@ -56,7 +56,9 @@ public:
|
|||
QUAVER = 0xE1D7,
|
||||
SEMIQUAVER = 0xE1D9,
|
||||
DEMISEMIQUAVER = 0xE1DB,
|
||||
DOT = 0xE1E7
|
||||
DOT = 0xE1E7,
|
||||
|
||||
NONE
|
||||
};
|
||||
|
||||
Q_ENUM(Code)
|
||||
|
|
|
@ -96,14 +96,14 @@ struct InstrumentGroup
|
|||
using InstrumentGroupList = QList<InstrumentGroup>;
|
||||
using InstrumentGroupMap = QMap<QString /*id*/, InstrumentGroup>;
|
||||
|
||||
struct InstrumentFamily
|
||||
struct InstrumentGenre
|
||||
{
|
||||
QString id;
|
||||
QString name;
|
||||
};
|
||||
using InstrumentFamilyMap = QMap<QString /*id*/, InstrumentFamily>;
|
||||
using InstrumentGenreMap = QMap<QString /*id*/, InstrumentGenre>;
|
||||
|
||||
static const QString COMMON_FAMILY_ID("common");
|
||||
static const QString COMMON_GENRE_ID("common");
|
||||
|
||||
struct Transposition
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ struct Instrument
|
|||
int staves = 1;
|
||||
|
||||
QString groupId;
|
||||
QStringList familyIds;
|
||||
QStringList genreIds;
|
||||
|
||||
PitchRange amateurPitchRange;
|
||||
PitchRange professionalPitchRange;
|
||||
|
@ -176,7 +176,7 @@ struct InstrumentsMeta
|
|||
{
|
||||
InstrumentTemplateMap instrumentTemplates;
|
||||
InstrumentGroupMap groups;
|
||||
InstrumentFamilyMap families;
|
||||
InstrumentGenreMap genres;
|
||||
MidiArticulationMap articulations;
|
||||
};
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@ RetVal<InstrumentsMeta> InstrumentsReader::readMeta(const io::path& path) const
|
|||
MidiArticulation articulation = readArticulation(reader);
|
||||
meta.articulations.insert(articulation.name, articulation); // TODO: name?
|
||||
} else if (reader.name() == "Genre") {
|
||||
InstrumentFamily family = readFamily(reader);
|
||||
meta.families.insert(family.id, family);
|
||||
InstrumentGenre genre = readGenre(reader);
|
||||
meta.genres.insert(genre.id, genre);
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
|
@ -131,20 +131,20 @@ MidiArticulation InstrumentsReader::readArticulation(Ms::XmlReader& reader) cons
|
|||
return articulation;
|
||||
}
|
||||
|
||||
InstrumentFamily InstrumentsReader::readFamily(Ms::XmlReader& reader) const
|
||||
InstrumentGenre InstrumentsReader::readGenre(Ms::XmlReader& reader) const
|
||||
{
|
||||
InstrumentFamily family;
|
||||
family.id = reader.attributes().value("id").toString();
|
||||
InstrumentGenre genre;
|
||||
genre.id = reader.attributes().value("id").toString();
|
||||
|
||||
while (reader.readNextStartElement()) {
|
||||
if (reader.name() == "name") {
|
||||
family.name = qApp->translate("InstrumentsXML", reader.readElementText().toUtf8().data());
|
||||
genre.name = qApp->translate("InstrumentsXML", reader.readElementText().toUtf8().data());
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
return family;
|
||||
return genre;
|
||||
}
|
||||
|
||||
InstrumentTemplate InstrumentsReader::readInstrumentTemplate(Ms::XmlReader& reader, InstrumentsMeta& generalMeta) const
|
||||
|
@ -295,7 +295,7 @@ InstrumentTemplate InstrumentsReader::readInstrumentTemplate(Ms::XmlReader& read
|
|||
} else if (reader.name() == "musicXMLid") {
|
||||
instrument.id = reader.readElementText();
|
||||
} else if (reader.name() == "genre") {
|
||||
instrument.familyIds << reader.readElementText();
|
||||
instrument.genreIds << reader.readElementText();
|
||||
} else if (reader.name() == "singleNoteDynamics") {
|
||||
instrument.singleNoteDynamics = reader.readElementText().toInt();
|
||||
} else {
|
||||
|
|
|
@ -47,7 +47,7 @@ private:
|
|||
|
||||
void loadGroupMeta(Ms::XmlReader& reader, InstrumentsMeta& generalMeta, int groupIndex) const;
|
||||
MidiArticulation readArticulation(Ms::XmlReader& reader) const;
|
||||
InstrumentFamily readFamily(Ms::XmlReader& reader) const;
|
||||
InstrumentGenre readGenre(Ms::XmlReader& reader) const;
|
||||
InstrumentTemplate readInstrumentTemplate(Ms::XmlReader& reader, InstrumentsMeta& generalMeta) const;
|
||||
|
||||
int readStaffIndex(Ms::XmlReader& reader) const;
|
||||
|
|
|
@ -101,9 +101,9 @@ void InstrumentsRepository::load()
|
|||
m_instrumentsMeta.articulations.insert(it.key(), it.value());
|
||||
}
|
||||
|
||||
const InstrumentFamilyMap& families = metaInstrument.val.families;
|
||||
for (auto it = families.cbegin(); it != families.cend(); ++it) {
|
||||
m_instrumentsMeta.families.insert(it.key(), it.value());
|
||||
const InstrumentGenreMap& genres = metaInstrument.val.genres;
|
||||
for (auto it = genres.cbegin(); it != genres.cend(); ++it) {
|
||||
m_instrumentsMeta.genres.insert(it.key(), it.value());
|
||||
}
|
||||
|
||||
const InstrumentGroupMap& groups = metaInstrument.val.groups;
|
||||
|
@ -128,7 +128,7 @@ void InstrumentsRepository::clear()
|
|||
Ms::clearInstrumentTemplates();
|
||||
|
||||
m_instrumentsMeta.instrumentTemplates.clear();
|
||||
m_instrumentsMeta.families.clear();
|
||||
m_instrumentsMeta.genres.clear();
|
||||
m_instrumentsMeta.groups.clear();
|
||||
m_instrumentsMeta.articulations.clear();
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ Item {
|
|||
textRoleName: "name"
|
||||
valueRoleName: "id"
|
||||
|
||||
onValueChanged: {
|
||||
onActivated: {
|
||||
root.familySelected(value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
using namespace mu::instruments;
|
||||
using namespace mu::notation;
|
||||
|
||||
static const QString ALL_INSTRUMENTS_ID("ALL_INSTRUMENTS");
|
||||
static const QString ALL_INSTRUMENTS_GENRE_ID("ALL_INSTRUMENTS");
|
||||
static const QString INSTRUMENT_EMPTY_TRANSPOSITION_ID("EMPTY_KEY");
|
||||
static const QString INSTRUMENT_EMPTY_TRANSPOSITION_NAME("--");
|
||||
|
||||
|
@ -52,7 +52,7 @@ void InstrumentListModel::load(bool canSelectMultipleInstruments, const QString&
|
|||
setInstrumentsMeta(newInstrumentsMeta);
|
||||
});
|
||||
|
||||
m_selectedFamilyId = COMMON_FAMILY_ID;
|
||||
m_selectedFamilyId = COMMON_GENRE_ID;
|
||||
m_canSelectMultipleInstruments = canSelectMultipleInstruments;
|
||||
setInstrumentsMeta(instrumentsMeta.val);
|
||||
|
||||
|
@ -84,23 +84,23 @@ void InstrumentListModel::initSelectedInstruments(const IDList& selectedInstrume
|
|||
|
||||
QVariantList InstrumentListModel::families() const
|
||||
{
|
||||
auto toMap = [](const InstrumentFamily& family) {
|
||||
auto toMap = [](const InstrumentGenre& genre) {
|
||||
return QVariantMap {
|
||||
{ ID_KEY, family.id },
|
||||
{ NAME_KEY, family.name }
|
||||
{ ID_KEY, genre.id },
|
||||
{ NAME_KEY, genre.name }
|
||||
};
|
||||
};
|
||||
|
||||
QVariantList result;
|
||||
result << toMap(m_instrumentsMeta.families[COMMON_FAMILY_ID]);
|
||||
result << toMap(m_instrumentsMeta.genres[COMMON_GENRE_ID]);
|
||||
result << allInstrumentsItem();
|
||||
|
||||
for (const InstrumentFamily& family: m_instrumentsMeta.families) {
|
||||
if (family.id == COMMON_FAMILY_ID) {
|
||||
for (const InstrumentGenre& genre: m_instrumentsMeta.genres) {
|
||||
if (genre.id == COMMON_GENRE_ID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result << toMap(family);
|
||||
result << toMap(genre);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -366,7 +366,7 @@ InstrumentGroupList InstrumentListModel::sortedGroupList() const
|
|||
QVariantMap InstrumentListModel::allInstrumentsItem() const
|
||||
{
|
||||
QVariantMap obj;
|
||||
obj[ID_KEY] = ALL_INSTRUMENTS_ID;
|
||||
obj[ID_KEY] = ALL_INSTRUMENTS_GENRE_ID;
|
||||
obj[NAME_KEY] = qtrc("instruments", "All instruments");
|
||||
return obj;
|
||||
}
|
||||
|
@ -382,9 +382,15 @@ QVariantMap InstrumentListModel::defaultInstrumentTranspositionItem() const
|
|||
|
||||
void InstrumentListModel::updateFamilyStateBySearch()
|
||||
{
|
||||
if (!m_searchText.isEmpty()) {
|
||||
selectFamily(ALL_INSTRUMENTS_ID);
|
||||
bool familySaved = !m_savedFamilyId.isEmpty();
|
||||
|
||||
if (isSearching() && !familySaved) {
|
||||
m_savedFamilyId = m_selectedFamilyId;
|
||||
selectFamily(ALL_INSTRUMENTS_GENRE_ID);
|
||||
selectGroup(QString());
|
||||
} else if (!isSearching() && familySaved) {
|
||||
selectFamily(m_savedFamilyId);
|
||||
m_savedFamilyId.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,11 +404,11 @@ bool InstrumentListModel::isInstrumentAccepted(const Instrument& instrument, boo
|
|||
return false;
|
||||
}
|
||||
|
||||
if (m_selectedFamilyId == ALL_INSTRUMENTS_ID) {
|
||||
if (m_selectedFamilyId == ALL_INSTRUMENTS_GENRE_ID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (instrument.familyIds.contains(m_selectedFamilyId)) {
|
||||
if (instrument.genreIds.contains(m_selectedFamilyId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ private:
|
|||
|
||||
QString m_selectedFamilyId;
|
||||
QString m_selectedGroupId;
|
||||
QString m_savedFamilyId;
|
||||
|
||||
InstrumentsMeta m_instrumentsMeta;
|
||||
QString m_searchText;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import QtQuick 2.12
|
||||
import QtQuick 2.15
|
||||
|
||||
import MuseScore.UiComponents 1.0
|
||||
|
||||
|
|
|
@ -277,7 +277,7 @@ QVariantMap AdditionalInfoModel::tempoValueRange() const
|
|||
|
||||
QVariantList AdditionalInfoModel::tempoNotes() const
|
||||
{
|
||||
auto makeNote = [](MusicalSymbolCodes::Code icon, bool withDot = false) {
|
||||
auto makeNote = [](MusicalSymbolCodes::Code icon, bool withDot = false) {
|
||||
QVariantMap note;
|
||||
note[NOTE_ICON_KEY] = static_cast<int>(icon);
|
||||
note[NOTE_SYMBOL_KEY] = formatNoteSymbol(icon, withDot);
|
||||
|
|
|
@ -123,7 +123,7 @@ private:
|
|||
|
||||
struct Tempo {
|
||||
int value = 0;
|
||||
ui::MusicalSymbolCodes::Code noteIcon;
|
||||
ui::MusicalSymbolCodes::Code noteIcon = ui::MusicalSymbolCodes::Code::NONE;
|
||||
bool withDot = false;
|
||||
|
||||
Tempo() = default;
|
||||
|
|
Loading…
Reference in a new issue