Skip to content

Commit

Permalink
fix #19693: New Instrument Selection Menu for the Create Score Dialogue
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Sep 12, 2013
1 parent 21a24cb commit a315216
Show file tree
Hide file tree
Showing 12 changed files with 637 additions and 504 deletions.
67 changes: 47 additions & 20 deletions libmscore/instrtemplate.cpp
Expand Up @@ -32,13 +32,11 @@ QList<InstrumentGenre*> instrumentGenres;

static InstrumentGenre * searchInstrumentGenre(const QString& genre)
{
InstrumentGenre * rVal = NULL;
foreach(InstrumentGenre* ig, instrumentGenres) {
if (ig->id == genre) {
rVal = ig;
}
if (ig->id == genre)
return ig;
}
return rVal;
return nullptr;
}

//---------------------------------------------------------
Expand All @@ -51,7 +49,7 @@ static InstrumentGroup* searchInstrumentGroup(const QString& name)
if (g->id == name)
return g;
}
return 0;
return nullptr;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -153,7 +151,6 @@ InstrumentTemplate::InstrumentTemplate(const InstrumentTemplate& t)

void InstrumentTemplate::init(const InstrumentTemplate& t)
{
trackName = t.trackName;
longNames = t.longNames;
shortNames = t.shortNames;
musicXMLid = t.musicXMLid;
Expand Down Expand Up @@ -580,7 +577,9 @@ bool saveInstrumentTemplates(const QString& instrTemplates)
Xml xml(&qf);
xml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
xml.stag("museScore");

foreach(const InstrumentGenre* genre, instrumentGenres)
genre->write(xml);
xml << "\n";
foreach(const MidiArticulation& a, articulation)
a.write(xml);
xml << "\n";
Expand Down Expand Up @@ -615,7 +614,8 @@ bool saveInstrumentTemplates1(const QString& instrTemplates)
Xml xml(&qf);
xml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
xml.stag("museScore");

foreach(const InstrumentGenre* genre, instrumentGenres)
genre->write1(xml);
foreach(InstrumentGroup* group, instrumentGroups) {
xml.stag(QString("InstrumentGroup id=\"%1\"").arg(group->id));
xml.tag("name", group->name);
Expand Down Expand Up @@ -663,9 +663,14 @@ bool loadInstrumentTemplates(const QString& instrTemplates)
a.read(e);
articulation.append(a);
}
else if (tag == "genre") {
else if (tag == "Genre") {
QString id(e.attribute("id"));
searchInstrumentGenre("id");
InstrumentGenre* genre = searchInstrumentGenre(id);
if (!genre) {
genre = new InstrumentGenre;
instrumentGenres.append(genre);
}
genre->read(e);
}
else
e.unknown();
Expand Down Expand Up @@ -702,14 +707,8 @@ InstrumentTemplate* searchTemplate(const QString& name)
void InstrumentTemplate::linkGenre(const QString& genre)
{
InstrumentGenre *ig = searchInstrumentGenre(genre);

if (!ig) {
ig = new InstrumentGenre;
ig->id = genre;
instrumentGenres.append(ig);
}

InstrumentGenres.append(ig);
if (ig)
genres.append(ig);
}

//---------------------------------------------------------
Expand All @@ -720,12 +719,40 @@ void InstrumentTemplate::linkGenre(const QString& genre)
bool InstrumentTemplate::genreMember(const QString& name)
{
bool rVal=false;
foreach(InstrumentGenre *instrumentGenre, InstrumentGenres ) {
foreach(InstrumentGenre *instrumentGenre, genres ) {
if(instrumentGenre->id == name) {
rVal = true;
break;
}
}
return rVal;
}

void InstrumentGenre::write(Xml& xml) const
{
xml.stag(QString("Genre id=\"%1\"").arg(id));
xml.tag("name", name);
xml.etag();
}

void InstrumentGenre::write1(Xml& xml) const
{
write(xml);
}

void InstrumentGenre::read(XmlReader& e)
{
id = e.attribute("id");
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "name") {
name = e.readElementText();
}
else
e.unknown();
}
}

}


