PhonologicalCorpusTools / SLPAA

5 stars 0 forks source link

research and possibly change approach to app settings #284

Closed kvesik closed 5 months ago

kvesik commented 5 months ago

Currently PyQt5.QtCore.QSettings is used to store and load user settings to/from memory, in between runs of the software. Settings are loaded from memory into MainWindow.app_settings when the software is started, and then any uses of or changes to settings while the software is open, are done with reference to that MainWindow.app_settings variable. When the user closes the software, the settings from MainWindow.app_settings are resaved to the QSettings object on disk.

In a small app with fairly simple functions, classes, GUI, etc, this is a fairly reasonable approach, as it is slightly faster than always referring to the QSettings object and it's not too hard to pass the MainWindow.app_settings variable (or constituents) around to various functions as necessary. However, in a larger app with more layers of GUI, backend functions, and their interactions, it's becoming a bit ridiculous trying to pass the MainWindow.app_settings variable around... and is also a bit problematic for cases like #283 where the entryid depends on user settings, but the settings might change during the time that an entryid object exists, and therefore its attributes would need to reflect that change rather than being statically aligned with how the settings looked when the entryid was first created. For this reason in particular of synchronizing entryid's attributes with the current user settings, I am considering revamping things so that there are only ever references to the main QSettings and no passing around of MainWindow.app_settings.

Need to do a bit more reading & thinking first though before making a final decision.

The resource I've found most useful so far: https://www.qtcentre.org/threads/37490-QSettings-how-to-use And to a lesser degree: https://stackoverflow.com/questions/2849513/qt-multiple-copies-of-the-same-app-open-settings-synchronisation

kvesik commented 5 months ago

Using MainWindow.app_settings for GUI purposes is not a problem, since each window/dialog/etc is only open temporarily and does not persist across (potential) changes to settings. However, using MainWindow.app_settings for underlying data structures (eg EntryID) could potentially be problematic, if the user changes the desired structure for EntryIDs once some have already been created in a particular session of the software or instance of the corpus. So QSettings should be directly available for at least data types.

kvesik commented 5 months ago

rolled into #283