X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fglobalsettings.cpp;h=c77327c3d1b6b18bd1c1255139b0a6b19323a7d9;hp=eabe4d3c185498a5c19fd71ecb7eef8a420b33f1;hb=fe060a4874fc72655cced0596ef610a13f5b0413;hpb=90ee1ed9a90bc0651f86ee4af07e0958572f86da diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index eabe4d3c..c77327c3 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -20,19 +20,19 @@ #include "globalsettings.hpp" #include -#include +#include #include #include -using std::function; using std::map; -using std::multimap; +using std::vector; namespace pv { const QString GlobalSettings::Key_View_ZoomToFitDuringAcq = "View_ZoomToFitDuringAcq"; const QString GlobalSettings::Key_View_ZoomToFitAfterAcq = "View_ZoomToFitAfterAcq"; -const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG"; +const QString GlobalSettings::Key_View_TriggerIsZeroTime = "View_TriggerIsZeroTime"; +const QString GlobalSettings::Key_View_ColoredBG = "View_ColoredBG"; const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling"; const QString GlobalSettings::Key_View_ShowSamplingPoints = "View_ShowSamplingPoints"; const QString GlobalSettings::Key_View_ShowAnalogMinorGrid = "View_ShowAnalogMinorGrid"; @@ -40,8 +40,10 @@ const QString GlobalSettings::Key_View_ConversionThresholdDispMode = "View_Conve const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight"; const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight"; const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable"; +const QString GlobalSettings::Key_Log_BufferSize = "Log_BufferSize"; +const QString GlobalSettings::Key_Log_NotifyOfStacktrace = "Log_NotifyOfStacktrace"; -multimap< QString, function > GlobalSettings::callbacks_; +vector GlobalSettings::callbacks_; bool GlobalSettings::tracking_ = false; map GlobalSettings::tracked_changes_; @@ -57,9 +59,9 @@ void GlobalSettings::set_defaults_where_needed() if (!contains(Key_View_ZoomToFitAfterAcq)) setValue(Key_View_ZoomToFitAfterAcq, true); - // Enable coloured trace backgrounds by default - if (!contains(Key_View_ColouredBG)) - setValue(Key_View_ColouredBG, true); + // Enable colored trace backgrounds by default + if (!contains(Key_View_ColoredBG)) + setValue(Key_View_ColoredBG, true); // Enable showing sampling points by default if (!contains(Key_View_ShowSamplingPoints)) @@ -72,12 +74,28 @@ void GlobalSettings::set_defaults_where_needed() if (!contains(Key_View_DefaultLogicHeight)) setValue(Key_View_DefaultLogicHeight, 2 * QFontMetrics(QApplication::font()).height()); + + // Default to 500 lines of backlog + if (!contains(Key_Log_BufferSize)) + setValue(Key_Log_BufferSize, 500); + + // Notify user of existing stack trace by default + if (!contains(Key_Log_NotifyOfStacktrace)) + setValue(Key_Log_NotifyOfStacktrace, true); +} + +void GlobalSettings::add_change_handler(GlobalSettingsInterface *cb) +{ + callbacks_.push_back(cb); } -void GlobalSettings::register_change_handler(const QString key, - function cb) +void GlobalSettings::remove_change_handler(GlobalSettingsInterface *cb) { - callbacks_.emplace(key, cb); + for (auto cb_it = callbacks_.begin(); cb_it != callbacks_.end(); cb_it++) + if (*cb_it == cb) { + callbacks_.erase(cb_it); + break; + } } void GlobalSettings::setValue(const QString &key, const QVariant &value) @@ -89,11 +107,12 @@ void GlobalSettings::setValue(const QString &key, const QVariant &value) QSettings::setValue(key, value); - // Call all registered callbacks for this key - auto range = callbacks_.equal_range(key); + // TODO Emulate noquote() + qDebug() << "Setting" << key << "changed to" << value; - for (auto it = range.first; it != range.second; it++) - it->second(value); + // Call all registered callbacks + for (GlobalSettingsInterface *cb : callbacks_) + cb->on_setting_changed(key, value); } void GlobalSettings::start_tracking()