Skip to content

Commit

Permalink
Move getting/setting user preferences to a dedicated class, `UserPref…
Browse files Browse the repository at this point in the history
…erences`.

This separation improves the separation of concerns a bit.
In addition to cleaning up the interface and fixing the callback issues that were still present, it cuts the initial initialization of user preferences down from ~60 ms, to about 1 millisecond; and for users with options already in the database it slightly increases things.

I think this was the last issue that needs to be fixed for the final 1.0.13 release.
  • Loading branch information
wcjohns committed Oct 22, 2024
1 parent cabb8f7 commit f85b713
Show file tree
Hide file tree
Showing 55 changed files with 1,548 additions and 1,213 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ set(sources
src/EnterAppUrlWindow.cpp
src/NuclideSourceEnter.cpp
src/AddNewPeakDialog.cpp
src/UserPreferences.cpp
js/SpectrumChart.js
js/InterSpec.js
)
Expand Down Expand Up @@ -432,6 +433,7 @@ set(headers
InterSpec/EnterAppUrlWindow.h
InterSpec/NuclideSourceEnter.h
InterSpec/AddNewPeakDialog.h
InterSpec/UserPreferences.h
)


Expand Down
22 changes: 15 additions & 7 deletions InterSpec/InterSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DrfSelectWindow;
class PeakInfoDisplay;
class SpecMeasManager;
class UndoRedoManager;
class UserPreferences;
class GammaCountDialog;
class PopupDivMenuItem;
class SpectraFileHeader;
Expand Down Expand Up @@ -902,10 +903,17 @@ class InterSpec : public Wt::WContainerWidget
/** Brings up a dialog asking the user to confirm starting a new session, and if they select so, will start new session. */
void startClearSession();

// The user itself gets to be public--no need to protect access to it.
//Note 20130116: m_user should be made protected, but really the whole
// preference thing should be re-done, see README
Wt::Dbo::ptr<InterSpecUser> m_user;
/** Pointer to class to access user preferences. */
UserPreferences *preferences();

/** The user information in the database. */
const Wt::Dbo::ptr<InterSpecUser> &user();

/** Calls the `reread()` function on `m_user`, which refreshes the information pointed to by
`m_user` to match what is currently in the database. Please note, this may (and maybe always)
cause the `m_user` pointer to point to a different location in memory.
*/
void reReadUserInfoFromDb();

//sql returns the DbSession (which holds the Wt::Dbo::Session) associated
// with m_user. The reason for using an indirection via
Expand Down Expand Up @@ -1303,6 +1311,9 @@ class InterSpec : public Wt::WContainerWidget
void changeLocale( std::string languageCode );

protected:
Wt::Dbo::ptr<InterSpecUser> m_user;
UserPreferences *m_preferences;

PeakModel *m_peakModel;
D3SpectrumDisplayDiv *m_spectrum;
D3TimeChart *m_timeSeries;
Expand All @@ -1315,9 +1326,6 @@ class InterSpec : public Wt::WContainerWidget

void handleUserIncrementSampleNum( SpecUtils::SpectrumType type, bool increment);


/* Start widgets this class keeps track of */

Wt::Signal< Wt::WString, int > m_messageLogged;

WarningWidget *m_warnings;
Expand Down
Loading

0 comments on commit f85b713

Please sign in to comment.