8 changes: 6 additions & 2 deletions libmscore/instrtemplate.h
Expand Up @@ -31,8 +31,12 @@ class Tablature;
class InstrumentGenre {
public:
QString id;
QString name;

InstrumentGenre() { id = ""; }
InstrumentGenre() {}
void write(Xml& xml) const;
void write1(Xml& xml) const;
void read(XmlReader&);
};

//---------------------------------------------------------// InstrumentTemplate
Expand Down Expand Up @@ -66,7 +70,7 @@ class InstrumentTemplate {
QList<NamedEventList> midiActions;
QList<MidiArticulation> articulation;
QList<Channel> channel;
QList<InstrumentGenre*> InstrumentGenres; //; list of genres this instrument belongs to
QList<InstrumentGenre*> genres; //; list of genres this instrument belongs to

ClefTypeList clefTypes[MAX_STAVES];
int staffLines[MAX_STAVES];
Expand Down
45 changes: 23 additions & 22 deletions mscore/instrdialog.cpp
Expand Up @@ -384,7 +384,6 @@ InstrumentsDialog::InstrumentsDialog(QWidget* parent)
partiturList->resizeColumnToContents(1); // shrink "visible "and "linked" columns as much as possible
partiturList->resizeColumnToContents(3);

populateGenreCombo();
buildTemplateList();

addButton->setEnabled(false);
Expand All @@ -393,44 +392,41 @@ InstrumentsDialog::InstrumentsDialog(QWidget* parent)
downButton->setEnabled(false);
belowButton->setEnabled(false);
linkedButton->setEnabled(false);
connect(showMore, SIGNAL(clicked()), SLOT(buildTemplateList()));
connect(instrumentList, SIGNAL(clicked(const QModelIndex &)), SLOT(expandOrCollapse(const QModelIndex &)));
}

//---------------------------------------------------------
// populateGenreCombo
//---------------------------------------------------------

void InstrumentsDialog::populateGenreCombo()
void populateGenreCombo(QComboBox* combo)
{
QStringList listGenres;
InstrumentGenreFilter->clear();
InstrumentGenreFilter->addItem(tr("All"));
combo->clear();
combo->addItem(QT_TR_NOOP("All instruments"), "all");
int i = 1;
int defaultIndex = 0;
foreach(InstrumentGenre *ig, instrumentGenres) {
listGenres.append(ig->id);
}
listGenres.sort();

InstrumentGenreFilter->addItems(listGenres);
combo->addItem(ig->name, ig->id);
if(ig->id == "common")
defaultIndex = i;
++i;
}
combo->setCurrentIndex(defaultIndex);
}


//---------------------------------------------------------
// populateInstrumentList
//---------------------------------------------------------

void populateInstrumentList(QTreeWidget* instrumentList, bool extended)
void populateInstrumentList(QTreeWidget* instrumentList)
{
instrumentList->clear();
// TODO: memory leak
foreach(InstrumentGroup* g, instrumentGroups) {
if (!extended && g->extended)
continue;
InstrumentTemplateListItem* group = new InstrumentTemplateListItem(g->name, instrumentList);
group->setFlags(Qt::ItemIsEnabled);
foreach(InstrumentTemplate* t, g->instrumentTemplates) {
if (!extended && t->extended)
continue;
new InstrumentTemplateListItem(t, group);
}
}
Expand All @@ -446,7 +442,8 @@ void InstrumentsDialog::buildTemplateList()
search->clear();
filterInstruments(instrumentList, search->text());

populateInstrumentList(instrumentList, showMore->isChecked());
populateInstrumentList(instrumentList);
populateGenreCombo(instrumentGenreFilter);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1294,6 +1291,9 @@ void filterInstruments(QTreeWidget* instrumentList, const QString &searchPhrase)
void InstrumentsDialog::on_search_textChanged(const QString &searchPhrase)
{
filterInstruments(instrumentList, searchPhrase);
instrumentGenreFilter->blockSignals(true);
instrumentGenreFilter->setCurrentIndex(0);
instrumentGenreFilter->blockSignals(false);
}

//---------------------------------------------------------
Expand All @@ -1306,13 +1306,14 @@ void InstrumentsDialog::on_clearSearch_clicked()
filterInstruments (instrumentList);
}
//---------------------------------------------------------
// on_InstrumentGenreFilter_currentTextChanged
// on_instrumentGenreFilter_currentTextChanged
//---------------------------------------------------------

