Skip to content

Commit a315216

Browse files
committed
fix #19693: New Instrument Selection Menu for the Create Score Dialogue
1 parent 21a24cb commit a315216

File tree

12 files changed

+637
-504
lines changed

12 files changed

+637
-504
lines changed

libmscore/instrtemplate.cpp

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ QList<InstrumentGenre*> instrumentGenres;
3232

3333
static InstrumentGenre * searchInstrumentGenre(const QString& genre)
3434
{
35-
InstrumentGenre * rVal = NULL;
3635
foreach(InstrumentGenre* ig, instrumentGenres) {
37-
if (ig->id == genre) {
38-
rVal = ig;
39-
}
36+
if (ig->id == genre)
37+
return ig;
4038
}
41-
return rVal;
39+
return nullptr;
4240
}
4341

4442
//---------------------------------------------------------
@@ -51,7 +49,7 @@ static InstrumentGroup* searchInstrumentGroup(const QString& name)
5149
if (g->id == name)
5250
return g;
5351
}
54-
return 0;
52+
return nullptr;
5553
}
5654

5755
//---------------------------------------------------------
@@ -153,7 +151,6 @@ InstrumentTemplate::InstrumentTemplate(const InstrumentTemplate& t)
153151

154152
void InstrumentTemplate::init(const InstrumentTemplate& t)
155153
{
156-
trackName = t.trackName;
157154
longNames = t.longNames;
158155
shortNames = t.shortNames;
159156
musicXMLid = t.musicXMLid;
@@ -580,7 +577,9 @@ bool saveInstrumentTemplates(const QString& instrTemplates)
580577
Xml xml(&qf);
581578
xml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
582579
xml.stag("museScore");
583-
580+
foreach(const InstrumentGenre* genre, instrumentGenres)
581+
genre->write(xml);
582+
xml << "\n";
584583
foreach(const MidiArticulation& a, articulation)
585584
a.write(xml);
586585
xml << "\n";
@@ -615,7 +614,8 @@ bool saveInstrumentTemplates1(const QString& instrTemplates)
615614
Xml xml(&qf);
616615
xml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
617616
xml.stag("museScore");
618-
617+
foreach(const InstrumentGenre* genre, instrumentGenres)
618+
genre->write1(xml);
619619
foreach(InstrumentGroup* group, instrumentGroups) {
620620
xml.stag(QString("InstrumentGroup id=\"%1\"").arg(group->id));
621621
xml.tag("name", group->name);
@@ -663,9 +663,14 @@ bool loadInstrumentTemplates(const QString& instrTemplates)
663663
a.read(e);
664664
articulation.append(a);
665665
}
666-
else if (tag == "genre") {
666+
else if (tag == "Genre") {
667667
QString id(e.attribute("id"));
668-
searchInstrumentGenre("id");
668+
InstrumentGenre* genre = searchInstrumentGenre(id);
669+
if (!genre) {
670+
genre = new InstrumentGenre;
671+
instrumentGenres.append(genre);
672+
}
673+
genre->read(e);
669674
}
670675
else
671676
e.unknown();
@@ -702,14 +707,8 @@ InstrumentTemplate* searchTemplate(const QString& name)
702707
void InstrumentTemplate::linkGenre(const QString& genre)
703708
{
704709
InstrumentGenre *ig = searchInstrumentGenre(genre);
705-
706-
if (!ig) {
707-
ig = new InstrumentGenre;
708-
ig->id = genre;
709-
instrumentGenres.append(ig);
710-
}
711-
712-
InstrumentGenres.append(ig);
710+
if (ig)
711+
genres.append(ig);
713712
}
714713

715714
//---------------------------------------------------------
@@ -720,12 +719,40 @@ void InstrumentTemplate::linkGenre(const QString& genre)
720719
bool InstrumentTemplate::genreMember(const QString& name)
721720
{
722721
bool rVal=false;
723-
foreach(InstrumentGenre *instrumentGenre, InstrumentGenres ) {
722+
foreach(InstrumentGenre *instrumentGenre, genres ) {
724723
if(instrumentGenre->id == name) {
725724
rVal = true;
726725
break;
727726
}
728727
}
729728
return rVal;
730729
}
730+
731+
void InstrumentGenre::write(Xml& xml) const
732+
{
733+
xml.stag(QString("Genre id=\"%1\"").arg(id));
734+
xml.tag("name", name);
735+
xml.etag();
736+
}
737+
738+
void InstrumentGenre::write1(Xml& xml) const
739+
{
740+
write(xml);
741+
}
742+
743+
void InstrumentGenre::read(XmlReader& e)
744+
{
745+
id = e.attribute("id");
746+
while (e.readNextStartElement()) {
747+
const QStringRef& tag(e.name());
748+
if (tag == "name") {
749+
name = e.readElementText();
750+
}
751+
else
752+
e.unknown();
753+
}
754+
}
755+
731756
}
757+
758+

libmscore/instrtemplate.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ class Tablature;
3131
class InstrumentGenre {
3232
public:
3333
QString id;
34+
QString name;
3435

35-
InstrumentGenre() { id = ""; }
36+
InstrumentGenre() {}
37+
void write(Xml& xml) const;
38+
void write1(Xml& xml) const;
39+
void read(XmlReader&);
3640
};
3741

3842
//---------------------------------------------------------// InstrumentTemplate
@@ -66,7 +70,7 @@ class InstrumentTemplate {
6670
QList<NamedEventList> midiActions;
6771
QList<MidiArticulation> articulation;
6872
QList<Channel> channel;
69-
QList<InstrumentGenre*> InstrumentGenres; //; list of genres this instrument belongs to
73+
QList<InstrumentGenre*> genres; //; list of genres this instrument belongs to
7074

7175
ClefTypeList clefTypes[MAX_STAVES];
7276
int staffLines[MAX_STAVES];

mscore/instrdialog.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ InstrumentsDialog::InstrumentsDialog(QWidget* parent)
384384
partiturList->resizeColumnToContents(1); // shrink "visible "and "linked" columns as much as possible
385385
partiturList->resizeColumnToContents(3);
386386

387-
populateGenreCombo();
388387
buildTemplateList();
389388

390389
addButton->setEnabled(false);
@@ -393,44 +392,41 @@ InstrumentsDialog::InstrumentsDialog(QWidget* parent)
393392
downButton->setEnabled(false);
394393
belowButton->setEnabled(false);
395394
linkedButton->setEnabled(false);
396-
connect(showMore, SIGNAL(clicked()), SLOT(buildTemplateList()));
397395
connect(instrumentList, SIGNAL(clicked(const QModelIndex &)), SLOT(expandOrCollapse(const QModelIndex &)));
398396
}
399397

400398
//---------------------------------------------------------
401399
// populateGenreCombo
402400
//---------------------------------------------------------
403401

404-
void InstrumentsDialog::populateGenreCombo()
402+
void populateGenreCombo(QComboBox* combo)
405403
{
406-
QStringList listGenres;
407-
InstrumentGenreFilter->clear();
408-
InstrumentGenreFilter->addItem(tr("All"));
404+
combo->clear();
405+
combo->addItem(QT_TR_NOOP("All instruments"), "all");
406+
int i = 1;
407+
int defaultIndex = 0;
409408
foreach(InstrumentGenre *ig, instrumentGenres) {
410-
listGenres.append(ig->id);
411-
}
412-
listGenres.sort();
413-
414-
InstrumentGenreFilter->addItems(listGenres);
409+
combo->addItem(ig->name, ig->id);
410+
if(ig->id == "common")
411+
defaultIndex = i;
412+
++i;
413+
}
414+
combo->setCurrentIndex(defaultIndex);
415415
}
416416

417417

418418
//---------------------------------------------------------
419419
// populateInstrumentList
420420
//---------------------------------------------------------
421421

422-
void populateInstrumentList(QTreeWidget* instrumentList, bool extended)
422+
void populateInstrumentList(QTreeWidget* instrumentList)
423423
{
424424
instrumentList->clear();
425425
// TODO: memory leak
426426
foreach(InstrumentGroup* g, instrumentGroups) {
427-
if (!extended && g->extended)
428-
continue;
429427
InstrumentTemplateListItem* group = new InstrumentTemplateListItem(g->name, instrumentList);
430428
group->setFlags(Qt::ItemIsEnabled);
431429
foreach(InstrumentTemplate* t, g->instrumentTemplates) {
432-
if (!extended && t->extended)
433-
continue;
434430
new InstrumentTemplateListItem(t, group);
435431
}
436432
}
@@ -446,7 +442,8 @@ void InstrumentsDialog::buildTemplateList()
446442
search->clear();
447443
filterInstruments(instrumentList, search->text());
448444

449-
populateInstrumentList(instrumentList, showMore->isChecked());
445+
populateInstrumentList(instrumentList);
446+
populateGenreCombo(instrumentGenreFilter);
450447
}
451448

452449
//---------------------------------------------------------
@@ -1294,6 +1291,9 @@ void filterInstruments(QTreeWidget* instrumentList, const QString &searchPhrase)
12941291
void InstrumentsDialog::on_search_textChanged(const QString &searchPhrase)
12951292
{
12961293
filterInstruments(instrumentList, searchPhrase);
1294+
instrumentGenreFilter->blockSignals(true);
1295+
instrumentGenreFilter->setCurrentIndex(0);
1296+
instrumentGenreFilter->blockSignals(false);
12971297
}
12981298

12991299
//---------------------------------------------------------
@@ -1306,13 +1306,14 @@ void InstrumentsDialog::on_clearSearch_clicked()
13061306
filterInstruments (instrumentList);
13071307
}
13081308
//---------------------------------------------------------
1309-
// on_InstrumentGenreFilter_currentTextChanged
1309+
// on_instrumentGenreFilter_currentTextChanged
13101310
//---------------------------------------------------------
13111311

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

