Skip to content

Commit

Permalink
fix #274540: save user choice of instrument genre
Browse files Browse the repository at this point in the history
  • Loading branch information
jthistle committed Feb 19, 2019
1 parent 2818f33 commit 59c92f5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
10 changes: 10 additions & 0 deletions mscore/instrdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ InstrumentsDialog::InstrumentsDialog(QWidget* parent)
readSettings();
}

//---------------------------------------------------------
// init
//---------------------------------------------------------

void InstrumentsDialog::init()
{
instrumentsWidget->init();
}

//---------------------------------------------------------
// accept
//---------------------------------------------------------
Expand Down Expand Up @@ -203,6 +212,7 @@ void MuseScore::editInstrList()
instrList->done(0);
return;
}
instrList->init();
MasterScore* masterScore = cs->masterScore();
instrList->genPartList(masterScore);
masterScore->startCmd();
Expand Down
1 change: 1 addition & 0 deletions mscore/instrdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class InstrumentsDialog : public QDialog, public Ui::InstrumentsDialog {

public:
InstrumentsDialog(QWidget* parent = 0);
void init();
void writeSettings();
void genPartList(Score*);
QTreeWidget* partiturList();
Expand Down
25 changes: 21 additions & 4 deletions mscore/instrwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,19 @@ InstrumentsWidget::InstrumentsWidget(QWidget* parent)

void populateGenreCombo(QComboBox* combo)
{
combo->blockSignals(true);
combo->clear();
combo->addItem(qApp->translate("InstrumentsDialog", "All instruments"), "all");
int i = 1;
int defaultIndex = 0;
foreach (InstrumentGenre *ig, instrumentGenres) {
for (InstrumentGenre *ig : instrumentGenres) {
combo->addItem(ig->name, ig->id);
if (ig->id == "common")
defaultIndex = i;
++i;
}
combo->setCurrentIndex(defaultIndex);
combo->blockSignals(false);
}

//---------------------------------------------------------
Expand All @@ -416,7 +418,7 @@ void populateInstrumentList(QTreeWidget* instrumentList)
{
instrumentList->clear();
// TODO: memory leak?
foreach(InstrumentGroup* g, instrumentGroups) {
for (InstrumentGroup* g : instrumentGroups) {
InstrumentTemplateListItem* group = new InstrumentTemplateListItem(g->name, instrumentList);
// provide feedback to blind users that they have selected a group rather than an instrument
group->setData(0, Qt::AccessibleTextRole, QVariant(QObject::tr("%1 category").arg(g->name))); // spoken by screen readers
Expand Down Expand Up @@ -449,7 +451,7 @@ void InstrumentsWidget::genPartList(Score* cs)
{
partiturList->clear();

foreach (Part* p, cs->parts()) {
for (Part* p : cs->parts()) {
PartListItem* pli = new PartListItem(p, partiturList);
pli->setVisible(p->show());
for (Staff* s : *p->staves()) {
Expand Down Expand Up @@ -557,7 +559,7 @@ void InstrumentsWidget::on_instrumentList_itemActivated(QTreeWidgetItem* item, i

void InstrumentsWidget::on_addButton_clicked()
{
foreach(QTreeWidgetItem* i, instrumentList->selectedItems()) {
for (QTreeWidgetItem* i : instrumentList->selectedItems()) {
InstrumentTemplateListItem* item = static_cast<InstrumentTemplateListItem*>(i);
const InstrumentTemplate* it = item->instrumentTemplate();
if (it == 0)
Expand Down Expand Up @@ -924,6 +926,11 @@ void InstrumentsWidget::on_instrumentSearch_textChanged(const QString&)

void InstrumentsWidget::on_instrumentGenreFilter_currentIndexChanged(int index)
{
QSettings settings;
settings.beginGroup("selectInstrument"); // hard coded, since this is also used in selinstrument
settings.setValue("selectedGenre", instrumentGenreFilter->currentText());
settings.endGroup();

QString id = instrumentGenreFilter->itemData(index).toString();
// Redisplay tree, only showing items from the selected genre
filterInstrumentsByGenre(instrumentList, id);
Expand Down Expand Up @@ -1056,6 +1063,16 @@ void InstrumentsWidget::init()
downButton->setEnabled(false);
addLinkedStaffButton->setEnabled(false);
addStaffButton->setEnabled(false);

// get last saved, user-selected instrument genre and set filter to it
QSettings settings;
settings.beginGroup("selectInstrument");
if (!settings.value("selectedGenre").isNull()){
QString selectedGenre = settings.value("selectedGenre").value<QString>();
instrumentGenreFilter->setCurrentText(selectedGenre);
}
settings.endGroup();

emit completeChanged(false);
}

Expand Down
1 change: 0 additions & 1 deletion mscore/instrwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class InstrumentsWidget : public QWidget, public Ui::InstrumentsWidget {
public:
InstrumentsWidget(QWidget* parent = 0);
void genPartList(Score*);
void writeSettings();
void init();
void createInstruments(Score*);
QTreeWidget* getPartiturList();
Expand Down
16 changes: 16 additions & 0 deletions mscore/selinstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ SelectInstrument::SelectInstrument(const Instrument* instrument, QWidget* parent
buildTemplateList();
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
instrumentSearch->setFilterableView(instrumentList);

// get last saved, user-selected instrument genre and set filter to it
QSettings settings;
settings.beginGroup("selectInstrument");
if (!settings.value("selectedGenre").isNull()){
QString selectedGenre = settings.value("selectedGenre").value<QString>();
instrumentGenreFilter->setCurrentText(selectedGenre);
}
settings.endGroup();

MuseScore::restoreGeometry(this);
}

Expand Down Expand Up @@ -128,7 +138,13 @@ void SelectInstrument::on_search_textChanged(const QString&)

void SelectInstrument::on_instrumentGenreFilter_currentIndexChanged(int index)
{
QSettings settings;
settings.beginGroup("selectInstrument"); // hard coded, since this is also used in instrwidget
settings.setValue("selectedGenre", instrumentGenreFilter->currentText());
settings.endGroup();

QString id = instrumentGenreFilter->itemData(index).toString();

// Redisplay tree, only showing items from the selected genre
filterInstrumentsByGenre(instrumentList, id);
}
Expand Down

0 comments on commit 59c92f5

Please sign in to comment.