Key signature not restored correctly when toggling concert pitch
The new scheme for specifying whether a staff should prefer flats or sharps when transposed is welcome and mostly seems to work well. However, there is a case that is not handled so well, leading to loss of information. This same problem could happen before the new option, but it will happen in new situations now. Here is a new case:
1) new score for Bb clarinet, key of B concert (will display as C#)
2) toggle to concert pitch and back and verify the key is B
3) staff properties, set to prefer flats
4) verify key signature now display as Db, which is good
4) turn off concert pitch
Result: key is now Cb. The "prefer sharps/flats" setting really should only apply to the display when concert pitch is off. When concert pitch is on, it should always reflect the "real" key, but this information is now lost. Once we change the C# to Db, there is no more record that the original concert pitch key was B. And the same thing happens if you try adding key changes after making this setting. A B major (concert) key signature cannot be made to happen on a staff set to prefer flats. You'll get Cb. The prefer flats setting should only apply to the transposed key.
I said it was possible to get a similar bug before. For that, you'd need an Eb instrument. So, Eb alto saxophone, key of B concert again. Here, even without the new prefer sharps/flats setting, MuseScore has no choice but to display the transposed key as Ab. And then there is no getting back to B when you turn concert pitch on.
I'm not sure there is a good fix for this. Once we've displayed the transposed key as Db, we've lost all record of the fact that the concert pitch key is actually supposed to be B. Even if we ignore the prefer sharps/flats setting when reverting to concert pitch, we're going to end up with Cb because that's the literally correct transposition of Db by major second. Similarly for the case of the Eb instrument that is displaying Ab as the transposed key - there's just no way to know this started out as B major in concert pitch.
The real solution is to maintain the equivalent of separate TPC1 and TPC2 for the key, just like we do for notes. And for that matter, we should do this for chord symbols too. But that may or may not be feasible without a file format change. Maybe we can do it in a way where the info might be lost when reading the score in older versions, but at least is maintained for 3.5 and up? Another somewhat hackier solution would be to look for a staff that doesn't transpose and "steal" the concert key signature from it. Doesn't help when writing for saxophone quartet, though.
Workaround is, I guess, toggle the prefer sharps/flats setting as needed. It's clumsy, but all in all, I'll still take the increase in occurrences of bug as a fair price to pay for the new feature, which will be welcome by many I'm sure. Will be good to get feedback from others on that matter, though.
See also #280835: Transposing instruments handle difficult key signatures incorrectly which covers the existing case with respect to Eb instruments, also #18147: When silently changing the key to enharmonic equivalent during transposition, change notes too which is kind of related I guess.