diff --git a/source/dialogs/tuningdialog.cpp b/source/dialogs/tuningdialog.cpp index bbb8a06da..0f960c27f 100644 --- a/source/dialogs/tuningdialog.cpp +++ b/source/dialogs/tuningdialog.cpp @@ -39,19 +39,19 @@ TuningDialog::TuningDialog(QWidget *parent, const Tuning ¤tTuning, connect(ui->sharpsCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleSharps(bool))); connect(ui->sharpsCheckBox, SIGNAL(clicked(bool)), this, - SLOT(invalidatePreset())); + SLOT(updateCurrentPreset())); ui->capoSpinBox->setMinimum(Tuning::MIN_CAPO); ui->capoSpinBox->setMaximum(Tuning::MAX_CAPO); ui->capoSpinBox->setValue(currentTuning.getCapo()); connect(ui->capoSpinBox, SIGNAL(valueChanged(int)), this, - SLOT(invalidatePreset())); + SLOT(updateCurrentPreset())); ui->notationOffsetSpinBox->setMinimum(Tuning::MIN_MUSIC_NOTATION_OFFSET); ui->notationOffsetSpinBox->setMaximum(Tuning::MAX_MUSIC_NOTATION_OFFSET); ui->notationOffsetSpinBox->setValue(currentTuning.getMusicNotationOffset()); connect(ui->notationOffsetSpinBox, SIGNAL(valueChanged(int)), this, - SLOT(invalidatePreset())); + SLOT(updateCurrentPreset())); ui->numStringsSpinBox->setMinimum(Tuning::MIN_STRING_COUNT); ui->numStringsSpinBox->setMaximum(Tuning::MAX_STRING_COUNT); @@ -73,7 +73,7 @@ TuningDialog::TuningDialog(QWidget *parent, const Tuning ¤tTuning, for (QComboBox *selector : myStringSelectors) { connect(selector, SIGNAL(activated(int)), this, - SLOT(invalidatePreset())); + SLOT(updateCurrentPreset())); } updateTuningDictionary(currentTuning.getStringCount()); @@ -83,6 +83,8 @@ TuningDialog::TuningDialog(QWidget *parent, const Tuning ¤tTuning, connect(ui->presetComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(loadPreset())); + + updateCurrentPreset(); } TuningDialog::~TuningDialog() @@ -200,7 +202,22 @@ Tuning TuningDialog::getTuning() const return newTuning; } -void TuningDialog::invalidatePreset() +void TuningDialog::updateCurrentPreset() { + const Tuning currentTuning = getTuning(); + + // Check if the current tuning matches one of the available presets. + for (int i = 0; i < ui->presetComboBox->count(); ++i) + { + auto tuning = ui->presetComboBox->itemData(i).value(); + + if (tuning->isSameTuning(currentTuning)) + { + ui->presetComboBox->setCurrentIndex(i); + return; + } + } + + // Otherwise, the tuning currently doesn't match any presets. ui->presetComboBox->setCurrentIndex(-1); } diff --git a/source/dialogs/tuningdialog.h b/source/dialogs/tuningdialog.h index e5a370914..b476be518 100644 --- a/source/dialogs/tuningdialog.h +++ b/source/dialogs/tuningdialog.h @@ -54,7 +54,7 @@ private slots: void loadPreset(); /// Once a change is made to the tuning, update the preset combobox. - void invalidatePreset(); + void updateCurrentPreset(); private: Ui::TuningDialog *ui; diff --git a/source/score/tuning.cpp b/source/score/tuning.cpp index 0eed36341..194a8c5d6 100644 --- a/source/score/tuning.cpp +++ b/source/score/tuning.cpp @@ -45,11 +45,14 @@ Tuning::Tuning() bool Tuning::operator==(const Tuning &other) const { - return myName == other.myName && - myNotes == other.myNotes && + return myName == other.myName && isSameTuning(other); +} + +bool Tuning::isSameTuning(const Tuning &other) const +{ + return myNotes == other.myNotes && myMusicNotationOffset == other.myMusicNotationOffset && - myUsesSharps == other.myUsesSharps && - myCapo == other.myCapo; + myUsesSharps == other.myUsesSharps && myCapo == other.myCapo; } const std::string &Tuning::getName() const diff --git a/source/score/tuning.h b/source/score/tuning.h index 6d862da8a..e10b4ce17 100644 --- a/source/score/tuning.h +++ b/source/score/tuning.h @@ -30,6 +30,8 @@ class Tuning Tuning(); bool operator==(const Tuning &other) const; + /// This is like operator==, but ignores the name of the tuning. + bool isSameTuning(const Tuning &other) const; template void serialize(Archive &ar, const FileVersion version);