void InstrumentsDialog::on_InstrumentGenreFilter_currentTextChanged(const QString &genre)
void InstrumentsDialog::on_instrumentGenreFilter_currentIndexChanged(int index)
{
QString id = instrumentGenreFilter->itemData(index).toString();
// Redisplay tree, only showing items from the selected genre
filterInstrumentsByGenre(instrumentList, genre);
filterInstrumentsByGenre(instrumentList, id);
}


Expand All @@ -1329,12 +1330,12 @@ void InstrumentsDialog::filterInstrumentsByGenre(QTreeWidget *instrumentList, QS
InstrumentTemplate *it=itli->instrumentTemplate();

if(it) {
if (genre == tr("All") || it->genreMember(genre)) {
if (genre == "all" || it->genreMember(genre)) {
(*iList)->setHidden(false);

QTreeWidgetItem *iParent = (*iList)->parent();
while(iParent) {
if(!iParent-isHidden())
if(!iParent->isHidden())
break;

iParent->setHidden(false);
Expand Down
8 changes: 4 additions & 4 deletions mscore/instrdialog.h
Expand Up @@ -131,10 +131,9 @@ class InstrumentsDialog : public QDialog, public Ui::InstrumentDialogBase {

void on_search_textChanged(const QString &searchPhrase);
void on_clearSearch_clicked();
void filterInstrumentsByGenre(QTreeWidget *, QString);
void populateGenreCombo();

void on_InstrumentGenreFilter_currentTextChanged(const QString &);
void on_instrumentGenreFilter_currentIndexChanged(int);
void filterInstrumentsByGenre(QTreeWidget *, QString);

public:
InstrumentsDialog(QWidget* parent = 0);
Expand All @@ -159,7 +158,8 @@ class InstrumentTemplateListItem : public QTreeWidgetItem {
virtual QString text(int col) const;
};

extern void populateInstrumentList(QTreeWidget* instrumentList, bool extended);
extern void populateInstrumentList(QTreeWidget* instrumentList);
extern void populateGenreCombo(QComboBox* combo);

} // namespace Ms

Expand Down
12 changes: 2 additions & 10 deletions mscore/instrdialog.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>405</height>
<height>500</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -37,7 +37,7 @@
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="InstrumentGenreFilter"/>
<widget class="QComboBox" name="instrumentGenreFilter"/>
</item>
<item>
<widget class="QTreeWidget" name="instrumentList">
Expand Down Expand Up @@ -102,13 +102,6 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="showMore">
<property name="text">
<string>show more</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
Expand Down Expand Up @@ -392,7 +385,6 @@
<tabstop>belowButton</tabstop>
<tabstop>linkedButton</tabstop>
<tabstop>partiturList</tabstop>
<tabstop>showMore</tabstop>
<tabstop>loadButton</tabstop>
<tabstop>saveButton</tabstop>
<tabstop>okButton</tabstop>
Expand Down
14 changes: 6 additions & 8 deletions mscore/instrwizard.ui
Expand Up @@ -16,6 +16,9 @@
<layout class="QHBoxLayout" name="horizontalLayout" stretch="10,0,15">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="instrumentGenreFilter"/>
</item>
<item>
<widget class="QTreeWidget" name="instrumentList">
<property name="alternatingRowColors">
Expand All @@ -36,6 +39,9 @@
<property name="columnCount">
<number>1</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>0</string>
Expand Down Expand Up @@ -64,13 +70,6 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="showMore">
<property name="text">
<string>show more</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -248,7 +247,6 @@
<tabstop>search</tabstop>
<tabstop>clearSearch</tabstop>
<tabstop>instrumentList</tabstop>
<tabstop>showMore</tabstop>
<tabstop>addButton</tabstop>
<tabstop>removeButton</tabstop>
<tabstop>upButton</tabstop>
Expand Down

0 comments on commit a315216

Please sign in to comment.