13181319

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

13311332
if(it) {
1332-
if (genre == tr("All") || it->genreMember(genre)) {
1333+
if (genre == "all" || it->genreMember(genre)) {
13331334
(*iList)->setHidden(false);
13341335

13351336
QTreeWidgetItem *iParent = (*iList)->parent();
13361337
while(iParent) {
1337-
if(!iParent-isHidden())
1338+
if(!iParent->isHidden())
13381339
break;
13391340

13401341
iParent->setHidden(false);

mscore/instrdialog.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,9 @@ class InstrumentsDialog : public QDialog, public Ui::InstrumentDialogBase {
131131

132132
void on_search_textChanged(const QString &searchPhrase);
133133
void on_clearSearch_clicked();
134-
void filterInstrumentsByGenre(QTreeWidget *, QString);
135-
void populateGenreCombo();
136134

137-
void on_InstrumentGenreFilter_currentTextChanged(const QString &);
135+
void on_instrumentGenreFilter_currentIndexChanged(int);
136+
void filterInstrumentsByGenre(QTreeWidget *, QString);
138137

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

162-
extern void populateInstrumentList(QTreeWidget* instrumentList, bool extended);
161+
extern void populateInstrumentList(QTreeWidget* instrumentList);
162+
extern void populateGenreCombo(QComboBox* combo);
163163

164164
} // namespace Ms
165165

mscore/instrdialog.ui

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>800</width>
10-
<height>405</height>
10+
<height>500</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -37,7 +37,7 @@
3737
<widget class="QWidget" name="layoutWidget">
3838
<layout class="QVBoxLayout" name="verticalLayout">
3939
<item>
40-
<widget class="QComboBox" name="InstrumentGenreFilter"/>
40+
<widget class="QComboBox" name="instrumentGenreFilter"/>
4141
</item>
4242
<item>
4343
<widget class="QTreeWidget" name="instrumentList">
@@ -102,13 +102,6 @@
102102
</item>
103103
</layout>
104104
</item>
105-
<item>
106-
<widget class="QCheckBox" name="showMore">
107-
<property name="text">
108-
<string>show more</string>
109-
</property>
110-
</widget>
111-
</item>
112105
</layout>
113106
</widget>
114107
<widget class="QWidget" name="layoutWidget">
@@ -392,7 +385,6 @@
392385
<tabstop>belowButton</tabstop>
393386
<tabstop>linkedButton</tabstop>
394387
<tabstop>partiturList</tabstop>
395-
<tabstop>showMore</tabstop>
396388
<tabstop>loadButton</tabstop>
397389
<tabstop>saveButton</tabstop>
398390
<tabstop>okButton</tabstop>

mscore/instrwizard.ui

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<layout class="QHBoxLayout" name="horizontalLayout" stretch="10,0,15">
1717
<item>
1818
<layout class="QVBoxLayout" name="verticalLayout">
19+
<item>
20+
<widget class="QComboBox" name="instrumentGenreFilter"/>
21+
</item>
1922
<item>
2023
<widget class="QTreeWidget" name="instrumentList">
2124
<property name="alternatingRowColors">
@@ -36,6 +39,9 @@
3639
<property name="columnCount">
3740
<number>1</number>
3841
</property>
42+
<attribute name="headerVisible">
43+
<bool>false</bool>
44+
</attribute>
3945
<column>
4046
<property name="text">
4147
<string>0</string>
@@ -64,13 +70,6 @@
6470
</item>
6571
</layout>
6672
</item>
67-
<item>
68-
<widget class="QCheckBox" name="showMore">
69-
<property name="text">
70-
<string>show more</string>
71-
</property>
72-
</widget>
73-
</item>
7473
</layout>
7574
</item>
7675
<item>
@@ -248,7 +247,6 @@
248247
<tabstop>search</tabstop>
249248
<tabstop>clearSearch</tabstop>
250249
<tabstop>instrumentList</tabstop>
251-
<tabstop>showMore</tabstop>
252250
<tabstop>addButton</tabstop>
253251
<tabstop>removeButton</tabstop>
254252
<tabstop>upButton</tabstop>

0 commit comments

Comments
 (0)